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