SSL_CONNECT(3SSL)
π SSL_CONNECT π (that's SSL_CONNECT(3SSL) bestie, from the OpenSSL manual, section 3SSL)
okay so picture this: you've got a client. The client wants to talk to a TLS/SSL server. Somebody has to actually start the lil handshake conversation, right? That somebody is this function. She's the opener. The main character who walks up and says hi first. π«Ά
β¨ NAME β¨
SSL_connect β bestie, she initiates the TLS/SSL handshake with an TLS/SSL server. That's it. That's the job. π
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
int SSL_connect(SSL *ssl);
β¨ DESCRIPTION β¨
So SSL_connect() kicks off the TLS/SSL handshake with a server. The whole conversation starter energy. πΈ
But listen β the communication channel must already have been set and assigned to the ssl by setting an underlying BIO. You can't just roll up with a bare ssl and expect the handshake to go anywhere. Set up your BIO first, queen. π₯
And ssl MUST NOT be NULL. Like. Not negotiable. That's not a vibe, that's a crash waiting to happen. π
β¨ NOTES β¨
The way that SSL_connect() behaves depends entirely on the underlying BIO. Like, fully. Depending on who your BIO is, you get a whole different experience. β
- If the underlying BIO is blocking,
SSL_connect()will only return once the handshake has been finished or an error occurred. One and done. She waits. She commits. π - If the underlying BIO is nonblocking,
SSL_connect()will also return when the underlying BIO could not satisfy the needs ofSSL_connect()to continue the handshake β and it tells you there's a problem by returning-1. In that case, callingSSL_get_error()with the return value ofSSL_connect()will give youSSL_ERROR_WANT_READorSSL_ERROR_WANT_WRITE. Then the calling process must repeat the call after taking the appropriate action to satisfy the needs ofSSL_connect().
And what's the "appropriate action"? Depends on the underlying BIO, bestie:
- 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
BIOpair, data must be written into or retrieved out of the BIO before being able to continue.
Now. The Nagle's algorithm tea. β
Many systems implement Nagle's algorithm by default, which means 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. And if the client is also the first to send application data (which is, like, super typical for many protocols π« ), then this data could be buffered until an ACK has been received for the final handshake message. Stalling. Not the vibe.
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. And 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, and each one is giving a very different mood:
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. π ate, no crumbs, periodt.<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. π
ngl bestie, if you get0or<0you gotta callSSL_get_error()β the raw return value alone will not tell you why. iykyk. π
β¨ 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>.
and that's the whole page, bestie!! π this one's from OpenSSL 4.0.3, dated 2026-09-29, and it lives in the 3SSL section of the manual. go forth and handshake responsibly. slay. πβ¨
π¦ 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