X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=ssl%2Ft1_trce.c;h=be3039af38223d26058a3a374d084ec320ce5534;hp=fa975be17419bb87934eae0dda08c78df2b2b409;hb=6b97cc6ec17586ff9c1d96ab5c3e0b6d829074a8;hpb=9d75dce3e1f94be6006500089491cb3284f70d06 diff --git a/ssl/t1_trce.c b/ssl/t1_trce.c index fa975be174..be3039af38 100644 --- a/ssl/t1_trce.c +++ b/ssl/t1_trce.c @@ -19,11 +19,11 @@ typedef struct { } ssl_trace_tbl; # define ssl_trace_str(val, tbl) \ - do_ssl_trace_str(val, tbl, OSSL_NELEM(tbl)) + do_ssl_trace_str(val, tbl, OSSL_NELEM(tbl)) # define ssl_trace_list(bio, indent, msg, msglen, value, table) \ - do_ssl_trace_list(bio, indent, msg, msglen, value, \ - table, OSSL_NELEM(table)) + do_ssl_trace_list(bio, indent, msg, msglen, value, \ + table, OSSL_NELEM(table)) static const char *do_ssl_trace_str(int val, const ssl_trace_tbl *tbl, size_t ntbl) @@ -65,8 +65,6 @@ static const ssl_trace_tbl ssl_version_tbl[] = { {TLS1_1_VERSION, "TLS 1.1"}, {TLS1_2_VERSION, "TLS 1.2"}, {TLS1_3_VERSION, "TLS 1.3"}, - /* TODO(TLS1.3): Remove this line before release */ - {TLS1_3_VERSION_DRAFT, TLS1_3_VERSION_DRAFT_TXT}, {DTLS1_VERSION, "DTLS 1.0"}, {DTLS1_2_VERSION, "DTLS 1.2"}, {DTLS1_BAD_VER, "DTLS 1.0 (bad)"} @@ -79,7 +77,7 @@ static const ssl_trace_tbl ssl_content_tbl[] = { {SSL3_RT_APPLICATION_DATA, "ApplicationData"}, }; -/* Handshake types */ +/* Handshake types, sorted by ascending id */ static const ssl_trace_tbl ssl_handshake_tbl[] = { {SSL3_MT_HELLO_REQUEST, "HelloRequest"}, {SSL3_MT_CLIENT_HELLO, "ClientHello"}, @@ -94,10 +92,10 @@ static const ssl_trace_tbl ssl_handshake_tbl[] = { {SSL3_MT_SERVER_DONE, "ServerHelloDone"}, {SSL3_MT_CERTIFICATE_VERIFY, "CertificateVerify"}, {SSL3_MT_CLIENT_KEY_EXCHANGE, "ClientKeyExchange"}, - {SSL3_MT_CERTIFICATE_STATUS, "CertificateStatus"}, - {SSL3_MT_CLIENT_KEY_EXCHANGE, "ClientKeyExchange"}, {SSL3_MT_FINISHED, "Finished"}, + {SSL3_MT_CERTIFICATE_URL, "CertificateUrl"}, {SSL3_MT_CERTIFICATE_STATUS, "CertificateStatus"}, + {SSL3_MT_SUPPLEMENTAL_DATA, "SupplementalData"}, {SSL3_MT_KEY_UPDATE, "KeyUpdate"}, # ifndef OPENSSL_NO_NEXTPROTONEG {SSL3_MT_NEXT_PROTO, "NextProto"}, @@ -184,6 +182,8 @@ static const ssl_trace_tbl ssl_ciphers_tbl[] = { {0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"}, {0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256"}, {0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256"}, + {0x0081, "TLS_GOSTR341001_WITH_28147_CNT_IMIT"}, + {0x0083, "TLS_GOSTR341001_WITH_NULL_GOSTR3411"}, {0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA"}, {0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA"}, {0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA"}, @@ -441,6 +441,8 @@ static const ssl_trace_tbl ssl_ciphers_tbl[] = { {0x1305, "TLS_AES_128_CCM_8_SHA256"}, {0xFEFE, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"}, {0xFEFF, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA"}, + {0xFF85, "GOST2012-GOST8912-GOST8912"}, + {0xFF87, "GOST2012-NULL-GOST12"}, }; /* Compression methods */ @@ -449,7 +451,7 @@ static const ssl_trace_tbl ssl_comp_tbl[] = { {0x0001, "Zlib Compression"} }; -/* Extensions */ +/* Extensions sorted by ascending id */ static const ssl_trace_tbl ssl_exts_tbl[] = { {TLSEXT_TYPE_server_name, "server_name"}, {TLSEXT_TYPE_max_fragment_length, "max_fragment_length"}, @@ -461,28 +463,32 @@ static const ssl_trace_tbl ssl_exts_tbl[] = { {TLSEXT_TYPE_client_authz, "client_authz"}, {TLSEXT_TYPE_server_authz, "server_authz"}, {TLSEXT_TYPE_cert_type, "cert_type"}, - {TLSEXT_TYPE_key_share, "key_share"}, - {TLSEXT_TYPE_psk, "psk"}, - {TLSEXT_TYPE_psk_kex_modes, "psk_key_exchange_modes"}, {TLSEXT_TYPE_supported_groups, "supported_groups"}, {TLSEXT_TYPE_ec_point_formats, "ec_point_formats"}, {TLSEXT_TYPE_srp, "srp"}, {TLSEXT_TYPE_signature_algorithms, "signature_algorithms"}, {TLSEXT_TYPE_use_srtp, "use_srtp"}, - {TLSEXT_TYPE_session_ticket, "session_ticket"}, - {TLSEXT_TYPE_supported_versions, "supported_versions"}, - {TLSEXT_TYPE_renegotiate, "renegotiate"}, -# ifndef OPENSSL_NO_NEXTPROTONEG - {TLSEXT_TYPE_next_proto_neg, "next_proto_neg"}, -# endif + {TLSEXT_TYPE_heartbeat, "tls_heartbeat"}, {TLSEXT_TYPE_application_layer_protocol_negotiation, "application_layer_protocol_negotiation"}, {TLSEXT_TYPE_signed_certificate_timestamp, "signed_certificate_timestamps"}, {TLSEXT_TYPE_padding, "padding"}, {TLSEXT_TYPE_encrypt_then_mac, "encrypt_then_mac"}, {TLSEXT_TYPE_extended_master_secret, "extended_master_secret"}, + {TLSEXT_TYPE_session_ticket, "session_ticket"}, + {TLSEXT_TYPE_psk, "psk"}, {TLSEXT_TYPE_early_data, "early_data"}, - {TLSEXT_TYPE_post_handshake_auth, "post_handshake_auth"} + {TLSEXT_TYPE_supported_versions, "supported_versions"}, + {TLSEXT_TYPE_cookie, "cookie_ext"}, + {TLSEXT_TYPE_psk_kex_modes, "psk_key_exchange_modes"}, + {TLSEXT_TYPE_certificate_authorities, "certificate_authorities"}, + {TLSEXT_TYPE_post_handshake_auth, "post_handshake_auth"}, + {TLSEXT_TYPE_signature_algorithms_cert, "signature_algorithms_cert"}, + {TLSEXT_TYPE_key_share, "key_share"}, + {TLSEXT_TYPE_renegotiate, "renegotiate"}, +# ifndef OPENSSL_NO_NEXTPROTONEG + {TLSEXT_TYPE_next_proto_neg, "next_proto_neg"}, +# endif }; static const ssl_trace_tbl ssl_groups_tbl[] = { @@ -515,6 +521,7 @@ static const ssl_trace_tbl ssl_groups_tbl[] = { {27, "brainpoolP384r1"}, {28, "brainpoolP512r1"}, {29, "ecdh_x25519"}, + {30, "ecdh_x448"}, {256, "ffdhe2048"}, {257, "ffdhe3072"}, {258, "ffdhe4096"}, @@ -544,6 +551,7 @@ static const ssl_trace_tbl ssl_sigalg_tbl[] = { {TLSEXT_SIGALG_ecdsa_secp521r1_sha512, "ecdsa_secp521r1_sha512"}, {TLSEXT_SIGALG_ecdsa_sha224, "ecdsa_sha224"}, {TLSEXT_SIGALG_ed25519, "ed25519"}, + {TLSEXT_SIGALG_ed448, "ed448"}, {TLSEXT_SIGALG_ecdsa_sha1, "ecdsa_sha1"}, {TLSEXT_SIGALG_rsa_pss_rsae_sha256, "rsa_pss_rsae_sha256"}, {TLSEXT_SIGALG_rsa_pss_rsae_sha384, "rsa_pss_rsae_sha384"}, @@ -630,10 +638,8 @@ static int ssl_print_version(BIO *bio, int indent, const char *name, if (*pmsglen < 2) return 0; vers = ((*pmsg)[0] << 8) | (*pmsg)[1]; - if (version != NULL) { - /* TODO(TLS1.3): Remove the draft conditional here before release */ - *version = (vers == TLS1_3_VERSION_DRAFT) ? TLS1_3_VERSION : vers; - } + if (version != NULL) + *version = vers; BIO_indent(bio, indent, 80); BIO_printf(bio, "%s=0x%x (%s)\n", name, vers, ssl_trace_str(vers, ssl_version_tbl)); @@ -723,7 +729,7 @@ static int ssl_print_extension(BIO *bio, int indent, int server, while (xlen > 0) { size_t plen = *ext++; - if (plen > xlen + 1) + if (plen + 1 > xlen) return 0; BIO_indent(bio, indent + 2, 80); BIO_write(bio, ext, plen); @@ -879,26 +885,35 @@ static int ssl_print_extensions(BIO *bio, int indent, int server, BIO_indent(bio, indent, 80); if (msglen == 0) { - BIO_puts(bio, "No Extensions\n"); + BIO_puts(bio, "No extensions\n"); return 1; } - extslen = (msg[0] << 8) | msg[1]; - if (extslen != msglen - 2) + if (msglen < 2) return 0; + extslen = (msg[0] << 8) | msg[1]; + msglen -= 2; msg += 2; - msglen = extslen; - BIO_printf(bio, "extensions, length = %d\n", (int)msglen); - while (msglen > 0) { + if (extslen == 0) { + BIO_puts(bio, "No extensions\n"); + *msgin = msg; + *msginlen = msglen; + return 1; + } + if (extslen > msglen) + return 0; + BIO_printf(bio, "extensions, length = %d\n", (int)extslen); + msglen -= extslen; + while (extslen > 0) { int extype; size_t extlen; - if (msglen < 4) + if (extslen < 4) return 0; extype = (msg[0] << 8) | msg[1]; extlen = (msg[2] << 8) | msg[3]; - if (msglen < extlen + 4) { + if (extslen < extlen + 4) { BIO_printf(bio, "extensions, extype = %d, extlen = %d\n", extype, (int)extlen); - BIO_dump_indent(bio, (const char *)msg, msglen, indent + 2); + BIO_dump_indent(bio, (const char *)msg, extslen, indent + 2); return 0; } msg += 4; @@ -906,7 +921,7 @@ static int ssl_print_extensions(BIO *bio, int indent, int server, extlen)) return 0; msg += extlen; - msglen -= extlen + 4; + extslen -= extlen + 4; } *msgin = msg; @@ -1080,10 +1095,10 @@ static int ssl_print_client_keyex(BIO *bio, int indent, const SSL *ssl, case SSL_kRSAPSK: if (TLS1_get_version(ssl) == SSL3_VERSION) { ssl_print_hex(bio, indent + 2, - "EncyptedPreMasterSecret", msg, msglen); + "EncryptedPreMasterSecret", msg, msglen); } else { if (!ssl_print_hexbuf(bio, indent + 2, - "EncyptedPreMasterSecret", 2, &msg, &msglen)) + "EncryptedPreMasterSecret", 2, &msg, &msglen)) return 0; } break; @@ -1287,6 +1302,8 @@ static int ssl_print_cert_request(BIO *bio, int indent, const SSL *ssl, msg += xlen; } + if (msglen < 2) + return 0; xlen = (msg[0] << 8) | msg[1]; BIO_indent(bio, indent, 80); if (msglen < xlen + 2) @@ -1348,8 +1365,8 @@ static int ssl_print_ticket(BIO *bio, int indent, const SSL *ssl, if (msglen < 4) return 0; - ticket_age_add = (msg[0] << 24) | (msg[1] << 16) | (msg[2] << 8) - | msg[3]; + ticket_age_add = + (msg[0] << 24) | (msg[1] << 16) | (msg[2] << 8) | msg[3]; msglen -= 4; msg += 4; BIO_indent(bio, indent + 2, 80); @@ -1487,7 +1504,16 @@ void SSL_trace(int write_p, int version, int content_type, switch (content_type) { case SSL3_RT_HEADER: { - int hvers = msg[1] << 8 | msg[2]; + int hvers; + + /* avoid overlapping with length at the end of buffer */ + if (msglen < (size_t)(SSL_IS_DTLS(ssl) ? + DTLS1_RT_HEADER_LENGTH : SSL3_RT_HEADER_LENGTH)) { + BIO_puts(bio, write_p ? "Sent" : "Received"); + ssl_print_hex(bio, 0, " too short message", msg, msglen); + break; + } + hvers = msg[1] << 8 | msg[2]; BIO_puts(bio, write_p ? "Sent" : "Received"); BIO_printf(bio, " Record\nHeader:\n Version = %s (0x%x)\n", ssl_trace_str(hvers, ssl_version_tbl), hvers);