SSL_CONNECT(3ossl)
okay so bestie, this is SSL_CONNECT(3ossl) β the OpenSSL page about kicking off a TLS/SSL handshake with a server. itβs giving β¨ secure-channel main character energy β¨ and weβre gonna read it together, fr fr.
π NAME π
SSL_connect β initiate the TLS/SSL handshake with an TLS/SSL server π
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
int SSL_connect(SSL *ssl);
πΈ DESCRIPTION πΈ
okay so SSL_connect() initiates the TLS/SSL handshake with a server. but bestie, the communication channel must already have been set and assigned to the ssl by setting an underlying BIO. and ssl MUST NOT be NULL β like, not me passing NULL, thatβs a whole red flag π©.
π¦ NOTES π¦
the behaviour of SSL_connect() depends on the underlying BIO. periodt.
- if the underlying
BIOis blocking,SSL_connect()will only return once the handshake has been finished or an error occurred. itβs gonna sit there and wait, no cap. - if the underlying
BIOis nonblocking,SSL_connect()will also return when the underlyingBIOcould not satisfy the needs ofSSL_connect()to continue the handshake, indicating the problem by the return value-1. in this case a call toSSL_get_error()with the return value ofSSL_connect()will yieldSSL_ERROR_WANT_READorSSL_ERROR_WANT_WRITE. the calling process then must repeat the call after taking appropriate action to satisfy the needs ofSSL_connect(). the action depends on the underlyingBIO. when using a nonblocking socket, nothing is to be done, butselect()can be used to check for the required condition. when using a bufferingBIO, like aBIOpair, data must be written into or retrieved out of theBIObefore being able to continue. iykyk π
many systems implement Nagleβs algorithm by default which means that it will buffer outgoing TCP data if a TCP packet has already been sent for which no corresponding ACK has been received yet from the peer. this can have performance impacts after a successful TLSv1.3 handshake or a successful TLSv1.2 (or below) resumption handshake, because the last peer to communicate in the handshake is the client. if the client is also the first to send application data (as is typical for many protocols) then this data could be buffered until an ACK has been received for the final handshake message. π the latency of it all, lowkey jumpscare.
the TCP_NODELAY socket option is often available to disable Nagleβs algorithm. if an application opts to disable Nagleβs algorithm consideration should be given to turning it back on again later if appropriate. the helper function BIO_set_tcp_ndelay() can be used to turn on or off the TCP_NODELAY option. π«Ά
π 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. 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, thatβs the dream π<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. π
π SEE ALSO π
SSL_get_error(3)SSL_accept(3)SSL_shutdown(3)ssl(7)bio(7)SSL_set_connect_state(3)SSL_do_handshake(3)SSL_CTX_new(3)
π COPYRIGHT π
Copyright 2000-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 bestie π β this was 3.5.0, dated 2026-09-25, and the manual name is SSL_CONNECT(3ossl). mwah, go establish some connections (responsibly). β¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms