Debian Codegraph @

upstream/debian-unstable/man3/SSL_set1_host.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "SSL_SET1_HOST 3SSL"
58 .TH SSL_SET1_HOST 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 SSL_set1_host, SSL_add1_host, SSL_set_hostflags, SSL_get0_peername \-
65 SSL server verification parameters
66 .SH SYNOPSIS
67 .IX Header "SYNOPSIS"
68 .Vb 1
69 \& #include <openssl/ssl.h>
70 \&
71 \& int SSL_set1_host(SSL *s, const char *host);
72 \& int SSL_add1_host(SSL *s, const char *host);
73 \& void SSL_set_hostflags(SSL *s, unsigned int flags);
74 \& const char *SSL_get0_peername(SSL *s);
75 .Ve
76 .SH DESCRIPTION
77 .IX Header "DESCRIPTION"
78 These functions configure server hostname checks in the SSL client.
79 .PP
80 \&\fBSSL_set1_host()\fR sets in the verification parameters of \fIs\fR
81 the expected DNS hostname or IP address to \fIhost\fR,
82 clearing any previously specified IP address and hostnames.
83 If \fIhost\fR is NULL or the empty string, IP address
84 and hostname checks are not performed on the peer certificate.
85 When a nonempty \fIhost\fR is specified, certificate verification automatically
86 checks the peer hostname via \fBX509_check_host\fR\|(3) with \fIflags\fR as specified
87 via \fBSSL_set_hostflags()\fR. Clients that enable DANE TLSA authentication
88 via \fBSSL_dane_enable\fR\|(3) should leave it to that function to set
89 the primary reference identifier of the peer, and should not call
90 \&\fBSSL_set1_host()\fR.
91 .PP
92 \&\fBSSL_add1_host()\fR adds \fIhost\fR as an additional reference identifier
93 that can match the peer's certificate. Any previous hostnames
94 set via \fBSSL_set1_host()\fR or \fBSSL_add1_host()\fR are retained.
95 Adding an IP address is allowed only if no IP address has been set before.
96 No change is made if \fIhost\fR is NULL or empty.
97 When an IP address and/or multiple hostnames are configured,
98 the peer is considered verified when any of these matches.
99 This function is required for DANE TLSA in the presence of service name indirection
100 via CNAME, MX or SRV records as specified in RFCs 7671, 7672, and 7673.
101 .PP
102 TLS clients are recommended to use \fBSSL_set1_host()\fR or \fBSSL_add1_host()\fR
103 for server hostname or IP address validation,
104 as well as \fBSSL_set_tlsext_host_name\fR\|(3) for Server Name Indication (SNI),
105 which may be crucial also for correct routing of the connection request.
106 .PP
107 \&\fBSSL_set_hostflags()\fR sets the \fIflags\fR that will be passed to
108 \&\fBX509_check_host\fR\|(3) when name checks are applicable, by default
109 the \fIflags\fR value is 0. See \fBX509_check_host\fR\|(3) for the list
110 of available flags and their meaning.
111 .PP
112 \&\fBSSL_get0_peername()\fR returns the DNS hostname or subject CommonName
113 from the peer certificate that matched one of the reference
114 identifiers. When wildcard matching is not disabled, the name
115 matched in the peer certificate may be a wildcard name. When one
116 of the reference identifiers configured via \fBSSL_set1_host()\fR or
117 \&\fBSSL_add1_host()\fR starts with ".", which indicates a parent domain prefix
118 rather than a fixed name, the matched peer name may be a sub-domain
119 of the reference identifier. The returned string is allocated by
120 the library and is no longer valid once the associated \fIssl\fR handle
121 is cleared or freed, or a renegotiation takes place. Applications
122 must not free the return value.
123 .PP
124 SSL clients are advised to use these functions in preference to
125 explicitly calling \fBX509_check_host\fR\|(3). Hostname checks may be out
126 of scope with the RFC 7671 \fBDANE\-EE\fR\|(3) certificate usage, and the
127 internal check will be suppressed as appropriate when DANE is
128 enabled.
129 .SH "RETURN VALUES"
130 .IX Header "RETURN VALUES"
131 \&\fBSSL_set1_host()\fR and \fBSSL_add1_host()\fR return 1 for success and 0 for
132 failure.
133 .PP
134 \&\fBSSL_set_hostflags()\fR returns nothing at all.
135 .PP
136 \&\fBSSL_get0_peername()\fR returns NULL if peername verification is not
137 applicable (as with RFC 7671 \fBDANE\-EE\fR\|(3)), or no trusted peername was
138 matched. Otherwise, it returns the matched peername. To determine
139 whether verification succeeded call \fBSSL_get_verify_result\fR\|(3).
140 .SH EXAMPLES
141 .IX Header "EXAMPLES"
142 Suppose "smtp.example.com" is the MX host of the domain "example.com".
143 The calls below will arrange to match either the MX hostname or the
144 destination domain name in the SMTP server certificate. Wildcards
145 are supported, but must match the entire label. The actual name
146 matched in the certificate (which might be a wildcard) is retrieved,
147 and must be copied by the application if it is to be retained beyond
148 the lifetime of the SSL connection.
149 .PP
150 .Vb 5
151 \& SSL_set_hostflags(ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
152 \& if (!SSL_set1_host(ssl, "smtp.example.com"))
153 \& /* error */
154 \& if (!SSL_add1_host(ssl, "example.com"))
155 \& /* error */
156 \&
157 \& /* XXX: Perform SSL_connect() handshake and handle errors here */
158 \&
159 \& if (SSL_get_verify_result(ssl) == X509_V_OK) {
160 \& const char *peername = SSL_get0_peername(ssl);
161 \&
162 \& if (peername != NULL)
163 \& /* Name checks were in scope and matched the peername */
164 \& }
165 .Ve
166 .SH "SEE ALSO"
167 .IX Header "SEE ALSO"
168 \&\fBssl\fR\|(7),
169 \&\fBX509_check_host\fR\|(3), \fBSSL_set_tlsext_host_name\fR\|(3),
170 \&\fBSSL_get_verify_result\fR\|(3), \fBSSL_dane_enable\fR\|(3)
171 .SH HISTORY
172 .IX Header "HISTORY"
173 These functions were added in OpenSSL 1.1.0.
174 .SH COPYRIGHT
175 .IX Header "COPYRIGHT"
176 Copyright 2016\-2025 The OpenSSL Project Authors. All Rights Reserved.
177 .PP
178 Licensed under the Apache License 2.0 (the "License"). You may not use
179 this file except in compliance with the License. You can obtain a copy
180 in the file LICENSE in the source distribution or at
181 <https://www.openssl.org/source/license.html>.