提交 1266eefd 编写于 作者: M Matt Caswell

Various style updates following extensions refactor

Perl changes reviewed by Richard Levitte. Non-perl changes reviewed by Rich
Salz
Reviewed-by: NRich Salz <rsalz@openssl.org>
Reviewed-by: NRichard Levitte <levitte@openssl.org>
上级 89247375
...@@ -10,59 +10,63 @@ ...@@ -10,59 +10,63 @@
#include "../ssl_locl.h" #include "../ssl_locl.h"
#include "statem_locl.h" #include "statem_locl.h"
static int tls_ext_final_renegotiate(SSL *s, unsigned int context, int sent, static int final_renegotiate(SSL *s, unsigned int context, int sent,
int *al); int *al);
static int tls_ext_init_server_name(SSL *s, unsigned int context); static int init_server_name(SSL *s, unsigned int context);
static int tls_ext_final_server_name(SSL *s, unsigned int context, int sent, static int final_server_name(SSL *s, unsigned int context, int sent,
int *al); int *al);
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
static int tls_ext_final_ec_pt_formats(SSL *s, unsigned int context, int sent, static int final_ec_pt_formats(SSL *s, unsigned int context, int sent,
int *al); int *al);
#endif #endif
static int tls_ext_init_session_ticket(SSL *s, unsigned int context); static int init_session_ticket(SSL *s, unsigned int context);
static int tls_ext_init_status_request(SSL *s, unsigned int context); static int init_status_request(SSL *s, unsigned int context);
static int tls_ext_final_status_request(SSL *s, unsigned int context, int sent, static int final_status_request(SSL *s, unsigned int context, int sent,
int *al); int *al);
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
static int tls_ext_init_npn(SSL *s, unsigned int context); static int init_npn(SSL *s, unsigned int context);
#endif #endif
static int tls_ext_init_alpn(SSL *s, unsigned int context); static int init_alpn(SSL *s, unsigned int context);
static int tls_ext_final_alpn(SSL *s, unsigned int context, int sent, int *al); static int final_alpn(SSL *s, unsigned int context, int sent, int *al);
static int tls_ext_init_sig_algs(SSL *s, unsigned int context); static int init_sig_algs(SSL *s, unsigned int context);
#ifndef OPENSSL_NO_SRP #ifndef OPENSSL_NO_SRP
static int tls_ext_init_srp(SSL *s, unsigned int context); static int init_srp(SSL *s, unsigned int context);
#endif #endif
static int tls_ext_init_etm(SSL *s, unsigned int context); static int init_etm(SSL *s, unsigned int context);
static int tls_ext_init_ems(SSL *s, unsigned int context); static int init_ems(SSL *s, unsigned int context);
static int tls_ext_final_ems(SSL *s, unsigned int context, int sent, int *al); static int final_ems(SSL *s, unsigned int context, int sent, int *al);
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
static int tls_ext_init_srtp(SSL *s, unsigned int context); static int init_srtp(SSL *s, unsigned int context);
#endif #endif
/* Structure to define a built-in extension */ /* Structure to define a built-in extension */
typedef struct { typedef struct extensions_definition_st {
/* The ID for the extension */ /* The defined type for the extension */
unsigned int type; unsigned int type;
/*
* The context that this extension applies to, e.g. what messages and
* protocol versions
*/
unsigned int context;
/* /*
* Initialise extension before parsing. Always called for relevant contexts * Initialise extension before parsing. Always called for relevant contexts
* even if extension not present * even if extension not present
*/ */
int (*init_ext)(SSL *s, unsigned int context); int (*init)(SSL *s, unsigned int context);
/* Parse extension received by server from client */ /* Parse extension sent from client to server */
int (*parse_client_ext)(SSL *s, PACKET *pkt, int *al); int (*parse_ctos)(SSL *s, PACKET *pkt, int *al);
/* Parse extension received by client from server */ /* Parse extension send from server to client */
int (*parse_server_ext)(SSL *s, PACKET *pkt, int *al); int (*parse_stoc)(SSL *s, PACKET *pkt, int *al);
/* Construct extension sent by server */ /* Construct extension sent from server to client */
int (*construct_server_ext)(SSL *s, WPACKET *pkt, int *al); int (*construct_stoc)(SSL *s, WPACKET *pkt, int *al);
/* Construct extension sent by client */ /* Construct extension sent from client to server */
int (*construct_client_ext)(SSL *s, WPACKET *pkt, int *al); int (*construct_ctos)(SSL *s, WPACKET *pkt, int *al);
/* /*
* Finalise extension after parsing. Always called where an extensions was * Finalise extension after parsing. Always called where an extensions was
* initialised even if the extension was not present. |sent| is set to 1 if * initialised even if the extension was not present. |sent| is set to 1 if
* the extension was seen, or 0 otherwise. * the extension was seen, or 0 otherwise.
*/ */
int (*finalise_ext)(SSL *s, unsigned int context, int sent, int *al); int (*final)(SSL *s, unsigned int context, int sent, int *al);
unsigned int context;
} EXTENSION_DEFINITION; } EXTENSION_DEFINITION;
/* /*
...@@ -91,103 +95,73 @@ typedef struct { ...@@ -91,103 +95,73 @@ typedef struct {
static const EXTENSION_DEFINITION ext_defs[] = { static const EXTENSION_DEFINITION ext_defs[] = {
{ {
TLSEXT_TYPE_renegotiate, TLSEXT_TYPE_renegotiate,
NULL,
tls_parse_client_renegotiate,
tls_parse_server_renegotiate,
tls_construct_server_renegotiate,
tls_construct_client_renegotiate,
tls_ext_final_renegotiate,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_SSL3_ALLOWED EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_SSL3_ALLOWED
| EXT_TLS1_2_AND_BELOW_ONLY | EXT_TLS1_2_AND_BELOW_ONLY,
NULL, tls_parse_ctos_renegotiate, tls_parse_stoc_renegotiate,
tls_construct_stoc_renegotiate, tls_construct_ctos_renegotiate,
final_renegotiate
}, },
{ {
TLSEXT_TYPE_server_name, TLSEXT_TYPE_server_name,
tls_ext_init_server_name,
tls_parse_client_server_name,
tls_parse_server_server_name,
tls_construct_server_server_name,
tls_construct_client_server_name,
tls_ext_final_server_name,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
| EXT_TLS1_3_ENCRYPTED_EXTENSIONS | EXT_TLS1_3_ENCRYPTED_EXTENSIONS,
init_server_name,
tls_parse_ctos_server_name, tls_parse_stoc_server_name,
tls_construct_stoc_server_name, tls_construct_ctos_server_name,
final_server_name
}, },
#ifndef OPENSSL_NO_SRP #ifndef OPENSSL_NO_SRP
{ {
TLSEXT_TYPE_srp, TLSEXT_TYPE_srp,
tls_ext_init_srp, EXT_CLIENT_HELLO | EXT_TLS1_2_AND_BELOW_ONLY,
tls_parse_client_srp, init_srp, tls_parse_ctos_srp, NULL, NULL, tls_construct_ctos_srp, NULL
NULL,
NULL,
tls_construct_client_srp,
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
}, },
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
{ {
TLSEXT_TYPE_ec_point_formats, TLSEXT_TYPE_ec_point_formats,
NULL, EXT_CLIENT_HELLO | EXT_TLS1_2_AND_BELOW_ONLY,
tls_parse_client_ec_pt_formats, NULL, tls_parse_ctos_ec_pt_formats, tls_parse_stoc_ec_pt_formats,
tls_parse_server_ec_pt_formats, tls_construct_stoc_ec_pt_formats, tls_construct_ctos_ec_pt_formats,
tls_construct_server_ec_pt_formats, final_ec_pt_formats
tls_construct_client_ec_pt_formats,
tls_ext_final_ec_pt_formats,
EXT_CLIENT_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
}, },
{ {
TLSEXT_TYPE_supported_groups, TLSEXT_TYPE_supported_groups,
NULL, EXT_CLIENT_HELLO | EXT_TLS1_3_ENCRYPTED_EXTENSIONS,
tls_parse_client_supported_groups, NULL, tls_parse_ctos_supported_groups, NULL,
NULL,
NULL /* TODO(TLS1.3): Need to add this */, NULL /* TODO(TLS1.3): Need to add this */,
tls_construct_client_supported_groups, tls_construct_ctos_supported_groups, NULL
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_3_ENCRYPTED_EXTENSIONS
}, },
#endif #endif
{ {
TLSEXT_TYPE_session_ticket, TLSEXT_TYPE_session_ticket,
tls_ext_init_session_ticket, EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY,
tls_parse_client_session_ticket, init_session_ticket, tls_parse_ctos_session_ticket,
tls_parse_server_session_ticket, tls_parse_stoc_session_ticket, tls_construct_stoc_session_ticket,
tls_construct_server_session_ticket, tls_construct_ctos_session_ticket, NULL
tls_construct_client_session_ticket,
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
}, },
{ {
TLSEXT_TYPE_signature_algorithms, TLSEXT_TYPE_signature_algorithms,
tls_ext_init_sig_algs, EXT_CLIENT_HELLO,
tls_parse_client_sig_algs, init_sig_algs, tls_parse_ctos_sig_algs, NULL, NULL,
NULL, tls_construct_ctos_sig_algs, NULL
NULL,
tls_construct_client_sig_algs,
NULL,
EXT_CLIENT_HELLO
}, },
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
{ {
TLSEXT_TYPE_status_request, TLSEXT_TYPE_status_request,
tls_ext_init_status_request,
tls_parse_client_status_request,
tls_parse_server_status_request,
tls_construct_server_status_request,
tls_construct_client_status_request,
tls_ext_final_status_request,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
| EXT_TLS1_3_CERTIFICATE | EXT_TLS1_3_CERTIFICATE,
init_status_request, tls_parse_ctos_status_request,
tls_parse_stoc_status_request, tls_construct_stoc_status_request,
tls_construct_ctos_status_request, final_status_request
}, },
#endif #endif
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
{ {
TLSEXT_TYPE_next_proto_neg, TLSEXT_TYPE_next_proto_neg,
tls_ext_init_npn, EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY,
tls_parse_client_npn, init_npn, tls_parse_ctos_npn, tls_parse_stoc_npn,
tls_parse_server_npn, tls_construct_stoc_next_proto_neg, tls_construct_ctos_npn, NULL
tls_construct_server_next_proto_neg,
tls_construct_client_npn,
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
}, },
#endif #endif
{ {
...@@ -196,76 +170,52 @@ static const EXTENSION_DEFINITION ext_defs[] = { ...@@ -196,76 +170,52 @@ static const EXTENSION_DEFINITION ext_defs[] = {
* happens after server_name callbacks * happens after server_name callbacks
*/ */
TLSEXT_TYPE_application_layer_protocol_negotiation, TLSEXT_TYPE_application_layer_protocol_negotiation,
tls_ext_init_alpn,
tls_parse_client_alpn,
tls_parse_server_alpn,
tls_construct_server_alpn,
tls_construct_client_alpn,
tls_ext_final_alpn,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
| EXT_TLS1_3_ENCRYPTED_EXTENSIONS | EXT_TLS1_3_ENCRYPTED_EXTENSIONS,
init_alpn, tls_parse_ctos_alpn, tls_parse_stoc_alpn,
tls_construct_stoc_alpn, tls_construct_ctos_alpn, final_alpn
}, },
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
{ {
TLSEXT_TYPE_use_srtp, TLSEXT_TYPE_use_srtp,
tls_ext_init_srtp,
tls_parse_client_use_srtp,
tls_parse_server_use_srtp,
tls_construct_server_use_srtp,
tls_construct_client_use_srtp,
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
| EXT_TLS1_3_ENCRYPTED_EXTENSIONS | EXT_DTLS_ONLY | EXT_TLS1_3_ENCRYPTED_EXTENSIONS | EXT_DTLS_ONLY,
init_srtp, tls_parse_ctos_use_srtp, tls_parse_stoc_use_srtp,
tls_construct_stoc_use_srtp, tls_construct_ctos_use_srtp, NULL
}, },
#endif #endif
{ {
TLSEXT_TYPE_encrypt_then_mac, TLSEXT_TYPE_encrypt_then_mac,
tls_ext_init_etm, EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY,
tls_parse_client_etm, init_etm, tls_parse_ctos_etm, tls_parse_stoc_etm,
tls_parse_server_etm, tls_construct_stoc_etm, tls_construct_ctos_etm, NULL
tls_construct_server_etm,
tls_construct_client_etm,
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
}, },
#ifndef OPENSSL_NO_CT #ifndef OPENSSL_NO_CT
{ {
TLSEXT_TYPE_signed_certificate_timestamp, TLSEXT_TYPE_signed_certificate_timestamp,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
| EXT_TLS1_3_CERTIFICATE,
NULL, NULL,
/* /*
* No server side support for this, but can be provided by a custom * No server side support for this, but can be provided by a custom
* extension. This is an exception to the rule that custom extensions * extension. This is an exception to the rule that custom extensions
* cannot override built in ones. * cannot override built in ones.
*/ */
NULL, NULL, tls_parse_stoc_sct, NULL, tls_construct_ctos_sct, NULL
tls_parse_server_sct,
NULL,
tls_construct_client_sct,
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO
| EXT_TLS1_3_CERTIFICATE
}, },
#endif #endif
{ {
TLSEXT_TYPE_extended_master_secret, TLSEXT_TYPE_extended_master_secret,
tls_ext_init_ems, EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY,
tls_parse_client_ems, init_ems, tls_parse_ctos_ems, tls_parse_stoc_ems,
tls_parse_server_ems, tls_construct_stoc_ems, tls_construct_ctos_ems, final_ems
tls_construct_server_ems,
tls_construct_client_ems,
tls_ext_final_ems,
EXT_CLIENT_HELLO | EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
}, },
{ {
TLSEXT_TYPE_supported_versions, TLSEXT_TYPE_supported_versions,
EXT_CLIENT_HELLO | EXT_TLS_IMPLEMENTATION_ONLY | EXT_TLS1_3_ONLY,
NULL, NULL,
/* Processed inline as part of version selection */ /* Processed inline as part of version selection */
NULL, NULL, NULL, NULL, tls_construct_ctos_supported_versions, NULL
NULL,
NULL,
tls_construct_client_supported_versions,
NULL,
EXT_CLIENT_HELLO | EXT_TLS_IMPLEMENTATION_ONLY | EXT_TLS1_3_ONLY
}, },
{ {
/* /*
...@@ -273,15 +223,11 @@ static const EXTENSION_DEFINITION ext_defs[] = { ...@@ -273,15 +223,11 @@ static const EXTENSION_DEFINITION ext_defs[] = {
* been parsed before we do this one. * been parsed before we do this one.
*/ */
TLSEXT_TYPE_key_share, TLSEXT_TYPE_key_share,
NULL,
tls_parse_client_key_share,
tls_parse_server_key_share,
tls_construct_server_key_share,
tls_construct_client_key_share,
NULL,
EXT_CLIENT_HELLO | EXT_TLS1_3_SERVER_HELLO EXT_CLIENT_HELLO | EXT_TLS1_3_SERVER_HELLO
| EXT_TLS1_3_HELLO_RETRY_REQUEST | EXT_TLS_IMPLEMENTATION_ONLY | EXT_TLS1_3_HELLO_RETRY_REQUEST | EXT_TLS_IMPLEMENTATION_ONLY
| EXT_TLS1_3_ONLY | EXT_TLS1_3_ONLY,
NULL, tls_parse_ctos_key_share, tls_parse_stoc_key_share,
tls_construct_stoc_key_share, tls_construct_ctos_key_share, NULL
}, },
{ {
/* /*
...@@ -289,25 +235,16 @@ static const EXTENSION_DEFINITION ext_defs[] = { ...@@ -289,25 +235,16 @@ static const EXTENSION_DEFINITION ext_defs[] = {
* SSL_OP_CRYPTOPRO_TLSEXT_BUG is set * SSL_OP_CRYPTOPRO_TLSEXT_BUG is set
*/ */
TLSEXT_TYPE_cryptopro_bug, TLSEXT_TYPE_cryptopro_bug,
NULL, EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY,
NULL, NULL, NULL, NULL, tls_construct_stoc_cryptopro_bug, NULL, NULL
NULL,
tls_construct_server_cryptopro_bug,
NULL,
NULL,
EXT_TLS1_2_SERVER_HELLO | EXT_TLS1_2_AND_BELOW_ONLY
}, },
{ {
/* Last in the list because it must be added as the last extension */ /* Last in the list because it must be added as the last extension */
TLSEXT_TYPE_padding, TLSEXT_TYPE_padding,
EXT_CLIENT_HELLO,
NULL, NULL,
/* We send this, but don't read it */ /* We send this, but don't read it */
NULL, NULL, NULL, NULL, tls_construct_ctos_padding, NULL
NULL,
NULL,
tls_construct_client_padding,
NULL,
EXT_CLIENT_HELLO
} }
}; };
...@@ -318,26 +255,27 @@ static const EXTENSION_DEFINITION ext_defs[] = { ...@@ -318,26 +255,27 @@ static const EXTENSION_DEFINITION ext_defs[] = {
* 1 if we found a definition for the extension, and |*idx| is set to its index * 1 if we found a definition for the extension, and |*idx| is set to its index
*/ */
static int verify_extension(SSL *s, unsigned int context, unsigned int type, static int verify_extension(SSL *s, unsigned int context, unsigned int type,
custom_ext_methods *meths, int *found, size_t *idx) custom_ext_methods *meths, RAW_EXTENSION *rawexlist,
RAW_EXTENSION **found)
{ {
size_t i; size_t i;
size_t builtin_num = OSSL_NELEM(ext_defs); size_t builtin_num = OSSL_NELEM(ext_defs);
EXTENSION_DEFINITION *thisext;
for (i = 0; i < builtin_num; i++) { for (i = 0, thisext = ext_defs; i < builtin_num; i++, thisext++) {
if (type == ext_defs[i].type) { if (type == thisext->type) {
/* Check we're allowed to use this extension in this context */ /* Check we're allowed to use this extension in this context */
if ((context & ext_defs[i].context) == 0) if ((context & thisext->context) == 0)
return 0; return 0;
if (SSL_IS_DTLS(s)) { if (SSL_IS_DTLS(s)) {
if ((ext_defs[i].context & EXT_TLS_ONLY) != 0) if ((thisext->context & EXT_TLS_ONLY) != 0)
return 0; return 0;
} else if ((ext_defs[i].context & EXT_DTLS_ONLY) != 0) { } else if ((thisext->context & EXT_DTLS_ONLY) != 0) {
return 0; return 0;
} }
*found = 1; *found = &rawexlist[i];
*idx = i;
return 1; return 1;
} }
} }
...@@ -347,7 +285,7 @@ static int verify_extension(SSL *s, unsigned int context, unsigned int type, ...@@ -347,7 +285,7 @@ static int verify_extension(SSL *s, unsigned int context, unsigned int type,
* Custom extensions only apply to <=TLS1.2. This extension is unknown * Custom extensions only apply to <=TLS1.2. This extension is unknown
* in this context - we allow it * in this context - we allow it
*/ */
*found = 0; *found = NULL;
return 1; return 1;
} }
...@@ -355,15 +293,14 @@ static int verify_extension(SSL *s, unsigned int context, unsigned int type, ...@@ -355,15 +293,14 @@ static int verify_extension(SSL *s, unsigned int context, unsigned int type,
if (meths != NULL) { if (meths != NULL) {
for (i = builtin_num; i < builtin_num + meths->meths_count; i++) { for (i = builtin_num; i < builtin_num + meths->meths_count; i++) {
if (meths->meths[i - builtin_num].ext_type == type) { if (meths->meths[i - builtin_num].ext_type == type) {
*found = 1; *found = &rawexlist[i];
*idx = i;
return 1; return 1;
} }
} }
} }
/* Unknown extension. We allow it */ /* Unknown extension. We allow it */
*found = 0; *found = NULL;
return 1; return 1;
} }
...@@ -390,16 +327,17 @@ static int extension_is_relevant(SSL *s, unsigned int extctx, ...@@ -390,16 +327,17 @@ static int extension_is_relevant(SSL *s, unsigned int extctx,
/* /*
* Gather a list of all the extensions from the data in |packet]. |context| * Gather a list of all the extensions from the data in |packet]. |context|
* tells us which message this extension is for. The raw extension data is * tells us which message this extension is for. The raw extension data is
* stored in |*res|. In the event of an error the alert type to use is stored in * stored in |*res| on success. In the event of an error the alert type to use
* |*al|. We don't actually process the content of the extensions yet, except to * is stored in |*al|. We don't actually process the content of the extensions
* check their types. This function also runs the initialiser functions for all * yet, except to check their types. This function also runs the initialiser
* known extensions (whether we have collected them or not). * functions for all known extensions (whether we have collected them or not).
* If successful the caller is responsible for freeing the contents of |*res|.
* *
* Per http://tools.ietf.org/html/rfc5246#section-7.4.1.4, there may not be * Per http://tools.ietf.org/html/rfc5246#section-7.4.1.4, there may not be
* more than one extension of the same type in a ClientHello or ServerHello. * more than one extension of the same type in a ClientHello or ServerHello.
* This function returns 1 if all extensions are unique and we have parsed their * This function returns 1 if all extensions are unique and we have parsed their
* types, and 0 if the extensions contain duplicates, could not be successfully * types, and 0 if the extensions contain duplicates, could not be successfully
* collected, or an internal error occurred. We only check duplicates for * found, or an internal error occurred. We only check duplicates for
* extensions that we know about. We ignore others. * extensions that we know about. We ignore others.
*/ */
int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context, int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
...@@ -410,6 +348,7 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context, ...@@ -410,6 +348,7 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
int found = 0; int found = 0;
custom_ext_methods *exts = NULL; custom_ext_methods *exts = NULL;
RAW_EXTENSION *raw_extensions = NULL; RAW_EXTENSION *raw_extensions = NULL;
EXTENSION_DEFINITION *thisexd;
/* /*
* Initialise server side custom extensions. Client side is done during * Initialise server side custom extensions. Client side is done during
...@@ -424,7 +363,7 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context, ...@@ -424,7 +363,7 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
raw_extensions = OPENSSL_zalloc((OSSL_NELEM(ext_defs) raw_extensions = OPENSSL_zalloc((OSSL_NELEM(ext_defs)
+ (exts != NULL ? exts->meths_count : 0)) + (exts != NULL ? exts->meths_count : 0))
* sizeof(RAW_EXTENSION)); * sizeof(*raw_extensions));
if (raw_extensions == NULL) { if (raw_extensions == NULL) {
*al = SSL_AD_INTERNAL_ERROR; *al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_TLS_COLLECT_EXTENSIONS, ERR_R_MALLOC_FAILURE); SSLerr(SSL_F_TLS_COLLECT_EXTENSIONS, ERR_R_MALLOC_FAILURE);
...@@ -434,6 +373,7 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context, ...@@ -434,6 +373,7 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
while (PACKET_remaining(&extensions) > 0) { while (PACKET_remaining(&extensions) > 0) {
unsigned int type; unsigned int type;
PACKET extension; PACKET extension;
RAW_EXTENSION *thisex;
if (!PACKET_get_net_2(&extensions, &type) || if (!PACKET_get_net_2(&extensions, &type) ||
!PACKET_get_length_prefixed_2(&extensions, &extension)) { !PACKET_get_length_prefixed_2(&extensions, &extension)) {
...@@ -445,17 +385,16 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context, ...@@ -445,17 +385,16 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
* Verify this extension is allowed. We only check duplicates for * Verify this extension is allowed. We only check duplicates for
* extensions that we recognise. * extensions that we recognise.
*/ */
if (!verify_extension(s, context, type, exts, &found, &idx) if (!verify_extension(s, context, type, exts, raw_extensions, &thisex)
|| (found == 1 || (thisex != NULL && thisex->present == 1)) {
&& raw_extensions[idx].present == 1)) {
SSLerr(SSL_F_TLS_COLLECT_EXTENSIONS, SSL_R_BAD_EXTENSION); SSLerr(SSL_F_TLS_COLLECT_EXTENSIONS, SSL_R_BAD_EXTENSION);
*al = SSL_AD_ILLEGAL_PARAMETER; *al = SSL_AD_ILLEGAL_PARAMETER;
goto err; goto err;
} }
if (found) { if (thisex != NULL) {
raw_extensions[idx].data = extension; thisex->data = extension;
raw_extensions[idx].present = 1; thisex->present = 1;
raw_extensions[idx].type = type; thisex->type = type;
} }
} }
...@@ -463,10 +402,10 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context, ...@@ -463,10 +402,10 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
* Initialise all known extensions relevant to this context, whether we have * Initialise all known extensions relevant to this context, whether we have
* found them or not * found them or not
*/ */
for (i = 0; i < OSSL_NELEM(ext_defs); i++) { for (thisexd = ext_defs, i = 0; i < OSSL_NELEM(ext_defs); i++, thisexd++) {
if(ext_defs[i].init_ext != NULL && (ext_defs[i].context & context) != 0 if(thisexd->init != NULL && (thisexd->context & context) != 0
&& extension_is_relevant(s, ext_defs[i].context, context) && extension_is_relevant(s, thisexd->context, context)
&& !ext_defs[i].init_ext(s, context)) { && !thisexd->init(s, context)) {
*al = SSL_AD_INTERNAL_ERROR; *al = SSL_AD_INTERNAL_ERROR;
goto err; goto err;
} }
...@@ -518,14 +457,10 @@ int tls_parse_extension(SSL *s, unsigned int idx, int context, ...@@ -518,14 +457,10 @@ int tls_parse_extension(SSL *s, unsigned int idx, int context,
if (!extension_is_relevant(s, extdef->context, context)) if (!extension_is_relevant(s, extdef->context, context))
return 1; return 1;
parser = s->server ? extdef->parse_client_ext : extdef->parse_server_ext; parser = s->server ? extdef->parse_ctos : extdef->parse_stoc;
if (parser != NULL) { if (parser != NULL)
if (!parser(s, &currext->data, al)) return parser(s, &currext->data, al);
return 0;
return 1;
}
/* /*
* If the parser is NULL we fall through to the custom extension * If the parser is NULL we fall through to the custom extension
...@@ -561,7 +496,8 @@ int tls_parse_extension(SSL *s, unsigned int idx, int context, ...@@ -561,7 +496,8 @@ int tls_parse_extension(SSL *s, unsigned int idx, int context,
*/ */
int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al) int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al)
{ {
size_t loop, numexts = OSSL_NELEM(ext_defs); size_t i, numexts = OSSL_NELEM(ext_defs);
EXTENSION_DEFINITION *thisexd;
/* Calculate the number of extensions in the extensions list */ /* Calculate the number of extensions in the extensions list */
if ((context & EXT_CLIENT_HELLO) != 0) { if ((context & EXT_CLIENT_HELLO) != 0) {
...@@ -571,7 +507,7 @@ int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al) ...@@ -571,7 +507,7 @@ int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al)
} }
/* Parse each extension in turn */ /* Parse each extension in turn */
for (loop = 0; loop < numexts; loop++) { for (i = 0; i < numexts; i++) {
if (!tls_parse_extension(s, loop, context, exts, al)) if (!tls_parse_extension(s, loop, context, exts, al))
return 0; return 0;
} }
...@@ -580,11 +516,10 @@ int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al) ...@@ -580,11 +516,10 @@ int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al)
* Finalise all known extensions relevant to this context, whether we have * Finalise all known extensions relevant to this context, whether we have
* found them or not * found them or not
*/ */
for (loop = 0; loop < OSSL_NELEM(ext_defs); loop++) { for (i = 0, thisexd = ext_defs; i < OSSL_NELEM(ext_defs); i++, thisexd++) {
if(ext_defs[loop].finalise_ext != NULL if(thisexd->final != NULL
&& (ext_defs[loop].context & context) != 0 && (thisexd->context & context) != 0
&& !ext_defs[loop].finalise_ext(s, context, exts[loop].present, && !thisexd->final(s, context, exts[i].present, al))
al))
return 0; return 0;
} }
...@@ -594,14 +529,15 @@ int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al) ...@@ -594,14 +529,15 @@ int tls_parse_all_extensions(SSL *s, int context, RAW_EXTENSION *exts, int *al)
/* /*
* Construct all the extensions relevant to the current |context| and write * Construct all the extensions relevant to the current |context| and write
* them to |pkt|. Returns 1 on success or 0 on failure. If a failure occurs then * them to |pkt|. Returns 1 on success or 0 on failure. If a failure occurs then
* |al| is populated with a suitable alert code. * |al| is populated with a suitable alert code. On a failure construction stops
* at the first extension to fail to construct.
*/ */
int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context, int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context,
int *al) int *al)
{ {
size_t loop; size_t i;
int addcustom = 0; int addcustom = 0, min_version, max_version = 0, reason, tmpal;
int min_version, max_version = 0, reason, tmpal; EXTENSION_DEFINITION *thisexd;
/* /*
* Normally if something goes wrong during construction it's an internal * Normally if something goes wrong during construction it's an internal
...@@ -651,29 +587,29 @@ int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context, ...@@ -651,29 +587,29 @@ int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context,
goto err; goto err;
} }
for (loop = 0; loop < OSSL_NELEM(ext_defs); loop++) { for (i = 0, thisexd = ext_defs; i < OSSL_NELEM(ext_defs); i++, thisexd++) {
int (*construct)(SSL *s, WPACKET *pkt, int *al); int (*construct)(SSL *s, WPACKET *pkt, int *al);
/* Skip if not relevant for our context */ /* Skip if not relevant for our context */
if ((ext_defs[loop].context & context) == 0) if ((ext_defs[loop].context & context) == 0)
continue; continue;
construct = s->server ? ext_defs[loop].construct_server_ext construct = s->server ? thisexd->construct_stoc
: ext_defs[loop].construct_client_ext; : thisexd->construct_ctos;
/* Check if this extension is defined for our protocol. If not, skip */ /* Check if this extension is defined for our protocol. If not, skip */
if ((SSL_IS_DTLS(s) if ((SSL_IS_DTLS(s)
&& (ext_defs[loop].context & EXT_TLS_IMPLEMENTATION_ONLY) && (thisexd->context & EXT_TLS_IMPLEMENTATION_ONLY)
!= 0) != 0)
|| (s->version == SSL3_VERSION || (s->version == SSL3_VERSION
&& (ext_defs[loop].context & EXT_SSL3_ALLOWED) == 0) && (thisexd->context & EXT_SSL3_ALLOWED) == 0)
|| (SSL_IS_TLS13(s) || (SSL_IS_TLS13(s)
&& (ext_defs[loop].context & EXT_TLS1_2_AND_BELOW_ONLY) && (thisexd->context & EXT_TLS1_2_AND_BELOW_ONLY)
!= 0) != 0)
|| (!SSL_IS_TLS13(s) || (!SSL_IS_TLS13(s)
&& (ext_defs[loop].context & EXT_TLS1_3_ONLY) != 0 && (thisexd->context & EXT_TLS1_3_ONLY) != 0
&& (context & EXT_CLIENT_HELLO) == 0) && (context & EXT_CLIENT_HELLO) == 0)
|| ((ext_defs[loop].context & EXT_TLS1_3_ONLY) != 0 || ((thisexd->context & EXT_TLS1_3_ONLY) != 0
&& (context & EXT_CLIENT_HELLO) != 0 && (context & EXT_CLIENT_HELLO) != 0
&& (SSL_IS_DTLS(s) || max_version < TLS1_3_VERSION)) && (SSL_IS_DTLS(s) || max_version < TLS1_3_VERSION))
|| construct == NULL) || construct == NULL)
...@@ -703,7 +639,7 @@ int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context, ...@@ -703,7 +639,7 @@ int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context,
* of a failure then |*al| is populated with a suitable error code. * of a failure then |*al| is populated with a suitable error code.
*/ */
static int tls_ext_final_renegotiate(SSL *s, unsigned int context, int sent, static int final_renegotiate(SSL *s, unsigned int context, int sent,
int *al) int *al)
{ {
if (!s->server) { if (!s->server) {
...@@ -737,7 +673,7 @@ static int tls_ext_final_renegotiate(SSL *s, unsigned int context, int sent, ...@@ -737,7 +673,7 @@ static int tls_ext_final_renegotiate(SSL *s, unsigned int context, int sent,
return 1; return 1;
} }
static int tls_ext_init_server_name(SSL *s, unsigned int context) static int init_server_name(SSL *s, unsigned int context)
{ {
if (s->server) if (s->server)
s->servername_done = 0; s->servername_done = 0;
...@@ -745,7 +681,7 @@ static int tls_ext_init_server_name(SSL *s, unsigned int context) ...@@ -745,7 +681,7 @@ static int tls_ext_init_server_name(SSL *s, unsigned int context)
return 1; return 1;
} }
static int tls_ext_final_server_name(SSL *s, unsigned int context, int sent, static int final_server_name(SSL *s, unsigned int context, int sent,
int *al) int *al)
{ {
int ret = SSL_TLSEXT_ERR_NOACK; int ret = SSL_TLSEXT_ERR_NOACK;
...@@ -778,7 +714,7 @@ static int tls_ext_final_server_name(SSL *s, unsigned int context, int sent, ...@@ -778,7 +714,7 @@ static int tls_ext_final_server_name(SSL *s, unsigned int context, int sent,
} }
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
static int tls_ext_final_ec_pt_formats(SSL *s, unsigned int context, int sent, static int final_ec_pt_formats(SSL *s, unsigned int context, int sent,
int *al) int *al)
{ {
unsigned long alg_k, alg_a; unsigned long alg_k, alg_a;
...@@ -794,23 +730,20 @@ static int tls_ext_final_ec_pt_formats(SSL *s, unsigned int context, int sent, ...@@ -794,23 +730,20 @@ static int tls_ext_final_ec_pt_formats(SSL *s, unsigned int context, int sent,
* suite, then if server returns an EC point formats lists extension it * suite, then if server returns an EC point formats lists extension it
* must contain uncompressed. * must contain uncompressed.
*/ */
if ((s->tlsext_ecpointformatlist != NULL) if (s->tlsext_ecpointformatlist != NULL
&& (s->tlsext_ecpointformatlist_length > 0) && s->tlsext_ecpointformatlist_length > 0
&& (s->session->tlsext_ecpointformatlist != NULL) && s->session->tlsext_ecpointformatlist != NULL
&& (s->session->tlsext_ecpointformatlist_length > 0) && s->session->tlsext_ecpointformatlist_length > 0
&& ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))) { && ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))) {
/* we are using an ECC cipher */ /* we are using an ECC cipher */
size_t i; size_t i;
unsigned char *list; unsigned char *list = s->session->tlsext_ecpointformatlist;
int found_uncompressed = 0;
list = s->session->tlsext_ecpointformatlist;
for (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++) { for (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++) {
if (*(list++) == TLSEXT_ECPOINTFORMAT_uncompressed) { if (*list++ == TLSEXT_ECPOINTFORMAT_uncompressed)
found_uncompressed = 1;
break; break;
}
} }
if (!found_uncompressed) { if (i == s->session->tlsext_ecpointformatlist_length) {
SSLerr(SSL_F_TLS_EXT_FINAL_EC_PT_FORMATS, SSLerr(SSL_F_TLS_EXT_FINAL_EC_PT_FORMATS,
SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST); SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST);
return 0; return 0;
...@@ -821,7 +754,7 @@ static int tls_ext_final_ec_pt_formats(SSL *s, unsigned int context, int sent, ...@@ -821,7 +754,7 @@ static int tls_ext_final_ec_pt_formats(SSL *s, unsigned int context, int sent,
} }
#endif #endif
static int tls_ext_init_session_ticket(SSL *s, unsigned int context) static int init_session_ticket(SSL *s, unsigned int context)
{ {
if (!s->server) if (!s->server)
s->tlsext_ticket_expected = 0; s->tlsext_ticket_expected = 0;
...@@ -829,7 +762,7 @@ static int tls_ext_init_session_ticket(SSL *s, unsigned int context) ...@@ -829,7 +762,7 @@ static int tls_ext_init_session_ticket(SSL *s, unsigned int context)
return 1; return 1;
} }
static int tls_ext_init_status_request(SSL *s, unsigned int context) static int init_status_request(SSL *s, unsigned int context)
{ {
if (s->server) if (s->server)
s->tlsext_status_type = -1; s->tlsext_status_type = -1;
...@@ -837,7 +770,7 @@ static int tls_ext_init_status_request(SSL *s, unsigned int context) ...@@ -837,7 +770,7 @@ static int tls_ext_init_status_request(SSL *s, unsigned int context)
return 1; return 1;
} }
static int tls_ext_final_status_request(SSL *s, unsigned int context, int sent, static int final_status_request(SSL *s, unsigned int context, int sent,
int *al) int *al)
{ {
if (s->server) if (s->server)
...@@ -855,7 +788,7 @@ static int tls_ext_final_status_request(SSL *s, unsigned int context, int sent, ...@@ -855,7 +788,7 @@ static int tls_ext_final_status_request(SSL *s, unsigned int context, int sent,
} }
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
static int tls_ext_init_npn(SSL *s, unsigned int context) static int init_npn(SSL *s, unsigned int context)
{ {
s->s3->next_proto_neg_seen = 0; s->s3->next_proto_neg_seen = 0;
...@@ -863,7 +796,7 @@ static int tls_ext_init_npn(SSL *s, unsigned int context) ...@@ -863,7 +796,7 @@ static int tls_ext_init_npn(SSL *s, unsigned int context)
} }
#endif #endif
static int tls_ext_init_alpn(SSL *s, unsigned int context) static int init_alpn(SSL *s, unsigned int context)
{ {
OPENSSL_free(s->s3->alpn_selected); OPENSSL_free(s->s3->alpn_selected);
s->s3->alpn_selected = NULL; s->s3->alpn_selected = NULL;
...@@ -876,7 +809,7 @@ static int tls_ext_init_alpn(SSL *s, unsigned int context) ...@@ -876,7 +809,7 @@ static int tls_ext_init_alpn(SSL *s, unsigned int context)
return 1; return 1;
} }
static int tls_ext_final_alpn(SSL *s, unsigned int context, int sent, int *al) static int final_alpn(SSL *s, unsigned int context, int sent, int *al)
{ {
const unsigned char *selected = NULL; const unsigned char *selected = NULL;
unsigned char selected_len = 0; unsigned char selected_len = 0;
...@@ -911,7 +844,7 @@ static int tls_ext_final_alpn(SSL *s, unsigned int context, int sent, int *al) ...@@ -911,7 +844,7 @@ static int tls_ext_final_alpn(SSL *s, unsigned int context, int sent, int *al)
return 1; return 1;
} }
static int tls_ext_init_sig_algs(SSL *s, unsigned int context) static int init_sig_algs(SSL *s, unsigned int context)
{ {
/* Clear any signature algorithms extension received */ /* Clear any signature algorithms extension received */
OPENSSL_free(s->s3->tmp.peer_sigalgs); OPENSSL_free(s->s3->tmp.peer_sigalgs);
...@@ -921,7 +854,7 @@ static int tls_ext_init_sig_algs(SSL *s, unsigned int context) ...@@ -921,7 +854,7 @@ static int tls_ext_init_sig_algs(SSL *s, unsigned int context)
} }
#ifndef OPENSSL_NO_SRP #ifndef OPENSSL_NO_SRP
static int tls_ext_init_srp(SSL *s, unsigned int context) static int init_srp(SSL *s, unsigned int context)
{ {
OPENSSL_free(s->srp_ctx.login); OPENSSL_free(s->srp_ctx.login);
s->srp_ctx.login = NULL; s->srp_ctx.login = NULL;
...@@ -930,14 +863,14 @@ static int tls_ext_init_srp(SSL *s, unsigned int context) ...@@ -930,14 +863,14 @@ static int tls_ext_init_srp(SSL *s, unsigned int context)
} }
#endif #endif
static int tls_ext_init_etm(SSL *s, unsigned int context) static int init_etm(SSL *s, unsigned int context)
{ {
s->s3->flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC; s->s3->flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC;
return 1; return 1;
} }
static int tls_ext_init_ems(SSL *s, unsigned int context) static int init_ems(SSL *s, unsigned int context)
{ {
if (!s->server) if (!s->server)
s->s3->flags &= ~TLS1_FLAGS_RECEIVED_EXTMS; s->s3->flags &= ~TLS1_FLAGS_RECEIVED_EXTMS;
...@@ -945,7 +878,7 @@ static int tls_ext_init_ems(SSL *s, unsigned int context) ...@@ -945,7 +878,7 @@ static int tls_ext_init_ems(SSL *s, unsigned int context)
return 1; return 1;
} }
static int tls_ext_final_ems(SSL *s, unsigned int context, int sent, int *al) static int final_ems(SSL *s, unsigned int context, int sent, int *al)
{ {
if (!s->server && s->hit) { if (!s->server && s->hit) {
/* /*
...@@ -964,7 +897,7 @@ static int tls_ext_final_ems(SSL *s, unsigned int context, int sent, int *al) ...@@ -964,7 +897,7 @@ static int tls_ext_final_ems(SSL *s, unsigned int context, int sent, int *al)
} }
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
static int tls_ext_init_srtp(SSL *s, unsigned int context) static int init_srtp(SSL *s, unsigned int context)
{ {
if (s->server) if (s->server)
s->srtp_profile = NULL; s->srtp_profile = NULL;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "../ssl_locl.h" #include "../ssl_locl.h"
#include "statem_locl.h" #include "statem_locl.h"
int tls_construct_client_renegotiate(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_renegotiate(SSL *s, WPACKET *pkt, int *al)
{ {
/* Add RI if renegotiating */ /* Add RI if renegotiating */
if (!s->renegotiate) if (!s->renegotiate)
...@@ -30,7 +30,7 @@ int tls_construct_client_renegotiate(SSL *s, WPACKET *pkt, int *al) ...@@ -30,7 +30,7 @@ int tls_construct_client_renegotiate(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_client_server_name(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_server_name(SSL *s, WPACKET *pkt, int *al)
{ {
if (s->tlsext_hostname == NULL) if (s->tlsext_hostname == NULL)
return 1; return 1;
...@@ -54,7 +54,7 @@ int tls_construct_client_server_name(SSL *s, WPACKET *pkt, int *al) ...@@ -54,7 +54,7 @@ int tls_construct_client_server_name(SSL *s, WPACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_SRP #ifndef OPENSSL_NO_SRP
int tls_construct_client_srp(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_srp(SSL *s, WPACKET *pkt, int *al)
{ {
/* Add SRP username if there is one */ /* Add SRP username if there is one */
if (s->srp_ctx.login == NULL) if (s->srp_ctx.login == NULL)
...@@ -81,8 +81,7 @@ int tls_construct_client_srp(SSL *s, WPACKET *pkt, int *al) ...@@ -81,8 +81,7 @@ int tls_construct_client_srp(SSL *s, WPACKET *pkt, int *al)
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
static int use_ecc(SSL *s) static int use_ecc(SSL *s)
{ {
int using_ecc = 0; int i, end;
int i;
unsigned long alg_k, alg_a; unsigned long alg_k, alg_a;
STACK_OF(SSL_CIPHER) *cipher_stack = NULL; STACK_OF(SSL_CIPHER) *cipher_stack = NULL;
...@@ -90,26 +89,23 @@ static int use_ecc(SSL *s) ...@@ -90,26 +89,23 @@ static int use_ecc(SSL *s)
if (s->version == SSL3_VERSION) if (s->version == SSL3_VERSION)
return 0; return 0;
cipher_stack = SSL_get_ciphers(s); cipher_stack = SSL_get_ciphers(s);
end = sk_SSL_CIPHER_num(cipher_stack);
for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) { for (i = 0; i < end; i++) {
const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i); const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);
alg_k = c->algorithm_mkey; alg_k = c->algorithm_mkey;
alg_a = c->algorithm_auth; alg_a = c->algorithm_auth;
if ((alg_k & (SSL_kECDHE | SSL_kECDHEPSK)) if ((alg_k & (SSL_kECDHE | SSL_kECDHEPSK))
|| (alg_a & SSL_aECDSA) || (alg_a & SSL_aECDSA)
|| c->min_tls >= TLS1_3_VERSION) { || c->min_tls >= TLS1_3_VERSION)
using_ecc = 1;
break; break;
}
} }
return using_ecc; return i < end;
} }
int tls_construct_client_ec_pt_formats(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_ec_pt_formats(SSL *s, WPACKET *pkt, int *al)
{ {
const unsigned char *pformats; const unsigned char *pformats;
size_t num_formats; size_t num_formats;
...@@ -118,7 +114,6 @@ int tls_construct_client_ec_pt_formats(SSL *s, WPACKET *pkt, int *al) ...@@ -118,7 +114,6 @@ int tls_construct_client_ec_pt_formats(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
/* Add TLS extension ECPointFormats to the ClientHello message */ /* Add TLS extension ECPointFormats to the ClientHello message */
tls1_get_formatlist(s, &pformats, &num_formats); tls1_get_formatlist(s, &pformats, &num_formats);
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats) if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)
...@@ -134,7 +129,7 @@ int tls_construct_client_ec_pt_formats(SSL *s, WPACKET *pkt, int *al) ...@@ -134,7 +129,7 @@ int tls_construct_client_ec_pt_formats(SSL *s, WPACKET *pkt, int *al)
} }
int tls_construct_client_supported_groups(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_supported_groups(SSL *s, WPACKET *pkt, int *al)
{ {
const unsigned char *pcurves = NULL, *pcurvestmp; const unsigned char *pcurves = NULL, *pcurvestmp;
size_t num_curves = 0, i; size_t num_curves = 0, i;
...@@ -183,7 +178,7 @@ int tls_construct_client_supported_groups(SSL *s, WPACKET *pkt, int *al) ...@@ -183,7 +178,7 @@ int tls_construct_client_supported_groups(SSL *s, WPACKET *pkt, int *al)
} }
#endif #endif
int tls_construct_client_session_ticket(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_session_ticket(SSL *s, WPACKET *pkt, int *al)
{ {
size_t ticklen; size_t ticklen;
...@@ -222,7 +217,7 @@ int tls_construct_client_session_ticket(SSL *s, WPACKET *pkt, int *al) ...@@ -222,7 +217,7 @@ int tls_construct_client_session_ticket(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_client_sig_algs(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_sig_algs(SSL *s, WPACKET *pkt, int *al)
{ {
size_t salglen; size_t salglen;
const unsigned char *salg; const unsigned char *salg;
...@@ -231,7 +226,6 @@ int tls_construct_client_sig_algs(SSL *s, WPACKET *pkt, int *al) ...@@ -231,7 +226,6 @@ int tls_construct_client_sig_algs(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
salglen = tls12_get_psigalgs(s, &salg); salglen = tls12_get_psigalgs(s, &salg);
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms) if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms)
/* Sub-packet for sig-algs extension */ /* Sub-packet for sig-algs extension */
|| !WPACKET_start_sub_packet_u16(pkt) || !WPACKET_start_sub_packet_u16(pkt)
...@@ -248,7 +242,7 @@ int tls_construct_client_sig_algs(SSL *s, WPACKET *pkt, int *al) ...@@ -248,7 +242,7 @@ int tls_construct_client_sig_algs(SSL *s, WPACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_construct_client_status_request(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_status_request(SSL *s, WPACKET *pkt, int *al)
{ {
int i; int i;
...@@ -266,11 +260,9 @@ int tls_construct_client_status_request(SSL *s, WPACKET *pkt, int *al) ...@@ -266,11 +260,9 @@ int tls_construct_client_status_request(SSL *s, WPACKET *pkt, int *al)
} }
for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) { for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {
unsigned char *idbytes; unsigned char *idbytes;
int idlen; OCSP_RESPID *id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);
OCSP_RESPID *id; int idlen = i2d_OCSP_RESPID(id, NULL);
id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);
idlen = i2d_OCSP_RESPID(id, NULL);
if (idlen <= 0 if (idlen <= 0
/* Sub-packet for an individual id */ /* Sub-packet for an individual id */
|| !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes) || !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes)
...@@ -312,7 +304,7 @@ int tls_construct_client_status_request(SSL *s, WPACKET *pkt, int *al) ...@@ -312,7 +304,7 @@ int tls_construct_client_status_request(SSL *s, WPACKET *pkt, int *al)
#endif #endif
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
int tls_construct_client_npn(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_npn(SSL *s, WPACKET *pkt, int *al)
{ {
if (s->ctx->next_proto_select_cb == NULL || s->s3->tmp.finish_md_len != 0) if (s->ctx->next_proto_select_cb == NULL || s->s3->tmp.finish_md_len != 0)
return 1; return 1;
...@@ -331,7 +323,7 @@ int tls_construct_client_npn(SSL *s, WPACKET *pkt, int *al) ...@@ -331,7 +323,7 @@ int tls_construct_client_npn(SSL *s, WPACKET *pkt, int *al)
} }
#endif #endif
int tls_construct_client_alpn(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_alpn(SSL *s, WPACKET *pkt, int *al)
{ {
s->s3->alpn_sent = 0; s->s3->alpn_sent = 0;
...@@ -359,11 +351,10 @@ int tls_construct_client_alpn(SSL *s, WPACKET *pkt, int *al) ...@@ -359,11 +351,10 @@ int tls_construct_client_alpn(SSL *s, WPACKET *pkt, int *al)
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_construct_client_use_srtp(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_use_srtp(SSL *s, WPACKET *pkt, int *al)
{ {
STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = SSL_get_srtp_profiles(s); STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = SSL_get_srtp_profiles(s);
SRTP_PROTECTION_PROFILE *prof; int i, end;
int i, ct;
if (clnt == NULL) if (clnt == NULL)
return 1; return 1;
...@@ -376,9 +367,12 @@ int tls_construct_client_use_srtp(SSL *s, WPACKET *pkt, int *al) ...@@ -376,9 +367,12 @@ int tls_construct_client_use_srtp(SSL *s, WPACKET *pkt, int *al)
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_USE_SRTP, ERR_R_INTERNAL_ERROR); SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_USE_SRTP, ERR_R_INTERNAL_ERROR);
return 0; return 0;
} }
ct = sk_SRTP_PROTECTION_PROFILE_num(clnt);
for (i = 0; i < ct; i++) { end = sk_SRTP_PROTECTION_PROFILE_num(clnt);
prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i); for (i = 0; i < end; i++) {
const SRTP_PROTECTION_PROFILE *prof =
sk_SRTP_PROTECTION_PROFILE_value(clnt, i);
if (prof == NULL || !WPACKET_put_bytes_u16(pkt, prof->id)) { if (prof == NULL || !WPACKET_put_bytes_u16(pkt, prof->id)) {
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_USE_SRTP, ERR_R_INTERNAL_ERROR); SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_USE_SRTP, ERR_R_INTERNAL_ERROR);
return 0; return 0;
...@@ -396,7 +390,7 @@ int tls_construct_client_use_srtp(SSL *s, WPACKET *pkt, int *al) ...@@ -396,7 +390,7 @@ int tls_construct_client_use_srtp(SSL *s, WPACKET *pkt, int *al)
} }
#endif #endif
int tls_construct_client_etm(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_etm(SSL *s, WPACKET *pkt, int *al)
{ {
if (s->options & SSL_OP_NO_ENCRYPT_THEN_MAC) if (s->options & SSL_OP_NO_ENCRYPT_THEN_MAC)
return 1; return 1;
...@@ -411,7 +405,7 @@ int tls_construct_client_etm(SSL *s, WPACKET *pkt, int *al) ...@@ -411,7 +405,7 @@ int tls_construct_client_etm(SSL *s, WPACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_CT #ifndef OPENSSL_NO_CT
int tls_construct_client_sct(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_sct(SSL *s, WPACKET *pkt, int *al)
{ {
if (s->ct_validation_callback == NULL) if (s->ct_validation_callback == NULL)
return 1; return 1;
...@@ -426,7 +420,7 @@ int tls_construct_client_sct(SSL *s, WPACKET *pkt, int *al) ...@@ -426,7 +420,7 @@ int tls_construct_client_sct(SSL *s, WPACKET *pkt, int *al)
} }
#endif #endif
int tls_construct_client_ems(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_ems(SSL *s, WPACKET *pkt, int *al)
{ {
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret) if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)
|| !WPACKET_put_bytes_u16(pkt, 0)) { || !WPACKET_put_bytes_u16(pkt, 0)) {
...@@ -437,7 +431,7 @@ int tls_construct_client_ems(SSL *s, WPACKET *pkt, int *al) ...@@ -437,7 +431,7 @@ int tls_construct_client_ems(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_client_supported_versions(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_supported_versions(SSL *s, WPACKET *pkt, int *al)
{ {
int currv, min_version, max_version, reason; int currv, min_version, max_version, reason;
...@@ -484,7 +478,7 @@ int tls_construct_client_supported_versions(SSL *s, WPACKET *pkt, int *al) ...@@ -484,7 +478,7 @@ int tls_construct_client_supported_versions(SSL *s, WPACKET *pkt, int *al)
} }
int tls_construct_client_key_share(SSL *s, WPACKET *pkt, int *al) int tls_construct_ctos_key_share(SSL *s, WPACKET *pkt, int *al)
{ {
size_t i, sharessent = 0, num_curves = 0; size_t i, sharessent = 0, num_curves = 0;
const unsigned char *pcurves = NULL; const unsigned char *pcurves = NULL;
...@@ -569,7 +563,10 @@ int tls_construct_client_key_share(SSL *s, WPACKET *pkt, int *al) ...@@ -569,7 +563,10 @@ int tls_construct_client_key_share(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al) #define F5_WORKAROUND_MIN_MSG_LEN 0xff
#define F5_WORKAROUND_MAX_MSG_LEN 0x200
int tls_construct_ctos_padding(SSL *s, WPACKET *pkt, int *al)
{ {
unsigned char *padbytes; unsigned char *padbytes;
size_t hlen; size_t hlen;
...@@ -580,7 +577,7 @@ int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al) ...@@ -580,7 +577,7 @@ int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al)
/* /*
* Add padding to workaround bugs in F5 terminators. See * Add padding to workaround bugs in F5 terminators. See
* https://tools.ietf.org/html/draft-agl-tls-padding-03 NB: because this * https://tools.ietf.org/html/draft-agl-tls-padding-03 NB: because this
* code works out the length of all existing extensions it MUST always * code calculates the length of all existing extensions it MUST always
* appear last. * appear last.
*/ */
if (!WPACKET_get_total_written(pkt, &hlen)) { if (!WPACKET_get_total_written(pkt, &hlen)) {
...@@ -588,8 +585,14 @@ int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al) ...@@ -588,8 +585,14 @@ int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al)
return 0; return 0;
} }
if (hlen > 0xff && hlen < 0x200) { if (hlen > F5_WORKAROUND_MIN_MSG_LEN && hlen < F5_WORKAROUND_MAX_MSG_LEN) {
hlen = 0x200 - hlen; /* Calculate the amond of padding we need to add */
hlen = F5_WORKAROUND_MAX_MSG_LEN - hlen;
/*
* Take off the size of extension header itself (2 bytes for type and
* 2 bytes for length bytes)
*/
if (hlen >= 4) if (hlen >= 4)
hlen -= 4; hlen -= 4;
else else
...@@ -609,7 +612,7 @@ int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al) ...@@ -609,7 +612,7 @@ int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al)
/* /*
* Parse the server's renegotiation binding and abort if it's not right * Parse the server's renegotiation binding and abort if it's not right
*/ */
int tls_parse_server_renegotiate(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_renegotiate(SSL *s, PACKET *pkt, int *al)
{ {
size_t expected_len = s->s3->previous_client_finished_len size_t expected_len = s->s3->previous_client_finished_len
+ s->s3->previous_server_finished_len; + s->s3->previous_server_finished_len;
...@@ -666,7 +669,7 @@ int tls_parse_server_renegotiate(SSL *s, PACKET *pkt, int *al) ...@@ -666,7 +669,7 @@ int tls_parse_server_renegotiate(SSL *s, PACKET *pkt, int *al)
return 1; return 1;
} }
int tls_parse_server_server_name(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_server_name(SSL *s, PACKET *pkt, int *al)
{ {
if (s->tlsext_hostname == NULL || PACKET_remaining(pkt) > 0) { if (s->tlsext_hostname == NULL || PACKET_remaining(pkt) > 0) {
*al = SSL_AD_UNRECOGNIZED_NAME; *al = SSL_AD_UNRECOGNIZED_NAME;
...@@ -689,7 +692,7 @@ int tls_parse_server_server_name(SSL *s, PACKET *pkt, int *al) ...@@ -689,7 +692,7 @@ int tls_parse_server_server_name(SSL *s, PACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_parse_server_ec_pt_formats(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_ec_pt_formats(SSL *s, PACKET *pkt, int *al)
{ {
unsigned int ecpointformatlist_length; unsigned int ecpointformatlist_length;
PACKET ecptformatlist; PACKET ecptformatlist;
...@@ -724,26 +727,28 @@ int tls_parse_server_ec_pt_formats(SSL *s, PACKET *pkt, int *al) ...@@ -724,26 +727,28 @@ int tls_parse_server_ec_pt_formats(SSL *s, PACKET *pkt, int *al)
} }
#endif #endif
int tls_parse_server_session_ticket(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_session_ticket(SSL *s, PACKET *pkt, int *al)
{ {
if (s->tls_session_ticket_ext_cb && if (s->tls_session_ticket_ext_cb != NULL &&
!s->tls_session_ticket_ext_cb(s, PACKET_data(pkt), !s->tls_session_ticket_ext_cb(s, PACKET_data(pkt),
PACKET_remaining(pkt), PACKET_remaining(pkt),
s->tls_session_ticket_ext_cb_arg)) { s->tls_session_ticket_ext_cb_arg)) {
*al = SSL_AD_INTERNAL_ERROR; *al = SSL_AD_INTERNAL_ERROR;
return 0; return 0;
} }
if (!tls_use_ticket(s) || PACKET_remaining(pkt) > 0) { if (!tls_use_ticket(s) || PACKET_remaining(pkt) > 0) {
*al = SSL_AD_UNSUPPORTED_EXTENSION; *al = SSL_AD_UNSUPPORTED_EXTENSION;
return 0; return 0;
} }
s->tlsext_ticket_expected = 1; s->tlsext_ticket_expected = 1;
return 1; return 1;
} }
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_parse_server_status_request(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_status_request(SSL *s, PACKET *pkt, int *al)
{ {
/* /*
* MUST be empty and only sent if we've requested a status * MUST be empty and only sent if we've requested a status
...@@ -762,7 +767,7 @@ int tls_parse_server_status_request(SSL *s, PACKET *pkt, int *al) ...@@ -762,7 +767,7 @@ int tls_parse_server_status_request(SSL *s, PACKET *pkt, int *al)
#ifndef OPENSSL_NO_CT #ifndef OPENSSL_NO_CT
int tls_parse_server_sct(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_sct(SSL *s, PACKET *pkt, int *al)
{ {
/* /*
* Only take it if we asked for it - i.e if there is no CT validation * Only take it if we asked for it - i.e if there is no CT validation
...@@ -773,10 +778,9 @@ int tls_parse_server_sct(SSL *s, PACKET *pkt, int *al) ...@@ -773,10 +778,9 @@ int tls_parse_server_sct(SSL *s, PACKET *pkt, int *al)
size_t size = PACKET_remaining(pkt); size_t size = PACKET_remaining(pkt);
/* Simply copy it off for later processing */ /* Simply copy it off for later processing */
if (s->tlsext_scts != NULL) { OPENSSL_free(s->tlsext_scts);
OPENSSL_free(s->tlsext_scts); s->tlsext_scts = NULL;
s->tlsext_scts = NULL;
}
s->tlsext_scts_len = size; s->tlsext_scts_len = size;
if (size > 0) { if (size > 0) {
s->tlsext_scts = OPENSSL_malloc(size); s->tlsext_scts = OPENSSL_malloc(size);
...@@ -816,12 +820,13 @@ static int ssl_next_proto_validate(PACKET *pkt) ...@@ -816,12 +820,13 @@ static int ssl_next_proto_validate(PACKET *pkt)
return 1; return 1;
} }
int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_npn(SSL *s, PACKET *pkt, int *al)
{ {
unsigned char *selected; unsigned char *selected;
unsigned char selected_len; unsigned char selected_len;
PACKET tmppkt; PACKET tmppkt;
/* Check if we are in a renegotiation. If so ignore this extension */
if (s->s3->tmp.finish_md_len != 0) if (s->s3->tmp.finish_md_len != 0)
return 1; return 1;
...@@ -830,6 +835,7 @@ int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al) ...@@ -830,6 +835,7 @@ int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al)
*al = SSL_AD_UNSUPPORTED_EXTENSION; *al = SSL_AD_UNSUPPORTED_EXTENSION;
return 0; return 0;
} }
/* The data must be valid */ /* The data must be valid */
tmppkt = *pkt; tmppkt = *pkt;
if (!ssl_next_proto_validate(&tmppkt)) { if (!ssl_next_proto_validate(&tmppkt)) {
...@@ -844,6 +850,7 @@ int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al) ...@@ -844,6 +850,7 @@ int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al)
*al = SSL_AD_INTERNAL_ERROR; *al = SSL_AD_INTERNAL_ERROR;
return 0; return 0;
} }
/* /*
* Could be non-NULL if server has sent multiple NPN extensions in * Could be non-NULL if server has sent multiple NPN extensions in
* a single Serverhello * a single Serverhello
...@@ -863,7 +870,7 @@ int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al) ...@@ -863,7 +870,7 @@ int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al)
} }
#endif #endif
int tls_parse_server_alpn(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_alpn(SSL *s, PACKET *pkt, int *al)
{ {
size_t len; size_t len;
...@@ -900,17 +907,17 @@ int tls_parse_server_alpn(SSL *s, PACKET *pkt, int *al) ...@@ -900,17 +907,17 @@ int tls_parse_server_alpn(SSL *s, PACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_parse_server_use_srtp(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_use_srtp(SSL *s, PACKET *pkt, int *al)
{ {
unsigned int id, ct, mki; unsigned int id, ct, mki;
int i; int i;
STACK_OF(SRTP_PROTECTION_PROFILE) *clnt; STACK_OF(SRTP_PROTECTION_PROFILE) *clnt;
SRTP_PROTECTION_PROFILE *prof; SRTP_PROTECTION_PROFILE *prof;
if (!PACKET_get_net_2(pkt, &ct) if (!PACKET_get_net_2(pkt, &ct) || ct != 2
|| ct != 2 || !PACKET_get_net_2(pkt, &id) || !PACKET_get_net_2(pkt, &id)
|| !PACKET_get_1(pkt, &mki) || !PACKET_get_1(pkt, &mki)
|| PACKET_remaining(pkt) != 0) { || PACKET_remaining(pkt) != 0) {
SSLerr(SSL_F_TLS_PARSE_SERVER_USE_SRTP, SSLerr(SSL_F_TLS_PARSE_SERVER_USE_SRTP,
SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST); SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
*al = SSL_AD_DECODE_ERROR; *al = SSL_AD_DECODE_ERROR;
...@@ -924,9 +931,8 @@ int tls_parse_server_use_srtp(SSL *s, PACKET *pkt, int *al) ...@@ -924,9 +931,8 @@ int tls_parse_server_use_srtp(SSL *s, PACKET *pkt, int *al)
return 0; return 0;
} }
clnt = SSL_get_srtp_profiles(s);
/* Throw an error if the server gave us an unsolicited extension */ /* Throw an error if the server gave us an unsolicited extension */
clnt = SSL_get_srtp_profiles(s);
if (clnt == NULL) { if (clnt == NULL) {
SSLerr(SSL_F_TLS_PARSE_SERVER_USE_SRTP, SSL_R_NO_SRTP_PROFILES); SSLerr(SSL_F_TLS_PARSE_SERVER_USE_SRTP, SSL_R_NO_SRTP_PROFILES);
*al = SSL_AD_DECODE_ERROR; *al = SSL_AD_DECODE_ERROR;
...@@ -954,7 +960,7 @@ int tls_parse_server_use_srtp(SSL *s, PACKET *pkt, int *al) ...@@ -954,7 +960,7 @@ int tls_parse_server_use_srtp(SSL *s, PACKET *pkt, int *al)
} }
#endif #endif
int tls_parse_server_etm(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_etm(SSL *s, PACKET *pkt, int *al)
{ {
/* Ignore if inappropriate ciphersuite */ /* Ignore if inappropriate ciphersuite */
if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC) if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC)
...@@ -965,7 +971,7 @@ int tls_parse_server_etm(SSL *s, PACKET *pkt, int *al) ...@@ -965,7 +971,7 @@ int tls_parse_server_etm(SSL *s, PACKET *pkt, int *al)
return 1; return 1;
} }
int tls_parse_server_ems(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_ems(SSL *s, PACKET *pkt, int *al)
{ {
s->s3->flags |= TLS1_FLAGS_RECEIVED_EXTMS; s->s3->flags |= TLS1_FLAGS_RECEIVED_EXTMS;
if (!s->hit) if (!s->hit)
...@@ -974,7 +980,7 @@ int tls_parse_server_ems(SSL *s, PACKET *pkt, int *al) ...@@ -974,7 +980,7 @@ int tls_parse_server_ems(SSL *s, PACKET *pkt, int *al)
return 1; return 1;
} }
int tls_parse_server_key_share(SSL *s, PACKET *pkt, int *al) int tls_parse_stoc_key_share(SSL *s, PACKET *pkt, int *al)
{ {
unsigned int group_id; unsigned int group_id;
PACKET encoded_pt; PACKET encoded_pt;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
/* /*
* Parse the client's renegotiation binding and abort if it's not right * Parse the client's renegotiation binding and abort if it's not right
*/ */
int tls_parse_client_renegotiate(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_renegotiate(SSL *s, PACKET *pkt, int *al)
{ {
unsigned int ilen; unsigned int ilen;
const unsigned char *data; const unsigned char *data;
...@@ -49,35 +49,34 @@ int tls_parse_client_renegotiate(SSL *s, PACKET *pkt, int *al) ...@@ -49,35 +49,34 @@ int tls_parse_client_renegotiate(SSL *s, PACKET *pkt, int *al)
return 1; return 1;
} }
int tls_parse_client_server_name(SSL *s, PACKET *pkt, int *al) /*-
* The servername extension is treated as follows:
*
* - Only the hostname type is supported with a maximum length of 255.
* - The servername is rejected if too long or if it contains zeros,
* in which case an fatal alert is generated.
* - The servername field is maintained together with the session cache.
* - When a session is resumed, the servername call back invoked in order
* to allow the application to position itself to the right context.
* - The servername is acknowledged if it is new for a session or when
* it is identical to a previously used for the same session.
* Applications can control the behaviour. They can at any time
* set a 'desirable' servername for a new SSL object. This can be the
* case for example with HTTPS when a Host: header field is received and
* a renegotiation is requested. In this case, a possible servername
* presented in the new client hello is only acknowledged if it matches
* the value of the Host: field.
* - Applications must use SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
* if they provide for changing an explicit servername context for the
* session, i.e. when the session has been established with a servername
* extension.
* - On session reconnect, the servername extension may be absent.
*/
int tls_parse_ctos_server_name(SSL *s, PACKET *pkt, int *al)
{ {
unsigned int servname_type; unsigned int servname_type;
PACKET sni, hostname; PACKET sni, hostname;
/*-
* The servername extension is treated as follows:
*
* - Only the hostname type is supported with a maximum length of 255.
* - The servername is rejected if too long or if it contains zeros,
* in which case an fatal alert is generated.
* - The servername field is maintained together with the session cache.
* - When a session is resumed, the servername call back invoked in order
* to allow the application to position itself to the right context.
* - The servername is acknowledged if it is new for a session or when
* it is identical to a previously used for the same session.
* Applications can control the behaviour. They can at any time
* set a 'desirable' servername for a new SSL object. This can be the
* case for example with HTTPS when a Host: header field is received and
* a renegotiation is requested. In this case, a possible servername
* presented in the new client hello is only acknowledged if it matches
* the value of the Host: field.
* - Applications must use SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
* if they provide for changing an explicit servername context for the
* session, i.e. when the session has been established with a servername
* extension.
* - On session reconnect, the servername extension may be absent.
*
*/
if (!PACKET_as_length_prefixed_2(pkt, &sni) if (!PACKET_as_length_prefixed_2(pkt, &sni)
/* ServerNameList must be at least 1 byte long. */ /* ServerNameList must be at least 1 byte long. */
|| PACKET_remaining(&sni) == 0) { || PACKET_remaining(&sni) == 0) {
...@@ -88,7 +87,7 @@ int tls_parse_client_server_name(SSL *s, PACKET *pkt, int *al) ...@@ -88,7 +87,7 @@ int tls_parse_client_server_name(SSL *s, PACKET *pkt, int *al)
/* /*
* Although the server_name extension was intended to be * Although the server_name extension was intended to be
* extensible to new name types, RFC 4366 defined the * extensible to new name types, RFC 4366 defined the
* syntax inextensibility and OpenSSL 1.0.x parses it as * syntax inextensibly and OpenSSL 1.0.x parses it as
* such. * such.
* RFC 6066 corrected the mistake but adding new name types * RFC 6066 corrected the mistake but adding new name types
* is nevertheless no longer feasible, so act as if no other * is nevertheless no longer feasible, so act as if no other
...@@ -135,7 +134,7 @@ int tls_parse_client_server_name(SSL *s, PACKET *pkt, int *al) ...@@ -135,7 +134,7 @@ int tls_parse_client_server_name(SSL *s, PACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_SRP #ifndef OPENSSL_NO_SRP
int tls_parse_client_srp(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_srp(SSL *s, PACKET *pkt, int *al)
{ {
PACKET srp_I; PACKET srp_I;
...@@ -159,7 +158,7 @@ int tls_parse_client_srp(SSL *s, PACKET *pkt, int *al) ...@@ -159,7 +158,7 @@ int tls_parse_client_srp(SSL *s, PACKET *pkt, int *al)
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_parse_client_ec_pt_formats(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_ec_pt_formats(SSL *s, PACKET *pkt, int *al)
{ {
PACKET ec_point_format_list; PACKET ec_point_format_list;
...@@ -182,7 +181,7 @@ int tls_parse_client_ec_pt_formats(SSL *s, PACKET *pkt, int *al) ...@@ -182,7 +181,7 @@ int tls_parse_client_ec_pt_formats(SSL *s, PACKET *pkt, int *al)
} }
#endif /* OPENSSL_NO_EC */ #endif /* OPENSSL_NO_EC */
int tls_parse_client_session_ticket(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_session_ticket(SSL *s, PACKET *pkt, int *al)
{ {
if (s->tls_session_ticket_ext_cb && if (s->tls_session_ticket_ext_cb &&
!s->tls_session_ticket_ext_cb(s, PACKET_data(pkt), !s->tls_session_ticket_ext_cb(s, PACKET_data(pkt),
...@@ -195,7 +194,7 @@ int tls_parse_client_session_ticket(SSL *s, PACKET *pkt, int *al) ...@@ -195,7 +194,7 @@ int tls_parse_client_session_ticket(SSL *s, PACKET *pkt, int *al)
return 1; return 1;
} }
int tls_parse_client_sig_algs(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_sig_algs(SSL *s, PACKET *pkt, int *al)
{ {
PACKET supported_sig_algs; PACKET supported_sig_algs;
...@@ -216,93 +215,93 @@ int tls_parse_client_sig_algs(SSL *s, PACKET *pkt, int *al) ...@@ -216,93 +215,93 @@ int tls_parse_client_sig_algs(SSL *s, PACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_parse_client_status_request(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_status_request(SSL *s, PACKET *pkt, int *al)
{ {
PACKET responder_id_list, exts;
if (!PACKET_get_1(pkt, (unsigned int *)&s->tlsext_status_type)) { if (!PACKET_get_1(pkt, (unsigned int *)&s->tlsext_status_type)) {
*al = SSL_AD_DECODE_ERROR; *al = SSL_AD_DECODE_ERROR;
return 0; return 0;
} }
if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) { if (s->tlsext_status_type != TLSEXT_STATUSTYPE_ocsp) {
const unsigned char *ext_data;
PACKET responder_id_list, exts;
if (!PACKET_get_length_prefixed_2 (pkt, &responder_id_list)) {
*al = SSL_AD_DECODE_ERROR;
return 0;
}
/* /*
* We remove any OCSP_RESPIDs from a previous handshake * We don't know what to do with any other type so ignore it.
* to prevent unbounded memory growth - CVE-2016-6304
*/ */
sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free); s->tlsext_status_type = -1;
if (PACKET_remaining(&responder_id_list) > 0) { return 1;
s->tlsext_ocsp_ids = sk_OCSP_RESPID_new_null(); }
if (s->tlsext_ocsp_ids == NULL) {
*al = SSL_AD_INTERNAL_ERROR;
return 0;
}
} else {
s->tlsext_ocsp_ids = NULL;
}
while (PACKET_remaining(&responder_id_list) > 0) { if (!PACKET_get_length_prefixed_2 (pkt, &responder_id_list)) {
OCSP_RESPID *id; *al = SSL_AD_DECODE_ERROR;
PACKET responder_id; return 0;
const unsigned char *id_data; }
if (!PACKET_get_length_prefixed_2(&responder_id_list, /*
&responder_id) * We remove any OCSP_RESPIDs from a previous handshake
|| PACKET_remaining(&responder_id) == 0) { * to prevent unbounded memory growth - CVE-2016-6304
*al = SSL_AD_DECODE_ERROR; */
return 0; sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);
} if (PACKET_remaining(&responder_id_list) > 0) {
s->tlsext_ocsp_ids = sk_OCSP_RESPID_new_null();
if (s->tlsext_ocsp_ids == NULL) {
*al = SSL_AD_INTERNAL_ERROR;
return 0;
}
} else {
s->tlsext_ocsp_ids = NULL;
}
id_data = PACKET_data(&responder_id); while (PACKET_remaining(&responder_id_list) > 0) {
/* TODO(size_t): Convert d2i_* to size_t */ OCSP_RESPID *id;
id = d2i_OCSP_RESPID(NULL, &id_data, PACKET responder_id;
(int)PACKET_remaining(&responder_id)); const unsigned char *id_data;
if (id == NULL) {
*al = SSL_AD_DECODE_ERROR;
return 0;
}
if (id_data != PACKET_end(&responder_id)) { if (!PACKET_get_length_prefixed_2(&responder_id_list, &responder_id)
OCSP_RESPID_free(id); || PACKET_remaining(&responder_id) == 0) {
*al = SSL_AD_DECODE_ERROR; *al = SSL_AD_DECODE_ERROR;
return 0; return 0;
} }
if (!sk_OCSP_RESPID_push(s->tlsext_ocsp_ids, id)) { id_data = PACKET_data(&responder_id);
OCSP_RESPID_free(id); /* TODO(size_t): Convert d2i_* to size_t */
*al = SSL_AD_INTERNAL_ERROR; id = d2i_OCSP_RESPID(NULL, &id_data,
return 0; (int)PACKET_remaining(&responder_id));
} if (id == NULL) {
*al = SSL_AD_DECODE_ERROR;
return 0;
} }
/* Read in request_extensions */ if (id_data != PACKET_end(&responder_id)) {
if (!PACKET_as_length_prefixed_2(pkt, &exts)) { OCSP_RESPID_free(id);
*al = SSL_AD_DECODE_ERROR; *al = SSL_AD_DECODE_ERROR;
return 0; return 0;
} }
if (PACKET_remaining(&exts) > 0) { if (!sk_OCSP_RESPID_push(s->tlsext_ocsp_ids, id)) {
ext_data = PACKET_data(&exts); OCSP_RESPID_free(id);
sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, *al = SSL_AD_INTERNAL_ERROR;
X509_EXTENSION_free); return 0;
s->tlsext_ocsp_exts = }
d2i_X509_EXTENSIONS(NULL, &ext_data, }
(int)PACKET_remaining(&exts));
if (s->tlsext_ocsp_exts == NULL || ext_data != PACKET_end(&exts)) { /* Read in request_extensions */
*al = SSL_AD_DECODE_ERROR; if (!PACKET_as_length_prefixed_2(pkt, &exts)) {
return 0; *al = SSL_AD_DECODE_ERROR;
} return 0;
}
if (PACKET_remaining(&exts) > 0) {
const unsigned char *ext_data = PACKET_data(&exts);
sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,
X509_EXTENSION_free);
s->tlsext_ocsp_exts =
d2i_X509_EXTENSIONS(NULL, &ext_data, (int)PACKET_remaining(&exts));
if (s->tlsext_ocsp_exts == NULL || ext_data != PACKET_end(&exts)) {
*al = SSL_AD_DECODE_ERROR;
return 0;
} }
} else {
/*
* We don't know what to do with any other type so ignore it.
*/
s->tlsext_status_type = -1;
} }
return 1; return 1;
...@@ -310,40 +309,38 @@ int tls_parse_client_status_request(SSL *s, PACKET *pkt, int *al) ...@@ -310,40 +309,38 @@ int tls_parse_client_status_request(SSL *s, PACKET *pkt, int *al)
#endif #endif
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
int tls_parse_client_npn(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_npn(SSL *s, PACKET *pkt, int *al)
{ {
if (s->s3->tmp.finish_md_len == 0) { /*
/*- * We shouldn't accept this extension on a
* We shouldn't accept this extension on a * renegotiation.
* renegotiation. *
* * s->new_session will be set on renegotiation, but we
* s->new_session will be set on renegotiation, but we * probably shouldn't rely that it couldn't be set on
* probably shouldn't rely that it couldn't be set on * the initial renegotiation too in certain cases (when
* the initial renegotiation too in certain cases (when * there's some other reason to disallow resuming an
* there's some other reason to disallow resuming an * earlier session -- the current code won't be doing
* earlier session -- the current code won't be doing * anything like that, but this might change).
* anything like that, but this might change). *
* * A valid sign that there's been a previous handshake
* A valid sign that there's been a previous handshake * in this connection is if s->s3->tmp.finish_md_len >
* in this connection is if s->s3->tmp.finish_md_len > * 0. (We are talking about a check that will happen
* 0. (We are talking about a check that will happen * in the Hello protocol round, well before a new
* in the Hello protocol round, well before a new * Finished message could have been computed.)
* Finished message could have been computed.) */
*/ if (s->s3->tmp.finish_md_len == 0)
s->s3->next_proto_neg_seen = 1; s->s3->next_proto_neg_seen = 1;
}
return 1; return 1;
} }
#endif #endif
/* /*
* Save the ALPN extension in a ClientHello. * Save the ALPN extension in a ClientHello.|pkt| holds the contents of the ALPN
* pkt: the contents of the ALPN extension, not including type and length. * extension, not including type and length. |al| is a pointer to the alert
* al: a pointer to the alert value to send in the event of a failure. * value to send in the event of a failure. Returns: 1 on success, 0 on error.
* returns: 1 on success, 0 on error.
*/ */
int tls_parse_client_alpn(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_alpn(SSL *s, PACKET *pkt, int *al)
{ {
PACKET protocol_list, save_protocol_list, protocol; PACKET protocol_list, save_protocol_list, protocol;
...@@ -376,9 +373,8 @@ int tls_parse_client_alpn(SSL *s, PACKET *pkt, int *al) ...@@ -376,9 +373,8 @@ int tls_parse_client_alpn(SSL *s, PACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_use_srtp(SSL *s, PACKET *pkt, int *al)
{ {
SRTP_PROTECTION_PROFILE *sprof;
STACK_OF(SRTP_PROTECTION_PROFILE) *srvr; STACK_OF(SRTP_PROTECTION_PROFILE) *srvr;
unsigned int ct, mki_len, id; unsigned int ct, mki_len, id;
int i, srtp_pref; int i, srtp_pref;
...@@ -389,8 +385,8 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al) ...@@ -389,8 +385,8 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al)
return 1; return 1;
/* Pull off the length of the cipher suite list and check it is even */ /* Pull off the length of the cipher suite list and check it is even */
if (!PACKET_get_net_2(pkt, &ct) if (!PACKET_get_net_2(pkt, &ct) || (ct & 1) != 0
|| (ct & 1) != 0 || !PACKET_get_sub_packet(pkt, &subpkt, ct)) { || !PACKET_get_sub_packet(pkt, &subpkt, ct)) {
SSLerr(SSL_F_TLS_PARSE_CLIENT_USE_SRTP, SSLerr(SSL_F_TLS_PARSE_CLIENT_USE_SRTP,
SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST); SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
*al = SSL_AD_DECODE_ERROR; *al = SSL_AD_DECODE_ERROR;
...@@ -417,7 +413,9 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al) ...@@ -417,7 +413,9 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al)
* does nothing. * does nothing.
*/ */
for (i = 0; i < srtp_pref; i++) { for (i = 0; i < srtp_pref; i++) {
sprof = sk_SRTP_PROTECTION_PROFILE_value(srvr, i); const SRTP_PROTECTION_PROFILE *sprof =
sk_SRTP_PROTECTION_PROFILE_value(srvr, i);
if (sprof->id == id) { if (sprof->id == id) {
s->srtp_profile = sprof; s->srtp_profile = sprof;
srtp_pref = i; srtp_pref = i;
...@@ -426,9 +424,7 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al) ...@@ -426,9 +424,7 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al)
} }
} }
/* /* Now extract the MKI value as a sanity check, but discard it for now */
* Now extract the MKI value as a sanity check, but discard it for now
*/
if (!PACKET_get_1(pkt, &mki_len)) { if (!PACKET_get_1(pkt, &mki_len)) {
SSLerr(SSL_F_TLS_PARSE_CLIENT_USE_SRTP, SSLerr(SSL_F_TLS_PARSE_CLIENT_USE_SRTP,
SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST); SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
...@@ -447,7 +443,7 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al) ...@@ -447,7 +443,7 @@ int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al)
} }
#endif #endif
int tls_parse_client_etm(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_etm(SSL *s, PACKET *pkt, int *al)
{ {
if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC)) if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC))
s->s3->flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC; s->s3->flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC;
...@@ -474,8 +470,8 @@ static int check_in_list(SSL *s, unsigned int group_id, ...@@ -474,8 +470,8 @@ static int check_in_list(SSL *s, unsigned int group_id,
unsigned int share_id = (groups[0] << 8) | (groups[1]); unsigned int share_id = (groups[0] << 8) | (groups[1]);
if (group_id == share_id if (group_id == share_id
&& (!checkallow || tls_curve_allowed(s, groups, && (!checkallow
SSL_SECOP_CURVE_CHECK))) { || tls_curve_allowed(s, groups, SSL_SECOP_CURVE_CHECK))) {
break; break;
} }
} }
...@@ -489,7 +485,7 @@ static int check_in_list(SSL *s, unsigned int group_id, ...@@ -489,7 +485,7 @@ static int check_in_list(SSL *s, unsigned int group_id,
* the raw PACKET data for the extension. Returns 1 on success or 0 on failure. * the raw PACKET data for the extension. Returns 1 on success or 0 on failure.
* If a failure occurs then |*al| is set to an appropriate alert value. * If a failure occurs then |*al| is set to an appropriate alert value.
*/ */
int tls_parse_client_key_share(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_key_share(SSL *s, PACKET *pkt, int *al)
{ {
unsigned int group_id; unsigned int group_id;
PACKET key_share_list, encoded_pt; PACKET key_share_list, encoded_pt;
...@@ -585,6 +581,7 @@ int tls_parse_client_key_share(SSL *s, PACKET *pkt, int *al) ...@@ -585,6 +581,7 @@ int tls_parse_client_key_share(SSL *s, PACKET *pkt, int *al)
} else { } else {
/* Set up EVP_PKEY with named curve as parameters */ /* Set up EVP_PKEY with named curve as parameters */
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL); EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
if (pctx == NULL if (pctx == NULL
|| EVP_PKEY_paramgen_init(pctx) <= 0 || EVP_PKEY_paramgen_init(pctx) <= 0
|| EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
...@@ -615,7 +612,7 @@ int tls_parse_client_key_share(SSL *s, PACKET *pkt, int *al) ...@@ -615,7 +612,7 @@ int tls_parse_client_key_share(SSL *s, PACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_parse_client_supported_groups(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_supported_groups(SSL *s, PACKET *pkt, int *al)
{ {
PACKET supported_groups_list; PACKET supported_groups_list;
...@@ -639,7 +636,7 @@ int tls_parse_client_supported_groups(SSL *s, PACKET *pkt, int *al) ...@@ -639,7 +636,7 @@ int tls_parse_client_supported_groups(SSL *s, PACKET *pkt, int *al)
} }
#endif #endif
int tls_parse_client_ems(SSL *s, PACKET *pkt, int *al) int tls_parse_ctos_ems(SSL *s, PACKET *pkt, int *al)
{ {
/* The extension must always be empty */ /* The extension must always be empty */
if (PACKET_remaining(pkt) != 0) { if (PACKET_remaining(pkt) != 0) {
...@@ -652,8 +649,10 @@ int tls_parse_client_ems(SSL *s, PACKET *pkt, int *al) ...@@ -652,8 +649,10 @@ int tls_parse_client_ems(SSL *s, PACKET *pkt, int *al)
return 1; return 1;
} }
/* Add the server's renegotiation binding */ /*
int tls_construct_server_renegotiate(SSL *s, WPACKET *pkt, int *al) * Add the server's renegotiation binding
*/
int tls_construct_stoc_renegotiate(SSL *s, WPACKET *pkt, int *al)
{ {
if (!s->s3->send_connection_binding) if (!s->s3->send_connection_binding)
return 1; return 1;
...@@ -674,7 +673,7 @@ int tls_construct_server_renegotiate(SSL *s, WPACKET *pkt, int *al) ...@@ -674,7 +673,7 @@ int tls_construct_server_renegotiate(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_server_server_name(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_server_name(SSL *s, WPACKET *pkt, int *al)
{ {
if (s->hit || s->servername_done != 1 if (s->hit || s->servername_done != 1
|| s->session->tlsext_hostname == NULL) || s->session->tlsext_hostname == NULL)
...@@ -690,7 +689,7 @@ int tls_construct_server_server_name(SSL *s, WPACKET *pkt, int *al) ...@@ -690,7 +689,7 @@ int tls_construct_server_server_name(SSL *s, WPACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_construct_server_ec_pt_formats(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_ec_pt_formats(SSL *s, WPACKET *pkt, int *al)
{ {
unsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey; unsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
unsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth; unsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth;
...@@ -703,7 +702,6 @@ int tls_construct_server_ec_pt_formats(SSL *s, WPACKET *pkt, int *al) ...@@ -703,7 +702,6 @@ int tls_construct_server_ec_pt_formats(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
tls1_get_formatlist(s, &plist, &plistlen); tls1_get_formatlist(s, &plist, &plistlen);
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats) if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)
|| !WPACKET_start_sub_packet_u16(pkt) || !WPACKET_start_sub_packet_u16(pkt)
|| !WPACKET_sub_memcpy_u8(pkt, plist, plistlen) || !WPACKET_sub_memcpy_u8(pkt, plist, plistlen)
...@@ -716,7 +714,7 @@ int tls_construct_server_ec_pt_formats(SSL *s, WPACKET *pkt, int *al) ...@@ -716,7 +714,7 @@ int tls_construct_server_ec_pt_formats(SSL *s, WPACKET *pkt, int *al)
} }
#endif #endif
int tls_construct_server_session_ticket(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_session_ticket(SSL *s, WPACKET *pkt, int *al)
{ {
if (!s->tlsext_ticket_expected || !tls_use_ticket(s)) { if (!s->tlsext_ticket_expected || !tls_use_ticket(s)) {
s->tlsext_ticket_expected = 0; s->tlsext_ticket_expected = 0;
...@@ -733,7 +731,7 @@ int tls_construct_server_session_ticket(SSL *s, WPACKET *pkt, int *al) ...@@ -733,7 +731,7 @@ int tls_construct_server_session_ticket(SSL *s, WPACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_construct_server_status_request(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_status_request(SSL *s, WPACKET *pkt, int *al)
{ {
if (!s->tlsext_status_expected) if (!s->tlsext_status_expected)
return 1; return 1;
...@@ -750,7 +748,7 @@ int tls_construct_server_status_request(SSL *s, WPACKET *pkt, int *al) ...@@ -750,7 +748,7 @@ int tls_construct_server_status_request(SSL *s, WPACKET *pkt, int *al)
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
int tls_construct_server_next_proto_neg(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_next_proto_neg(SSL *s, WPACKET *pkt, int *al)
{ {
const unsigned char *npa; const unsigned char *npa;
unsigned int npalen; unsigned int npalen;
...@@ -777,7 +775,7 @@ int tls_construct_server_next_proto_neg(SSL *s, WPACKET *pkt, int *al) ...@@ -777,7 +775,7 @@ int tls_construct_server_next_proto_neg(SSL *s, WPACKET *pkt, int *al)
} }
#endif #endif
int tls_construct_server_alpn(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_alpn(SSL *s, WPACKET *pkt, int *al)
{ {
if (s->s3->alpn_selected == NULL) if (s->s3->alpn_selected == NULL)
return 1; return 1;
...@@ -798,7 +796,7 @@ int tls_construct_server_alpn(SSL *s, WPACKET *pkt, int *al) ...@@ -798,7 +796,7 @@ int tls_construct_server_alpn(SSL *s, WPACKET *pkt, int *al)
} }
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_construct_server_use_srtp(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_use_srtp(SSL *s, WPACKET *pkt, int *al)
{ {
if (s->srtp_profile == NULL) if (s->srtp_profile == NULL)
return 1; return 1;
...@@ -817,7 +815,7 @@ int tls_construct_server_use_srtp(SSL *s, WPACKET *pkt, int *al) ...@@ -817,7 +815,7 @@ int tls_construct_server_use_srtp(SSL *s, WPACKET *pkt, int *al)
} }
#endif #endif
int tls_construct_server_etm(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_etm(SSL *s, WPACKET *pkt, int *al)
{ {
if ((s->s3->flags & TLS1_FLAGS_ENCRYPT_THEN_MAC) == 0) if ((s->s3->flags & TLS1_FLAGS_ENCRYPT_THEN_MAC) == 0)
return 1; return 1;
...@@ -843,7 +841,7 @@ int tls_construct_server_etm(SSL *s, WPACKET *pkt, int *al) ...@@ -843,7 +841,7 @@ int tls_construct_server_etm(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_server_ems(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_ems(SSL *s, WPACKET *pkt, int *al)
{ {
if ((s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS) == 0) if ((s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS) == 0)
return 1; return 1;
...@@ -857,7 +855,7 @@ int tls_construct_server_ems(SSL *s, WPACKET *pkt, int *al) ...@@ -857,7 +855,7 @@ int tls_construct_server_ems(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_server_key_share(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_key_share(SSL *s, WPACKET *pkt, int *al)
{ {
unsigned char *encodedPoint; unsigned char *encodedPoint;
size_t encoded_pt_len = 0; size_t encoded_pt_len = 0;
...@@ -911,7 +909,7 @@ int tls_construct_server_key_share(SSL *s, WPACKET *pkt, int *al) ...@@ -911,7 +909,7 @@ int tls_construct_server_key_share(SSL *s, WPACKET *pkt, int *al)
return 1; return 1;
} }
int tls_construct_server_cryptopro_bug(SSL *s, WPACKET *pkt, int *al) int tls_construct_stoc_cryptopro_bug(SSL *s, WPACKET *pkt, int *al)
{ {
const unsigned char cryptopro_ext[36] = { const unsigned char cryptopro_ext[36] = {
0xfd, 0xe8, /* 65000 */ 0xfd, 0xe8, /* 65000 */
......
...@@ -1132,7 +1132,7 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt) ...@@ -1132,7 +1132,7 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt)
* server wants to resume. * server wants to resume.
*/ */
if (s->version >= TLS1_VERSION && !SSL_IS_TLS13(s) if (s->version >= TLS1_VERSION && !SSL_IS_TLS13(s)
&& s->tls_session_secret_cb && s->session->tlsext_tick) { && s->tls_session_secret_cb != NULL && s->session->tlsext_tick) {
const SSL_CIPHER *pref_cipher = NULL; const SSL_CIPHER *pref_cipher = NULL;
/* /*
* s->session->master_key_length is a size_t, but this is an int for * s->session->master_key_length is a size_t, but this is an int for
...@@ -3112,10 +3112,11 @@ static MSG_PROCESS_RETURN tls_process_encrypted_extensions(SSL *s, PACKET *pkt) ...@@ -3112,10 +3112,11 @@ static MSG_PROCESS_RETURN tls_process_encrypted_extensions(SSL *s, PACKET *pkt)
*/ */
if (!tls_collect_extensions(s, &extensions, if (!tls_collect_extensions(s, &extensions,
EXT_TLS1_3_ENCRYPTED_EXTENSIONS EXT_TLS1_3_ENCRYPTED_EXTENSIONS
| EXT_TLS1_3_CERTIFICATE, &rawexts, &al) | EXT_TLS1_3_CERTIFICATE,
&rawexts, &al)
|| !tls_parse_all_extensions(s, || !tls_parse_all_extensions(s,
EXT_TLS1_3_ENCRYPTED_EXTENSIONS EXT_TLS1_3_ENCRYPTED_EXTENSIONS
| EXT_TLS1_3_CERTIFICATE, | EXT_TLS1_3_CERTIFICATE,
rawexts, &al)) rawexts, &al))
goto err; goto err;
......
...@@ -163,106 +163,106 @@ __owur int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context, ...@@ -163,106 +163,106 @@ __owur int tls_construct_extensions(SSL *s, WPACKET *pkt, unsigned int context,
int *al); int *al);
/* Server Extension processing */ /* Server Extension processing */
int tls_parse_client_renegotiate(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_renegotiate(SSL *s, PACKET *pkt, int *al);
int tls_parse_client_server_name(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_server_name(SSL *s, PACKET *pkt, int *al);
#ifndef OPENSSL_NO_SRP #ifndef OPENSSL_NO_SRP
int tls_parse_client_srp(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_srp(SSL *s, PACKET *pkt, int *al);
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_parse_client_ec_pt_formats(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_ec_pt_formats(SSL *s, PACKET *pkt, int *al);
int tls_parse_client_supported_groups(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_supported_groups(SSL *s, PACKET *pkt, int *al);
#endif #endif
int tls_parse_client_session_ticket(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_session_ticket(SSL *s, PACKET *pkt, int *al);
int tls_parse_client_sig_algs(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_sig_algs(SSL *s, PACKET *pkt, int *al);
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_parse_client_status_request(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_status_request(SSL *s, PACKET *pkt, int *al);
#endif #endif
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
int tls_parse_client_npn(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_npn(SSL *s, PACKET *pkt, int *al);
#endif #endif
int tls_parse_client_alpn(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_alpn(SSL *s, PACKET *pkt, int *al);
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_parse_client_use_srtp(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_use_srtp(SSL *s, PACKET *pkt, int *al);
#endif #endif
int tls_parse_client_etm(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_etm(SSL *s, PACKET *pkt, int *al);
int tls_parse_client_key_share(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_key_share(SSL *s, PACKET *pkt, int *al);
int tls_parse_client_ems(SSL *s, PACKET *pkt, int *al); int tls_parse_ctos_ems(SSL *s, PACKET *pkt, int *al);
int tls_construct_server_renegotiate(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_renegotiate(SSL *s, WPACKET *pkt, int *al);
int tls_construct_server_server_name(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_server_name(SSL *s, WPACKET *pkt, int *al);
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_construct_server_ec_pt_formats(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_ec_pt_formats(SSL *s, WPACKET *pkt, int *al);
#endif #endif
int tls_construct_server_session_ticket(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_session_ticket(SSL *s, WPACKET *pkt, int *al);
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_construct_server_status_request(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_status_request(SSL *s, WPACKET *pkt, int *al);
#endif #endif
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
int tls_construct_server_next_proto_neg(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_next_proto_neg(SSL *s, WPACKET *pkt, int *al);
#endif #endif
int tls_construct_server_alpn(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_alpn(SSL *s, WPACKET *pkt, int *al);
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_construct_server_use_srtp(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_use_srtp(SSL *s, WPACKET *pkt, int *al);
#endif #endif
int tls_construct_server_etm(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_etm(SSL *s, WPACKET *pkt, int *al);
int tls_construct_server_ems(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_ems(SSL *s, WPACKET *pkt, int *al);
int tls_construct_server_key_share(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_key_share(SSL *s, WPACKET *pkt, int *al);
/* /*
* Not in public headers as this is not an official extension. Only used when * Not in public headers as this is not an official extension. Only used when
* SSL_OP_CRYPTOPRO_TLSEXT_BUG is set. * SSL_OP_CRYPTOPRO_TLSEXT_BUG is set.
*/ */
#define TLSEXT_TYPE_cryptopro_bug 0xfde8 #define TLSEXT_TYPE_cryptopro_bug 0xfde8
int tls_construct_server_cryptopro_bug(SSL *s, WPACKET *pkt, int *al); int tls_construct_stoc_cryptopro_bug(SSL *s, WPACKET *pkt, int *al);
/* Client Extension processing */ /* Client Extension processing */
int tls_construct_client_renegotiate(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_renegotiate(SSL *s, WPACKET *pkt, int *al);
int tls_construct_client_server_name(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_server_name(SSL *s, WPACKET *pkt, int *al);
#ifndef OPENSSL_NO_SRP #ifndef OPENSSL_NO_SRP
int tls_construct_client_srp(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_srp(SSL *s, WPACKET *pkt, int *al);
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_construct_client_ec_pt_formats(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_ec_pt_formats(SSL *s, WPACKET *pkt, int *al);
int tls_construct_client_supported_groups(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_supported_groups(SSL *s, WPACKET *pkt, int *al);
#endif #endif
int tls_construct_client_session_ticket(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_session_ticket(SSL *s, WPACKET *pkt, int *al);
int tls_construct_client_sig_algs(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_sig_algs(SSL *s, WPACKET *pkt, int *al);
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_construct_client_status_request(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_status_request(SSL *s, WPACKET *pkt, int *al);
#endif #endif
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
int tls_construct_client_npn(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_npn(SSL *s, WPACKET *pkt, int *al);
#endif #endif
int tls_construct_client_alpn(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_alpn(SSL *s, WPACKET *pkt, int *al);
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_construct_client_use_srtp(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_use_srtp(SSL *s, WPACKET *pkt, int *al);
#endif #endif
int tls_construct_client_etm(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_etm(SSL *s, WPACKET *pkt, int *al);
#ifndef OPENSSL_NO_CT #ifndef OPENSSL_NO_CT
int tls_construct_client_sct(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_sct(SSL *s, WPACKET *pkt, int *al);
#endif #endif
int tls_construct_client_ems(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_ems(SSL *s, WPACKET *pkt, int *al);
int tls_construct_client_supported_versions(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_supported_versions(SSL *s, WPACKET *pkt, int *al);
int tls_construct_client_key_share(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_key_share(SSL *s, WPACKET *pkt, int *al);
int tls_construct_client_padding(SSL *s, WPACKET *pkt, int *al); int tls_construct_ctos_padding(SSL *s, WPACKET *pkt, int *al);
int tls_parse_server_renegotiate(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_renegotiate(SSL *s, PACKET *pkt, int *al);
int tls_parse_server_server_name(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_server_name(SSL *s, PACKET *pkt, int *al);
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
int tls_parse_server_ec_pt_formats(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_ec_pt_formats(SSL *s, PACKET *pkt, int *al);
#endif #endif
int tls_parse_server_session_ticket(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_session_ticket(SSL *s, PACKET *pkt, int *al);
#ifndef OPENSSL_NO_OCSP #ifndef OPENSSL_NO_OCSP
int tls_parse_server_status_request(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_status_request(SSL *s, PACKET *pkt, int *al);
#endif #endif
#ifndef OPENSSL_NO_CT #ifndef OPENSSL_NO_CT
int tls_parse_server_sct(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_sct(SSL *s, PACKET *pkt, int *al);
#endif #endif
#ifndef OPENSSL_NO_NEXTPROTONEG #ifndef OPENSSL_NO_NEXTPROTONEG
int tls_parse_server_npn(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_npn(SSL *s, PACKET *pkt, int *al);
#endif #endif
int tls_parse_server_alpn(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_alpn(SSL *s, PACKET *pkt, int *al);
#ifndef OPENSSL_NO_SRTP #ifndef OPENSSL_NO_SRTP
int tls_parse_server_use_srtp(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_use_srtp(SSL *s, PACKET *pkt, int *al);
#endif #endif
int tls_parse_server_etm(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_etm(SSL *s, PACKET *pkt, int *al);
int tls_parse_server_ems(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_ems(SSL *s, PACKET *pkt, int *al);
int tls_parse_server_key_share(SSL *s, PACKET *pkt, int *al); int tls_parse_stoc_key_share(SSL *s, PACKET *pkt, int *al);
...@@ -1078,10 +1078,6 @@ int dtls_construct_hello_verify_request(SSL *s, WPACKET *pkt) ...@@ -1078,10 +1078,6 @@ int dtls_construct_hello_verify_request(SSL *s, WPACKET *pkt)
*/ */
static void ssl_check_for_safari(SSL *s, const CLIENTHELLO_MSG *hello) static void ssl_check_for_safari(SSL *s, const CLIENTHELLO_MSG *hello)
{ {
unsigned int type;
PACKET sni, tmppkt;
size_t ext_len;
static const unsigned char kSafariExtensionsBlock[] = { static const unsigned char kSafariExtensionsBlock[] = {
0x00, 0x0a, /* elliptic_curves extension */ 0x00, 0x0a, /* elliptic_curves extension */
0x00, 0x08, /* 8 bytes */ 0x00, 0x08, /* 8 bytes */
...@@ -1104,9 +1100,11 @@ static void ssl_check_for_safari(SSL *s, const CLIENTHELLO_MSG *hello) ...@@ -1104,9 +1100,11 @@ static void ssl_check_for_safari(SSL *s, const CLIENTHELLO_MSG *hello)
0x04, 0x03, /* SHA-256/ECDSA */ 0x04, 0x03, /* SHA-256/ECDSA */
0x02, 0x03, /* SHA-1/ECDSA */ 0x02, 0x03, /* SHA-1/ECDSA */
}; };
/* Length of the common prefix (first two extensions). */ /* Length of the common prefix (first two extensions). */
static const size_t kSafariCommonExtensionsLength = 18; static const size_t kSafariCommonExtensionsLength = 18;
unsigned int type;
PACKET sni, tmppkt;
size_t ext_len;
tmppkt = hello->extensions; tmppkt = hello->extensions;
...@@ -1694,7 +1692,7 @@ MSG_PROCESS_RETURN tls_process_client_hello(SSL *s, PACKET *pkt) ...@@ -1694,7 +1692,7 @@ MSG_PROCESS_RETURN tls_process_client_hello(SSL *s, PACKET *pkt)
/* /*
* Call the status request callback if needed. Upon success, returns 1. * Call the status request callback if needed. Upon success, returns 1.
* Upon failure, returns 0 and sets |al| to the appropriate fatal alert. * Upon failure, returns 0 and sets |*al| to the appropriate fatal alert.
*/ */
static int tls_handle_status_request(SSL *s, int *al) static int tls_handle_status_request(SSL *s, int *al)
{ {
...@@ -1706,10 +1704,11 @@ static int tls_handle_status_request(SSL *s, int *al) ...@@ -1706,10 +1704,11 @@ static int tls_handle_status_request(SSL *s, int *al)
* and must be called after the cipher has been chosen because this may * and must be called after the cipher has been chosen because this may
* influence which certificate is sent * influence which certificate is sent
*/ */
if ((s->tlsext_status_type != -1) && s->ctx && s->ctx->tlsext_status_cb) { if (s->tlsext_status_type != -1 && s->ctx != NULL
&& s->ctx->tlsext_status_cb != NULL) {
int ret; int ret;
CERT_PKEY *certpkey; CERT_PKEY *certpkey = ssl_get_server_send_pkey(s);
certpkey = ssl_get_server_send_pkey(s);
/* If no certificate can't return certificate status */ /* If no certificate can't return certificate status */
if (certpkey != NULL) { if (certpkey != NULL) {
/* /*
...@@ -1912,8 +1911,8 @@ int tls_construct_server_hello(SSL *s, WPACKET *pkt) ...@@ -1912,8 +1911,8 @@ int tls_construct_server_hello(SSL *s, WPACKET *pkt)
&& !WPACKET_put_bytes_u8(pkt, compm)) && !WPACKET_put_bytes_u8(pkt, compm))
|| !tls_construct_extensions(s, pkt, || !tls_construct_extensions(s, pkt,
SSL_IS_TLS13(s) SSL_IS_TLS13(s)
? EXT_TLS1_3_SERVER_HELLO ? EXT_TLS1_3_SERVER_HELLO
: EXT_TLS1_2_SERVER_HELLO, &al)) { : EXT_TLS1_2_SERVER_HELLO, &al)) {
SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_HELLO, ERR_R_INTERNAL_ERROR); SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_HELLO, ERR_R_INTERNAL_ERROR);
goto err; goto err;
} }
......
...@@ -593,6 +593,7 @@ static int ssl_print_version(BIO *bio, int indent, const char *name, ...@@ -593,6 +593,7 @@ static int ssl_print_version(BIO *bio, int indent, const char *name,
unsigned int *version) unsigned int *version)
{ {
int vers; int vers;
if (*pmsglen < 2) if (*pmsglen < 2)
return 0; return 0;
vers = ((*pmsg)[0] << 8) | (*pmsg)[1]; vers = ((*pmsg)[0] << 8) | (*pmsg)[1];
...@@ -867,6 +868,7 @@ static int ssl_print_server_hello(BIO *bio, int indent, ...@@ -867,6 +868,7 @@ static int ssl_print_server_hello(BIO *bio, int indent,
{ {
unsigned int cs; unsigned int cs;
unsigned int vers; unsigned int vers;
if (!ssl_print_version(bio, indent, "server_version", &msg, &msglen, &vers)) if (!ssl_print_version(bio, indent, "server_version", &msg, &msglen, &vers))
return 0; return 0;
if (!ssl_print_random(bio, indent, &msg, &msglen)) if (!ssl_print_random(bio, indent, &msg, &msglen))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册