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