SSL_DO_HANDSHAKE(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

🌸 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 a BIO pair, data must be written into or retrieved out of the BIO before 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. Call SSL_get_error() with the return value ret to 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. Call SSL_get_error() with the return value ret to 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 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