SSL_CLEAR(3SSL)
β¨ SSL_CLEAR β¨
okay bestie, welcome to SSL_clear β the "reset this whole SSL object so it can go do another connection" girlie π
she lives in the OpenSSL fam and she's genuinely so useful, no cap.
πΈ NAME πΈ
SSL_clear β reset that SSL object so it can allow another connection π¦
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
int SSL_clear(SSL *ssl);
π DESCRIPTION π
So like, what she does is reset ssl so it can allow another connection. And the important part? All settings (method, ciphers, BIOs) are kept. Like she's not wiping your whole vibe, she's just getting it ready for round two β¨
π NOTES π
SSL_clear is used to prepare an SSL object for a new connection. And while all the settings are kept, there's a little side effect hiding in there β the way it handles the current SSL session π
So here's the tea: if a session is still open, it's considered bad and it will be removed from the session cache, as required by RFC2246. And a session counts as "open" if SSL_shutdown(3) was not called for the connection, or if at least SSL_set_shutdown(3) was used to set the SSL_SENT_SHUTDOWN state π«Ά
Now if a session was closed cleanly? Then the session object will be kept, along with all the settings corresponding to it. And this explicitly means that, like, e.g. the special method used during the session will be kept for the next handshake π₯
So if the session was a TLSv1 session, an SSL client object will use a TLSv1 client method for the next handshake, and an SSL server object will use a TLSv1 server method β even if TLS_*_methods were chosen on startup. And yes, this will might lead to connection failures π (go check SSL_new(3) for a description of the method's properties, iykyk).
Also β very important bestie β this function is not supported on QUIC SSL objects and returns failure if you call it on such an object. periodt.
β οΈ WARNINGS β οΈ
SSL_clear() resets the SSL object to allow for another connection. But the reset operation however keeps several settings of the last sessions (and some of these settings were made automatically during the last handshake, sneaky π). It only makes sense for a new connection with the exact same peer that shares these settings, and it may fail if that peer changes its settings between connections.
So instead, use this sequence to avoid such failures:
SSL_get_session(3); SSL_new(3); SSL_set_session(3); SSL_free(3);
...or simply SSL_free(3); SSL_new(3) if session reuse is not desired π§
π RETURN VALUES π
Here's what she can hand back to you:
0β TheSSL_clear()operation could not be performed. Check the error stack to find out the reason π1β TheSSL_clear()operation was successful π
Also go read these, they're the whole friend group: SSL_new(3), SSL_free(3), SSL_shutdown(3), SSL_set_shutdown(3), SSL_CTX_set_options(3), ssl(7), SSL_CTX_set_client_cert_cb(3) π
π COPYRIGHT π
Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
k that's the whole page bestie, slay π
this was OpenSSL 4.0.3, dated 2026-09-29, and you've been reading SSL_CLEAR(3SSL) β mwah, go clear some SSL objects responsibly πβ¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms