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