SSL_DO_HANDSHAKE(3ossl)
πΈ NAME πΈ
SSL_do_handshake β bestie, this is the function that actually does the TLS/SSL handshake β¨ (and yes, this is the 3ossl manpage, hi, welcome, come in π«Ά)
π¦ SYNOPSIS π¦
#include <openssl/ssl.h>
int SSL_do_handshake(SSL *ssl);
π DESCRIPTION π
Okay so SSL_do_handshake() literally just waits for an SSL/TLS handshake to take place. That's it. That's the whole vibe check. π§
If your connection is in client mode, this call is what kicks the handshake off β it starts the whole thing. Lowkey important detail though: the handshake routines might have to be explicitly set in advance first, using either SSL_set_connect_state(3) or SSL_set_accept_state(3). Set them up before you come in here or it's giving unprepared energy π
β¨ NOTES β¨
Not me needing to tell you that the behaviour of SSL_do_handshake() depends on the underlying BIO π Like, that's the whole plot twist.
π blocking BIO
If the underlying BIO is blocking, SSL_do_handshake() will only return once the handshake has been finished or an error occurred. One and done. It commits. Main character energy π
π nonblocking BIO
If the underlying BIO is nonblocking, SSL_do_handshake() will also return when the underlying BIO could not satisfy the needs of SSL_do_handshake() to continue the handshake. Iconic flaky behaviour, honestly.
In that case, a call to SSL_get_error() with the return value of SSL_do_handshake() will yield SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. Then the calling process must repeat the call after taking appropriate action to satisfy the needs of SSL_do_handshake(). No skipping this step, bestie π«Ά
And 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. - When using a buffering
BIO, like aBIOpair, data must be written into or retrieved out of theBIObefore being able to continue.
π₯ RETURN VALUES π₯
Here's the rundown of what you can get back β memorize these fr fr:
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. π1β The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been established. Slay!! ππ<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.
β οΈ Note the difference, bestie:0= clean-ish controlled shutdown per the protocol specs,<0= fatal error / unclean shutdown (or just "needs more action" on a nonblocking BIO). Don't mix them up π
π SEE ALSO π
π 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>.
k bye ily, go handshake something π
β¨ β this was version 3.5.6, dated 2026-04-07, from your favorite SSL_DO_HANDSHAKE(3ossl) era ππ¦
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms