1SSL_EXTENSION_SUPPORTED(3ossl)      OpenSSL     SSL_EXTENSION_SUPPORTED(3ossl)
2
3
4

NAME

6       SSL_extension_supported, SSL_custom_ext_add_cb_ex,
7       SSL_custom_ext_free_cb_ex, SSL_custom_ext_parse_cb_ex,
8       SSL_CTX_add_custom_ext, SSL_CTX_add_client_custom_ext,
9       SSL_CTX_add_server_custom_ext, custom_ext_add_cb, custom_ext_free_cb,
10       custom_ext_parse_cb - custom TLS extension handling
11

SYNOPSIS

13        #include <openssl/ssl.h>
14
15        typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type,
16                                                unsigned int context,
17                                                const unsigned char **out,
18                                                size_t *outlen, X509 *x,
19                                                size_t chainidx, int *al,
20                                                void *add_arg);
21
22        typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type,
23                                                  unsigned int context,
24                                                  const unsigned char *out,
25                                                  void *add_arg);
26
27        typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type,
28                                                  unsigned int context,
29                                                  const unsigned char *in,
30                                                  size_t inlen, X509 *x,
31                                                  size_t chainidx, int *al,
32                                                  void *parse_arg);
33
34        int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
35                                   unsigned int context,
36                                   SSL_custom_ext_add_cb_ex add_cb,
37                                   SSL_custom_ext_free_cb_ex free_cb,
38                                   void *add_arg,
39                                   SSL_custom_ext_parse_cb_ex parse_cb,
40                                   void *parse_arg);
41
42        typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type,
43                                         const unsigned char **out,
44                                         size_t *outlen, int *al,
45                                         void *add_arg);
46
47        typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type,
48                                           const unsigned char *out,
49                                           void *add_arg);
50
51        typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type,
52                                           const unsigned char *in,
53                                           size_t inlen, int *al,
54                                           void *parse_arg);
55
56        int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
57                                          custom_ext_add_cb add_cb,
58                                          custom_ext_free_cb free_cb, void *add_arg,
59                                          custom_ext_parse_cb parse_cb,
60                                          void *parse_arg);
61
62        int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
63                                          custom_ext_add_cb add_cb,
64                                          custom_ext_free_cb free_cb, void *add_arg,
65                                          custom_ext_parse_cb parse_cb,
66                                          void *parse_arg);
67
68        int SSL_extension_supported(unsigned int ext_type);
69

DESCRIPTION

