SSL_DO_HANDSHAKE(3SSL)

πŸ’… SSL_do_handshake β€” it's giving "let's do the handshake, bestie"

okay so this is a page from the 3SSL manual collection (SSL_DO_HANDSHAKE(3SSL), if you're keeping receipts) and it's literally about making a TLS/SSL handshake actually happen. Obsessed. Let's get into it. πŸ¦‹


✨ NAME ✨

SSL_do_handshake β€” perform a TLS/SSL handshake, no cap 🫱🀝🫲


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

int SSL_do_handshake(SSL *ssl);

πŸ’– DESCRIPTION πŸ’–

SSL_do_handshake() will wait for an SSL/TLS handshake to take place. That's it, that's the vibe. πŸŽ€

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). Don't skip that step, bestie, or you'll be standing there like πŸ§β€β™€οΈ waiting for a handshake that never comes.


πŸ“ NOTES πŸ“

The behaviour of SSL_do_handshake() depends on the underlying BIO. Yes, the BIO. Everything comes back to the BIO. It's giving main character energy but for file descriptors. ✨

  • If the underlying BIO is blocking, SSL_do_handshake() will only return once the handshake has been finished or an error occurred. You sit there until it's done. 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. So it's not failing, it's just... not ready yet. πŸ™ˆ

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. The calling process then must repeat the call after taking appropriate action to satisfy the needs of SSL_do_handshake(). Like, you have to come back, okay? 😀

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. Easy. Iconic.
  • 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 drain it first, bestie, otherwise it just sits there 🌸

πŸ”₯ RETURN VALUES πŸ”₯

Here's the vibe check on what you can get back:

  • 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. So like, it's over but it was a clean breakup πŸ₯²
  • 1 β€” The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been established. SLAY. We love to see it. πŸ‘‘
  • <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. Red flag 🚩 energy, go read the error.

πŸ‘€ SEE ALSO πŸ‘€

go read those too, iykyk πŸ’œ


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


okay that's the whole page, you ate πŸ’…βœ¨ this was SSL_DO_HANDSHAKE(3SSL) from OpenSSL 4.0.3, dated 2026-09-29 β€” mwah, bye bestie! πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from