1SSL_SET1_HOST(3)                    OpenSSL                   SSL_SET1_HOST(3)
2
3
4

NAME

6       SSL_set1_host, SSL_add1_host, SSL_set_hostflags, SSL_get0_peername -
7       SSL server verification parameters
8

SYNOPSIS

10        #include <openssl/ssl.h>
11
12        int SSL_set1_host(SSL *s, const char *hostname);
13        int SSL_add1_host(SSL *s, const char *hostname);
14        void SSL_set_hostflags(SSL *s, unsigned int flags);
15        const char *SSL_get0_peername(SSL *s);
16

DESCRIPTION

18       These functions configure server hostname checks in the SSL client.
19
20       SSL_set1_host() sets the expected DNS hostname to name clearing any
21       previously specified hostname or names.  If name is NULL, or the empty
22       string the list of hostnames is cleared, and name checks are not
23       performed on the peer certificate.  When a nonempty name is specified,
24       certificate verification automatically checks the peer hostname via
25       X509_check_host(3) with flags as specified via SSL_set_hostflags().
26       Clients that enable DANE TLSA authentication via SSL_dane_enable(3)
27       should leave it to that function to set the primary reference
28       identifier of the peer, and should not call SSL_set1_host().
29
30       SSL_add1_host() adds name as an additional reference identifier that
31       can match the peer's certificate.  Any previous names set via
32       SSL_set1_host() or SSL_add1_host() are retained, no change is made if
33       name is NULL or empty.  When multiple names are configured, the peer is
34       considered verified when any name matches.  This function is required
35       for DANE TLSA in the presence of service name indirection via CNAME, MX
36       or SRV records as specified in RFC7671, RFC7672 or RFC7673.
37
38       SSL_set_hostflags() sets the flags that will be passed to
39       X509_check_host(3) when name checks are applicable, by default the
40       flags value is 0.  See X509_check_host(3) for the list of available
41       flags and their meaning.
42
43       SSL_get0_peername() returns the DNS hostname or subject CommonName from
44       the peer certificate that matched one of the reference identifiers.
45       When wildcard matching is not disabled, the name matched in the peer
46       certificate may be a wildcard name.  When one of the reference
47       identifiers configured via SSL_set1_host() or SSL_add1_host() starts
48       with ".", which indicates a parent domain prefix rather than a fixed
49       name, the matched peer name may be a sub-domain of the reference
50       identifier.  The returned string is allocated by the library and is no
51       longer valid once the associated ssl handle is cleared or freed, or a
52       renegotiation takes place.  Applications must not free the return
53       value.
54
55       SSL clients are advised to use these functions in preference to
56       explicitly calling X509_check_host(3).  Hostname checks may be out of
57       scope with the RFC7671 DANE-EE(3) certificate usage, and the internal
58       check will be suppressed as appropriate when DANE is enabled.
59

RETURN VALUES

61       SSL_set1_host() and SSL_add1_host() return 1 for success and 0 for
62       failure.
63
64       SSL_get0_peername() returns NULL if peername verification is not
65       applicable (as with RFC7671 DANE-EE(3)), or no trusted peername was
66       matched.  Otherwise, it returns the matched peername.  To determine
67       whether verification succeeded call SSL_get_verify_result(3).
68

EXAMPLES

70       Suppose "smtp.example.com" is the MX host of the domain "example.com".
71       The calls below will arrange to match either the MX hostname or the
72       destination domain name in the SMTP server certificate.  Wildcards are
73       supported, but must match the entire label.  The actual name matched in
74       the certificate (which might be a wildcard) is retrieved, and must be
75       copied by the application if it is to be retained beyond the lifetime
76       of the SSL connection.
77
78        SSL_set_hostflags(ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
79        if (!SSL_set1_host(ssl, "smtp.example.com"))
80            /* error */
81        if (!SSL_add1_host(ssl, "example.com"))
82            /* error */
83
84        /* XXX: Perform SSL_connect() handshake and handle errors here */
85
86        if (SSL_get_verify_result(ssl) == X509_V_OK) {
87            const char *peername = SSL_get0_peername(ssl);
88
89            if (peername != NULL)
90                /* Name checks were in scope and matched the peername */
91        }
92

SEE ALSO

94       X509_check_host(3), SSL_get_verify_result(3).  SSL_dane_enable(3).
95

HISTORY

97       These functions were added in OpenSSL 1.1.0.
98
100       Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
101
102       Licensed under the OpenSSL license (the "License").  You may not use
103       this file except in compliance with the License.  You can obtain a copy
104       in the file LICENSE in the source distribution or at
105       <https://www.openssl.org/source/license.html>.
106
107
108
1091.1.1q                            2022-07-07                  SSL_SET1_HOST(3)
Impressum