2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "../ssl_locl.h"
11 #include "statem_locl.h"
13 static int tls_ext_final_renegotiate(SSL *s, unsigned int context, int sent,
15 static int tls_ext_init_server_name(SSL *s, unsigned int context);
16 static int tls_ext_final_server_name(SSL *s, unsigned int context, int sent,
18 static int tls_ext_init_status_request(SSL *s, unsigned int context);
19 #ifndef OPENSSL_NO_NEXTPROTONEG
20 static int tls_ext_init_npn(SSL *s, unsigned int context);
22 static int tls_ext_init_alpn(SSL *s, unsigned int context);
23 static int tls_ext_final_alpn(SSL *s, unsigned int context, int sent, int *al);
24 static int tls_ext_init_sig_algs(SSL *s, unsigned int context);
25 #ifndef OPENSSL_NO_SRP
26 static int tls_ext_init_srp(SSL *s, unsigned int context);
28 static int tls_ext_init_etm(SSL *s, unsigned int context);
29 #ifndef OPENSSL_NO_SRTP
30 static int tls_ext_init_srtp(SSL *s, unsigned int context);
33 /* Structure to define a built-in extension */
35 /* The ID for the extension */
38 * Initialise extension before parsing. Always called for relevant contexts
39 * even if extension not present
41 int (*init_ext)(SSL *s, unsigned int context);
42 /* Parse extension received by server from client */
43 int (*parse_client_ext)(SSL *s, PACKET *pkt, int *al);
44 /* Parse extension received by client from server */
45 int (*parse_server_ext)(SSL *s, PACKET *pkt, int *al);
46 /* Construct extension sent by server */
47 int (*construct_server_ext)(SSL *s, WPACKET *pkt, int *al);
48 /* Construct extension sent by client */
49 int (*construct_client_ext)(SSL *s, WPACKET *pkt, int *al);
51 * Finalise extension after parsing. Always called where an extensions was
52 * initialised even if the extension was not present. |sent| is set to 1 if
53 * the extension was seen, or 0 otherwise.
55 int (*finalise_ext)(SSL *s, unsigned int context, int sent, int *al);
57 } EXTENSION_DEFINITION;
60 * Definitions of all built-in extensions. NOTE: Changes in the number or order
61 * of these extensions should be mirrored with equivalent changes to the indexes
62 * defined in statem_locl.h.
63 * Each extension has an initialiser, a client and
64 * server side parser and a finaliser. The initialiser is called (if the
65 * extension is relevant to the given context) even if we did not see the
66 * extension in the message that we received. The parser functions are only
67 * called if we see the extension in the message. The finalisers are always
68 * called if the initialiser was called.
69 * There are also server and client side constructor functions which are always
70 * called during message construction if the extension is relevant for the
72 * The initialisation, parsing, finalisation and construction functions are
73 * always called in the order defined in this list. Some extensions may depend
74 * on others having been processed first, so the order of this list is
76 * The extension context is defined by a series of flags which specify which
77 * messages the extension is relevant to. These flags also specify whether the
78 * extension is relevant to a paricular protocol or protocol version.
80 * TODO(TLS1.3): Make sure we have a test to check the consistency of these
82 static const EXTENSION_DEFINITION ext_defs[] = {
84 TLSEXT_TYPE_renegotiate,
86 tls_parse_client_renegotiate,
87 tls_parse_server_renegotiate,
88 tls_construct_server_renegotiate,
89 tls_construct_client_renegotiate,
90 tls_ext_final_renegotiate,
91 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_SSL3_ALLOWED
92 | EXT_TLS1_2_AND_BELOW_ONLY
95 TLSEXT_TYPE_server_name,
96 tls_ext_init_server_name,
97 tls_parse_client_server_name,
98 tls_parse_server_server_name,
99 tls_construct_server_server_name,
100 tls_construct_client_server_name,
101 tls_ext_final_server_name,
102 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
103 | EXT_TLS1_3_ENCRYPTED_EXTENSIONS
105 #ifndef OPENSSL_NO_SRP
109 tls_parse_client_srp,
112 tls_construct_client_srp,
114 EXT_CLIENT_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
117 #ifndef OPENSSL_NO_EC
119 TLSEXT_TYPE_ec_point_formats,
121 tls_parse_client_ec_pt_formats,
122 tls_parse_server_ec_pt_formats,
123 tls_construct_server_ec_pt_formats,
124 tls_construct_client_ec_pt_formats,
126 EXT_CLIENT_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
129 TLSEXT_TYPE_supported_groups,
131 tls_parse_client_supported_groups,
133 NULL /* TODO(TLS1.3): Need to add this */,
134 tls_construct_client_supported_groups,
136 EXT_CLIENT_HELLO | EXT_TLS1_3_ENCRYPTED_EXTENSIONS
140 TLSEXT_TYPE_session_ticket,
142 tls_parse_client_session_ticket,
143 tls_parse_server_session_ticket,
144 tls_construct_server_session_ticket,
145 tls_construct_client_session_ticket,
147 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
150 TLSEXT_TYPE_signature_algorithms,
151 tls_ext_init_sig_algs,
152 tls_parse_client_sig_algs,
155 tls_construct_client_sig_algs,
159 #ifndef OPENSSL_NO_OCSP
161 TLSEXT_TYPE_status_request,
162 tls_ext_init_status_request,
163 tls_parse_client_status_request,
164 tls_parse_server_status_request,
165 tls_construct_server_status_request,
166 tls_construct_client_status_request,
168 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
169 | EXT_TLS1_3_CERTIFICATE
172 #ifndef OPENSSL_NO_NEXTPROTONEG
174 TLSEXT_TYPE_next_proto_neg,
176 tls_parse_client_npn,
177 tls_parse_server_npn,
178 tls_construct_server_next_proto_neg,
179 tls_construct_client_npn,
181 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
186 * Must appear in this list after server_name so that finalisation
187 * happens after server_name callbacks
189 TLSEXT_TYPE_application_layer_protocol_negotiation,
191 tls_parse_client_alpn,
192 tls_parse_server_alpn,
193 tls_construct_server_alpn,
194 tls_construct_client_alpn,
196 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
197 | EXT_TLS1_3_ENCRYPTED_EXTENSIONS
199 #ifndef OPENSSL_NO_SRTP
201 TLSEXT_TYPE_use_srtp,
203 tls_parse_client_use_srtp,
204 tls_parse_server_use_srtp,
205 tls_construct_server_use_srtp,
206 tls_construct_client_use_srtp,
208 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
209 | EXT_TLS1_3_ENCRYPTED_EXTENSIONS | EXT_DTLS_ONLY
213 TLSEXT_TYPE_encrypt_then_mac,
215 tls_parse_client_etm,
216 tls_parse_server_etm,
217 tls_construct_server_etm,
218 tls_construct_client_etm,
220 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
222 #ifndef OPENSSL_NO_CT
224 TLSEXT_TYPE_signed_certificate_timestamp,
227 * No server side support for this, but can be provided by a custom
228 * extension. This is an exception to the rule that custom extensions
229 * cannot override built in ones.
232 tls_parse_server_sct,
234 tls_construct_client_sct,
236 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
237 | EXT_TLS1_3_CERTIFICATE
241 TLSEXT_TYPE_extended_master_secret,
243 tls_parse_client_ems,
244 tls_parse_server_ems,
245 tls_construct_server_ems,
246 tls_construct_client_ems,
248 EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
251 TLSEXT_TYPE_supported_versions,
253 /* Processed inline as part of version selection */
257 tls_construct_client_supported_versions,
259 EXT_CLIENT_HELLO | EXT_TLS_IMPLEMENTATION_ONLY | EXT_TLS1_3_ONLY
263 * Must be in this list after supported_groups. We need that to have
264 * been parsed before we do this one.
266 TLSEXT_TYPE_key_share,
268 tls_parse_client_key_share,
269 tls_parse_server_key_share,
270 tls_construct_server_key_share,
271 tls_construct_client_key_share,
273 EXT_CLIENT_HELLO | EXT_TLS1_3_SERVER_HELLO
274 | EXT_TLS1_3_HELLO_RETRY_REQUEST | EXT_TLS_IMPLEMENTATION_ONLY
279 * Special unsolicited ServerHello extension only used when
280 * SSL_OP_CRYPTOPRO_TLSEXT_BUG is set
282 TLSEXT_TYPE_cryptopro_bug,
286 tls_construct_server_cryptopro_bug,
289 EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
292 /* Last in the list because it must be added as the last extension */
295 /* We send this, but don't read it */
299 tls_construct_client_padding,
306 * Verify whether we are allowed to use the extension |type| in the current
307 * |context|. Returns 1 to indicate the extension is allowed or unknown or 0 to
308 * indicate the extension is not allowed. If returning 1 then |*found| is set to
309 * 1 if we found a definition for the extension, and |*idx| is set to its index
311 static int verify_extension(SSL *s, unsigned int context, unsigned int type,
312 custom_ext_methods *meths, int *found, size_t *idx)
315 size_t builtin_num = OSSL_NELEM(ext_defs);
317 for (i = 0; i < builtin_num; i++) {
318 if (type == ext_defs[i].type) {
319 /* Check we're allowed to use this extension in this context */
320 if ((context & ext_defs[i].context) == 0)
323 if (SSL_IS_DTLS(s)) {
324 if ((ext_defs[i].context & EXT_TLS_ONLY) != 0)
326 } else if ((ext_defs[i].context & EXT_DTLS_ONLY) != 0) {
336 if ((context & (EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO)) == 0) {
338 * Custom extensions only apply to <=TLS1.2. This extension is unknown
339 * in this context - we allow it
345 /* Check the custom extensions */
347 for (i = builtin_num; i < builtin_num + meths->meths_count; i++) {
348 if (meths->meths[i - builtin_num].ext_type == type) {
356 /* Unknown extension. We allow it */
362 * Check whether the context defined for an extension |extctx| means whether
363 * the extension is relevant for the current context |thisctx| or not. Returns
364 * 1 if the extension is relevant for this context, and 0 otherwise
366 static int extension_is_relevant(SSL *s, unsigned int extctx,
367 unsigned int thisctx)
370 && (extctx & EXT_TLS_IMPLEMENTATION_ONLY) != 0)
371 || (s->version == SSL3_VERSION
372 && (extctx & EXT_SSL3_ALLOWED) == 0)
374 && (extctx & EXT_TLS1_2_AND_BELOW_ONLY) != 0)
375 || (!SSL_IS_TLS13(s) && (extctx & EXT_TLS1_3_ONLY) != 0))
382 * Gather a list of all the extensions from the data in |packet]. |context|
383 * tells us which message this extension is for. The raw extension data is
384 * stored in |*res|. In the event of an error the alert type to use is stored in
385 * |*al|. We don't actually process the content of the extensions yet, except to
386 * check their types. This function also runs the initialiser functions for all
387 * known extensions (whether we have collected them or not).
389 * Per http://tools.ietf.org/html/rfc5246#section-7.4.1.4, there may not be
390 * more than one extension of the same type in a ClientHello or ServerHello.
391 * This function returns 1 if all extensions are unique and we have parsed their
392 * types, and 0 if the extensions contain duplicates, could not be successfully
393 * collected, or an internal error occurred. We only check duplicates for
394 * extensions that we know about. We ignore others.
396 int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
397 RAW_EXTENSION **res, int *al)
399 PACKET extensions = *packet;
402 custom_ext_methods *exts = NULL;
403 RAW_EXTENSION *raw_extensions = NULL;
406 * Initialise server side custom extensions. Client side is done during
407 * construction of extensions for the ClientHello.
409 if ((context & EXT_CLIENT_HELLO) != 0) {
410 exts = &s->cert->srv_ext;
411 custom_ext_init(&s->cert->srv_ext);
412 } else if ((context & EXT_TLS1_2_SERVER_HELLO) != 0) {
413 exts = &s->cert->cli_ext;
416 raw_extensions = OPENSSL_zalloc((OSSL_NELEM(ext_defs)
417 + (exts != NULL ? exts->meths_count : 0))
418 * sizeof(RAW_EXTENSION));
419 if (raw_extensions == NULL) {
420 *al = SSL_AD_INTERNAL_ERROR;
421 SSLerr(SSL_F_TLS_COLLECT_EXTENSIONS, ERR_R_MALLOC_FAILURE);
425 while (PACKET_remaining(&extensions) > 0) {
429 if (!PACKET_get_net_2(&extensions, &type) ||
430 !PACKET_get_length_prefixed_2(&extensions, &extension)) {
431 SSLerr(SSL_F_TLS_COLLECT_EXTENSIONS, SSL_R_BAD_EXTENSION);
432 *al = SSL_AD_DECODE_ERROR;
436 * Verify this extension is allowed. We only check duplicates for
437 * extensions that we recognise.
439 if (!verify_extension(s, context, type, exts, &found, &idx)
441 && raw_extensions[idx].present == 1)) {
442 SSLerr(SSL_F_TLS_COLLECT_EXTENSIONS, SSL_R_BAD_EXTENSION);
443 *al = SSL_AD_ILLEGAL_PARAMETER;
447 raw_extensions[idx].data = extension;
448 raw_extensions[idx].present = 1;
449 raw_extensions[idx].type = type;
454 * Initialise all known extensions relevant to this context, whether we have
457 for (i = 0; i < OSSL_NELEM(ext_defs); i++) {
458 if(ext_defs[i].init_ext != NULL && (ext_defs[i].context & context) != 0
459 && extension_is_relevant(s, ext_defs[i].context, context)
460 && !ext_defs[i].init_ext(s, context)) {
461 *al = SSL_AD_INTERNAL_ERROR;
466 *res = raw_extensions;
470 OPENSSL_free(raw_extensions);
475 * Runs the parser for a given extension with index |idx|. |exts| contains the
476 * list of all parsed extensions previously collected by
477 * tls_collect_extensions(). The parser is only run if it is applicable for the
478 * given |context| and the parser has not already been run. Returns 1 on success
479 * or 0 on failure. In the event of a failure |*al| is populated with a suitable
480 * alert code. If an extension is not present this counted as success.
482 int tls_parse_extension(SSL *s, unsigned int idx, int context,
483 RAW_EXTENSION *exts, int *al)
485 RAW_EXTENSION *currext = &exts[idx];
486 int (*parser)(SSL *s, PACKET *pkt, int *al) = NULL;
488 /* Skip if the extension is not present */
489 if (!currext->present)
492 if (s->tlsext_debug_cb)
493 s->tlsext_debug_cb(s, !s->server, currext->type,
494 PACKET_data(&currext->data),
495 PACKET_remaining(&currext->data),
496 s->tlsext_debug_arg);
498 /* Skip if we've already parsed this extension */
504 if (idx < OSSL_NELEM(ext_defs)) {
505 /* We are handling a built-in extension */
506 const EXTENSION_DEFINITION *extdef = &ext_defs[idx];
508 /* Check if extension is defined for our protocol. If not, skip */
509 if (!extension_is_relevant(s, extdef->context, context))
512 parser = s->server ? extdef->parse_client_ext : extdef->parse_server_ext;
514 if (parser != NULL) {
515 if (!parser(s, &currext->data, al))
522 * If the parser is NULL we fall through to the custom extension
528 * This is a custom extension. We only allow this if it is a non
529 * resumed session on the server side.
531 * TODO(TLS1.3): We only allow old style <=TLS1.2 custom extensions.
532 * We're going to need a new mechanism for TLS1.3 to specify which
533 * messages to add the custom extensions to.
535 if ((!s->hit || !s->server)
537 & (EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO)) != 0
538 && custom_ext_parse(s, s->server, currext->type,
539 PACKET_data(&currext->data),
540 PACKET_remaining(&currext->data),
548 * Parse all remaining extensions that have not yet been parsed. Also calls the
549 * finalisation for all extensions at the end, whether we collected them or not.
550 * Returns 1 for success or 0 for failure. On failure, |*al| is populated with a
551 * suitable alert code.
553 int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al)
555 size_t loop, numexts = OSSL_NELEM(ext_defs);
557 /* Calculate the number of extensions in the extensions list */
558 if ((context & EXT_CLIENT_HELLO) != 0) {
559 numexts += s->cert->srv_ext.meths_count;
560 } else if ((context & EXT_TLS1_2_SERVER_HELLO) != 0) {
561 numexts += s->cert->cli_ext.meths_count;
564 /* Parse each extension in turn */
565 for (loop = 0; loop < numexts; loop++) {
566 if (!tls_parse_extension(s, loop, context, exts, al))
571 * Finalise all known extensions relevant to this context, whether we have
574 for (loop = 0; loop < OSSL_NELEM(ext_defs); loop++) {
575 if(ext_defs[loop].finalise_ext != NULL
576 && (ext_defs[loop].context & context) != 0
577 && !ext_defs[loop].finalise_ext(s, context, exts[loop].present,
586 * Construct all the extensions relevant to the current |context| and write
587 * them to |pkt|. Returns 1 on success or 0 on failure. If a failure occurs then
588 * |al| is populated with a suitable alert code.
590 int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context,
595 int min_version, max_version = 0, reason, tmpal;
598 * Normally if something goes wrong during construction it's an internal
599 * error. We can always override this later.
601 tmpal = SSL_AD_INTERNAL_ERROR;
603 if (!WPACKET_start_sub_packet_u16(pkt)
605 * If extensions are of zero length then we don't even add the
606 * extensions length bytes to a ClientHello/ServerHello in SSLv3
608 || ((context & (EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO)) != 0
609 && s->version == SSL3_VERSION
610 && !WPACKET_set_flags(pkt,
611 WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH))) {
612 SSLerr(SSL_F_TLS_CONSTRUCT_EXTENSIONS, ERR_R_INTERNAL_ERROR);
616 if ((context & EXT_CLIENT_HELLO) != 0) {
617 reason = ssl_get_client_min_max_version(s, &min_version, &max_version);
619 SSLerr(SSL_F_TLS_CONSTRUCT_EXTENSIONS, reason);
624 /* Add custom extensions first */
625 if ((context & EXT_CLIENT_HELLO) != 0) {
626 custom_ext_init(&s->cert->cli_ext);
628 } else if ((context & EXT_TLS1_2_SERVER_HELLO) != 0) {
630 * We already initialised the custom extensions during ClientHello
633 * TODO(TLS1.3): We're going to need a new custom extension mechanism
634 * for TLS1.3, so that custom extensions can specify which of the
635 * multiple message they wish to add themselves to.
640 if (addcustom && !custom_ext_add(s, s->server, pkt, &tmpal)) {
641 SSLerr(SSL_F_TLS_CONSTRUCT_EXTENSIONS, ERR_R_INTERNAL_ERROR);
645 for (loop = 0; loop < OSSL_NELEM(ext_defs); loop++) {
646 int (*construct)(SSL *s, WPACKET *pkt, int *al);
648 /* Skip if not relevant for our context */
649 if ((ext_defs[loop].context & context) == 0)
652 construct = s->server ? ext_defs[loop].construct_server_ext
653 : ext_defs[loop].construct_client_ext;
655 /* Check if this extension is defined for our protocol. If not, skip */
657 && (ext_defs[loop].context & EXT_TLS_IMPLEMENTATION_ONLY)
659 || (s->version == SSL3_VERSION
660 && (ext_defs[loop].context & EXT_SSL3_ALLOWED) == 0)
662 && (ext_defs[loop].context & EXT_TLS1_2_AND_BELOW_ONLY)
665 && (ext_defs[loop].context & EXT_TLS1_3_ONLY) != 0
666 && (context & EXT_CLIENT_HELLO) == 0)
667 || ((ext_defs[loop].context & EXT_TLS1_3_ONLY) != 0
668 && (context & EXT_CLIENT_HELLO) != 0
669 && (SSL_IS_DTLS(s) || max_version < TLS1_3_VERSION))
670 || construct == NULL)
673 if (!construct(s, pkt, &tmpal))
677 if (!WPACKET_close(pkt)) {
678 SSLerr(SSL_F_TLS_CONSTRUCT_EXTENSIONS, ERR_R_INTERNAL_ERROR);
690 * Built in extension finalisation and initialisation functions. All initialise
691 * or finalise the associated extension type for the given |context|. For
692 * finalisers |sent| is set to 1 if we saw the extension during parsing, and 0
693 * otherwise. These functions return 1 on success or 0 on failure. In the event
694 * of a failure then |*al| is populated with a suitable error code.
697 static int tls_ext_final_renegotiate(SSL *s, unsigned int context, int sent,
703 /* Need RI if renegotiating */
705 && !(s->options & SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)
707 *al = SSL_AD_HANDSHAKE_FAILURE;
708 SSLerr(SSL_F_TLS_EXT_FINAL_RENEGOTIATE,
709 SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);
716 static int tls_ext_init_server_name(SSL *s, unsigned int context)
719 s->servername_done = 0;
724 static int tls_ext_final_server_name(SSL *s, unsigned int context, int sent,
727 int ret = SSL_TLSEXT_ERR_NOACK;
728 int altmp = SSL_AD_UNRECOGNIZED_NAME;
733 if (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0)
734 ret = s->ctx->tlsext_servername_callback(s, &altmp,
735 s->ctx->tlsext_servername_arg);
736 else if (s->initial_ctx != NULL
737 && s->initial_ctx->tlsext_servername_callback != 0)
738 ret = s->initial_ctx->tlsext_servername_callback(s, &altmp,
739 s->initial_ctx->tlsext_servername_arg);
742 case SSL_TLSEXT_ERR_ALERT_FATAL:
746 case SSL_TLSEXT_ERR_ALERT_WARNING:
750 case SSL_TLSEXT_ERR_NOACK:
751 s->servername_done = 0;
759 static int tls_ext_init_status_request(SSL *s, unsigned int context)
762 s->tlsext_status_type = -1;
767 #ifndef OPENSSL_NO_NEXTPROTONEG
768 static int tls_ext_init_npn(SSL *s, unsigned int context)
771 s->s3->next_proto_neg_seen = 0;
777 static int tls_ext_init_alpn(SSL *s, unsigned int context)
780 OPENSSL_free(s->s3->alpn_selected);
781 s->s3->alpn_selected = NULL;
782 s->s3->alpn_selected_len = 0;
783 OPENSSL_free(s->s3->alpn_proposed);
784 s->s3->alpn_proposed = NULL;
785 s->s3->alpn_proposed_len = 0;
791 static int tls_ext_final_alpn(SSL *s, unsigned int context, int sent, int *al)
793 const unsigned char *selected = NULL;
794 unsigned char selected_len = 0;
799 if (s->ctx->alpn_select_cb != NULL && s->s3->alpn_proposed != NULL) {
800 int r = s->ctx->alpn_select_cb(s, &selected, &selected_len,
801 s->s3->alpn_proposed,
802 (unsigned int)s->s3->alpn_proposed_len,
803 s->ctx->alpn_select_cb_arg);
805 if (r == SSL_TLSEXT_ERR_OK) {
806 OPENSSL_free(s->s3->alpn_selected);
807 s->s3->alpn_selected = OPENSSL_memdup(selected, selected_len);
808 if (s->s3->alpn_selected == NULL) {
809 *al = SSL_AD_INTERNAL_ERROR;
812 s->s3->alpn_selected_len = selected_len;
813 #ifndef OPENSSL_NO_NEXTPROTONEG
814 /* ALPN takes precedence over NPN. */
815 s->s3->next_proto_neg_seen = 0;
818 *al = SSL_AD_NO_APPLICATION_PROTOCOL;
826 static int tls_ext_init_sig_algs(SSL *s, unsigned int context)
828 /* Clear any signature algorithms extension received */
829 OPENSSL_free(s->s3->tmp.peer_sigalgs);
830 s->s3->tmp.peer_sigalgs = NULL;
835 #ifndef OPENSSL_NO_SRP
836 static int tls_ext_init_srp(SSL *s, unsigned int context)
838 OPENSSL_free(s->srp_ctx.login);
839 s->srp_ctx.login = NULL;
845 static int tls_ext_init_etm(SSL *s, unsigned int context)
848 s->s3->flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC;
853 #ifndef OPENSSL_NO_SRTP
854 static int tls_ext_init_srtp(SSL *s, unsigned int context)
857 s->srtp_profile = NULL;