1*4724848cSchristos=pod 2*4724848cSchristos 3*4724848cSchristos=head1 NAME 4*4724848cSchristos 5*4724848cSchristosSSL_set1_host, SSL_add1_host, SSL_set_hostflags, SSL_get0_peername - 6*4724848cSchristosSSL server verification parameters 7*4724848cSchristos 8*4724848cSchristos=head1 SYNOPSIS 9*4724848cSchristos 10*4724848cSchristos #include <openssl/ssl.h> 11*4724848cSchristos 12*4724848cSchristos int SSL_set1_host(SSL *s, const char *hostname); 13*4724848cSchristos int SSL_add1_host(SSL *s, const char *hostname); 14*4724848cSchristos void SSL_set_hostflags(SSL *s, unsigned int flags); 15*4724848cSchristos const char *SSL_get0_peername(SSL *s); 16*4724848cSchristos 17*4724848cSchristos=head1 DESCRIPTION 18*4724848cSchristos 19*4724848cSchristosThese functions configure server hostname checks in the SSL client. 20*4724848cSchristos 21*4724848cSchristosSSL_set1_host() sets the expected DNS hostname to B<name> clearing 22*4724848cSchristosany previously specified hostname or names. If B<name> is NULL, 23*4724848cSchristosor the empty string the list of hostnames is cleared, and name 24*4724848cSchristoschecks are not performed on the peer certificate. When a nonempty 25*4724848cSchristosB<name> is specified, certificate verification automatically checks 26*4724848cSchristosthe peer hostname via L<X509_check_host(3)> with B<flags> as specified 27*4724848cSchristosvia SSL_set_hostflags(). Clients that enable DANE TLSA authentication 28*4724848cSchristosvia L<SSL_dane_enable(3)> should leave it to that function to set 29*4724848cSchristosthe primary reference identifier of the peer, and should not call 30*4724848cSchristosSSL_set1_host(). 31*4724848cSchristos 32*4724848cSchristosSSL_add1_host() adds B<name> as an additional reference identifier 33*4724848cSchristosthat can match the peer's certificate. Any previous names set via 34*4724848cSchristosSSL_set1_host() or SSL_add1_host() are retained, no change is made 35*4724848cSchristosif B<name> is NULL or empty. When multiple names are configured, 36*4724848cSchristosthe peer is considered verified when any name matches. This function 37*4724848cSchristosis required for DANE TLSA in the presence of service name indirection 38*4724848cSchristosvia CNAME, MX or SRV records as specified in RFC7671, RFC7672 or 39*4724848cSchristosRFC7673. 40*4724848cSchristos 41*4724848cSchristosSSL_set_hostflags() sets the B<flags> that will be passed to 42*4724848cSchristosL<X509_check_host(3)> when name checks are applicable, by default 43*4724848cSchristosthe B<flags> value is 0. See L<X509_check_host(3)> for the list 44*4724848cSchristosof available flags and their meaning. 45*4724848cSchristos 46*4724848cSchristosSSL_get0_peername() returns the DNS hostname or subject CommonName 47*4724848cSchristosfrom the peer certificate that matched one of the reference 48*4724848cSchristosidentifiers. When wildcard matching is not disabled, the name 49*4724848cSchristosmatched in the peer certificate may be a wildcard name. When one 50*4724848cSchristosof the reference identifiers configured via SSL_set1_host() or 51*4724848cSchristosSSL_add1_host() starts with ".", which indicates a parent domain prefix 52*4724848cSchristosrather than a fixed name, the matched peer name may be a sub-domain 53*4724848cSchristosof the reference identifier. The returned string is allocated by 54*4724848cSchristosthe library and is no longer valid once the associated B<ssl> handle 55*4724848cSchristosis cleared or freed, or a renegotiation takes place. Applications 56*4724848cSchristosmust not free the return value. 57*4724848cSchristos 58*4724848cSchristosSSL clients are advised to use these functions in preference to 59*4724848cSchristosexplicitly calling L<X509_check_host(3)>. Hostname checks may be out 60*4724848cSchristosof scope with the RFC7671 DANE-EE(3) certificate usage, and the 61*4724848cSchristosinternal check will be suppressed as appropriate when DANE is 62*4724848cSchristosenabled. 63*4724848cSchristos 64*4724848cSchristos=head1 RETURN VALUES 65*4724848cSchristos 66*4724848cSchristosSSL_set1_host() and SSL_add1_host() return 1 for success and 0 for 67*4724848cSchristosfailure. 68*4724848cSchristos 69*4724848cSchristosSSL_get0_peername() returns NULL if peername verification is not 70*4724848cSchristosapplicable (as with RFC7671 DANE-EE(3)), or no trusted peername was 71*4724848cSchristosmatched. Otherwise, it returns the matched peername. To determine 72*4724848cSchristoswhether verification succeeded call L<SSL_get_verify_result(3)>. 73*4724848cSchristos 74*4724848cSchristos=head1 EXAMPLES 75*4724848cSchristos 76*4724848cSchristosSuppose "smtp.example.com" is the MX host of the domain "example.com". 77*4724848cSchristosThe calls below will arrange to match either the MX hostname or the 78*4724848cSchristosdestination domain name in the SMTP server certificate. Wildcards 79*4724848cSchristosare supported, but must match the entire label. The actual name 80*4724848cSchristosmatched in the certificate (which might be a wildcard) is retrieved, 81*4724848cSchristosand must be copied by the application if it is to be retained beyond 82*4724848cSchristosthe lifetime of the SSL connection. 83*4724848cSchristos 84*4724848cSchristos SSL_set_hostflags(ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); 85*4724848cSchristos if (!SSL_set1_host(ssl, "smtp.example.com")) 86*4724848cSchristos /* error */ 87*4724848cSchristos if (!SSL_add1_host(ssl, "example.com")) 88*4724848cSchristos /* error */ 89*4724848cSchristos 90*4724848cSchristos /* XXX: Perform SSL_connect() handshake and handle errors here */ 91*4724848cSchristos 92*4724848cSchristos if (SSL_get_verify_result(ssl) == X509_V_OK) { 93*4724848cSchristos const char *peername = SSL_get0_peername(ssl); 94*4724848cSchristos 95*4724848cSchristos if (peername != NULL) 96*4724848cSchristos /* Name checks were in scope and matched the peername */ 97*4724848cSchristos } 98*4724848cSchristos 99*4724848cSchristos=head1 SEE ALSO 100*4724848cSchristos 101*4724848cSchristosL<X509_check_host(3)>, 102*4724848cSchristosL<SSL_get_verify_result(3)>. 103*4724848cSchristosL<SSL_dane_enable(3)>. 104*4724848cSchristos 105*4724848cSchristos=head1 HISTORY 106*4724848cSchristos 107*4724848cSchristosThese functions were added in OpenSSL 1.1.0. 108*4724848cSchristos 109*4724848cSchristos=head1 COPYRIGHT 110*4724848cSchristos 111*4724848cSchristosCopyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. 112*4724848cSchristos 113*4724848cSchristosLicensed under the OpenSSL license (the "License"). You may not use 114*4724848cSchristosthis file except in compliance with the License. You can obtain a copy 115*4724848cSchristosin the file LICENSE in the source distribution or at 116*4724848cSchristosL<https://www.openssl.org/source/license.html>. 117*4724848cSchristos 118*4724848cSchristos=cut 119