71       SSL_CTX_add_custom_ext() adds a custom extension for a TLS/DTLS client
72       or server for all supported protocol versions with extension type
73       ext_type and callbacks add_cb, free_cb and parse_cb (see the "EXTENSION
74       CALLBACKS" section below). The context value determines which messages
75       and under what conditions the extension will be added/parsed (see the
76       "EXTENSION CONTEXTS" section below).
77
78       SSL_CTX_add_client_custom_ext() adds a custom extension for a TLS/DTLS
79       client with extension type ext_type and callbacks add_cb, free_cb and
80       parse_cb. This function is similar to SSL_CTX_add_custom_ext() except
81       it only applies to clients, uses the older style of callbacks, and
82       implicitly sets the context value to:
83
84        SSL_EXT_TLS1_2_AND_BELOW_ONLY | SSL_EXT_CLIENT_HELLO
85        | SSL_EXT_TLS1_2_SERVER_HELLO | SSL_EXT_IGNORE_ON_RESUMPTION
86
87       SSL_CTX_add_server_custom_ext() adds a custom extension for a TLS/DTLS
88       server with extension type ext_type and callbacks add_cb, free_cb and
89       parse_cb. This function is similar to SSL_CTX_add_custom_ext() except
90       it only applies to servers, uses the older style of callbacks, and
91       implicitly sets the context value to the same as for
92       SSL_CTX_add_client_custom_ext() above.
93
94       The ext_type parameter corresponds to the extension_type field of
95       RFC5246 et al. It is not a NID. In all cases the extension type must
96       not be handled by OpenSSL internally or an error occurs.
97
98       SSL_extension_supported() returns 1 if the extension ext_type is
99       handled internally by OpenSSL and 0 otherwise.
100

EXTENSION CALLBACKS

102       The callback add_cb is called to send custom extension data to be
103       included in various TLS messages. The ext_type parameter is set to the
104       extension type which will be added and add_arg to the value set when
105       the extension handler was added. When using the new style callbacks the
106       context parameter will indicate which message is currently being
107       constructed e.g. for the ClientHello it will be set to
108       SSL_EXT_CLIENT_HELLO.
109
110       If the application wishes to include the extension ext_type it should
111       set *out to the extension data, set *outlen to the length of the
112       extension data and return 1.
113
114       If the add_cb does not wish to include the extension it must return 0.
115
116       If add_cb returns -1 a fatal handshake error occurs using the TLS alert
117       value specified in *al.
118
119       When constructing the ClientHello, if add_cb is set to NULL a zero
120       length extension is added for ext_type. For all other messages if
121       add_cb is set to NULL then no extension is added.
122
123       When constructing a Certificate message the callback will be called for
124       each certificate in the message. The x parameter will indicate the
125       current certificate and the chainidx parameter will indicate the
126       position of the certificate in the message. The first certificate is
127       always the end entity certificate and has a chainidx value of 0. The
128       certificates are in the order that they were received in the
129       Certificate message.
130
131       For all messages except the ServerHello and EncryptedExtensions every
132       registered add_cb is always called to see if the application wishes to
133       add an extension (as long as all requirements of the specified context
134       are met).
135
136       For the ServerHello and EncryptedExtension messages every registered
137       add_cb is called once if and only if the requirements of the specified
138       context are met and the corresponding extension was received in the
139       ClientHello. That is, if no corresponding extension was received in the
140       ClientHello then add_cb will not be called.
141
142       If an extension is added (that is add_cb returns 1) free_cb is called
143       (if it is set) with the value of out set by the add callback. It can be
144       used to free up any dynamic extension data set by add_cb. Since out is
145       constant (to permit use of constant data in add_cb) applications may
146       need to cast away const to free the data.
147
148       The callback parse_cb receives data for TLS extensions. The callback is
149       only called if the extension is present and relevant for the context
150       (see "EXTENSION CONTEXTS" below).
151
152       The extension data consists of inlen bytes in the buffer in for the
153       extension ext_type.
154
155       If the message being parsed is a TLSv1.3 compatible Certificate message
156       then parse_cb will be called for each certificate contained within the
157       message.  The x parameter will indicate the current certificate and the
158       chainidx parameter will indicate the position of the certificate in the
159       message. The first certificate is always the end entity certificate and
160       has a chainidx value of 0.
161
162       If the parse_cb considers the extension data acceptable it must return
163       1. If it returns 0 or a negative value a fatal handshake error occurs
164       using the TLS alert value specified in *al.
165
166       The buffer in is a temporary internal buffer which will not be valid
167       after the callback returns.
168

EXTENSION CONTEXTS

170       An extension context defines which messages and under which conditions
171       an extension should be added or expected. The context is built up by
172       performing a bitwise OR of multiple pre-defined values together. The
173       valid context values are:
174
175       SSL_EXT_TLS_ONLY
176           The extension is only allowed in TLS
177
178       SSL_EXT_DTLS_ONLY
179           The extension is only allowed in DTLS
180
181       SSL_EXT_TLS_IMPLEMENTATION_ONLY
182           The extension is allowed in DTLS, but there is only a TLS
183           implementation available (so it is ignored in DTLS).
184
185       SSL_EXT_SSL3_ALLOWED
186           Extensions are not typically defined for SSLv3. Setting this value
187           will allow the extension in SSLv3. Applications will not typically
188           need to use this.
189
190       SSL_EXT_TLS1_2_AND_BELOW_ONLY
191           The extension is only defined for TLSv1.2/DTLSv1.2 and below.
192           Servers will ignore this extension if it is present in the
193           ClientHello and TLSv1.3 is negotiated.
194
195       SSL_EXT_TLS1_3_ONLY
196           The extension is only defined for TLS1.3 and above. Servers will
197           ignore this extension if it is present in the ClientHello and
198           TLSv1.2 or below is negotiated.
199
200       SSL_EXT_IGNORE_ON_RESUMPTION
201           The extension will be ignored during parsing if a previous session
202           is being successfully resumed.
203
204       SSL_EXT_CLIENT_HELLO
205           The extension may be present in the ClientHello message.
206
207       SSL_EXT_TLS1_2_SERVER_HELLO
208           The extension may be present in a TLSv1.2 or below compatible
209           ServerHello message.
210
211       SSL_EXT_TLS1_3_SERVER_HELLO
212           The extension may be present in a TLSv1.3 compatible ServerHello
213           message.
214
215       SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS
216           The extension may be present in an EncryptedExtensions message.
217
218       SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST
219           The extension may be present in a HelloRetryRequest message.
220
221       SSL_EXT_TLS1_3_CERTIFICATE
222           The extension may be present in a TLSv1.3 compatible Certificate
223           message.
224
225       SSL_EXT_TLS1_3_NEW_SESSION_TICKET
226           The extension may be present in a TLSv1.3 compatible
227           NewSessionTicket message.
228
229       SSL_EXT_TLS1_3_CERTIFICATE_REQUEST
230           The extension may be present in a TLSv1.3 compatible
231           CertificateRequest message.
232
233       The context must include at least one message value (otherwise the
234       extension will never be used).
235

NOTES

237       The add_arg and parse_arg parameters can be set to arbitrary values
238       which will be passed to the corresponding callbacks. They can, for
239       example, be used to store the extension data received in a convenient
240       structure or pass the extension data to be added or freed when adding
241       extensions.
242
243       If the same custom extension type is received multiple times a fatal
244       decode_error alert is sent and the handshake aborts. If a custom
245       extension is received in a ServerHello/EncryptedExtensions message
246       which was not sent in the ClientHello a fatal unsupported_extension
247       alert is sent and the handshake is aborted. The
248       ServerHello/EncryptedExtensions add_cb callback is only called if the
249       corresponding extension was received in the ClientHello. This is
250       compliant with the TLS specifications. This behaviour ensures that each
251       callback is called at most once and that an application can never send
252       unsolicited extensions.
253

RETURN VALUES

255       SSL_CTX_add_custom_ext(), SSL_CTX_add_client_custom_ext() and
256       SSL_CTX_add_server_custom_ext() return 1 for success and 0 for failure.
257       A failure can occur if an attempt is made to add the same ext_type more
258       than once, if an attempt is made to use an extension type handled
259       internally by OpenSSL or if an internal error occurs (for example a
260       memory allocation failure).
261
262       SSL_extension_supported() returns 1 if the extension ext_type is
263       handled internally by OpenSSL and 0 otherwise.
264

SEE ALSO

266       ssl(7)
267

HISTORY

269       The SSL_CTX_add_custom_ext() function was added in OpenSSL 1.1.1.
270
272       Copyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved.
273
274       Licensed under the Apache License 2.0 (the "License").  You may not use
275       this file except in compliance with the License.  You can obtain a copy
276       in the file LICENSE in the source distribution or at
277       <https://www.openssl.org/source/license.html>.
278
279
280
2813.1.1                             2023-08-31    SSL_EXTENSION_SUPPORTED(3ossl)
Impressum