xref: /freebsd/crypto/openssl/doc/man3/SSL_extension_supported.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimSSL_extension_supported,
6*b077aed3SPierre ProncherySSL_custom_ext_add_cb_ex,
7*b077aed3SPierre ProncherySSL_custom_ext_free_cb_ex,
8*b077aed3SPierre ProncherySSL_custom_ext_parse_cb_ex,
9e71b7053SJung-uk KimSSL_CTX_add_custom_ext,
10e71b7053SJung-uk KimSSL_CTX_add_client_custom_ext, SSL_CTX_add_server_custom_ext,
11e71b7053SJung-uk Kimcustom_ext_add_cb, custom_ext_free_cb, custom_ext_parse_cb
12e71b7053SJung-uk Kim- custom TLS extension handling
13e71b7053SJung-uk Kim
14e71b7053SJung-uk Kim=head1 SYNOPSIS
15e71b7053SJung-uk Kim
16e71b7053SJung-uk Kim #include <openssl/ssl.h>
17e71b7053SJung-uk Kim
18e71b7053SJung-uk Kim typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type,
19e71b7053SJung-uk Kim                                         unsigned int context,
20e71b7053SJung-uk Kim                                         const unsigned char **out,
21e71b7053SJung-uk Kim                                         size_t *outlen, X509 *x,
22e71b7053SJung-uk Kim                                         size_t chainidx, int *al,
23e71b7053SJung-uk Kim                                         void *add_arg);
24e71b7053SJung-uk Kim
25e71b7053SJung-uk Kim typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type,
26e71b7053SJung-uk Kim                                           unsigned int context,
27e71b7053SJung-uk Kim                                           const unsigned char *out,
28e71b7053SJung-uk Kim                                           void *add_arg);
29e71b7053SJung-uk Kim
30e71b7053SJung-uk Kim typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type,
31e71b7053SJung-uk Kim                                           unsigned int context,
32e71b7053SJung-uk Kim                                           const unsigned char *in,
33e71b7053SJung-uk Kim                                           size_t inlen, X509 *x,
34e71b7053SJung-uk Kim                                           size_t chainidx, int *al,
35e71b7053SJung-uk Kim                                           void *parse_arg);
36e71b7053SJung-uk Kim
37e71b7053SJung-uk Kim int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
38e71b7053SJung-uk Kim                            unsigned int context,
39e71b7053SJung-uk Kim                            SSL_custom_ext_add_cb_ex add_cb,
40e71b7053SJung-uk Kim                            SSL_custom_ext_free_cb_ex free_cb,
41e71b7053SJung-uk Kim                            void *add_arg,
42e71b7053SJung-uk Kim                            SSL_custom_ext_parse_cb_ex parse_cb,
43e71b7053SJung-uk Kim                            void *parse_arg);
44e71b7053SJung-uk Kim
45e71b7053SJung-uk Kim typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type,
46e71b7053SJung-uk Kim                                  const unsigned char **out,
47e71b7053SJung-uk Kim                                  size_t *outlen, int *al,
48e71b7053SJung-uk Kim                                  void *add_arg);
49e71b7053SJung-uk Kim
50e71b7053SJung-uk Kim typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type,
51e71b7053SJung-uk Kim                                    const unsigned char *out,
52e71b7053SJung-uk Kim                                    void *add_arg);
53e71b7053SJung-uk Kim
54e71b7053SJung-uk Kim typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type,
55e71b7053SJung-uk Kim                                    const unsigned char *in,
56e71b7053SJung-uk Kim                                    size_t inlen, int *al,
57e71b7053SJung-uk Kim                                    void *parse_arg);
58e71b7053SJung-uk Kim
59e71b7053SJung-uk Kim int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
60e71b7053SJung-uk Kim                                   custom_ext_add_cb add_cb,
61e71b7053SJung-uk Kim                                   custom_ext_free_cb free_cb, void *add_arg,
62e71b7053SJung-uk Kim                                   custom_ext_parse_cb parse_cb,
63e71b7053SJung-uk Kim                                   void *parse_arg);
64e71b7053SJung-uk Kim
65e71b7053SJung-uk Kim int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
66e71b7053SJung-uk Kim                                   custom_ext_add_cb add_cb,
67e71b7053SJung-uk Kim                                   custom_ext_free_cb free_cb, void *add_arg,
68e71b7053SJung-uk Kim                                   custom_ext_parse_cb parse_cb,
69e71b7053SJung-uk Kim                                   void *parse_arg);
70e71b7053SJung-uk Kim
71e71b7053SJung-uk Kim int SSL_extension_supported(unsigned int ext_type);
72e71b7053SJung-uk Kim
73e71b7053SJung-uk Kim=head1 DESCRIPTION
74e71b7053SJung-uk Kim
75e71b7053SJung-uk KimSSL_CTX_add_custom_ext() adds a custom extension for a TLS/DTLS client or server
76e71b7053SJung-uk Kimfor all supported protocol versions with extension type B<ext_type> and
77e71b7053SJung-uk Kimcallbacks B<add_cb>, B<free_cb> and B<parse_cb> (see the
78e71b7053SJung-uk KimL</EXTENSION CALLBACKS> section below). The B<context> value determines
79e71b7053SJung-uk Kimwhich messages and under what conditions the extension will be added/parsed (see
80e71b7053SJung-uk Kimthe L</EXTENSION CONTEXTS> section below).
81e71b7053SJung-uk Kim
82e71b7053SJung-uk KimSSL_CTX_add_client_custom_ext() adds a custom extension for a TLS/DTLS client
83e71b7053SJung-uk Kimwith extension type B<ext_type> and callbacks B<add_cb>, B<free_cb> and
84e71b7053SJung-uk KimB<parse_cb>. This function is similar to SSL_CTX_add_custom_ext() except it only
85e71b7053SJung-uk Kimapplies to clients, uses the older style of callbacks, and implicitly sets the
86e71b7053SJung-uk KimB<context> value to:
87e71b7053SJung-uk Kim
88e71b7053SJung-uk Kim SSL_EXT_TLS1_2_AND_BELOW_ONLY | SSL_EXT_CLIENT_HELLO
89e71b7053SJung-uk Kim | SSL_EXT_TLS1_2_SERVER_HELLO | SSL_EXT_IGNORE_ON_RESUMPTION
90e71b7053SJung-uk Kim
91e71b7053SJung-uk KimSSL_CTX_add_server_custom_ext() adds a custom extension for a TLS/DTLS server
92e71b7053SJung-uk Kimwith extension type B<ext_type> and callbacks B<add_cb>, B<free_cb> and
93e71b7053SJung-uk KimB<parse_cb>. This function is similar to SSL_CTX_add_custom_ext() except it
94e71b7053SJung-uk Kimonly applies to servers, uses the older style of callbacks, and implicitly sets
95e71b7053SJung-uk Kimthe B<context> value to the same as for SSL_CTX_add_client_custom_ext() above.
96e71b7053SJung-uk Kim
97e71b7053SJung-uk KimThe B<ext_type> parameter corresponds to the B<extension_type> field of
98e71b7053SJung-uk KimRFC5246 et al. It is B<not> a NID. In all cases the extension type must not be
99e71b7053SJung-uk Kimhandled by OpenSSL internally or an error occurs.
100e71b7053SJung-uk Kim
101e71b7053SJung-uk KimSSL_extension_supported() returns 1 if the extension B<ext_type> is handled
102e71b7053SJung-uk Kiminternally by OpenSSL and 0 otherwise.
103e71b7053SJung-uk Kim
104e71b7053SJung-uk Kim=head1 EXTENSION CALLBACKS
105e71b7053SJung-uk Kim
106e71b7053SJung-uk KimThe callback B<add_cb> is called to send custom extension data to be
107e71b7053SJung-uk Kimincluded in various TLS messages. The B<ext_type> parameter is set to the
108e71b7053SJung-uk Kimextension type which will be added and B<add_arg> to the value set when the
109e71b7053SJung-uk Kimextension handler was added. When using the new style callbacks the B<context>
110e71b7053SJung-uk Kimparameter will indicate which message is currently being constructed e.g. for
111e71b7053SJung-uk Kimthe ClientHello it will be set to B<SSL_EXT_CLIENT_HELLO>.
112e71b7053SJung-uk Kim
113e71b7053SJung-uk KimIf the application wishes to include the extension B<ext_type> it should
114e71b7053SJung-uk Kimset B<*out> to the extension data, set B<*outlen> to the length of the
115e71b7053SJung-uk Kimextension data and return 1.
116e71b7053SJung-uk Kim
117e71b7053SJung-uk KimIf the B<add_cb> does not wish to include the extension it must return 0.
118e71b7053SJung-uk Kim
119e71b7053SJung-uk KimIf B<add_cb> returns -1 a fatal handshake error occurs using the TLS
120e71b7053SJung-uk Kimalert value specified in B<*al>.
121e71b7053SJung-uk Kim
122e71b7053SJung-uk KimWhen constructing the ClientHello, if B<add_cb> is set to NULL a zero length
123e71b7053SJung-uk Kimextension is added for B<ext_type>. For all other messages if B<add_cb> is set
124e71b7053SJung-uk Kimto NULL then no extension is added.
125e71b7053SJung-uk Kim
126e71b7053SJung-uk KimWhen constructing a Certificate message the callback will be called for each
127e71b7053SJung-uk Kimcertificate in the message. The B<x> parameter will indicate the
128e71b7053SJung-uk Kimcurrent certificate and the B<chainidx> parameter will indicate the position
129e71b7053SJung-uk Kimof the certificate in the message. The first certificate is always the end
130e71b7053SJung-uk Kimentity certificate and has a B<chainidx> value of 0. The certificates are in the
131e71b7053SJung-uk Kimorder that they were received in the Certificate message.
132e71b7053SJung-uk Kim
133e71b7053SJung-uk KimFor all messages except the ServerHello and EncryptedExtensions every
134e71b7053SJung-uk Kimregistered B<add_cb> is always called to see if the application wishes to add an
135e71b7053SJung-uk Kimextension (as long as all requirements of the specified B<context> are met).
136e71b7053SJung-uk Kim
137e71b7053SJung-uk KimFor the ServerHello and EncryptedExtension messages every registered B<add_cb>
138e71b7053SJung-uk Kimis called once if and only if the requirements of the specified B<context> are
139e71b7053SJung-uk Kimmet and the corresponding extension was received in the ClientHello. That is, if
140e71b7053SJung-uk Kimno corresponding extension was received in the ClientHello then B<add_cb> will
141e71b7053SJung-uk Kimnot be called.
142e71b7053SJung-uk Kim
143e71b7053SJung-uk KimIf an extension is added (that is B<add_cb> returns 1) B<free_cb> is called
144e71b7053SJung-uk Kim(if it is set) with the value of B<out> set by the add callback. It can be
145e71b7053SJung-uk Kimused to free up any dynamic extension data set by B<add_cb>. Since B<out> is
146e71b7053SJung-uk Kimconstant (to permit use of constant data in B<add_cb>) applications may need to
147e71b7053SJung-uk Kimcast away const to free the data.
148e71b7053SJung-uk Kim
149e71b7053SJung-uk KimThe callback B<parse_cb> receives data for TLS extensions. The callback is only
150e71b7053SJung-uk Kimcalled if the extension is present and relevant for the context (see
151e71b7053SJung-uk KimL</EXTENSION CONTEXTS> below).
152e71b7053SJung-uk Kim
153e71b7053SJung-uk KimThe extension data consists of B<inlen> bytes in the buffer B<in> for the
154e71b7053SJung-uk Kimextension B<ext_type>.
155e71b7053SJung-uk Kim
156e71b7053SJung-uk KimIf the message being parsed is a TLSv1.3 compatible Certificate message then
157e71b7053SJung-uk KimB<parse_cb> will be called for each certificate contained within the message.
158e71b7053SJung-uk KimThe B<x> parameter will indicate the current certificate and the B<chainidx>
159e71b7053SJung-uk Kimparameter will indicate the position of the certificate in the message. The
160e71b7053SJung-uk Kimfirst certificate is always the end entity certificate and has a B<chainidx>
161e71b7053SJung-uk Kimvalue of 0.
162e71b7053SJung-uk Kim
163e71b7053SJung-uk KimIf the B<parse_cb> considers the extension data acceptable it must return
164e71b7053SJung-uk Kim1. If it returns 0 or a negative value a fatal handshake error occurs
165e71b7053SJung-uk Kimusing the TLS alert value specified in B<*al>.
166e71b7053SJung-uk Kim
167e71b7053SJung-uk KimThe buffer B<in> is a temporary internal buffer which will not be valid after
168e71b7053SJung-uk Kimthe callback returns.
169e71b7053SJung-uk Kim
170e71b7053SJung-uk Kim=head1 EXTENSION CONTEXTS
171e71b7053SJung-uk Kim
172e71b7053SJung-uk KimAn extension context defines which messages and under which conditions an
173e71b7053SJung-uk Kimextension should be added or expected. The context is built up by performing
174e71b7053SJung-uk Kima bitwise OR of multiple pre-defined values together. The valid context values
175e71b7053SJung-uk Kimare:
176e71b7053SJung-uk Kim
177e71b7053SJung-uk Kim=over 4
178e71b7053SJung-uk Kim
179e71b7053SJung-uk Kim=item SSL_EXT_TLS_ONLY
180e71b7053SJung-uk Kim
181e71b7053SJung-uk KimThe extension is only allowed in TLS
182e71b7053SJung-uk Kim
183e71b7053SJung-uk Kim=item SSL_EXT_DTLS_ONLY
184e71b7053SJung-uk Kim
185e71b7053SJung-uk KimThe extension is only allowed in DTLS
186e71b7053SJung-uk Kim
187e71b7053SJung-uk Kim=item SSL_EXT_TLS_IMPLEMENTATION_ONLY
188e71b7053SJung-uk Kim
189e71b7053SJung-uk KimThe extension is allowed in DTLS, but there is only a TLS implementation
190e71b7053SJung-uk Kimavailable (so it is ignored in DTLS).
191e71b7053SJung-uk Kim
192e71b7053SJung-uk Kim=item SSL_EXT_SSL3_ALLOWED
193e71b7053SJung-uk Kim
194e71b7053SJung-uk KimExtensions are not typically defined for SSLv3. Setting this value will allow
195e71b7053SJung-uk Kimthe extension in SSLv3. Applications will not typically need to use this.
196e71b7053SJung-uk Kim
197e71b7053SJung-uk Kim=item SSL_EXT_TLS1_2_AND_BELOW_ONLY
198e71b7053SJung-uk Kim
199e71b7053SJung-uk KimThe extension is only defined for TLSv1.2/DTLSv1.2 and below. Servers will
200e71b7053SJung-uk Kimignore this extension if it is present in the ClientHello and TLSv1.3 is
201e71b7053SJung-uk Kimnegotiated.
202e71b7053SJung-uk Kim
203e71b7053SJung-uk Kim=item SSL_EXT_TLS1_3_ONLY
204e71b7053SJung-uk Kim
205e71b7053SJung-uk KimThe extension is only defined for TLS1.3 and above. Servers will ignore this
206e71b7053SJung-uk Kimextension if it is present in the ClientHello and TLSv1.2 or below is
207e71b7053SJung-uk Kimnegotiated.
208e71b7053SJung-uk Kim
209e71b7053SJung-uk Kim=item SSL_EXT_IGNORE_ON_RESUMPTION
210e71b7053SJung-uk Kim
211e71b7053SJung-uk KimThe extension will be ignored during parsing if a previous session is being
212e71b7053SJung-uk Kimsuccessfully resumed.
213e71b7053SJung-uk Kim
214e71b7053SJung-uk Kim=item SSL_EXT_CLIENT_HELLO
215e71b7053SJung-uk Kim
216e71b7053SJung-uk KimThe extension may be present in the ClientHello message.
217e71b7053SJung-uk Kim
218e71b7053SJung-uk Kim=item SSL_EXT_TLS1_2_SERVER_HELLO
219e71b7053SJung-uk Kim
220e71b7053SJung-uk KimThe extension may be present in a TLSv1.2 or below compatible ServerHello
221e71b7053SJung-uk Kimmessage.
222e71b7053SJung-uk Kim
223e71b7053SJung-uk Kim=item SSL_EXT_TLS1_3_SERVER_HELLO
224e71b7053SJung-uk Kim
225e71b7053SJung-uk KimThe extension may be present in a TLSv1.3 compatible ServerHello message.
226e71b7053SJung-uk Kim
227e71b7053SJung-uk Kim=item SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS
228e71b7053SJung-uk Kim
229e71b7053SJung-uk KimThe extension may be present in an EncryptedExtensions message.
230e71b7053SJung-uk Kim
231e71b7053SJung-uk Kim=item SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST
232e71b7053SJung-uk Kim
233e71b7053SJung-uk KimThe extension may be present in a HelloRetryRequest message.
234e71b7053SJung-uk Kim
235e71b7053SJung-uk Kim=item SSL_EXT_TLS1_3_CERTIFICATE
236e71b7053SJung-uk Kim
237e71b7053SJung-uk KimThe extension may be present in a TLSv1.3 compatible Certificate message.
238e71b7053SJung-uk Kim
239e71b7053SJung-uk Kim=item SSL_EXT_TLS1_3_NEW_SESSION_TICKET
240e71b7053SJung-uk Kim
241e71b7053SJung-uk KimThe extension may be present in a TLSv1.3 compatible NewSessionTicket message.
242e71b7053SJung-uk Kim
243e71b7053SJung-uk Kim=item SSL_EXT_TLS1_3_CERTIFICATE_REQUEST
244e71b7053SJung-uk Kim
245e71b7053SJung-uk KimThe extension may be present in a TLSv1.3 compatible CertificateRequest message.
246e71b7053SJung-uk Kim
247e71b7053SJung-uk Kim=back
248e71b7053SJung-uk Kim
249e71b7053SJung-uk KimThe context must include at least one message value (otherwise the extension
250e71b7053SJung-uk Kimwill never be used).
251e71b7053SJung-uk Kim
252e71b7053SJung-uk Kim=head1 NOTES
253e71b7053SJung-uk Kim
254e71b7053SJung-uk KimThe B<add_arg> and B<parse_arg> parameters can be set to arbitrary values
255e71b7053SJung-uk Kimwhich will be passed to the corresponding callbacks. They can, for example,
256e71b7053SJung-uk Kimbe used to store the extension data received in a convenient structure or
257e71b7053SJung-uk Kimpass the extension data to be added or freed when adding extensions.
258e71b7053SJung-uk Kim
259e71b7053SJung-uk KimIf the same custom extension type is received multiple times a fatal
260e71b7053SJung-uk KimB<decode_error> alert is sent and the handshake aborts. If a custom extension
261e71b7053SJung-uk Kimis received in a ServerHello/EncryptedExtensions message which was not sent in
262e71b7053SJung-uk Kimthe ClientHello a fatal B<unsupported_extension> alert is sent and the
263e71b7053SJung-uk Kimhandshake is aborted. The ServerHello/EncryptedExtensions B<add_cb> callback is
264e71b7053SJung-uk Kimonly called if the corresponding extension was received in the ClientHello. This
265e71b7053SJung-uk Kimis compliant with the TLS specifications. This behaviour ensures that each
266e71b7053SJung-uk Kimcallback is called at most once and that an application can never send
267e71b7053SJung-uk Kimunsolicited extensions.
268e71b7053SJung-uk Kim
269e71b7053SJung-uk Kim=head1 RETURN VALUES
270e71b7053SJung-uk Kim
271e71b7053SJung-uk KimSSL_CTX_add_custom_ext(), SSL_CTX_add_client_custom_ext() and
272e71b7053SJung-uk KimSSL_CTX_add_server_custom_ext() return 1 for success and 0 for failure. A
273e71b7053SJung-uk Kimfailure can occur if an attempt is made to add the same B<ext_type> more than
274e71b7053SJung-uk Kimonce, if an attempt is made to use an extension type handled internally by
275e71b7053SJung-uk KimOpenSSL or if an internal error occurs (for example a memory allocation
276e71b7053SJung-uk Kimfailure).
277e71b7053SJung-uk Kim
278e71b7053SJung-uk KimSSL_extension_supported() returns 1 if the extension B<ext_type> is handled
279e71b7053SJung-uk Kiminternally by OpenSSL and 0 otherwise.
280e71b7053SJung-uk Kim
281*b077aed3SPierre Pronchery=head1 SEE ALSO
282*b077aed3SPierre Pronchery
283*b077aed3SPierre ProncheryL<ssl(7)>
284*b077aed3SPierre Pronchery
285e71b7053SJung-uk Kim=head1 HISTORY
286e71b7053SJung-uk Kim
2876935a639SJung-uk KimThe SSL_CTX_add_custom_ext() function was added in OpenSSL 1.1.1.
288e71b7053SJung-uk Kim
289e71b7053SJung-uk Kim=head1 COPYRIGHT
290e71b7053SJung-uk Kim
291*b077aed3SPierre ProncheryCopyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved.
292e71b7053SJung-uk Kim
293*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
294e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
295e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
296e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
297e71b7053SJung-uk Kim
298e71b7053SJung-uk Kim=cut
299