xref: /freebsd/crypto/openssl/doc/man3/SSL_connect.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimSSL_connect - initiate the TLS/SSL handshake with an TLS/SSL server
6e71b7053SJung-uk Kim
7e71b7053SJung-uk Kim=head1 SYNOPSIS
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim #include <openssl/ssl.h>
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim int SSL_connect(SSL *ssl);
12e71b7053SJung-uk Kim
13e71b7053SJung-uk Kim=head1 DESCRIPTION
14e71b7053SJung-uk Kim
15e71b7053SJung-uk KimSSL_connect() initiates the TLS/SSL handshake with a server. The communication
16e71b7053SJung-uk Kimchannel must already have been set and assigned to the B<ssl> by setting an
17e71b7053SJung-uk Kimunderlying B<BIO>.
18e71b7053SJung-uk Kim
19e71b7053SJung-uk Kim=head1 NOTES
20e71b7053SJung-uk Kim
21e71b7053SJung-uk KimThe behaviour of SSL_connect() depends on the underlying BIO.
22e71b7053SJung-uk Kim
23e71b7053SJung-uk KimIf the underlying BIO is B<blocking>, SSL_connect() will only return once the
24e71b7053SJung-uk Kimhandshake has been finished or an error occurred.
25e71b7053SJung-uk Kim
2658f35182SJung-uk KimIf the underlying BIO is B<nonblocking>, SSL_connect() will also return
27e71b7053SJung-uk Kimwhen the underlying BIO could not satisfy the needs of SSL_connect()
28e71b7053SJung-uk Kimto continue the handshake, indicating the problem by the return value -1.
29e71b7053SJung-uk KimIn this case a call to SSL_get_error() with the
30e71b7053SJung-uk Kimreturn value of SSL_connect() will yield B<SSL_ERROR_WANT_READ> or
31e71b7053SJung-uk KimB<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
32e71b7053SJung-uk Kimtaking appropriate action to satisfy the needs of SSL_connect().
3358f35182SJung-uk KimThe action depends on the underlying BIO. When using a nonblocking socket,
34e71b7053SJung-uk Kimnothing is to be done, but select() can be used to check for the required
35e71b7053SJung-uk Kimcondition. When using a buffering BIO, like a BIO pair, data must be written
36e71b7053SJung-uk Kiminto or retrieved out of the BIO before being able to continue.
37e71b7053SJung-uk Kim
38e71b7053SJung-uk KimMany systems implement Nagle's algorithm by default which means that it will
39e71b7053SJung-uk Kimbuffer outgoing TCP data if a TCP packet has already been sent for which no
40e71b7053SJung-uk Kimcorresponding ACK has been received yet from the peer. This can have performance
41e71b7053SJung-uk Kimimpacts after a successful TLSv1.3 handshake or a successful TLSv1.2 (or below)
42e71b7053SJung-uk Kimresumption handshake, because the last peer to communicate in the handshake is
43e71b7053SJung-uk Kimthe client. If the client is also the first to send application data (as is
44e71b7053SJung-uk Kimtypical for many protocols) then this data could be buffered until an ACK has
45e71b7053SJung-uk Kimbeen received for the final handshake message.
46e71b7053SJung-uk Kim
47e71b7053SJung-uk KimThe B<TCP_NODELAY> socket option is often available to disable Nagle's
48e71b7053SJung-uk Kimalgorithm. If an application opts to disable Nagle's algorithm consideration
49e71b7053SJung-uk Kimshould be given to turning it back on again later if appropriate. The helper
50e71b7053SJung-uk Kimfunction BIO_set_tcp_ndelay() can be used to turn on or off the B<TCP_NODELAY>
51e71b7053SJung-uk Kimoption.
52e71b7053SJung-uk Kim
53e71b7053SJung-uk Kim=head1 RETURN VALUES
54e71b7053SJung-uk Kim
55e71b7053SJung-uk KimThe following return values can occur:
56e71b7053SJung-uk Kim
57e71b7053SJung-uk Kim=over 4
58e71b7053SJung-uk Kim
59e71b7053SJung-uk Kim=item Z<>0
60e71b7053SJung-uk Kim
61e71b7053SJung-uk KimThe TLS/SSL handshake was not successful but was shut down controlled and
62e71b7053SJung-uk Kimby the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
63e71b7053SJung-uk Kimreturn value B<ret> to find out the reason.
64e71b7053SJung-uk Kim
65e71b7053SJung-uk Kim=item Z<>1
66e71b7053SJung-uk Kim
67e71b7053SJung-uk KimThe TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
68e71b7053SJung-uk Kimestablished.
69e71b7053SJung-uk Kim
70e71b7053SJung-uk Kim=item E<lt>0
71e71b7053SJung-uk Kim
72e71b7053SJung-uk KimThe TLS/SSL handshake was not successful, because a fatal error occurred either
73e71b7053SJung-uk Kimat the protocol level or a connection failure occurred. The shutdown was
7417f01e99SJung-uk Kimnot clean. It can also occur if action is needed to continue the operation
7558f35182SJung-uk Kimfor nonblocking BIOs. Call SSL_get_error() with the return value B<ret>
76e71b7053SJung-uk Kimto find out the reason.
77e71b7053SJung-uk Kim
78e71b7053SJung-uk Kim=back
79e71b7053SJung-uk Kim
80e71b7053SJung-uk Kim=head1 SEE ALSO
81e71b7053SJung-uk Kim
82e71b7053SJung-uk KimL<SSL_get_error(3)>, L<SSL_accept(3)>,
83e71b7053SJung-uk KimL<SSL_shutdown(3)>, L<ssl(7)>, L<bio(7)>,
84e71b7053SJung-uk KimL<SSL_set_connect_state(3)>,
85e71b7053SJung-uk KimL<SSL_do_handshake(3)>,
86e71b7053SJung-uk KimL<SSL_CTX_new(3)>
87e71b7053SJung-uk Kim
88e71b7053SJung-uk Kim=head1 COPYRIGHT
89e71b7053SJung-uk Kim
9017f01e99SJung-uk KimCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
91e71b7053SJung-uk Kim
92*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
93e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
94e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
95e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
96e71b7053SJung-uk Kim
97e71b7053SJung-uk Kim=cut
98