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