Path: blob/main/crypto/openssl/ssl/statem/extensions.c
48266 views
/*1* Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#if defined(__TANDEM) && defined(_SPT_MODEL_)10# include <spthread.h>11# include <spt_extensions.h> /* timeval */12#endif1314#include <string.h>15#include "internal/nelem.h"16#include "internal/cryptlib.h"17#include "internal/ssl_unwrap.h"18#include "../ssl_local.h"19#include "statem_local.h"2021static int final_renegotiate(SSL_CONNECTION *s, unsigned int context, int sent);22static int init_server_name(SSL_CONNECTION *s, unsigned int context);23static int final_server_name(SSL_CONNECTION *s, unsigned int context, int sent);24static int final_ec_pt_formats(SSL_CONNECTION *s, unsigned int context,25int sent);26static int init_session_ticket(SSL_CONNECTION *s, unsigned int context);27#ifndef OPENSSL_NO_OCSP28static int init_status_request(SSL_CONNECTION *s, unsigned int context);29#endif30#ifndef OPENSSL_NO_NEXTPROTONEG31static int init_npn(SSL_CONNECTION *s, unsigned int context);32#endif33static int init_alpn(SSL_CONNECTION *s, unsigned int context);34static int final_alpn(SSL_CONNECTION *s, unsigned int context, int sent);35static int init_sig_algs_cert(SSL_CONNECTION *s, unsigned int context);36static int init_sig_algs(SSL_CONNECTION *s, unsigned int context);37static int init_server_cert_type(SSL_CONNECTION *sc, unsigned int context);38static int init_client_cert_type(SSL_CONNECTION *sc, unsigned int context);39static int init_certificate_authorities(SSL_CONNECTION *s,40unsigned int context);41static EXT_RETURN tls_construct_certificate_authorities(SSL_CONNECTION *s,42WPACKET *pkt,43unsigned int context,44X509 *x,45size_t chainidx);46static int tls_parse_certificate_authorities(SSL_CONNECTION *s, PACKET *pkt,47unsigned int context, X509 *x,48size_t chainidx);49#ifndef OPENSSL_NO_SRP50static int init_srp(SSL_CONNECTION *s, unsigned int context);51#endif52static int init_ec_point_formats(SSL_CONNECTION *s, unsigned int context);53static int init_etm(SSL_CONNECTION *s, unsigned int context);54static int init_ems(SSL_CONNECTION *s, unsigned int context);55static int final_ems(SSL_CONNECTION *s, unsigned int context, int sent);56static int init_psk_kex_modes(SSL_CONNECTION *s, unsigned int context);57static int final_key_share(SSL_CONNECTION *s, unsigned int context, int sent);58#ifndef OPENSSL_NO_SRTP59static int init_srtp(SSL_CONNECTION *s, unsigned int context);60#endif61static int final_sig_algs(SSL_CONNECTION *s, unsigned int context, int sent);62static int final_supported_versions(SSL_CONNECTION *s, unsigned int context,63int sent);64static int final_early_data(SSL_CONNECTION *s, unsigned int context, int sent);65static int final_maxfragmentlen(SSL_CONNECTION *s, unsigned int context,66int sent);67static int init_post_handshake_auth(SSL_CONNECTION *s, unsigned int context);68static int final_psk(SSL_CONNECTION *s, unsigned int context, int sent);69static int tls_init_compress_certificate(SSL_CONNECTION *sc, unsigned int context);70static EXT_RETURN tls_construct_compress_certificate(SSL_CONNECTION *sc, WPACKET *pkt,71unsigned int context,72X509 *x, size_t chainidx);73static int tls_parse_compress_certificate(SSL_CONNECTION *sc, PACKET *pkt,74unsigned int context,75X509 *x, size_t chainidx);7677/* Structure to define a built-in extension */78typedef struct extensions_definition_st {79/* The defined type for the extension */80unsigned int type;81/*82* The context that this extension applies to, e.g. what messages and83* protocol versions84*/85unsigned int context;86/*87* Initialise extension before parsing. Always called for relevant contexts88* even if extension not present89*/90int (*init)(SSL_CONNECTION *s, unsigned int context);91/* Parse extension sent from client to server */92int (*parse_ctos)(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,93X509 *x, size_t chainidx);94/* Parse extension send from server to client */95int (*parse_stoc)(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,96X509 *x, size_t chainidx);97/* Construct extension sent from server to client */98EXT_RETURN (*construct_stoc)(SSL_CONNECTION *s, WPACKET *pkt,99unsigned int context,100X509 *x, size_t chainidx);101/* Construct extension sent from client to server */102EXT_RETURN (*construct_ctos)(SSL_CONNECTION *s, WPACKET *pkt,103unsigned int context,104X509 *x, size_t chainidx);105/*106* Finalise extension after parsing. Always called where an extensions was107* initialised even if the extension was not present. |sent| is set to 1 if108* the extension was seen, or 0 otherwise.109*/110int (*final)(SSL_CONNECTION *s, unsigned int context, int sent);111} EXTENSION_DEFINITION;112113/*114* Definitions of all built-in extensions. NOTE: Changes in the number or order115* of these extensions should be mirrored with equivalent changes to the116* indexes ( TLSEXT_IDX_* ) defined in ssl_local.h.117* Extensions should be added to test/ext_internal_test.c as well, as that118* tests the ordering of the extensions.119*120* Each extension has an initialiser, a client and121* server side parser and a finaliser. The initialiser is called (if the122* extension is relevant to the given context) even if we did not see the123* extension in the message that we received. The parser functions are only124* called if we see the extension in the message. The finalisers are always125* called if the initialiser was called.126* There are also server and client side constructor functions which are always127* called during message construction if the extension is relevant for the128* given context.129* The initialisation, parsing, finalisation and construction functions are130* always called in the order defined in this list. Some extensions may depend131* on others having been processed first, so the order of this list is132* significant.133* The extension context is defined by a series of flags which specify which134* messages the extension is relevant to. These flags also specify whether the135* extension is relevant to a particular protocol or protocol version.136*137* NOTE: WebSphere Application Server 7+ cannot handle empty extensions at138* the end, keep these extensions before signature_algorithm.139*/140#define INVALID_EXTENSION { TLSEXT_TYPE_invalid, 0, NULL, NULL, NULL, NULL, NULL, NULL }141static const EXTENSION_DEFINITION ext_defs[] = {142{143TLSEXT_TYPE_renegotiate,144SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO145| SSL_EXT_SSL3_ALLOWED | SSL_EXT_TLS1_2_AND_BELOW_ONLY,146NULL, tls_parse_ctos_renegotiate, tls_parse_stoc_renegotiate,147tls_construct_stoc_renegotiate, tls_construct_ctos_renegotiate,148final_renegotiate149},150{151TLSEXT_TYPE_server_name,152SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO153| SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS,154init_server_name,155tls_parse_ctos_server_name, tls_parse_stoc_server_name,156tls_construct_stoc_server_name, tls_construct_ctos_server_name,157final_server_name158},159{160TLSEXT_TYPE_max_fragment_length,161SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO162| SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS,163NULL, tls_parse_ctos_maxfragmentlen, tls_parse_stoc_maxfragmentlen,164tls_construct_stoc_maxfragmentlen, tls_construct_ctos_maxfragmentlen,165final_maxfragmentlen166},167#ifndef OPENSSL_NO_SRP168{169TLSEXT_TYPE_srp,170SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_AND_BELOW_ONLY,171init_srp, tls_parse_ctos_srp, NULL, NULL, tls_construct_ctos_srp, NULL172},173#else174INVALID_EXTENSION,175#endif176{177TLSEXT_TYPE_ec_point_formats,178SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO179| SSL_EXT_TLS1_2_AND_BELOW_ONLY,180init_ec_point_formats, tls_parse_ctos_ec_pt_formats, tls_parse_stoc_ec_pt_formats,181tls_construct_stoc_ec_pt_formats, tls_construct_ctos_ec_pt_formats,182final_ec_pt_formats183},184{185/*186* "supported_groups" is spread across several specifications.187* It was originally specified as "elliptic_curves" in RFC 4492,188* and broadened to include named FFDH groups by RFC 7919.189* Both RFCs 4492 and 7919 do not include a provision for the server190* to indicate to the client the complete list of groups supported191* by the server, with the server instead just indicating the192* selected group for this connection in the ServerKeyExchange193* message. TLS 1.3 adds a scheme for the server to indicate194* to the client its list of supported groups in the195* EncryptedExtensions message, but none of the relevant196* specifications permit sending supported_groups in the ServerHello.197* Nonetheless (possibly due to the close proximity to the198* "ec_point_formats" extension, which is allowed in the ServerHello),199* there are several servers that send this extension in the200* ServerHello anyway. Up to and including the 1.1.0 release,201* we did not check for the presence of nonpermitted extensions,202* so to avoid a regression, we must permit this extension in the203* TLS 1.2 ServerHello as well.204*205* Note that there is no tls_parse_stoc_supported_groups function,206* so we do not perform any additional parsing, validation, or207* processing on the server's group list -- this is just a minimal208* change to preserve compatibility with these misbehaving servers.209*/210TLSEXT_TYPE_supported_groups,211SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS212| SSL_EXT_TLS1_2_SERVER_HELLO,213NULL, tls_parse_ctos_supported_groups, NULL,214tls_construct_stoc_supported_groups,215tls_construct_ctos_supported_groups, NULL216},217{218TLSEXT_TYPE_session_ticket,219SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO220| SSL_EXT_TLS1_2_AND_BELOW_ONLY,221init_session_ticket, tls_parse_ctos_session_ticket,222tls_parse_stoc_session_ticket, tls_construct_stoc_session_ticket,223tls_construct_ctos_session_ticket, NULL224},225#ifndef OPENSSL_NO_OCSP226{227TLSEXT_TYPE_status_request,228SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO229| SSL_EXT_TLS1_3_CERTIFICATE | SSL_EXT_TLS1_3_CERTIFICATE_REQUEST,230init_status_request, tls_parse_ctos_status_request,231tls_parse_stoc_status_request, tls_construct_stoc_status_request,232tls_construct_ctos_status_request, NULL233},234#else235INVALID_EXTENSION,236#endif237#ifndef OPENSSL_NO_NEXTPROTONEG238{239TLSEXT_TYPE_next_proto_neg,240SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO241| SSL_EXT_TLS1_2_AND_BELOW_ONLY,242init_npn, tls_parse_ctos_npn, tls_parse_stoc_npn,243tls_construct_stoc_next_proto_neg, tls_construct_ctos_npn, NULL244},245#else246INVALID_EXTENSION,247#endif248{249/*250* Must appear in this list after server_name so that finalisation251* happens after server_name callbacks252*/253TLSEXT_TYPE_application_layer_protocol_negotiation,254SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO255| SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS,256init_alpn, tls_parse_ctos_alpn, tls_parse_stoc_alpn,257tls_construct_stoc_alpn, tls_construct_ctos_alpn, final_alpn258},259#ifndef OPENSSL_NO_SRTP260{261TLSEXT_TYPE_use_srtp,262SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO263| SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS | SSL_EXT_DTLS_ONLY,264init_srtp, tls_parse_ctos_use_srtp, tls_parse_stoc_use_srtp,265tls_construct_stoc_use_srtp, tls_construct_ctos_use_srtp, NULL266},267#else268INVALID_EXTENSION,269#endif270{271TLSEXT_TYPE_encrypt_then_mac,272SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO273| SSL_EXT_TLS1_2_AND_BELOW_ONLY,274init_etm, tls_parse_ctos_etm, tls_parse_stoc_etm,275tls_construct_stoc_etm, tls_construct_ctos_etm, NULL276},277#ifndef OPENSSL_NO_CT278{279TLSEXT_TYPE_signed_certificate_timestamp,280SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO281| SSL_EXT_TLS1_3_CERTIFICATE | SSL_EXT_TLS1_3_CERTIFICATE_REQUEST,282NULL,283/*284* No server side support for this, but can be provided by a custom285* extension. This is an exception to the rule that custom extensions286* cannot override built in ones.287*/288NULL, tls_parse_stoc_sct, NULL, tls_construct_ctos_sct, NULL289},290#else291INVALID_EXTENSION,292#endif293{294TLSEXT_TYPE_extended_master_secret,295SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO296| SSL_EXT_TLS1_2_AND_BELOW_ONLY,297init_ems, tls_parse_ctos_ems, tls_parse_stoc_ems,298tls_construct_stoc_ems, tls_construct_ctos_ems, final_ems299},300{301TLSEXT_TYPE_signature_algorithms_cert,302SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_CERTIFICATE_REQUEST,303init_sig_algs_cert, tls_parse_ctos_sig_algs_cert,304tls_parse_ctos_sig_algs_cert,305/* We do not generate signature_algorithms_cert at present. */306NULL, NULL, NULL307},308{309TLSEXT_TYPE_post_handshake_auth,310SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ONLY,311init_post_handshake_auth,312tls_parse_ctos_post_handshake_auth, NULL,313NULL, tls_construct_ctos_post_handshake_auth,314NULL,315},316{317TLSEXT_TYPE_client_cert_type,318SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS319| SSL_EXT_TLS1_2_SERVER_HELLO,320init_client_cert_type,321tls_parse_ctos_client_cert_type, tls_parse_stoc_client_cert_type,322tls_construct_stoc_client_cert_type, tls_construct_ctos_client_cert_type,323NULL324},325{326TLSEXT_TYPE_server_cert_type,327SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS328| SSL_EXT_TLS1_2_SERVER_HELLO,329init_server_cert_type,330tls_parse_ctos_server_cert_type, tls_parse_stoc_server_cert_type,331tls_construct_stoc_server_cert_type, tls_construct_ctos_server_cert_type,332NULL333},334{335TLSEXT_TYPE_signature_algorithms,336SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_CERTIFICATE_REQUEST,337init_sig_algs, tls_parse_ctos_sig_algs,338tls_parse_ctos_sig_algs, tls_construct_ctos_sig_algs,339tls_construct_ctos_sig_algs, final_sig_algs340},341{342TLSEXT_TYPE_supported_versions,343SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_SERVER_HELLO344| SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST | SSL_EXT_TLS_IMPLEMENTATION_ONLY,345NULL,346/* Processed inline as part of version selection */347NULL, tls_parse_stoc_supported_versions,348tls_construct_stoc_supported_versions,349tls_construct_ctos_supported_versions, final_supported_versions350},351{352TLSEXT_TYPE_psk_kex_modes,353SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS_IMPLEMENTATION_ONLY354| SSL_EXT_TLS1_3_ONLY,355init_psk_kex_modes, tls_parse_ctos_psk_kex_modes, NULL, NULL,356tls_construct_ctos_psk_kex_modes, NULL357},358{359/*360* Must be in this list after supported_groups. We need that to have361* been parsed before we do this one.362*/363TLSEXT_TYPE_key_share,364SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_SERVER_HELLO365| SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST | SSL_EXT_TLS_IMPLEMENTATION_ONLY366| SSL_EXT_TLS1_3_ONLY,367NULL, tls_parse_ctos_key_share, tls_parse_stoc_key_share,368tls_construct_stoc_key_share, tls_construct_ctos_key_share,369final_key_share370},371{372/* Must be after key_share */373TLSEXT_TYPE_cookie,374SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST375| SSL_EXT_TLS_IMPLEMENTATION_ONLY | SSL_EXT_TLS1_3_ONLY,376NULL, tls_parse_ctos_cookie, tls_parse_stoc_cookie,377tls_construct_stoc_cookie, tls_construct_ctos_cookie, NULL378},379{380/*381* Special unsolicited ServerHello extension only used when382* SSL_OP_CRYPTOPRO_TLSEXT_BUG is set. We allow it in a ClientHello but383* ignore it.384*/385TLSEXT_TYPE_cryptopro_bug,386SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO387| SSL_EXT_TLS1_2_AND_BELOW_ONLY,388NULL, NULL, NULL, tls_construct_stoc_cryptopro_bug, NULL, NULL389},390{391TLSEXT_TYPE_compress_certificate,392SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_CERTIFICATE_REQUEST393| SSL_EXT_TLS_IMPLEMENTATION_ONLY | SSL_EXT_TLS1_3_ONLY,394tls_init_compress_certificate,395tls_parse_compress_certificate, tls_parse_compress_certificate,396tls_construct_compress_certificate, tls_construct_compress_certificate,397NULL398},399{400TLSEXT_TYPE_early_data,401SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS402| SSL_EXT_TLS1_3_NEW_SESSION_TICKET | SSL_EXT_TLS1_3_ONLY,403NULL, tls_parse_ctos_early_data, tls_parse_stoc_early_data,404tls_construct_stoc_early_data, tls_construct_ctos_early_data,405final_early_data406},407{408TLSEXT_TYPE_certificate_authorities,409SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_CERTIFICATE_REQUEST410| SSL_EXT_TLS1_3_ONLY,411init_certificate_authorities,412tls_parse_certificate_authorities, tls_parse_certificate_authorities,413tls_construct_certificate_authorities,414tls_construct_certificate_authorities, NULL,415},416{417/* Must be immediately before pre_shared_key */418TLSEXT_TYPE_padding,419SSL_EXT_CLIENT_HELLO,420NULL,421/* We send this, but don't read it */422NULL, NULL, NULL, tls_construct_ctos_padding, NULL423},424{425/* Required by the TLSv1.3 spec to always be the last extension */426TLSEXT_TYPE_psk,427SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_SERVER_HELLO428| SSL_EXT_TLS_IMPLEMENTATION_ONLY | SSL_EXT_TLS1_3_ONLY,429NULL, tls_parse_ctos_psk, tls_parse_stoc_psk, tls_construct_stoc_psk,430tls_construct_ctos_psk, final_psk431}432};433434/* Returns a TLSEXT_TYPE for the given index */435unsigned int ossl_get_extension_type(size_t idx)436{437size_t num_exts = OSSL_NELEM(ext_defs);438439if (idx >= num_exts)440return TLSEXT_TYPE_out_of_range;441442return ext_defs[idx].type;443}444445/* Check whether an extension's context matches the current context */446static int validate_context(SSL_CONNECTION *s, unsigned int extctx,447unsigned int thisctx)448{449/* Check we're allowed to use this extension in this context */450if ((thisctx & extctx) == 0)451return 0;452453if (SSL_CONNECTION_IS_DTLS(s)) {454if ((extctx & SSL_EXT_TLS_ONLY) != 0)455return 0;456} else if ((extctx & SSL_EXT_DTLS_ONLY) != 0) {457return 0;458}459460return 1;461}462463int tls_validate_all_contexts(SSL_CONNECTION *s, unsigned int thisctx,464RAW_EXTENSION *exts)465{466size_t i, num_exts, builtin_num = OSSL_NELEM(ext_defs), offset;467RAW_EXTENSION *thisext;468unsigned int context;469ENDPOINT role = ENDPOINT_BOTH;470471if ((thisctx & SSL_EXT_CLIENT_HELLO) != 0)472role = ENDPOINT_SERVER;473else if ((thisctx & SSL_EXT_TLS1_2_SERVER_HELLO) != 0)474role = ENDPOINT_CLIENT;475476/* Calculate the number of extensions in the extensions list */477num_exts = builtin_num + s->cert->custext.meths_count;478479for (thisext = exts, i = 0; i < num_exts; i++, thisext++) {480if (!thisext->present)481continue;482483if (i < builtin_num) {484context = ext_defs[i].context;485} else {486custom_ext_method *meth = NULL;487488meth = custom_ext_find(&s->cert->custext, role, thisext->type,489&offset);490if (!ossl_assert(meth != NULL))491return 0;492context = meth->context;493}494495if (!validate_context(s, context, thisctx))496return 0;497}498499return 1;500}501502/*503* Verify whether we are allowed to use the extension |type| in the current504* |context|. Returns 1 to indicate the extension is allowed or unknown or 0 to505* indicate the extension is not allowed. If returning 1 then |*found| is set to506* the definition for the extension we found.507*/508static int verify_extension(SSL_CONNECTION *s, unsigned int context,509unsigned int type, custom_ext_methods *meths,510RAW_EXTENSION *rawexlist, RAW_EXTENSION **found)511{512size_t i;513size_t builtin_num = OSSL_NELEM(ext_defs);514const EXTENSION_DEFINITION *thisext;515516for (i = 0, thisext = ext_defs; i < builtin_num; i++, thisext++) {517if (type == thisext->type) {518if (!validate_context(s, thisext->context, context))519return 0;520521*found = &rawexlist[i];522return 1;523}524}525526/* Check the custom extensions */527if (meths != NULL) {528size_t offset = 0;529ENDPOINT role = ENDPOINT_BOTH;530custom_ext_method *meth = NULL;531532if ((context & SSL_EXT_CLIENT_HELLO) != 0)533role = ENDPOINT_SERVER;534else if ((context & SSL_EXT_TLS1_2_SERVER_HELLO) != 0)535role = ENDPOINT_CLIENT;536537meth = custom_ext_find(meths, role, type, &offset);538if (meth != NULL) {539if (!validate_context(s, meth->context, context))540return 0;541*found = &rawexlist[offset + builtin_num];542return 1;543}544}545546/* Unknown extension. We allow it */547*found = NULL;548return 1;549}550551/*552* Check whether the context defined for an extension |extctx| means whether553* the extension is relevant for the current context |thisctx| or not. Returns554* 1 if the extension is relevant for this context, and 0 otherwise555*/556int extension_is_relevant(SSL_CONNECTION *s, unsigned int extctx,557unsigned int thisctx)558{559int is_tls13;560561/*562* For HRR we haven't selected the version yet but we know it will be563* TLSv1.3564*/565if ((thisctx & SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST) != 0)566is_tls13 = 1;567else568is_tls13 = SSL_CONNECTION_IS_TLS13(s);569570if ((SSL_CONNECTION_IS_DTLS(s)571&& (extctx & SSL_EXT_TLS_IMPLEMENTATION_ONLY) != 0)572|| (s->version == SSL3_VERSION573&& (extctx & SSL_EXT_SSL3_ALLOWED) == 0)574/*575* Note that SSL_IS_TLS13() means "TLS 1.3 has been negotiated",576* which is never true when generating the ClientHello.577* However, version negotiation *has* occurred by the time the578* ClientHello extensions are being parsed.579* Be careful to allow TLS 1.3-only extensions when generating580* the ClientHello.581*/582|| (is_tls13 && (extctx & SSL_EXT_TLS1_2_AND_BELOW_ONLY) != 0)583|| (!is_tls13 && (extctx & SSL_EXT_TLS1_3_ONLY) != 0584&& (thisctx & SSL_EXT_CLIENT_HELLO) == 0)585|| (s->server && !is_tls13 && (extctx & SSL_EXT_TLS1_3_ONLY) != 0)586|| (s->hit && (extctx & SSL_EXT_IGNORE_ON_RESUMPTION) != 0))587return 0;588return 1;589}590591/*592* Gather a list of all the extensions from the data in |packet]. |context|593* tells us which message this extension is for. The raw extension data is594* stored in |*res| on success. We don't actually process the content of the595* extensions yet, except to check their types. This function also runs the596* initialiser functions for all known extensions if |init| is nonzero (whether597* we have collected them or not). If successful the caller is responsible for598* freeing the contents of |*res|.599*600* Per http://tools.ietf.org/html/rfc5246#section-7.4.1.4, there may not be601* more than one extension of the same type in a ClientHello or ServerHello.602* This function returns 1 if all extensions are unique and we have parsed their603* types, and 0 if the extensions contain duplicates, could not be successfully604* found, or an internal error occurred. We only check duplicates for605* extensions that we know about. We ignore others.606*/607int tls_collect_extensions(SSL_CONNECTION *s, PACKET *packet,608unsigned int context,609RAW_EXTENSION **res, size_t *len, int init)610{611PACKET extensions = *packet;612size_t i = 0;613size_t num_exts;614custom_ext_methods *exts = &s->cert->custext;615RAW_EXTENSION *raw_extensions = NULL;616const EXTENSION_DEFINITION *thisexd;617618*res = NULL;619620/*621* Initialise server side custom extensions. Client side is done during622* construction of extensions for the ClientHello.623*/624if ((context & SSL_EXT_CLIENT_HELLO) != 0)625custom_ext_init(&s->cert->custext);626627num_exts = OSSL_NELEM(ext_defs) + (exts != NULL ? exts->meths_count : 0);628raw_extensions = OPENSSL_zalloc(num_exts * sizeof(*raw_extensions));629if (raw_extensions == NULL) {630SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_CRYPTO_LIB);631return 0;632}633634i = 0;635while (PACKET_remaining(&extensions) > 0) {636unsigned int type, idx;637PACKET extension;638RAW_EXTENSION *thisex;639640if (!PACKET_get_net_2(&extensions, &type) ||641!PACKET_get_length_prefixed_2(&extensions, &extension)) {642SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);643goto err;644}645/*646* Verify this extension is allowed. We only check duplicates for647* extensions that we recognise. We also have a special case for the648* PSK extension, which must be the last one in the ClientHello.649*/650if (!verify_extension(s, context, type, exts, raw_extensions, &thisex)651|| (thisex != NULL && thisex->present == 1)652|| (type == TLSEXT_TYPE_psk653&& (context & SSL_EXT_CLIENT_HELLO) != 0654&& PACKET_remaining(&extensions) != 0)) {655SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_EXTENSION);656goto err;657}658idx = thisex - raw_extensions;659/*-660* Check that we requested this extension (if appropriate). Requests can661* be sent in the ClientHello and CertificateRequest. Unsolicited662* extensions can be sent in the NewSessionTicket. We only do this for663* the built-in extensions. Custom extensions have a different but664* similar check elsewhere.665* Special cases:666* - The HRR cookie extension is unsolicited667* - The renegotiate extension is unsolicited (the client signals668* support via an SCSV)669* - The signed_certificate_timestamp extension can be provided by a670* custom extension or by the built-in version. We let the extension671* itself handle unsolicited response checks.672*/673if (idx < OSSL_NELEM(ext_defs)674&& (context & (SSL_EXT_CLIENT_HELLO675| SSL_EXT_TLS1_3_CERTIFICATE_REQUEST676| SSL_EXT_TLS1_3_NEW_SESSION_TICKET)) == 0677&& type != TLSEXT_TYPE_cookie678&& type != TLSEXT_TYPE_renegotiate679&& type != TLSEXT_TYPE_signed_certificate_timestamp680&& (s->ext.extflags[idx] & SSL_EXT_FLAG_SENT) == 0681#ifndef OPENSSL_NO_GOST682&& !((context & SSL_EXT_TLS1_2_SERVER_HELLO) != 0683&& type == TLSEXT_TYPE_cryptopro_bug)684#endif685) {686SSLfatal(s, SSL_AD_UNSUPPORTED_EXTENSION,687SSL_R_UNSOLICITED_EXTENSION);688goto err;689}690if (thisex != NULL) {691thisex->data = extension;692thisex->present = 1;693thisex->type = type;694thisex->received_order = i++;695if (s->ext.debug_cb)696s->ext.debug_cb(SSL_CONNECTION_GET_USER_SSL(s), !s->server,697thisex->type, PACKET_data(&thisex->data),698PACKET_remaining(&thisex->data),699s->ext.debug_arg);700}701}702703if (init) {704/*705* Initialise all known extensions relevant to this context,706* whether we have found them or not707*/708for (thisexd = ext_defs, i = 0; i < OSSL_NELEM(ext_defs);709i++, thisexd++) {710if (thisexd->init != NULL && (thisexd->context & context) != 0711&& extension_is_relevant(s, thisexd->context, context)712&& !thisexd->init(s, context)) {713/* SSLfatal() already called */714goto err;715}716}717}718719*res = raw_extensions;720if (len != NULL)721*len = num_exts;722return 1;723724err:725OPENSSL_free(raw_extensions);726return 0;727}728729/*730* Runs the parser for a given extension with index |idx|. |exts| contains the731* list of all parsed extensions previously collected by732* tls_collect_extensions(). The parser is only run if it is applicable for the733* given |context| and the parser has not already been run. If this is for a734* Certificate message, then we also provide the parser with the relevant735* Certificate |x| and its position in the |chainidx| with 0 being the first736* Certificate. Returns 1 on success or 0 on failure. If an extension is not737* present this counted as success.738*/739int tls_parse_extension(SSL_CONNECTION *s, TLSEXT_INDEX idx, int context,740RAW_EXTENSION *exts, X509 *x, size_t chainidx)741{742RAW_EXTENSION *currext = &exts[idx];743int (*parser)(SSL_CONNECTION *s, PACKET *pkt, unsigned int context, X509 *x,744size_t chainidx) = NULL;745746/* Skip if the extension is not present */747if (!currext->present)748return 1;749750/* Skip if we've already parsed this extension */751if (currext->parsed)752return 1;753754currext->parsed = 1;755756if (idx < OSSL_NELEM(ext_defs)) {757/* We are handling a built-in extension */758const EXTENSION_DEFINITION *extdef = &ext_defs[idx];759760/* Check if extension is defined for our protocol. If not, skip */761if (!extension_is_relevant(s, extdef->context, context))762return 1;763764parser = s->server ? extdef->parse_ctos : extdef->parse_stoc;765766if (parser != NULL)767return parser(s, &currext->data, context, x, chainidx);768769/*770* If the parser is NULL we fall through to the custom extension771* processing772*/773}774775/* Parse custom extensions */776return custom_ext_parse(s, context, currext->type,777PACKET_data(&currext->data),778PACKET_remaining(&currext->data),779x, chainidx);780}781782/*783* Parse all remaining extensions that have not yet been parsed. Also calls the784* finalisation for all extensions at the end if |fin| is nonzero, whether we785* collected them or not. Returns 1 for success or 0 for failure. If we are786* working on a Certificate message then we also pass the Certificate |x| and787* its position in the |chainidx|, with 0 being the first certificate.788*/789int tls_parse_all_extensions(SSL_CONNECTION *s, int context,790RAW_EXTENSION *exts, X509 *x,791size_t chainidx, int fin)792{793size_t i, numexts = OSSL_NELEM(ext_defs);794const EXTENSION_DEFINITION *thisexd;795796/* Calculate the number of extensions in the extensions list */797numexts += s->cert->custext.meths_count;798799/* Parse each extension in turn */800for (i = 0; i < numexts; i++) {801if (!tls_parse_extension(s, i, context, exts, x, chainidx)) {802/* SSLfatal() already called */803return 0;804}805}806807if (fin) {808/*809* Finalise all known extensions relevant to this context,810* whether we have found them or not811*/812for (i = 0, thisexd = ext_defs; i < OSSL_NELEM(ext_defs);813i++, thisexd++) {814if (thisexd->final != NULL && (thisexd->context & context) != 0815&& !thisexd->final(s, context, exts[i].present)) {816/* SSLfatal() already called */817return 0;818}819}820}821822return 1;823}824825int should_add_extension(SSL_CONNECTION *s, unsigned int extctx,826unsigned int thisctx, int max_version)827{828/* Skip if not relevant for our context */829if ((extctx & thisctx) == 0)830return 0;831832/* Check if this extension is defined for our protocol. If not, skip */833if (!extension_is_relevant(s, extctx, thisctx)834|| ((extctx & SSL_EXT_TLS1_3_ONLY) != 0835&& (thisctx & SSL_EXT_CLIENT_HELLO) != 0836&& (SSL_CONNECTION_IS_DTLS(s) || max_version < TLS1_3_VERSION)))837return 0;838839return 1;840}841842/*843* Construct all the extensions relevant to the current |context| and write844* them to |pkt|. If this is an extension for a Certificate in a Certificate845* message, then |x| will be set to the Certificate we are handling, and846* |chainidx| will indicate the position in the chainidx we are processing (with847* 0 being the first in the chain). Returns 1 on success or 0 on failure. On a848* failure construction stops at the first extension to fail to construct.849*/850int tls_construct_extensions(SSL_CONNECTION *s, WPACKET *pkt,851unsigned int context,852X509 *x, size_t chainidx)853{854size_t i;855int min_version, max_version = 0, reason;856const EXTENSION_DEFINITION *thisexd;857int for_comp = (context & SSL_EXT_TLS1_3_CERTIFICATE_COMPRESSION) != 0;858859if (!WPACKET_start_sub_packet_u16(pkt)860/*861* If extensions are of zero length then we don't even add the862* extensions length bytes to a ClientHello/ServerHello863* (for non-TLSv1.3).864*/865|| ((context &866(SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO)) != 0867&& !WPACKET_set_flags(pkt,868WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH))) {869if (!for_comp)870SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);871return 0;872}873874if ((context & SSL_EXT_CLIENT_HELLO) != 0) {875reason = ssl_get_min_max_version(s, &min_version, &max_version, NULL);876if (reason != 0) {877if (!for_comp)878SSLfatal(s, SSL_AD_INTERNAL_ERROR, reason);879return 0;880}881}882883/* Add custom extensions first */884if ((context & SSL_EXT_CLIENT_HELLO) != 0) {885/* On the server side with initialise during ClientHello parsing */886custom_ext_init(&s->cert->custext);887}888if (!custom_ext_add(s, context, pkt, x, chainidx, max_version)) {889/* SSLfatal() already called */890return 0;891}892893for (i = 0, thisexd = ext_defs; i < OSSL_NELEM(ext_defs); i++, thisexd++) {894EXT_RETURN (*construct)(SSL_CONNECTION *s, WPACKET *pkt,895unsigned int context,896X509 *x, size_t chainidx);897EXT_RETURN ret;898899/* Skip if not relevant for our context */900if (!should_add_extension(s, thisexd->context, context, max_version))901continue;902903construct = s->server ? thisexd->construct_stoc904: thisexd->construct_ctos;905906if (construct == NULL)907continue;908909ret = construct(s, pkt, context, x, chainidx);910if (ret == EXT_RETURN_FAIL) {911/* SSLfatal() already called */912return 0;913}914if (ret == EXT_RETURN_SENT915&& (context & (SSL_EXT_CLIENT_HELLO916| SSL_EXT_TLS1_3_CERTIFICATE_REQUEST917| SSL_EXT_TLS1_3_NEW_SESSION_TICKET)) != 0)918s->ext.extflags[i] |= SSL_EXT_FLAG_SENT;919}920921if (!WPACKET_close(pkt)) {922if (!for_comp)923SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);924return 0;925}926927return 1;928}929930/*931* Built in extension finalisation and initialisation functions. All initialise932* or finalise the associated extension type for the given |context|. For933* finalisers |sent| is set to 1 if we saw the extension during parsing, and 0934* otherwise. These functions return 1 on success or 0 on failure.935*/936937static int final_renegotiate(SSL_CONNECTION *s, unsigned int context, int sent)938{939if (!s->server) {940/*941* Check if we can connect to a server that doesn't support safe942* renegotiation943*/944if (!(s->options & SSL_OP_LEGACY_SERVER_CONNECT)945&& !(s->options & SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)946&& !sent) {947SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE,948SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);949return 0;950}951952return 1;953}954955/* Need RI if renegotiating */956if (s->renegotiate957&& !(s->options & SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)958&& !sent) {959SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE,960SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);961return 0;962}963964965return 1;966}967968static ossl_inline void ssl_tsan_decr(const SSL_CTX *ctx,969TSAN_QUALIFIER int *stat)970{971if (ssl_tsan_lock(ctx)) {972tsan_decr(stat);973ssl_tsan_unlock(ctx);974}975}976977static int init_server_name(SSL_CONNECTION *s, unsigned int context)978{979if (s->server) {980s->servername_done = 0;981982OPENSSL_free(s->ext.hostname);983s->ext.hostname = NULL;984}985986return 1;987}988989static int final_server_name(SSL_CONNECTION *s, unsigned int context, int sent)990{991int ret = SSL_TLSEXT_ERR_NOACK;992int altmp = SSL_AD_UNRECOGNIZED_NAME;993SSL *ssl = SSL_CONNECTION_GET_SSL(s);994SSL *ussl = SSL_CONNECTION_GET_USER_SSL(s);995SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);996int was_ticket = (SSL_get_options(ssl) & SSL_OP_NO_TICKET) == 0;997998if (!ossl_assert(sctx != NULL) || !ossl_assert(s->session_ctx != NULL)) {999SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1000return 0;1001}10021003if (sctx->ext.servername_cb != NULL)1004ret = sctx->ext.servername_cb(ussl, &altmp,1005sctx->ext.servername_arg);1006else if (s->session_ctx->ext.servername_cb != NULL)1007ret = s->session_ctx->ext.servername_cb(ussl, &altmp,1008s->session_ctx->ext.servername_arg);10091010/*1011* For servers, propagate the SNI hostname from the temporary1012* storage in the SSL to the persistent SSL_SESSION, now that we1013* know we accepted it.1014* Clients make this copy when parsing the server's response to1015* the extension, which is when they find out that the negotiation1016* was successful.1017*/1018if (s->server) {1019if (sent && ret == SSL_TLSEXT_ERR_OK && !s->hit) {1020/* Only store the hostname in the session if we accepted it. */1021OPENSSL_free(s->session->ext.hostname);1022s->session->ext.hostname = OPENSSL_strdup(s->ext.hostname);1023if (s->session->ext.hostname == NULL && s->ext.hostname != NULL) {1024SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1025}1026}1027}10281029/*1030* If we switched contexts (whether here or in the client_hello callback),1031* move the sess_accept increment from the session_ctx to the new1032* context, to avoid the confusing situation of having sess_accept_good1033* exceed sess_accept (zero) for the new context.1034*/1035if (SSL_IS_FIRST_HANDSHAKE(s) && sctx != s->session_ctx1036&& s->hello_retry_request == SSL_HRR_NONE) {1037ssl_tsan_counter(sctx, &sctx->stats.sess_accept);1038ssl_tsan_decr(s->session_ctx, &s->session_ctx->stats.sess_accept);1039}10401041/*1042* If we're expecting to send a ticket, and tickets were previously enabled,1043* and now tickets are disabled, then turn off expected ticket.1044* Also, if this is not a resumption, create a new session ID1045*/1046if (ret == SSL_TLSEXT_ERR_OK && s->ext.ticket_expected1047&& was_ticket && (SSL_get_options(ssl) & SSL_OP_NO_TICKET) != 0) {1048s->ext.ticket_expected = 0;1049if (!s->hit) {1050SSL_SESSION* ss = SSL_get_session(ssl);10511052if (ss != NULL) {1053OPENSSL_free(ss->ext.tick);1054ss->ext.tick = NULL;1055ss->ext.ticklen = 0;1056ss->ext.tick_lifetime_hint = 0;1057ss->ext.tick_age_add = 0;1058if (!ssl_generate_session_id(s, ss)) {1059SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1060return 0;1061}1062} else {1063SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1064return 0;1065}1066}1067}10681069switch (ret) {1070case SSL_TLSEXT_ERR_ALERT_FATAL:1071SSLfatal(s, altmp, SSL_R_CALLBACK_FAILED);1072return 0;10731074case SSL_TLSEXT_ERR_ALERT_WARNING:1075/* TLSv1.3 doesn't have warning alerts so we suppress this */1076if (!SSL_CONNECTION_IS_TLS13(s))1077ssl3_send_alert(s, SSL3_AL_WARNING, altmp);1078s->servername_done = 0;1079return 1;10801081case SSL_TLSEXT_ERR_NOACK:1082s->servername_done = 0;1083return 1;10841085default:1086return 1;1087}1088}10891090static int final_ec_pt_formats(SSL_CONNECTION *s, unsigned int context,1091int sent)1092{1093unsigned long alg_k, alg_a;10941095if (s->server)1096return 1;10971098alg_k = s->s3.tmp.new_cipher->algorithm_mkey;1099alg_a = s->s3.tmp.new_cipher->algorithm_auth;11001101/*1102* If we are client and using an elliptic curve cryptography cipher1103* suite, then if server returns an EC point formats lists extension it1104* must contain uncompressed.1105*/1106if (s->ext.ecpointformats != NULL1107&& s->ext.ecpointformats_len > 01108&& s->ext.peer_ecpointformats != NULL1109&& s->ext.peer_ecpointformats_len > 01110&& ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))) {1111/* we are using an ECC cipher */1112size_t i;1113unsigned char *list = s->ext.peer_ecpointformats;11141115for (i = 0; i < s->ext.peer_ecpointformats_len; i++) {1116if (*list++ == TLSEXT_ECPOINTFORMAT_uncompressed)1117break;1118}1119if (i == s->ext.peer_ecpointformats_len) {1120SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,1121SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST);1122return 0;1123}1124}11251126return 1;1127}11281129static int init_session_ticket(SSL_CONNECTION *s, unsigned int context)1130{1131if (!s->server)1132s->ext.ticket_expected = 0;11331134return 1;1135}11361137#ifndef OPENSSL_NO_OCSP1138static int init_status_request(SSL_CONNECTION *s, unsigned int context)1139{1140if (s->server) {1141s->ext.status_type = TLSEXT_STATUSTYPE_nothing;1142} else {1143/*1144* Ensure we get sensible values passed to tlsext_status_cb in the event1145* that we don't receive a status message1146*/1147OPENSSL_free(s->ext.ocsp.resp);1148s->ext.ocsp.resp = NULL;1149s->ext.ocsp.resp_len = 0;1150}11511152return 1;1153}1154#endif11551156#ifndef OPENSSL_NO_NEXTPROTONEG1157static int init_npn(SSL_CONNECTION *s, unsigned int context)1158{1159s->s3.npn_seen = 0;11601161return 1;1162}1163#endif11641165static int init_alpn(SSL_CONNECTION *s, unsigned int context)1166{1167OPENSSL_free(s->s3.alpn_selected);1168s->s3.alpn_selected = NULL;1169s->s3.alpn_selected_len = 0;1170if (s->server) {1171OPENSSL_free(s->s3.alpn_proposed);1172s->s3.alpn_proposed = NULL;1173s->s3.alpn_proposed_len = 0;1174}1175return 1;1176}11771178static int final_alpn(SSL_CONNECTION *s, unsigned int context, int sent)1179{1180if (!s->server && !sent && s->session->ext.alpn_selected != NULL)1181s->ext.early_data_ok = 0;11821183if (!s->server || !SSL_CONNECTION_IS_TLS13(s))1184return 1;11851186/*1187* Call alpn_select callback if needed. Has to be done after SNI and1188* cipher negotiation (HTTP/2 restricts permitted ciphers). In TLSv1.31189* we also have to do this before we decide whether to accept early_data.1190* In TLSv1.3 we've already negotiated our cipher so we do this call now.1191* For < TLSv1.3 we defer it until after cipher negotiation.1192*1193* On failure SSLfatal() already called.1194*/1195return tls_handle_alpn(s);1196}11971198static int init_sig_algs(SSL_CONNECTION *s, unsigned int context)1199{1200/* Clear any signature algorithms extension received */1201OPENSSL_free(s->s3.tmp.peer_sigalgs);1202s->s3.tmp.peer_sigalgs = NULL;1203s->s3.tmp.peer_sigalgslen = 0;12041205return 1;1206}12071208static int init_sig_algs_cert(SSL_CONNECTION *s,1209ossl_unused unsigned int context)1210{1211/* Clear any signature algorithms extension received */1212OPENSSL_free(s->s3.tmp.peer_cert_sigalgs);1213s->s3.tmp.peer_cert_sigalgs = NULL;1214s->s3.tmp.peer_cert_sigalgslen = 0;12151216return 1;1217}12181219#ifndef OPENSSL_NO_SRP1220static int init_srp(SSL_CONNECTION *s, unsigned int context)1221{1222OPENSSL_free(s->srp_ctx.login);1223s->srp_ctx.login = NULL;12241225return 1;1226}1227#endif12281229static int init_ec_point_formats(SSL_CONNECTION *s, unsigned int context)1230{1231OPENSSL_free(s->ext.peer_ecpointformats);1232s->ext.peer_ecpointformats = NULL;1233s->ext.peer_ecpointformats_len = 0;12341235return 1;1236}12371238static int init_etm(SSL_CONNECTION *s, unsigned int context)1239{1240s->ext.use_etm = 0;12411242return 1;1243}12441245static int init_ems(SSL_CONNECTION *s, unsigned int context)1246{1247if (s->s3.flags & TLS1_FLAGS_RECEIVED_EXTMS) {1248s->s3.flags &= ~TLS1_FLAGS_RECEIVED_EXTMS;1249s->s3.flags |= TLS1_FLAGS_REQUIRED_EXTMS;1250}12511252return 1;1253}12541255static int final_ems(SSL_CONNECTION *s, unsigned int context, int sent)1256{1257/*1258* Check extended master secret extension is not dropped on1259* renegotiation.1260*/1261if (!(s->s3.flags & TLS1_FLAGS_RECEIVED_EXTMS)1262&& (s->s3.flags & TLS1_FLAGS_REQUIRED_EXTMS)) {1263SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_R_INCONSISTENT_EXTMS);1264return 0;1265}1266if (!s->server && s->hit) {1267/*1268* Check extended master secret extension is consistent with1269* original session.1270*/1271if (!(s->s3.flags & TLS1_FLAGS_RECEIVED_EXTMS) !=1272!(s->session->flags & SSL_SESS_FLAG_EXTMS)) {1273SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_R_INCONSISTENT_EXTMS);1274return 0;1275}1276}12771278return 1;1279}12801281static int init_certificate_authorities(SSL_CONNECTION *s, unsigned int context)1282{1283sk_X509_NAME_pop_free(s->s3.tmp.peer_ca_names, X509_NAME_free);1284s->s3.tmp.peer_ca_names = NULL;1285return 1;1286}12871288static EXT_RETURN tls_construct_certificate_authorities(SSL_CONNECTION *s,1289WPACKET *pkt,1290unsigned int context,1291X509 *x,1292size_t chainidx)1293{1294const STACK_OF(X509_NAME) *ca_sk = get_ca_names(s);12951296if (ca_sk == NULL || sk_X509_NAME_num(ca_sk) == 0)1297return EXT_RETURN_NOT_SENT;12981299if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_certificate_authorities)1300|| !WPACKET_start_sub_packet_u16(pkt)) {1301SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1302return EXT_RETURN_FAIL;1303}13041305if (!construct_ca_names(s, ca_sk, pkt)) {1306/* SSLfatal() already called */1307return EXT_RETURN_FAIL;1308}13091310if (!WPACKET_close(pkt)) {1311SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1312return EXT_RETURN_FAIL;1313}13141315return EXT_RETURN_SENT;1316}13171318static int tls_parse_certificate_authorities(SSL_CONNECTION *s, PACKET *pkt,1319unsigned int context, X509 *x,1320size_t chainidx)1321{1322if (!parse_ca_names(s, pkt))1323return 0;1324if (PACKET_remaining(pkt) != 0) {1325SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);1326return 0;1327}1328return 1;1329}13301331#ifndef OPENSSL_NO_SRTP1332static int init_srtp(SSL_CONNECTION *s, unsigned int context)1333{1334if (s->server)1335s->srtp_profile = NULL;13361337return 1;1338}1339#endif13401341static int final_sig_algs(SSL_CONNECTION *s, unsigned int context, int sent)1342{1343if (!sent && SSL_CONNECTION_IS_TLS13(s) && !s->hit) {1344SSLfatal(s, TLS13_AD_MISSING_EXTENSION,1345SSL_R_MISSING_SIGALGS_EXTENSION);1346return 0;1347}13481349return 1;1350}13511352static int final_supported_versions(SSL_CONNECTION *s, unsigned int context,1353int sent)1354{1355if (!sent && context == SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST) {1356SSLfatal(s, TLS13_AD_MISSING_EXTENSION,1357SSL_R_MISSING_SUPPORTED_VERSIONS_EXTENSION);1358return 0;1359}13601361return 1;1362}13631364static int final_key_share(SSL_CONNECTION *s, unsigned int context, int sent)1365{1366#if !defined(OPENSSL_NO_TLS1_3)1367if (!SSL_CONNECTION_IS_TLS13(s))1368return 1;13691370/* Nothing to do for key_share in an HRR */1371if ((context & SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST) != 0)1372return 1;13731374/*1375* If1376* we are a client1377* AND1378* we have no key_share1379* AND1380* (we are not resuming1381* OR the kex_mode doesn't allow non key_share resumes)1382* THEN1383* fail;1384*/1385if (!s->server1386&& !sent) {1387if ((s->ext.psk_kex_mode & TLSEXT_KEX_MODE_FLAG_KE) == 0) {1388SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_NO_SUITABLE_KEY_SHARE);1389return 0;1390}1391if (!s->hit) {1392SSLfatal(s, SSL_AD_MISSING_EXTENSION, SSL_R_NO_SUITABLE_KEY_SHARE);1393return 0;1394}1395}1396/*1397* IF1398* we are a server1399* THEN1400* IF1401* we have a suitable key_share1402* THEN1403* IF1404* we are stateless AND we have no cookie1405* THEN1406* send a HelloRetryRequest1407* ELSE1408* IF1409* we didn't already send a HelloRetryRequest1410* AND1411* the client sent a key_share extension1412* AND1413* (we are not resuming1414* OR the kex_mode allows key_share resumes)1415* AND1416* a shared group exists1417* THEN1418* send a HelloRetryRequest1419* ELSE IF1420* we are not resuming1421* OR1422* the kex_mode doesn't allow non key_share resumes1423* THEN1424* fail1425* ELSE IF1426* we are stateless AND we have no cookie1427* THEN1428* send a HelloRetryRequest1429*/1430if (s->server) {1431if (s->s3.peer_tmp != NULL) {1432/* We have a suitable key_share */1433if ((s->s3.flags & TLS1_FLAGS_STATELESS) != 01434&& !s->ext.cookieok) {1435if (!ossl_assert(s->hello_retry_request == SSL_HRR_NONE)) {1436/*1437* If we are stateless then we wouldn't know about any1438* previously sent HRR - so how can this be anything other1439* than 0?1440*/1441SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1442return 0;1443}1444s->hello_retry_request = SSL_HRR_PENDING;1445return 1;1446}1447} else {1448/* No suitable key_share */1449if (s->hello_retry_request == SSL_HRR_NONE && sent1450&& (!s->hit1451|| (s->ext.psk_kex_mode & TLSEXT_KEX_MODE_FLAG_KE_DHE) != 0)) {14521453/* Did we detect group overlap in tls_parse_ctos_key_share ? */1454if (s->s3.group_id_candidate != 0) {1455/* A shared group exists so send a HelloRetryRequest */1456s->s3.group_id = s->s3.group_id_candidate;1457s->hello_retry_request = SSL_HRR_PENDING;1458return 1;1459}1460}1461if (!s->hit1462|| (s->ext.psk_kex_mode & TLSEXT_KEX_MODE_FLAG_KE) == 0) {1463/* Nothing left we can do - just fail */1464SSLfatal(s, sent ? SSL_AD_HANDSHAKE_FAILURE1465: SSL_AD_MISSING_EXTENSION,1466SSL_R_NO_SUITABLE_KEY_SHARE);1467return 0;1468}14691470if ((s->s3.flags & TLS1_FLAGS_STATELESS) != 01471&& !s->ext.cookieok) {1472if (!ossl_assert(s->hello_retry_request == SSL_HRR_NONE)) {1473/*1474* If we are stateless then we wouldn't know about any1475* previously sent HRR - so how can this be anything other1476* than 0?1477*/1478SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1479return 0;1480}1481s->hello_retry_request = SSL_HRR_PENDING;1482return 1;1483}1484}14851486/*1487* We have a key_share so don't send any more HelloRetryRequest1488* messages1489*/1490if (s->hello_retry_request == SSL_HRR_PENDING)1491s->hello_retry_request = SSL_HRR_COMPLETE;1492} else {1493/*1494* For a client side resumption with no key_share we need to generate1495* the handshake secret (otherwise this is done during key_share1496* processing).1497*/1498if (!sent && !tls13_generate_handshake_secret(s, NULL, 0)) {1499SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1500return 0;1501}1502}1503#endif /* !defined(OPENSSL_NO_TLS1_3) */1504return 1;1505}15061507static int init_psk_kex_modes(SSL_CONNECTION *s, unsigned int context)1508{1509s->ext.psk_kex_mode = TLSEXT_KEX_MODE_FLAG_NONE;1510return 1;1511}15121513int tls_psk_do_binder(SSL_CONNECTION *s, const EVP_MD *md,1514const unsigned char *msgstart,1515size_t binderoffset, const unsigned char *binderin,1516unsigned char *binderout, SSL_SESSION *sess, int sign,1517int external)1518{1519EVP_PKEY *mackey = NULL;1520EVP_MD_CTX *mctx = NULL;1521unsigned char hash[EVP_MAX_MD_SIZE], binderkey[EVP_MAX_MD_SIZE];1522unsigned char finishedkey[EVP_MAX_MD_SIZE], tmpbinder[EVP_MAX_MD_SIZE];1523unsigned char *early_secret;1524/* ASCII: "res binder", in hex for EBCDIC compatibility */1525static const unsigned char resumption_label[] = "\x72\x65\x73\x20\x62\x69\x6E\x64\x65\x72";1526/* ASCII: "ext binder", in hex for EBCDIC compatibility */1527static const unsigned char external_label[] = "\x65\x78\x74\x20\x62\x69\x6E\x64\x65\x72";1528const unsigned char *label;1529size_t bindersize, labelsize, hashsize;1530int hashsizei = EVP_MD_get_size(md);1531int ret = -1;1532int usepskfored = 0;1533SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);15341535/* Ensure cast to size_t is safe */1536if (!ossl_assert(hashsizei > 0)) {1537SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1538goto err;1539}1540hashsize = (size_t)hashsizei;15411542if (external1543&& s->early_data_state == SSL_EARLY_DATA_CONNECTING1544&& s->session->ext.max_early_data == 01545&& sess->ext.max_early_data > 0)1546usepskfored = 1;15471548if (external) {1549label = external_label;1550labelsize = sizeof(external_label) - 1;1551} else {1552label = resumption_label;1553labelsize = sizeof(resumption_label) - 1;1554}15551556/*1557* Generate the early_secret. On the server side we've selected a PSK to1558* resume with (internal or external) so we always do this. On the client1559* side we do this for a non-external (i.e. resumption) PSK or external PSK1560* that will be used for early_data so that it is in place for sending early1561* data. For client side external PSK not being used for early_data we1562* generate it but store it away for later use.1563*/1564if (s->server || !external || usepskfored)1565early_secret = (unsigned char *)s->early_secret;1566else1567early_secret = (unsigned char *)sess->early_secret;15681569if (!tls13_generate_secret(s, md, NULL, sess->master_key,1570sess->master_key_length, early_secret)) {1571/* SSLfatal() already called */1572goto err;1573}15741575/*1576* Create the handshake hash for the binder key...the messages so far are1577* empty!1578*/1579mctx = EVP_MD_CTX_new();1580if (mctx == NULL1581|| EVP_DigestInit_ex(mctx, md, NULL) <= 01582|| EVP_DigestFinal_ex(mctx, hash, NULL) <= 0) {1583SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1584goto err;1585}15861587/* Generate the binder key */1588if (!tls13_hkdf_expand(s, md, early_secret, label, labelsize, hash,1589hashsize, binderkey, hashsize, 1)) {1590/* SSLfatal() already called */1591goto err;1592}15931594/* Generate the finished key */1595if (!tls13_derive_finishedkey(s, md, binderkey, finishedkey, hashsize)) {1596/* SSLfatal() already called */1597goto err;1598}15991600if (EVP_DigestInit_ex(mctx, md, NULL) <= 0) {1601SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1602goto err;1603}16041605/*1606* Get a hash of the ClientHello up to the start of the binders. If we are1607* following a HelloRetryRequest then this includes the hash of the first1608* ClientHello and the HelloRetryRequest itself.1609*/1610if (s->hello_retry_request == SSL_HRR_PENDING) {1611size_t hdatalen;1612long hdatalen_l;1613void *hdata;16141615hdatalen = hdatalen_l =1616BIO_get_mem_data(s->s3.handshake_buffer, &hdata);1617if (hdatalen_l <= 0) {1618SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_HANDSHAKE_LENGTH);1619goto err;1620}16211622/*1623* For servers the handshake buffer data will include the second1624* ClientHello - which we don't want - so we need to take that bit off.1625*/1626if (s->server) {1627PACKET hashprefix, msg;16281629/* Find how many bytes are left after the first two messages */1630if (!PACKET_buf_init(&hashprefix, hdata, hdatalen)1631|| !PACKET_forward(&hashprefix, 1)1632|| !PACKET_get_length_prefixed_3(&hashprefix, &msg)1633|| !PACKET_forward(&hashprefix, 1)1634|| !PACKET_get_length_prefixed_3(&hashprefix, &msg)) {1635SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1636goto err;1637}1638hdatalen -= PACKET_remaining(&hashprefix);1639}16401641if (EVP_DigestUpdate(mctx, hdata, hdatalen) <= 0) {1642SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1643goto err;1644}1645}16461647if (EVP_DigestUpdate(mctx, msgstart, binderoffset) <= 01648|| EVP_DigestFinal_ex(mctx, hash, NULL) <= 0) {1649SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1650goto err;1651}16521653mackey = EVP_PKEY_new_raw_private_key_ex(sctx->libctx, "HMAC",1654sctx->propq, finishedkey,1655hashsize);1656if (mackey == NULL) {1657SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1658goto err;1659}16601661if (!sign)1662binderout = tmpbinder;16631664bindersize = hashsize;1665if (EVP_DigestSignInit_ex(mctx, NULL, EVP_MD_get0_name(md), sctx->libctx,1666sctx->propq, mackey, NULL) <= 01667|| EVP_DigestSignUpdate(mctx, hash, hashsize) <= 01668|| EVP_DigestSignFinal(mctx, binderout, &bindersize) <= 01669|| bindersize != hashsize) {1670SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1671goto err;1672}16731674if (sign) {1675ret = 1;1676} else {1677/* HMAC keys can't do EVP_DigestVerify* - use CRYPTO_memcmp instead */1678ret = (CRYPTO_memcmp(binderin, binderout, hashsize) == 0);1679if (!ret)1680SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_R_BINDER_DOES_NOT_VERIFY);1681}16821683err:1684OPENSSL_cleanse(binderkey, sizeof(binderkey));1685OPENSSL_cleanse(finishedkey, sizeof(finishedkey));1686EVP_PKEY_free(mackey);1687EVP_MD_CTX_free(mctx);16881689return ret;1690}16911692static int final_early_data(SSL_CONNECTION *s, unsigned int context, int sent)1693{1694if (!sent)1695return 1;16961697if (!s->server) {1698if (context == SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS1699&& sent1700&& !s->ext.early_data_ok) {1701/*1702* If we get here then the server accepted our early_data but we1703* later realised that it shouldn't have done (e.g. inconsistent1704* ALPN)1705*/1706SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_EARLY_DATA);1707return 0;1708}17091710return 1;1711}17121713if (s->max_early_data == 01714|| !s->hit1715|| s->early_data_state != SSL_EARLY_DATA_ACCEPTING1716|| !s->ext.early_data_ok1717|| s->hello_retry_request != SSL_HRR_NONE1718|| (s->allow_early_data_cb != NULL1719&& !s->allow_early_data_cb(SSL_CONNECTION_GET_USER_SSL(s),1720s->allow_early_data_cb_data))) {1721s->ext.early_data = SSL_EARLY_DATA_REJECTED;1722} else {1723s->ext.early_data = SSL_EARLY_DATA_ACCEPTED;17241725if (!tls13_change_cipher_state(s,1726SSL3_CC_EARLY | SSL3_CHANGE_CIPHER_SERVER_READ)) {1727/* SSLfatal() already called */1728return 0;1729}1730}17311732return 1;1733}17341735static int final_maxfragmentlen(SSL_CONNECTION *s, unsigned int context,1736int sent)1737{1738if (s->session == NULL)1739return 1;17401741/* MaxFragmentLength defaults to disabled */1742if (s->session->ext.max_fragment_len_mode == TLSEXT_max_fragment_length_UNSPECIFIED)1743s->session->ext.max_fragment_len_mode = TLSEXT_max_fragment_length_DISABLED;17441745if (USE_MAX_FRAGMENT_LENGTH_EXT(s->session)) {1746s->rlayer.rrlmethod->set_max_frag_len(s->rlayer.rrl,1747GET_MAX_FRAGMENT_LENGTH(s->session));1748s->rlayer.wrlmethod->set_max_frag_len(s->rlayer.wrl,1749ssl_get_max_send_fragment(s));1750}17511752return 1;1753}17541755static int init_post_handshake_auth(SSL_CONNECTION *s,1756ossl_unused unsigned int context)1757{1758s->post_handshake_auth = SSL_PHA_NONE;17591760return 1;1761}17621763/*1764* If clients offer "pre_shared_key" without a "psk_key_exchange_modes"1765* extension, servers MUST abort the handshake.1766*/1767static int final_psk(SSL_CONNECTION *s, unsigned int context, int sent)1768{1769if (s->server && sent && s->clienthello != NULL1770&& !s->clienthello->pre_proc_exts[TLSEXT_IDX_psk_kex_modes].present) {1771SSLfatal(s, TLS13_AD_MISSING_EXTENSION,1772SSL_R_MISSING_PSK_KEX_MODES_EXTENSION);1773return 0;1774}17751776return 1;1777}17781779static int tls_init_compress_certificate(SSL_CONNECTION *sc, unsigned int context)1780{1781memset(sc->ext.compress_certificate_from_peer, 0,1782sizeof(sc->ext.compress_certificate_from_peer));1783return 1;1784}17851786/* The order these are put into the packet imply a preference order: [brotli, zlib, zstd] */1787static EXT_RETURN tls_construct_compress_certificate(SSL_CONNECTION *sc, WPACKET *pkt,1788unsigned int context,1789X509 *x, size_t chainidx)1790{1791#ifndef OPENSSL_NO_COMP_ALG1792int i;17931794if (!ossl_comp_has_alg(0))1795return EXT_RETURN_NOT_SENT;17961797/* Server: Don't attempt to compress a non-X509 (i.e. an RPK) */1798if (sc->server && sc->ext.server_cert_type != TLSEXT_cert_type_x509) {1799sc->cert_comp_prefs[0] = TLSEXT_comp_cert_none;1800return EXT_RETURN_NOT_SENT;1801}18021803/* Client: If we sent a client cert-type extension, don't indicate compression */1804if (!sc->server && sc->ext.client_cert_type_ctos) {1805sc->cert_comp_prefs[0] = TLSEXT_comp_cert_none;1806return EXT_RETURN_NOT_SENT;1807}18081809/* Do not indicate we support receiving compressed certificates */1810if ((sc->options & SSL_OP_NO_RX_CERTIFICATE_COMPRESSION) != 0)1811return EXT_RETURN_NOT_SENT;18121813if (sc->cert_comp_prefs[0] == TLSEXT_comp_cert_none)1814return EXT_RETURN_NOT_SENT;18151816if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_compress_certificate)1817|| !WPACKET_start_sub_packet_u16(pkt)1818|| !WPACKET_start_sub_packet_u8(pkt))1819goto err;18201821for (i = 0; sc->cert_comp_prefs[i] != TLSEXT_comp_cert_none; i++) {1822if (!WPACKET_put_bytes_u16(pkt, sc->cert_comp_prefs[i]))1823goto err;1824}1825if (!WPACKET_close(pkt) || !WPACKET_close(pkt))1826goto err;18271828sc->ext.compress_certificate_sent = 1;1829return EXT_RETURN_SENT;1830err:1831SSLfatal(sc, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);1832return EXT_RETURN_FAIL;1833#else1834return EXT_RETURN_NOT_SENT;1835#endif1836}18371838#ifndef OPENSSL_NO_COMP_ALG1839static int tls_comp_in_pref(SSL_CONNECTION *sc, int alg)1840{1841int i;18421843/* ossl_comp_has_alg() considers 0 as "any" */1844if (alg == 0)1845return 0;1846/* Make sure algorithm is enabled */1847if (!ossl_comp_has_alg(alg))1848return 0;1849/* If no preferences are set, it's ok */1850if (sc->cert_comp_prefs[0] == TLSEXT_comp_cert_none)1851return 1;1852/* Find the algorithm */1853for (i = 0; i < TLSEXT_comp_cert_limit; i++)1854if (sc->cert_comp_prefs[i] == alg)1855return 1;1856return 0;1857}1858#endif18591860int tls_parse_compress_certificate(SSL_CONNECTION *sc, PACKET *pkt, unsigned int context,1861X509 *x, size_t chainidx)1862{1863#ifndef OPENSSL_NO_COMP_ALG1864PACKET supported_comp_algs;1865unsigned int comp;1866int already_set[TLSEXT_comp_cert_limit];1867int j = 0;18681869/* If no algorithms are available, ignore the extension */1870if (!ossl_comp_has_alg(0))1871return 1;18721873/* Don't attempt to compress a non-X509 (i.e. an RPK) */1874if (sc->server && sc->ext.server_cert_type != TLSEXT_cert_type_x509)1875return 1;1876if (!sc->server && sc->ext.client_cert_type != TLSEXT_cert_type_x509)1877return 1;18781879/* Ignore the extension and don't send compressed certificates */1880if ((sc->options & SSL_OP_NO_TX_CERTIFICATE_COMPRESSION) != 0)1881return 1;18821883if (!PACKET_as_length_prefixed_1(pkt, &supported_comp_algs)1884|| PACKET_remaining(&supported_comp_algs) == 0) {1885SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);1886return 0;1887}18881889memset(already_set, 0, sizeof(already_set));1890/*1891* The preference array has real values, so take a look at each1892* value coming in, and make sure it's in our preference list1893* The array is 0 (i.e. "none") terminated1894* The preference list only contains supported algorithms1895*/1896while (PACKET_get_net_2(&supported_comp_algs, &comp)) {1897if (tls_comp_in_pref(sc, comp) && !already_set[comp]) {1898sc->ext.compress_certificate_from_peer[j++] = comp;1899already_set[comp] = 1;1900}1901}1902if (PACKET_remaining(&supported_comp_algs) != 0) {1903SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);1904return 0;1905}1906#endif1907return 1;1908}19091910static int init_server_cert_type(SSL_CONNECTION *sc, unsigned int context)1911{1912/* Only reset when parsing client hello */1913if (sc->server) {1914sc->ext.server_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;1915sc->ext.server_cert_type = TLSEXT_cert_type_x509;1916}1917return 1;1918}19191920static int init_client_cert_type(SSL_CONNECTION *sc, unsigned int context)1921{1922/* Only reset when parsing client hello */1923if (sc->server) {1924sc->ext.client_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;1925sc->ext.client_cert_type = TLSEXT_cert_type_x509;1926}1927return 1;1928}192919301931