SSL_DO_HANDSHAKE(3ossl)
π SSL_DO_HANDSHAKE π
okay so bestie, we're in the OpenSSL manual β this is the SSL_DO_HANDSHAKE(3ossl) page, and it's literally the one that tells you how to do a TLS/SSL handshake. yes. the whole β¨connection-establishingβ¨ moment. let's go π
πΈ NAME πΈ
SSL_do_handshake β perform a TLS/SSL handshake π«Ά
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
int SSL_do_handshake(SSL *ssl);
that's it. one function, one SSL *ssl, iconic behavior only π
π¦ DESCRIPTION π¦
so SSL_do_handshake() will wait for an SSL/TLS handshake to take place. that's the vibe. it's giving "hold on, we're negotiating" π
if the connection is in client mode, the handshake will be started. main character energy fr fr π
lowkey important though: the handshake routines may have to be explicitly set in advance using either SSL_set_connect_state(3) or SSL_set_accept_state(3). don't skip that step bestie, i'm begging π₯Ί
π NOTES π
the behavior of SSL_do_handshake() depends on the underlying BIO. yep. it's a whole thing. let me break it down:
- blocking BIO β
SSL_do_handshake()will only return once the handshake has been finished or an error occurred. that's it, it just sits there until something happens. patient queen π§ββοΈ - nonblocking BIO β
SSL_do_handshake()will also return when the underlying BIO could not satisfy the needs ofSSL_do_handshake()to continue the handshake. so it bails early, no drama. in this case a call toSSL_get_error()with the return value ofSSL_do_handshake()will yieldSSL_ERROR_WANT_READorSSL_ERROR_WANT_WRITE. πβ¨
then the calling process must repeat the call after taking appropriate action to satisfy the needs of SSL_do_handshake(). the action depends on the underlying BIO:
- when using a nonblocking socket, nothing is to be done, but
select()can be used to check for the required condition. literally nothing to do, just vibe check it withselect()π - when using a buffering BIO, like a BIO pair, data must be written into or retrieved out of the BIO before being able to continue. so you gotta feed it or empty it first, iykyk π
π₯ RETURN VALUES π₯
the following return values can occur β pay attention bestie, these matter so much:
0β the TLS/SSL handshake was not successful but was shut down controlled and by the specifications of the TLS/SSL protocol. callSSL_get_error()with the return valueretto find out the reason. not a crash, just a polite shutdown π1β the TLS/SSL handshake was successfully completed, a TLS/SSL connection has been established. slay!! that's the good ending ππ<0β the TLS/SSL handshake was not successful because a fatal error occurred either at the protocol level or a connection failure occurred. the shutdown was not clean. π it can also occur if action is needed to continue the operation for nonblocking BIOs. callSSL_get_error()with the return valueretto find out the reason. yes,<0does double duty, no cap π
ok real talk: whenever you get0or<0, runSSL_get_error()withret. that's the move. always. π«Ά
π SEE ALSO π
SSL_get_error(3), SSL_connect(3), SSL_accept(3), ssl(7), bio(7), SSL_set_connect_state(3)
go read those too, they're all part of the friend group bestie π
π COPYRIGHT π
Copyright 2002-2020 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>.
and that's the whole page!! this was OpenSSL 3.5.0, dated 2026-09-25, manual SSL_DO_HANDSHAKE(3ossl) β mwah, go forth and handshake responsibly π
β¨π¦
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms