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