SSL_DO_HANDSHAKE(3ossl)

πŸ’– NAME πŸ’–

ok so SSL_do_handshake β€” it performs a TLS/SSL handshake. that's it, that's the whole job. this is the 3ossl page bestie, and she's about to explain the handshake ritual to you.


✨ SYNOPSIS ✨

#include <openssl/ssl.h>

int SSL_do_handshake(SSL *ssl);

like, one function, one arg, no drama. slay.


🌸 DESCRIPTION 🌸

SSL_do_handshake() will wait for an SSL/TLS handshake to take place. if the connection is in client mode, the handshake will be started. lowkey important: the handshake routines may have to be explicitly set in advance using either SSL_set_connect_state(3) or SSL_set_accept_state(3). so do that first, or she's just gonna stand there like 🧍


πŸ¦‹ NOTES πŸ¦‹

the behaviour of SSL_do_handshake() depends on the underlying BIO. it's giving "your mileage may vary based on the vibes of the BIO underneath." two whole situations:

  • if the underlying BIO is blocking, SSL_do_handshake() will only return once the handshake has been finished or an error occurred. she commits. no half-sending. periodt.
  • 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. in this 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. 😭

so what do you do then? the calling process then 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.
  • 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 basically: loop, check, retry. the handshake is not ghosting you, she's just buffering. πŸ™ˆ


πŸ‘‘ RETURN VALUES πŸ‘‘

the following return values can occur:

  • 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. like, it's over but it ended politely, okay?
  • 1 β€” the TLS/SSL handshake was successfully completed, a TLS/SSL connection has been established. ATE. ICONIC. NO CAP. πŸ”₯ that's the one you want.
  • <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. do not ignore this one bestie, this is the main character of bad news.
fr fr: whatever the return value is, SSL_get_error() is the one holding the receipts. go ask her.

🌈 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>.


ok that's the whole page, you're all caught up πŸ’… this was SSL_DO_HANDSHAKE(3ossl), living in OpenSSL 3.5.9, dated 2026-09-29. go forth and handshake, bestie 🫢✨

πŸ“¦ where this page comes from