diff options
author | Ron Yorston <rmy@pobox.com> | 2022-10-12 10:43:26 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-10-12 10:43:26 +0100 |
commit | 49c6f079acb4edae84b4496bd941cdbb5048ba01 (patch) | |
tree | ac54ecaad45050f7bfe274a11db29882aa32a9a8 /networking/tls.c | |
parent | a55cf07365ec2ff51749a77e09ae9edac79a99fe (diff) | |
parent | c8c1fcdba163f264a503380bc63485aacd09214c (diff) | |
download | busybox-w32-49c6f079acb4edae84b4496bd941cdbb5048ba01.tar.gz busybox-w32-49c6f079acb4edae84b4496bd941cdbb5048ba01.tar.bz2 busybox-w32-49c6f079acb4edae84b4496bd941cdbb5048ba01.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'networking/tls.c')
-rw-r--r-- | networking/tls.c | 113 |
1 files changed, 79 insertions, 34 deletions
diff --git a/networking/tls.c b/networking/tls.c index 5f40aec70..9f1dd67ec 100644 --- a/networking/tls.c +++ b/networking/tls.c | |||
@@ -948,11 +948,46 @@ static int tls_has_buffered_record(tls_state_t *tls) | |||
948 | 948 | ||
949 | static const char *alert_text(int code) | 949 | static const char *alert_text(int code) |
950 | { | 950 | { |
951 | //10 unexpected_message | ||
952 | //20 bad_record_mac | ||
953 | //21 decryption_failed | ||
954 | //22 record_overflow | ||
955 | //30 decompression_failure | ||
956 | //40 handshake_failure | ||
957 | //41 no_certificate | ||
958 | //42 bad_certificate | ||
959 | //43 unsupported_certificate | ||
960 | //44 certificate_revoked | ||
961 | //45 certificate_expired | ||
962 | //46 certificate_unknown | ||
963 | //47 illegal_parameter | ||
964 | //48 unknown_ca | ||
965 | //49 access_denied | ||
966 | //50 decode_error | ||
967 | //51 decrypt_error | ||
968 | //52 too_many_cids_requested | ||
969 | //60 export_restriction | ||
970 | //70 protocol_version | ||
971 | //71 insufficient_security | ||
972 | //80 internal_error | ||
973 | //86 inappropriate_fallback | ||
974 | //90 user_canceled | ||
975 | //100 no_renegotiation | ||
976 | //109 missing_extension | ||
977 | //110 unsupported_extension | ||
978 | //111 certificate_unobtainable | ||
979 | //112 unrecognized_name | ||
980 | //113 bad_certificate_status_response | ||
981 | //114 bad_certificate_hash_value | ||
982 | //115 unknown_psk_identity | ||
983 | //116 certificate_required | ||
984 | //120 no_application_protocol | ||
951 | switch (code) { | 985 | switch (code) { |
952 | case 20: return "bad MAC"; | 986 | case 20: return "bad MAC"; |
953 | case 50: return "decode error"; | 987 | case 50: return "decode error"; |
954 | case 51: return "decrypt error"; | ||
955 | case 40: return "handshake failure"; | 988 | case 40: return "handshake failure"; |
989 | case 51: return "decrypt error"; | ||
990 | case 80: return "internal error"; | ||
956 | case 112: return "unrecognized name"; | 991 | case 112: return "unrecognized name"; |
957 | } | 992 | } |
958 | return itoa(code); | 993 | return itoa(code); |
@@ -1531,27 +1566,6 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni) | |||
1531 | #endif | 1566 | #endif |
1532 | 0x01,0x00, //not a cipher - comprtypes_len, comprtype | 1567 | 0x01,0x00, //not a cipher - comprtypes_len, comprtype |
1533 | }; | 1568 | }; |
1534 | static const uint8_t supported_groups[] = { | ||
1535 | 0x00,0x0a, //extension_type: "supported_groups" | ||
1536 | 0x00,2 * (1 + ALLOW_CURVE_P256 + ALLOW_CURVE_X25519), //ext len | ||
1537 | 0x00,2 * (0 + ALLOW_CURVE_P256 + ALLOW_CURVE_X25519), //list len | ||
1538 | #if ALLOW_CURVE_P256 | ||
1539 | 0x00,0x17, //curve_secp256r1 (aka P256, aka prime256v1) | ||
1540 | #endif | ||
1541 | //0x00,0x18, //curve_secp384r1 | ||
1542 | //0x00,0x19, //curve_secp521r1 | ||
1543 | #if ALLOW_CURVE_X25519 | ||
1544 | 0x00,0x1d, //curve_x25519 (RFC 7748) | ||
1545 | #endif | ||
1546 | //0x00,0x1e, //curve_x448 (RFC 7748) | ||
1547 | }; | ||
1548 | //static const uint8_t signature_algorithms[] = { | ||
1549 | // 000d | ||
1550 | // 0020 | ||
1551 | // 001e | ||
1552 | // 0601 0602 0603 0501 0502 0503 0401 0402 0403 0301 0302 0303 0201 0202 0203 | ||
1553 | //}; | ||
1554 | |||
1555 | struct client_hello { | 1569 | struct client_hello { |
1556 | uint8_t type; | 1570 | uint8_t type; |
1557 | uint8_t len24_hi, len24_mid, len24_lo; | 1571 | uint8_t len24_hi, len24_mid, len24_lo; |
@@ -1563,15 +1577,47 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni) | |||
1563 | uint8_t cipherid[2 * (1 + NUM_CIPHERS)]; /* actually variable */ | 1577 | uint8_t cipherid[2 * (1 + NUM_CIPHERS)]; /* actually variable */ |
1564 | uint8_t comprtypes_len; | 1578 | uint8_t comprtypes_len; |
1565 | uint8_t comprtypes[1]; /* actually variable */ | 1579 | uint8_t comprtypes[1]; /* actually variable */ |
1566 | /* Extensions (SNI shown): | 1580 | }; |
1567 | * hi,lo // len of all extensions | 1581 | // https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml |
1568 | * 00,00 // extension_type: "Server Name" | 1582 | static const uint8_t extensions[] = { |
1569 | * 00,0e // list len (there can be more than one SNI) | 1583 | // is.gd responds with "handshake failure" to our hello if there's no supported_groups |
1570 | * 00,0c // len of 1st Server Name Indication | 1584 | 0x00,0x0a, //extension_type: "supported_groups" |
1571 | * 00 // name type: host_name | 1585 | 0x00,2 * (1 + ALLOW_CURVE_P256 + ALLOW_CURVE_X25519), //ext len |
1572 | * 00,09 // name len | 1586 | 0x00,2 * (0 + ALLOW_CURVE_P256 + ALLOW_CURVE_X25519), //list len |
1573 | * "localhost" // name | 1587 | #if ALLOW_CURVE_P256 |
1574 | */ | 1588 | 0x00,0x17, //curve_secp256r1 (aka P256, aka prime256v1) |
1589 | #endif | ||
1590 | //0x00,0x18, //curve_secp384r1 | ||
1591 | //0x00,0x19, //curve_secp521r1 | ||
1592 | #if ALLOW_CURVE_X25519 | ||
1593 | 0x00,0x1d, //curve_x25519 (RFC 7748) | ||
1594 | #endif | ||
1595 | //0x00,0x1e, //curve_x448 (RFC 7748) | ||
1596 | |||
1597 | //0x00,0x0b,0x00,0x04,0x03,0x00,0x01,0x02, //extension_type: "ec_point_formats" | ||
1598 | //0x00,0x16,0x00,0x00, //extension_type: "encrpypt-then-mac" | ||
1599 | //0x00,0x17,0x00,0x00, //extension_type: "extended_master" | ||
1600 | //0x00,0x23,0x00,0x00, //extension_type: "session_ticket" | ||
1601 | |||
1602 | // kojipkgs.fedoraproject.org responds with alert code 80 ("internal error") | ||
1603 | // to our hello without signature_algorithms. | ||
1604 | // It is satisfied with just 0x04,0x01. | ||
1605 | 0x00,0x0d, //extension_type: "signature_algorithms" (RFC5246 section 7.4.1.4.1): | ||
1606 | #define SIGALGS (3 + 3 * ENABLE_FEATURE_TLS_SHA1) | ||
1607 | 0x00,2 * (1 + SIGALGS), //ext len | ||
1608 | 0x00,2 * (0 + SIGALGS), //list len | ||
1609 | //Format: two bytes | ||
1610 | // byte 1: 0:none,1:md5,2:sha1,3:sha224,4:sha256,5:sha384,6:sha512 | ||
1611 | // byte 2: 1:rsa,2:dsa,3:ecdsa | ||
1612 | // (note that TLS 1.3 changes this, see RFC8446 section 4.2.3) | ||
1613 | #if ENABLE_FEATURE_TLS_SHA1 | ||
1614 | 0x02,0x01, //sha1 + rsa | ||
1615 | 0x02,0x02, //sha1 + dsa | ||
1616 | 0x02,0x03, //sha1 + ecdsa | ||
1617 | #endif | ||
1618 | 0x04,0x01, //sha256 + rsa - kojipkgs.fedoraproject.org wants this | ||
1619 | 0x04,0x02, //sha256 + dsa | ||
1620 | 0x04,0x03, //sha256 + ecdsa | ||
1575 | // GNU Wget 1.18 to cdn.kernel.org sends these extensions: | 1621 | // GNU Wget 1.18 to cdn.kernel.org sends these extensions: |
1576 | // 0055 | 1622 | // 0055 |
1577 | // 0005 0005 0100000000 - status_request | 1623 | // 0005 0005 0100000000 - status_request |
@@ -1591,8 +1637,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni) | |||
1591 | int sni_len = sni ? strnlen(sni, 127 - 5) : 0; | 1637 | int sni_len = sni ? strnlen(sni, 127 - 5) : 0; |
1592 | 1638 | ||
1593 | ext_len = 0; | 1639 | ext_len = 0; |
1594 | /* is.gd responds with "handshake failure" to our hello if there's no supported_groups element */ | 1640 | ext_len += sizeof(extensions); |
1595 | ext_len += sizeof(supported_groups); | ||
1596 | if (sni_len) | 1641 | if (sni_len) |
1597 | ext_len += 9 + sni_len; | 1642 | ext_len += 9 + sni_len; |
1598 | 1643 | ||
@@ -1626,7 +1671,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni) | |||
1626 | ptr[8] = sni_len; //name len | 1671 | ptr[8] = sni_len; //name len |
1627 | ptr = mempcpy(&ptr[9], sni, sni_len); | 1672 | ptr = mempcpy(&ptr[9], sni, sni_len); |
1628 | } | 1673 | } |
1629 | memcpy(ptr, supported_groups, sizeof(supported_groups)); | 1674 | memcpy(ptr, extensions, sizeof(extensions)); |
1630 | 1675 | ||
1631 | tls->hsd = xzalloc(sizeof(*tls->hsd)); | 1676 | tls->hsd = xzalloc(sizeof(*tls->hsd)); |
1632 | /* HANDSHAKE HASH: ^^^ + len if need to save saved_client_hello */ | 1677 | /* HANDSHAKE HASH: ^^^ + len if need to save saved_client_hello */ |