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 ofSSL_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. CallSSL_get_error()with the return valueretto 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. CallSSL_get_error()with the return valueretto find out the reason. Red flag π© energy, go read the error.
π SEE ALSO π
go read those too, iykyk π
π 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>.
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
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms