Debian Codegraph @

upstream/debian-unstable/man3/SSL_CTX_dane_enable.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_CTX_DANE_ENABLE 3SSL"
58 .TH SSL_CTX_DANE_ENABLE 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_CTX_dane_enable, SSL_CTX_dane_mtype_set, SSL_dane_enable,
65 SSL_dane_tlsa_add, SSL_get0_dane_authority, SSL_get0_dane_tlsa,
66 SSL_CTX_dane_set_flags, SSL_CTX_dane_clear_flags,
67 SSL_dane_set_flags, SSL_dane_clear_flags
68 \&\- enable DANE TLS authentication of the remote TLS server in the local
69 TLS client
70 .SH SYNOPSIS
71 .IX Header "SYNOPSIS"
72 .Vb 1
73 \& #include <openssl/ssl.h>
74 \&
75 \& int SSL_CTX_dane_enable(SSL_CTX *ctx);
76 \& int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md,
77 \& uint8_t mtype, uint8_t ord);
78 \& int SSL_dane_enable(SSL *s, const char *basedomain);
79 \& int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector,
80 \& uint8_t mtype, const unsigned char *data, size_t dlen);
81 \& int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki);
82 \& int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector,
83 \& uint8_t *mtype, const unsigned char **data,
84 \& size_t *dlen);
85 \& unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags);
86 \& unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags);
87 \& unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags);
88 \& unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags);
89 .Ve
90 .SH DESCRIPTION
91 .IX Header "DESCRIPTION"
92 These functions implement support for DANE TLSA (RFC6698 and RFC7671)
93 peer authentication.
94 .PP
95 \&\fBSSL_CTX_dane_enable()\fR must be called first to initialize the shared state
96 required for DANE support.
97 Individual connections associated with the context can then enable
98 per-connection DANE support as appropriate.
99 DANE authentication is implemented in the \fBX509_verify_cert\fR\|(3) function, and
100 applications that override \fBX509_verify_cert\fR\|(3) via
101 \&\fBSSL_CTX_set_cert_verify_callback\fR\|(3) are responsible to authenticate the peer
102 chain in whatever manner they see fit.
103 .PP
104 \&\fBSSL_CTX_dane_mtype_set()\fR may then be called zero or more times to adjust the
105 supported digest algorithms.
106 This must be done before any SSL handles are created for the context.
107 .PP
108 The \fBmtype\fR argument specifies a DANE TLSA matching type and the \fBmd\fR
109 argument specifies the associated digest algorithm handle.
110 The \fBord\fR argument specifies a strength ordinal.
111 Algorithms with a larger strength ordinal are considered more secure.
112 Strength ordinals are used to implement RFC7671 digest algorithm agility.
113 Specifying a \fBNULL\fR digest algorithm for a matching type disables
114 support for that matching type.
115 Matching type \fBFull\fR\|(0) cannot be modified or disabled.
116 .PP
117 By default, matching type \f(CW\*(C`SHA2\-256(1)\*(C'\fR (see RFC7218 for definitions
118 of the DANE TLSA parameter acronyms) is mapped to \f(CWEVP_sha256()\fR
119 with a strength ordinal of \f(CW1\fR and matching type \f(CW\*(C`SHA2\-512(2)\*(C'\fR
120 is mapped to \f(CWEVP_sha512()\fR with a strength ordinal of \f(CW2\fR.
121 .PP
122 \&\fBSSL_dane_enable()\fR must be called before the SSL handshake is initiated with
123 \&\fBSSL_connect\fR\|(3) if (and only if) you want to enable DANE for that connection.
124 (The connection must be associated with a DANE-enabled SSL context).
125 The \fBbasedomain\fR argument specifies the RFC7671 TLSA base domain,
126 which will be the primary peer reference identifier for certificate
127 name checks.
128 Additional server names can be specified via \fBSSL_add1_host\fR\|(3).
129 The \fBbasedomain\fR is used as the default SNI hint if none has yet been
130 specified via \fBSSL_set_tlsext_host_name\fR\|(3).
131 .PP
132 \&\fBSSL_dane_tlsa_add()\fR may then be called one or more times, to load each of the
133 TLSA records that apply to the remote TLS peer.
134 (This too must be done prior to the beginning of the SSL handshake).
135 The arguments specify the fields of the TLSA record.
136 The \fBdata\fR field is provided in binary (wire RDATA) form, not the hexadecimal
137 ASCII presentation form, with an explicit length passed via \fBdlen\fR.
138 The library takes a copy of the \fBdata\fR buffer contents and the caller may
139 free the original \fBdata\fR buffer when convenient.
140 A return value of 0 indicates that "unusable" TLSA records (with invalid or
141 unsupported parameters) were provided.
142 A negative return value indicates an internal error in processing the record.
143 .PP
144 The caller is expected to check the return value of each \fBSSL_dane_tlsa_add()\fR
145 call and take appropriate action if none are usable or an internal error
146 is encountered in processing some records.
147 .PP
148 If no TLSA records are added successfully, DANE authentication is not enabled,
149 and authentication will be based on any configured traditional trust-anchors;
150 authentication success in this case does not mean that the peer was
151 DANE-authenticated.
152 .PP
153 \&\fBSSL_get0_dane_authority()\fR can be used to get more detailed information about
154 the matched DANE trust-anchor after successful connection completion.
155 The return value is negative if DANE verification failed (or was not enabled),
156 0 if an EE TLSA record directly matched the leaf certificate, or a positive
157 number indicating the depth at which a TA record matched an issuer certificate.
158 The complete verified chain can be retrieved via \fBSSL_get0_verified_chain\fR\|(3).
159 The return value is an index into this verified chain, rather than the list of
160 certificates sent by the peer as returned by \fBSSL_get_peer_cert_chain\fR\|(3).
161 .PP
162 If the \fBmcert\fR argument is not \fBNULL\fR and a TLSA record matched a chain
163 certificate, a pointer to the matching certificate is returned via \fBmcert\fR.
164 The returned address is a short-term internal reference to the certificate and
165 must not be freed by the application.
166 Applications that want to retain access to the certificate can call
167 \&\fBX509_up_ref\fR\|(3) to obtain a long-term reference which must then be freed via
168 \&\fBX509_free\fR\|(3) once no longer needed.
169 .PP
170 If no TLSA records directly matched any elements of the certificate chain, but
171 a \fBDANE\-TA\fR\|(2) \fBSPKI\fR\|(1) \fBFull\fR\|(0) record provided the public key that signed an
172 element of the chain, then that key is returned via \fBmspki\fR argument (if not
173 NULL).
174 In this case the return value is the depth of the top-most element of the
175 validated certificate chain.
176 As with \fBmcert\fR this is a short-term internal reference, and
177 \&\fBEVP_PKEY_up_ref\fR\|(3) and \fBEVP_PKEY_free\fR\|(3) can be used to acquire and
178 release long-term references respectively.
179 .PP
180 \&\fBSSL_get0_dane_tlsa()\fR can be used to retrieve the fields of the TLSA record that
181 matched the peer certificate chain.
182 The return value indicates the match depth or failure to match just as with
183 \&\fBSSL_get0_dane_authority()\fR.
184 When the return value is nonnegative, the storage pointed to by the \fBusage\fR,
185 \&\fBselector\fR, \fBmtype\fR and \fBdata\fR parameters is updated to the corresponding
186 TLSA record fields.
187 The \fBdata\fR field is in binary wire form, and is therefore not NUL-terminated,
188 its length is returned via the \fBdlen\fR parameter.
189 If any of these parameters is NULL, the corresponding field is not returned.
190 The \fBdata\fR parameter is set to a short-term internal-copy of the associated
191 data field and must not be freed by the application.
192 Applications that need long-term access to this field need to copy the content.
193 .PP
194 \&\fBSSL_CTX_dane_set_flags()\fR and \fBSSL_dane_set_flags()\fR can be used to enable
195 optional DANE verification features.
196 \&\fBSSL_CTX_dane_clear_flags()\fR and \fBSSL_dane_clear_flags()\fR can be used to disable
197 the same features.
198 The \fBflags\fR argument is a bit-mask of the features to enable or disable.
199 The \fBflags\fR set for an \fBSSL_CTX\fR context are copied to each \fBSSL\fR handle
200 associated with that context at the time the handle is created.
201 Subsequent changes in the context's \fBflags\fR have no effect on the \fBflags\fR set
202 for the handle.
203 .PP
204 At present, the only available option is \fBDANE_FLAG_NO_DANE_EE_NAMECHECKS\fR
205 which can be used to disable server name checks when authenticating via
206 \&\fBDANE\-EE\fR\|(3) TLSA records.
207 For some applications, primarily web browsers, it is not safe to disable name
208 checks due to "unknown key share" attacks, in which a malicious server can
209 convince a client that a connection to a victim server is instead a secure
210 connection to the malicious server.
211 The malicious server may then be able to violate cross-origin scripting
212 restrictions.
213 Thus, despite the text of RFC7671, name checks are by default enabled for
214 \&\fBDANE\-EE\fR\|(3) TLSA records, and can be disabled in applications where it is safe
215 to do so.
216 In particular, SMTP and XMPP clients should set this option as SRV and MX
217 records already make it possible for a remote domain to redirect client
218 connections to any server of its choice, and in any case SMTP and XMPP clients
219 do not execute scripts downloaded from remote servers.
220 .SH "RETURN VALUES"
221 .IX Header "RETURN VALUES"
222 The functions \fBSSL_CTX_dane_enable()\fR, \fBSSL_CTX_dane_mtype_set()\fR,
223 \&\fBSSL_dane_enable()\fR and \fBSSL_dane_tlsa_add()\fR return a positive value on success.
224 Negative return values indicate resource problems (out of memory, etc.) in the
225 SSL library, while a return value of \fB0\fR indicates incorrect usage or invalid
226 input, such as an unsupported TLSA record certificate usage, selector or
227 matching type.
228 Invalid input also includes malformed data, either a digest length that does
229 not match the digest algorithm, or a \f(CWFull(0)\fR (binary ASN.1 DER form)
230 certificate or a public key that fails to parse.
231 .PP
232 The functions \fBSSL_get0_dane_authority()\fR and \fBSSL_get0_dane_tlsa()\fR return a
233 negative value when DANE authentication failed or was not enabled, a
234 nonnegative value indicates the chain depth at which the TLSA record matched a
235 chain certificate, or the depth of the top-most certificate, when the TLSA
236 record is a full public key that is its signer.
237 .PP
238 The functions \fBSSL_CTX_dane_set_flags()\fR, \fBSSL_CTX_dane_clear_flags()\fR,
239 \&\fBSSL_dane_set_flags()\fR and \fBSSL_dane_clear_flags()\fR return the \fBflags\fR in effect
240 before they were called.
241 .SH EXAMPLES
242 .IX Header "EXAMPLES"
243 Suppose "smtp.example.com" is the MX host of the domain "example.com", and has
244 DNSSEC-validated TLSA records.
245 The calls below will perform DANE authentication and arrange to match either
246 the MX hostname or the destination domain name in the SMTP server certificate.
247 Wildcards are supported, but must match the entire label.
248 The actual name matched in the certificate (which might be a wildcard) is
249 retrieved, and must be copied by the application if it is to be retained beyond
250 the lifetime of the SSL connection.
251 .PP
252 .Vb 7
253 \& SSL_CTX *ctx;
254 \& SSL *ssl;
255 \& int (*verify_cb)(int ok, X509_STORE_CTX *sctx) = NULL;
256 \& int num_usable = 0;
257 \& const char *nexthop_domain = "example.com";
258 \& const char *dane_tlsa_domain = "smtp.example.com";
259 \& uint8_t usage, selector, mtype;
260 \&
261 \& if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL)
262 \& /* error */
263 \& if (SSL_CTX_dane_enable(ctx) <= 0)
264 \& /* error */
265 \& if ((ssl = SSL_new(ctx)) == NULL)
266 \& /* error */
267 \& if (SSL_dane_enable(ssl, dane_tlsa_domain) <= 0)
268 \& /* error */
269 \&
270 \& /*
271 \& * For many applications it is safe to skip DANE\-EE(3) namechecks. Do not
272 \& * disable the checks unless "unknown key share" attacks pose no risk for
273 \& * your application.
274 \& */
275 \& SSL_dane_set_flags(ssl, DANE_FLAG_NO_DANE_EE_NAMECHECKS);
276 \&
277 \& if (!SSL_add1_host(ssl, nexthop_domain))
278 \& /* error */
279 \& SSL_set_hostflags(ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
280 \&
281 \& for (... each TLSA record ...) {
282 \& unsigned char *data;
283 \& size_t len;
284 \& int ret;
285 \&
286 \& /* set usage, selector, mtype, data, len */
287 \&
288 \& /*
289 \& * Opportunistic DANE TLS clients support only DANE\-TA(2) or DANE\-EE(3).
290 \& * They treat all other certificate usages, and in particular PKIX\-TA(0)
291 \& * and PKIX\-EE(1), as unusable.
292 \& */
293 \& switch (usage) {
294 \& default:
295 \& case 0: /* PKIX\-TA(0) */
296 \& case 1: /* PKIX\-EE(1) */
297 \& continue;
298 \& case 2: /* DANE\-TA(2) */
299 \& case 3: /* DANE\-EE(3) */
300 \& break;
301 \& }
302 \&
303 \& ret = SSL_dane_tlsa_add(ssl, usage, selector, mtype, data, len);
304 \& /* free data as appropriate */
305 \&
306 \& if (ret < 0)
307 \& /* handle SSL library internal error */
308 \& else if (ret == 0)
309 \& /* handle unusable TLSA record */
310 \& else
311 \& ++num_usable;
312 \& }
313 \&
314 \& /*
315 \& * At this point, the verification mode is still the default SSL_VERIFY_NONE.
316 \& * Opportunistic DANE clients use unauthenticated TLS when all TLSA records
317 \& * are unusable, so continue the handshake even if authentication fails.
318 \& */
319 \& if (num_usable == 0) {
320 \& /* Log all records unusable? */
321 \&
322 \& /* Optionally set verify_cb to a suitable non\-NULL callback. */
323 \& SSL_set_verify(ssl, SSL_VERIFY_NONE, verify_cb);
324 \& } else {
325 \& /* At least one usable record. We expect to verify the peer */
326 \&
327 \& /* Optionally set verify_cb to a suitable non\-NULL callback. */
328 \&
329 \& /*
330 \& * Below we elect to fail the handshake when peer verification fails.
331 \& * Alternatively, use the permissive SSL_VERIFY_NONE verification mode,
332 \& * complete the handshake, check the verification status, and if not
333 \& * verified disconnect gracefully at the application layer, especially if
334 \& * application protocol supports informing the server that authentication
335 \& * failed.
336 \& */
337 \& SSL_set_verify(ssl, SSL_VERIFY_PEER, verify_cb);
338 \& }
339 \&
340 \& /*
341 \& * Load any saved session for resumption, making sure that the previous
342 \& * session applied the same security and authentication requirements that
343 \& * would be expected of a fresh connection.
344 \& */
345 \&
346 \& /* Perform SSL_connect() handshake and handle errors here */
347 \&
348 \& if (SSL_session_reused(ssl)) {
349 \& if (SSL_get_verify_result(ssl) == X509_V_OK) {
350 \& /*
351 \& * Resumed session was originally verified, this connection is
352 \& * authenticated.
353 \& */
354 \& } else {
355 \& /*
356 \& * Resumed session was not originally verified, this connection is not
357 \& * authenticated.
358 \& */
359 \& }
360 \& } else if (SSL_get_verify_result(ssl) == X509_V_OK) {
361 \& const char *peername = SSL_get0_peername(ssl);
362 \& EVP_PKEY *mspki = NULL;
363 \&
364 \& int depth = SSL_get0_dane_authority(ssl, NULL, &mspki);
365 \& if (depth >= 0) {
366 \& (void) SSL_get0_dane_tlsa(ssl, &usage, &selector, &mtype, NULL, NULL);
367 \& printf("DANE TLSA %d %d %d ", usage, selector, mtype);
368 \& if (SSL_get0_peer_rpk(ssl) == NULL)
369 \& printf("%s certificate at depth %d\en",
370 \& (mspki != NULL) ? "signed the peer" :
371 \& mdpth ? "matched the TA" : "matched the EE", mdpth);
372 \& else
373 \& printf(bio, "matched the peer raw public key\en");
374 \& }
375 \& if (peername != NULL) {
376 \& /* Name checks were in scope and matched the peername */
377 \& printf("Verified peername: %s\en", peername);
378 \& }
379 \& } else {
380 \& /*
381 \& * Not authenticated, presumably all TLSA rrs unusable, but possibly a
382 \& * callback suppressed connection termination despite the presence of
383 \& * usable TLSA RRs none of which matched. Do whatever is appropriate for
384 \& * fresh unauthenticated connections.
385 \& */
386 \& }
387 .Ve
388 .SH NOTES
389 .IX Header "NOTES"
390 It is expected that the majority of clients employing DANE TLS will be doing
391 "opportunistic DANE TLS" in the sense of RFC7672 and RFC7435.
392 That is, they will use DANE authentication when DNSSEC-validated TLSA records
393 are published for a given peer, and otherwise will use unauthenticated TLS or
394 even cleartext.
395 .PP
396 Such applications should generally treat any TLSA records published by the peer
397 with usages \fBPKIX\-TA\fR\|(0) and \fBPKIX\-EE\fR\|(1) as "unusable", and should not include
398 them among the TLSA records used to authenticate peer connections.
399 In addition, some TLSA records with supported usages may be "unusable" as a
400 result of invalid or unsupported parameters.
401 .PP
402 When a peer has TLSA records, but none are "usable", an opportunistic
403 application must avoid cleartext, but cannot authenticate the peer,
404 and so should generally proceed with an unauthenticated connection.
405 Opportunistic applications need to note the return value of each
406 call to \fBSSL_dane_tlsa_add()\fR, and if all return 0 (due to invalid
407 or unsupported parameters) disable peer authentication by calling
408 \&\fBSSL_set_verify\fR\|(3) with \fBmode\fR equal to \fBSSL_VERIFY_NONE\fR.
409 .SH "SEE ALSO"
410 .IX Header "SEE ALSO"
411 \&\fBssl\fR\|(7),
412 \&\fBSSL_new\fR\|(3),
413 \&\fBSSL_add1_host\fR\|(3),
414 \&\fBSSL_set_hostflags\fR\|(3),
415 \&\fBSSL_set_tlsext_host_name\fR\|(3),
416 \&\fBSSL_set_verify\fR\|(3),
417 \&\fBSSL_CTX_set_cert_verify_callback\fR\|(3),
418 \&\fBSSL_get0_verified_chain\fR\|(3),
419 \&\fBSSL_get_peer_cert_chain\fR\|(3),
420 \&\fBSSL_get_verify_result\fR\|(3),
421 \&\fBSSL_connect\fR\|(3),
422 \&\fBSSL_get0_peername\fR\|(3),
423 \&\fBX509_verify_cert\fR\|(3),
424 \&\fBX509_up_ref\fR\|(3),
425 \&\fBX509_free\fR\|(3),
426 \&\fBEVP_get_digestbyname\fR\|(3),
427 \&\fBEVP_PKEY_up_ref\fR\|(3),
428 \&\fBEVP_PKEY_free\fR\|(3)
429 .SH HISTORY
430 .IX Header "HISTORY"
431 These functions were added in OpenSSL 1.1.0.
432 .SH COPYRIGHT
433 .IX Header "COPYRIGHT"
434 Copyright 2016\-2023 The OpenSSL Project Authors. All Rights Reserved.
435 .PP
436 Licensed under the Apache License 2.0 (the "License"). You may not use
437 this file except in compliance with the License. You can obtain a copy
438 in the file LICENSE in the source distribution or at
439 <https://www.openssl.org/source/license.html>.