xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/SSL_connect.pod (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
513d40330SchristosSSL_connect - initiate the TLS/SSL handshake with an TLS/SSL server
613d40330Schristos
713d40330Schristos=head1 SYNOPSIS
813d40330Schristos
913d40330Schristos #include <openssl/ssl.h>
1013d40330Schristos
1113d40330Schristos int SSL_connect(SSL *ssl);
1213d40330Schristos
1313d40330Schristos=head1 DESCRIPTION
1413d40330Schristos
1513d40330SchristosSSL_connect() initiates the TLS/SSL handshake with a server. The communication
1613d40330Schristoschannel must already have been set and assigned to the B<ssl> by setting an
1713d40330Schristosunderlying B<BIO>.
1813d40330Schristos
1913d40330Schristos=head1 NOTES
2013d40330Schristos
2113d40330SchristosThe behaviour of SSL_connect() depends on the underlying BIO.
2213d40330Schristos
2313d40330SchristosIf the underlying BIO is B<blocking>, SSL_connect() will only return once the
2413d40330Schristoshandshake has been finished or an error occurred.
2513d40330Schristos
26f30e0929SchristosIf the underlying BIO is B<nonblocking>, SSL_connect() will also return
2713d40330Schristoswhen the underlying BIO could not satisfy the needs of SSL_connect()
2813d40330Schristosto continue the handshake, indicating the problem by the return value -1.
2913d40330SchristosIn this case a call to SSL_get_error() with the
3013d40330Schristosreturn value of SSL_connect() will yield B<SSL_ERROR_WANT_READ> or
3113d40330SchristosB<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
3213d40330Schristostaking appropriate action to satisfy the needs of SSL_connect().
33f30e0929SchristosThe action depends on the underlying BIO. When using a nonblocking socket,
3413d40330Schristosnothing is to be done, but select() can be used to check for the required
3513d40330Schristoscondition. When using a buffering BIO, like a BIO pair, data must be written
3613d40330Schristosinto or retrieved out of the BIO before being able to continue.
3713d40330Schristos
3813d40330SchristosMany systems implement Nagle's algorithm by default which means that it will
3913d40330Schristosbuffer outgoing TCP data if a TCP packet has already been sent for which no
4013d40330Schristoscorresponding ACK has been received yet from the peer. This can have performance
4113d40330Schristosimpacts after a successful TLSv1.3 handshake or a successful TLSv1.2 (or below)
4213d40330Schristosresumption handshake, because the last peer to communicate in the handshake is
4313d40330Schristosthe client. If the client is also the first to send application data (as is
4413d40330Schristostypical for many protocols) then this data could be buffered until an ACK has
4513d40330Schristosbeen received for the final handshake message.
4613d40330Schristos
4713d40330SchristosThe B<TCP_NODELAY> socket option is often available to disable Nagle's
4813d40330Schristosalgorithm. If an application opts to disable Nagle's algorithm consideration
4913d40330Schristosshould be given to turning it back on again later if appropriate. The helper
5013d40330Schristosfunction BIO_set_tcp_ndelay() can be used to turn on or off the B<TCP_NODELAY>
5113d40330Schristosoption.
5213d40330Schristos
5313d40330Schristos=head1 RETURN VALUES
5413d40330Schristos
5513d40330SchristosThe following return values can occur:
5613d40330Schristos
5713d40330Schristos=over 4
5813d40330Schristos
5913d40330Schristos=item Z<>0
6013d40330Schristos
6113d40330SchristosThe TLS/SSL handshake was not successful but was shut down controlled and
6213d40330Schristosby the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
6313d40330Schristosreturn value B<ret> to find out the reason.
6413d40330Schristos
6513d40330Schristos=item Z<>1
6613d40330Schristos
6713d40330SchristosThe TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
6813d40330Schristosestablished.
6913d40330Schristos
7013d40330Schristos=item E<lt>0
7113d40330Schristos
7213d40330SchristosThe TLS/SSL handshake was not successful, because a fatal error occurred either
7313d40330Schristosat the protocol level or a connection failure occurred. The shutdown was
747d004720Schristosnot clean. It can also occur if action is needed to continue the operation
75f30e0929Schristosfor nonblocking BIOs. Call SSL_get_error() with the return value B<ret>
7613d40330Schristosto find out the reason.
7713d40330Schristos
7813d40330Schristos=back
7913d40330Schristos
8013d40330Schristos=head1 SEE ALSO
8113d40330Schristos
8213d40330SchristosL<SSL_get_error(3)>, L<SSL_accept(3)>,
8313d40330SchristosL<SSL_shutdown(3)>, L<ssl(7)>, L<bio(7)>,
8413d40330SchristosL<SSL_set_connect_state(3)>,
8513d40330SchristosL<SSL_do_handshake(3)>,
8613d40330SchristosL<SSL_CTX_new(3)>
8713d40330Schristos
8813d40330Schristos=head1 COPYRIGHT
8913d40330Schristos
907d004720SchristosCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
9113d40330Schristos
92*b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
9313d40330Schristosthis file except in compliance with the License.  You can obtain a copy
9413d40330Schristosin the file LICENSE in the source distribution or at
9513d40330SchristosL<https://www.openssl.org/source/license.html>.
9613d40330Schristos
9713d40330Schristos=cut
98