xref: /openbsd-src/lib/libssl/man/SSL_set1_host.3 (revision b99ef4df7fac99f3475b694d6cd4990521c99ae6)
1.\" $OpenBSD: SSL_set1_host.3,v 1.3 2021/01/27 17:57:40 tb Exp $
2.\" selective merge up to: OpenSSL 6328d367 Jul 4 21:58:30 2020 +0200
3.\"
4.\" This file was written by Viktor Dukhovni <viktor@openssl.org>
5.\" Copyright (c) 2015 The OpenSSL Project.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in
16.\"    the documentation and/or other materials provided with the
17.\"    distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\"    software must display the following acknowledgment:
21.\"    "This product includes software developed by the OpenSSL Project
22.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\"    endorse or promote products derived from this software without
26.\"    prior written permission. For written permission, please contact
27.\"    openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\"    nor may "OpenSSL" appear in their names without prior written
31.\"    permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\"    acknowledgment:
35.\"    "This product includes software developed by the OpenSSL Project
36.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: January 27 2021 $
52.Dt SSL_SET1_HOST 3
53.Os
54.Sh NAME
55.Nm SSL_set1_host
56.ig  \" won't make Ox 6.8 but will appear in 6.9
57.Nm SSL_set_hostflags
58.Nm SSL_get0_peername
59..
60.Nd SSL server verification parameters
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft int
64.Fo SSL_set1_host
65.Fa "SSL *ssl"
66.Fa "const char *hostname"
67.Fc
68.ig
69.Ft void
70.Fo SSL_set_hostflags
71.Fa "SSL *ssl"
72.Fa "unsigned int flags"
73.Fc
74.Ft const char *
75.Fo SSL_get0_peername
76.Fa "SSL *ssl"
77.Fc
78..
79.Sh DESCRIPTION
80.Fn SSL_set1_host
81configures a server hostname check in the
82.Fa ssl
83client, setting the expected DNS hostname to
84.Fa hostname
85and clearing any previously specified hostname.
86If
87.Fa hostname
88is
89.Dv NULL
90or the empty string, name checks are not performed on the peer certificate.
91If a nonempty
92.Fa hostname
93is specified, certificate verification automatically checks the peer
94hostname via
95.Xr X509_check_host 3
96with
97.Fa flags
98set to 0.
99.Pp
100.ig
101.Fn SSL_set_hostflags
102sets the flags that will be passed to
103.Xr X509_check_host 3
104when name checks are applicable,
105by default the flags value is 0.
106See
107.Xr X509_check_host 3
108for the list of available flags and their meaning.
109.Pp
110.Fn SSL_get0_peername
111returns the DNS hostname or subject CommonName from the peer certificate
112that matched one of the reference identifiers.
113Unless wildcard matching is disabled, the name matched in the peer
114certificate may be a wildcard name.
115A reference identifier starting with
116.Sq \&.
117indicates a parent domain prefix rather than a fixed name.
118In this case, the matched peername may be a sub-domain
119of the reference identifier.
120The returned string is owned by the library and is no longer valid
121once the associated
122.Fa ssl
123object is cleared or freed, or if a renegotiation takes place.
124Applications must not free the return value.
125.Pp
126SSL clients are advised to use these functions in preference to
127..
128SSL clients are advised to use this function in preference to
129explicitly calling
130.Xr X509_check_host 3 .
131.Sh RETURN VALUES
132.Fn SSL_set1_host
133returns 1 for success or 0 for failure.
134.ig
135.Pp
136.Fn SSL_get0_peername
137returns the matched peername or
138.Dv NULL
139if peername verification is not applicable
140or no trusted peername was matched.
141Use
142.Xr SSL_get_verify_result 3
143to determine whether verification succeeded.
144.Sh EXAMPLES
145The calls below check the hostname.
146Wildcards are supported, but they must match the entire label.
147The actual name matched in the certificate (which might be a wildcard)
148is retrieved, and must be copied by the application if it is to be
149retained beyond the lifetime of the SSL connection.
150.Bd -literal
151if (!SSL_set1_host(ssl, "smtp.example.com"))
152	/* error */
153
154/* XXX: Perform SSL_connect() handshake and handle errors here */
155
156if (SSL_get_verify_result(ssl) == X509_V_OK) {
157	const char *peername = SSL_get0_peername(ssl);
158
159	if (peername != NULL)
160		/* Name checks were in scope and matched the peername */
161}
162.Ed
163..
164.Sh SEE ALSO
165.Xr ssl 3 ,
166.Xr SSL_CTX_set_verify 3 ,
167.Xr SSL_get_peer_certificate 3 ,
168.Xr SSL_get_verify_result 3 ,
169.Xr X509_check_host 3 ,
170.Xr X509_VERIFY_PARAM_set1_host 3
171.Sh HISTORY
172This function first appeared in OpenSSL 1.1.0
173and has been available since
174.Ox 6.5 .
175.ig
176All three functions first appeared in OpenSSL 1.1.0.
177.Fn SSL_set1_host
178has been available since
179.Ox 6.5 ,
180and
181.Fn SSL_set_hostflags
182and
183.Fn SSL_get0_peername
184since
185.Ox 6.9 .
186..
187