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