aboutsummaryrefslogtreecommitdiff
path: root/networking/tls.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-01-10 08:38:15 +0000
committerRon Yorston <rmy@pobox.com>2019-01-10 08:38:15 +0000
commitf99a280743e877c14ee90a3f9e93a34ca3476a27 (patch)
tree60ca3d17596e190c8c7cbca587168946598bee8a /networking/tls.c
parent40d5dd07ea1f290eaed30a03fd598e33a8eaf495 (diff)
parent6ca8e347fed8c24655df692f22694baf7c572770 (diff)
downloadbusybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.tar.gz
busybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.tar.bz2
busybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'networking/tls.c')
-rw-r--r--networking/tls.c79
1 files changed, 62 insertions, 17 deletions
diff --git a/networking/tls.c b/networking/tls.c
index 38eb79798..d2385efe8 100644
--- a/networking/tls.c
+++ b/networking/tls.c
@@ -6,6 +6,8 @@
6//config:config TLS 6//config:config TLS
7//config: bool #No description makes it a hidden option 7//config: bool #No description makes it a hidden option
8//config: default n 8//config: default n
9//Note:
10//Config.src also defines FEATURE_TLS_SHA1 option
9 11
10//kbuild:lib-$(CONFIG_TLS) += tls.o 12//kbuild:lib-$(CONFIG_TLS) += tls.o
11//kbuild:lib-$(CONFIG_TLS) += tls_pstm.o 13//kbuild:lib-$(CONFIG_TLS) += tls_pstm.o
@@ -400,7 +402,7 @@ static void hash_handshake(tls_state_t *tls, const char *fmt, const void *buffer
400 dump_hex(fmt, buffer, len); 402 dump_hex(fmt, buffer, len);
401 dbg(" (%u bytes) ", (int)len); 403 dbg(" (%u bytes) ", (int)len);
402 len = sha_peek(&tls->hsd->handshake_hash_ctx, h); 404 len = sha_peek(&tls->hsd->handshake_hash_ctx, h);
403 if (len == SHA1_OUTSIZE) 405 if (ENABLE_FEATURE_TLS_SHA1 && len == SHA1_OUTSIZE)
404 dump_hex("sha1:%s\n", h, len); 406 dump_hex("sha1:%s\n", h, len);
405 else 407 else
406 if (len == SHA256_OUTSIZE) 408 if (len == SHA256_OUTSIZE)
@@ -411,6 +413,12 @@ static void hash_handshake(tls_state_t *tls, const char *fmt, const void *buffer
411#endif 413#endif
412} 414}
413 415
416#if !ENABLE_FEATURE_TLS_SHA1
417# define TLS_MAC_SIZE(tls) SHA256_OUTSIZE
418#else
419# define TLS_MAC_SIZE(tls) (tls)->MAC_size
420#endif
421
414// RFC 2104: 422// RFC 2104:
415// HMAC(key, text) based on a hash H (say, sha256) is: 423// HMAC(key, text) based on a hash H (say, sha256) is:
416// ipad = [0x36 x INSIZE] 424// ipad = [0x36 x INSIZE]
@@ -427,6 +435,11 @@ typedef struct hmac_precomputed {
427} hmac_precomputed_t; 435} hmac_precomputed_t;
428 436
429typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; 437typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC;
438#if !ENABLE_FEATURE_TLS_SHA1
439#define hmac_begin(pre,key,key_size,begin) \
440 hmac_begin(pre,key,key_size)
441#define begin sha256_begin
442#endif
430static void hmac_begin(hmac_precomputed_t *pre, uint8_t *key, unsigned key_size, md5sha_begin_func *begin) 443static void hmac_begin(hmac_precomputed_t *pre, uint8_t *key, unsigned key_size, md5sha_begin_func *begin)
431{ 444{
432 uint8_t key_xor_ipad[SHA_INSIZE]; 445 uint8_t key_xor_ipad[SHA_INSIZE];
@@ -467,6 +480,7 @@ static void hmac_begin(hmac_precomputed_t *pre, uint8_t *key, unsigned key_size,
467 md5sha_hash(&pre->hashed_key_xor_ipad, key_xor_ipad, SHA_INSIZE); 480 md5sha_hash(&pre->hashed_key_xor_ipad, key_xor_ipad, SHA_INSIZE);
468 md5sha_hash(&pre->hashed_key_xor_opad, key_xor_opad, SHA_INSIZE); 481 md5sha_hash(&pre->hashed_key_xor_opad, key_xor_opad, SHA_INSIZE);
469} 482}
483#undef begin
470 484
471static unsigned hmac_sha_precomputed_v( 485static unsigned hmac_sha_precomputed_v(
472 hmac_precomputed_t *pre, 486 hmac_precomputed_t *pre,
@@ -504,6 +518,10 @@ static unsigned hmac_sha_precomputed(hmac_precomputed_t *pre_init, uint8_t *out,
504 return len; 518 return len;
505} 519}
506 520
521#if !ENABLE_FEATURE_TLS_SHA1
522#define hmac(tls,out,key,key_size,...) \
523 hmac(out,key,key_size, __VA_ARGS__)
524#endif
507static unsigned hmac(tls_state_t *tls, uint8_t *out, uint8_t *key, unsigned key_size, ...) 525static unsigned hmac(tls_state_t *tls, uint8_t *out, uint8_t *key, unsigned key_size, ...)
508{ 526{
509 hmac_precomputed_t pre; 527 hmac_precomputed_t pre;
@@ -513,9 +531,9 @@ static unsigned hmac(tls_state_t *tls, uint8_t *out, uint8_t *key, unsigned key_
513 va_start(va, key_size); 531 va_start(va, key_size);
514 532
515 hmac_begin(&pre, key, key_size, 533 hmac_begin(&pre, key, key_size,
516 (tls->MAC_size == SHA256_OUTSIZE) 534 (ENABLE_FEATURE_TLS_SHA1 && tls->MAC_size == SHA1_OUTSIZE)
517 ? sha256_begin 535 ? sha1_begin
518 : sha1_begin 536 : sha256_begin
519 ); 537 );
520 len = hmac_sha_precomputed_v(&pre, out, va); 538 len = hmac_sha_precomputed_v(&pre, out, va);
521 539
@@ -685,7 +703,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
685 703
686 /* Calculate MAC signature */ 704 /* Calculate MAC signature */
687 hmac(tls, buf + size, /* result */ 705 hmac(tls, buf + size, /* result */
688 tls->client_write_MAC_key, tls->MAC_size, 706 tls->client_write_MAC_key, TLS_MAC_SIZE(tls),
689 &tls->write_seq64_be, sizeof(tls->write_seq64_be), 707 &tls->write_seq64_be, sizeof(tls->write_seq64_be),
690 xhdr, RECHDR_LEN, 708 xhdr, RECHDR_LEN,
691 buf, size, 709 buf, size,
@@ -693,7 +711,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
693 ); 711 );
694 tls->write_seq64_be = SWAP_BE64(1 + SWAP_BE64(tls->write_seq64_be)); 712 tls->write_seq64_be = SWAP_BE64(1 + SWAP_BE64(tls->write_seq64_be));
695 713
696 size += tls->MAC_size; 714 size += TLS_MAC_SIZE(tls);
697 715
698 // RFC 5246: 716 // RFC 5246:
699 // 6.2.3.1. Null or Standard Stream Cipher 717 // 6.2.3.1. Null or Standard Stream Cipher
@@ -778,7 +796,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
778 796
779 tls_get_random(buf - AES_BLOCK_SIZE, AES_BLOCK_SIZE); /* IV */ 797 tls_get_random(buf - AES_BLOCK_SIZE, AES_BLOCK_SIZE); /* IV */
780 dbg("before crypt: 5 hdr + %u data + %u hash bytes\n", 798 dbg("before crypt: 5 hdr + %u data + %u hash bytes\n",
781 size - tls->MAC_size, tls->MAC_size); 799 size - TLS_MAC_SIZE(tls), TLS_MAC_SIZE(tls));
782 800
783 /* Fill IV and padding in outbuf */ 801 /* Fill IV and padding in outbuf */
784 // RFC is talking nonsense: 802 // RFC is talking nonsense:
@@ -1093,7 +1111,7 @@ static int tls_xread_record(tls_state_t *tls, const char *expected)
1093 tls_aesgcm_decrypt(tls, p, sz); 1111 tls_aesgcm_decrypt(tls, p, sz);
1094 dbg("encrypted size:%u\n", sz); 1112 dbg("encrypted size:%u\n", sz);
1095 } else 1113 } else
1096 if (tls->min_encrypted_len_on_read > tls->MAC_size) { 1114 if (tls->min_encrypted_len_on_read > TLS_MAC_SIZE(tls)) {
1097 /* AES+SHA */ 1115 /* AES+SHA */
1098 uint8_t *p = tls->inbuf + RECHDR_LEN; 1116 uint8_t *p = tls->inbuf + RECHDR_LEN;
1099 int padding_len; 1117 int padding_len;
@@ -1112,7 +1130,7 @@ static int tls_xread_record(tls_state_t *tls, const char *expected)
1112 padding_len = p[sz - 1]; 1130 padding_len = p[sz - 1];
1113 dbg("encrypted size:%u type:0x%02x padding_length:0x%02x\n", sz, p[0], padding_len); 1131 dbg("encrypted size:%u type:0x%02x padding_length:0x%02x\n", sz, p[0], padding_len);
1114 padding_len++; 1132 padding_len++;
1115 sz -= tls->MAC_size + padding_len; /* drop MAC and padding */ 1133 sz -= TLS_MAC_SIZE(tls) + padding_len; /* drop MAC and padding */
1116 } else { 1134 } else {
1117 /* if nonzero, then it's TLS_RSA_WITH_NULL_SHA256: drop MAC */ 1135 /* if nonzero, then it's TLS_RSA_WITH_NULL_SHA256: drop MAC */
1118 /* else: no encryption yet on input, subtract zero = NOP */ 1136 /* else: no encryption yet on input, subtract zero = NOP */
@@ -1472,15 +1490,19 @@ static ALWAYS_INLINE void fill_handshake_record_hdr(void *buf, unsigned type, un
1472 1490
1473static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni) 1491static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1474{ 1492{
1475#define NUM_CIPHERS (13 + ALLOW_RSA_NULL_SHA256) 1493#define NUM_CIPHERS (7 + 6 * ENABLE_FEATURE_TLS_SHA1 + ALLOW_RSA_NULL_SHA256)
1476 static const uint8_t ciphers[] = { 1494 static const uint8_t ciphers[] = {
1477 0x00,(1 + NUM_CIPHERS) * 2, //len16_be 1495 0x00,2 + NUM_CIPHERS*2, //len16_be
1478 0x00,0xFF, //not a cipher - TLS_EMPTY_RENEGOTIATION_INFO_SCSV 1496 0x00,0xFF, //not a cipher - TLS_EMPTY_RENEGOTIATION_INFO_SCSV
1479 /* ^^^^^^ RFC 5746 Renegotiation Indication Extension - some servers will refuse to work with us otherwise */ 1497 /* ^^^^^^ RFC 5746 Renegotiation Indication Extension - some servers will refuse to work with us otherwise */
1498#if ENABLE_FEATURE_TLS_SHA1
1480 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/ 1499 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/
1481 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/ 1500 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/
1482 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA 1501 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA
1483 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl) 1502 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl)
1503 // 0xC0,0x18, // TLS_ECDH_anon_WITH_AES_128_CBC_SHA
1504 // 0xC0,0x19, // TLS_ECDH_anon_WITH_AES_256_CBC_SHA
1505#endif
1484 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/ 1506 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/
1485 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1507 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1486 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256 1508 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256
@@ -1491,12 +1513,16 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1491 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256 1513 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256
1492 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac" 1514 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac"
1493 //possibly these too: 1515 //possibly these too:
1516#if ENABLE_FEATURE_TLS_SHA1
1494 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 1517 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
1495 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 1518 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
1519#endif
1496 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 1520 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
1497 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1521 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1522#if ENABLE_FEATURE_TLS_SHA1
1498 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA 1523 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA
1499 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA 1524 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA
1525#endif
1500 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256 1526 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256
1501 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256 1527 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256
1502 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256 1528 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256
@@ -1511,9 +1537,17 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1511 0x00,0x04, //ext len 1537 0x00,0x04, //ext len
1512 0x00,0x02, //list len 1538 0x00,0x02, //list len
1513 0x00,0x1d, //curve_x25519 (RFC 7748) 1539 0x00,0x1d, //curve_x25519 (RFC 7748)
1540 //0x00,0x1e, //curve_x448 (RFC 7748)
1514 //0x00,0x17, //curve_secp256r1 1541 //0x00,0x17, //curve_secp256r1
1515 //0x00,0x18, //curve_secp384r1 1542 //0x00,0x18, //curve_secp384r1
1516 //0x00,0x19, //curve_secp521r1 1543 //0x00,0x19, //curve_secp521r1
1544//TODO: implement secp256r1 (at least): dl.fedoraproject.org immediately aborts
1545//if only x25519/x448 are advertised, seems to support only secpNNNr1 curves:
1546// openssl s_client -connect dl.fedoraproject.org:443 -debug -tls1_2 -cipher ECDHE-RSA-AES128-GCM-SHA256
1547//Peer signing digest: SHA512
1548//Peer signature type: RSA
1549//Server Temp Key: ECDH, P-256, 256 bits
1550//TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256
1517 }; 1551 };
1518 //static const uint8_t signature_algorithms[] = { 1552 //static const uint8_t signature_algorithms[] = {
1519 // 000d 1553 // 000d
@@ -1530,7 +1564,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1530 uint8_t session_id_len; 1564 uint8_t session_id_len;
1531 /* uint8_t session_id[]; */ 1565 /* uint8_t session_id[]; */
1532 uint8_t cipherid_len16_hi, cipherid_len16_lo; 1566 uint8_t cipherid_len16_hi, cipherid_len16_lo;
1533 uint8_t cipherid[(1 + NUM_CIPHERS) * 2]; /* actually variable */ 1567 uint8_t cipherid[2 + NUM_CIPHERS*2]; /* actually variable */
1534 uint8_t comprtypes_len; 1568 uint8_t comprtypes_len;
1535 uint8_t comprtypes[1]; /* actually variable */ 1569 uint8_t comprtypes[1]; /* actually variable */
1536 /* Extensions (SNI shown): 1570 /* Extensions (SNI shown):
@@ -1578,7 +1612,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1578 memset(record->rand32, 0x11, sizeof(record->rand32)); 1612 memset(record->rand32, 0x11, sizeof(record->rand32));
1579 /* record->session_id_len = 0; - already is */ 1613 /* record->session_id_len = 0; - already is */
1580 1614
1581 BUILD_BUG_ON(sizeof(ciphers) != 2 + (1 + NUM_CIPHERS) * 2 + 2); 1615 BUILD_BUG_ON(sizeof(ciphers) != 2 + 2 + NUM_CIPHERS*2 + 2);
1582 memcpy(&record->cipherid_len16_hi, ciphers, sizeof(ciphers)); 1616 memcpy(&record->cipherid_len16_hi, ciphers, sizeof(ciphers));
1583 1617
1584 ptr = (void*)(record + 1); 1618 ptr = (void*)(record + 1);
@@ -1675,31 +1709,42 @@ static void get_server_hello(tls_state_t *tls)
1675 1709
1676 /* Set up encryption params based on selected cipher */ 1710 /* Set up encryption params based on selected cipher */
1677#if 0 1711#if 0
1712#if ENABLE_FEATURE_TLS_SHA1
1678 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/ 1713 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/
1679 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/ 1714 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/
1680 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA 1715 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA
1681 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl) 1716 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl)
1717 // 0xC0,0x18, // TLS_ECDH_anon_WITH_AES_128_CBC_SHA
1718 // 0xC0,0x19, // TLS_ECDH_anon_WITH_AES_256_CBC_SHA
1719#endif
1682 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/ 1720 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/
1683 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1721 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1684 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256 1722 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256
1685 // 0xC0,0x28, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1723 // 0xC0,0x28, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1686 0xC0,0x2B, // 7 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - ok: wget https://is.gd/ 1724 0xC0,0x2B, // 7 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - ok: wget https://is.gd/
1687 // 0xC0,0x2C, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - wget https://is.gd/: "TLS error from peer (alert code 20): bad MAC" 1725 // 0xC0,0x2C, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - wget https://is.gd/: "TLS error from peer (alert code 20): bad MAC"
1726//TODO: GCM_SHA384 ciphers can be supported, only need sha384-based PRF?
1688 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256 1727 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256
1689 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac" 1728 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac"
1690 //possibly these too: 1729 //possibly these too:
1730#if ENABLE_FEATURE_TLS_SHA1
1691 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 1731 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
1692 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 1732 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
1733#endif
1693 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 1734 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
1694 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1735 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1736#if ENABLE_FEATURE_TLS_SHA1
1695 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA 1737 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA
1696 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA 1738 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA
1739#endif
1697 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256 1740 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256
1698 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256 1741 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256
1699 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256 1742 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256
1700 // 0x00,0x9D, // TLS_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher AES256-GCM-SHA384: "decryption failed or bad record mac" 1743 // 0x00,0x9D, // TLS_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher AES256-GCM-SHA384: "decryption failed or bad record mac"
1744#if ALLOW_RSA_NULL_SHA256
1701 0x00,0x3B, // TLS_RSA_WITH_NULL_SHA256 1745 0x00,0x3B, // TLS_RSA_WITH_NULL_SHA256
1702#endif 1746#endif
1747#endif
1703 cipherid1 = cipherid[1]; 1748 cipherid1 = cipherid[1];
1704 tls->cipher_id = 0x100 * cipherid[0] + cipherid1; 1749 tls->cipher_id = 0x100 * cipherid[0] + cipherid1;
1705 tls->key_size = AES256_KEYSIZE; 1750 tls->key_size = AES256_KEYSIZE;
@@ -1712,7 +1757,7 @@ static void get_server_hello(tls_state_t *tls)
1712 /* Odd numbered C0xx use AES128 (even ones use AES256) */ 1757 /* Odd numbered C0xx use AES128 (even ones use AES256) */
1713 tls->key_size = AES128_KEYSIZE; 1758 tls->key_size = AES128_KEYSIZE;
1714 } 1759 }
1715 if (cipherid1 <= 0x14) { 1760 if (ENABLE_FEATURE_TLS_SHA1 && cipherid1 <= 0x19) {
1716 tls->MAC_size = SHA1_OUTSIZE; 1761 tls->MAC_size = SHA1_OUTSIZE;
1717 } else 1762 } else
1718 if (cipherid1 >= 0x2B && cipherid1 <= 0x30) { 1763 if (cipherid1 >= 0x2B && cipherid1 <= 0x30) {
@@ -1723,13 +1768,13 @@ static void get_server_hello(tls_state_t *tls)
1723 } 1768 }
1724 } else { 1769 } else {
1725 /* All 00xx are RSA */ 1770 /* All 00xx are RSA */
1726 if (cipherid1 == 0x2F 1771 if ((ENABLE_FEATURE_TLS_SHA1 && cipherid1 == 0x2F)
1727 || cipherid1 == 0x3C 1772 || cipherid1 == 0x3C
1728 || cipherid1 == 0x9C 1773 || cipherid1 == 0x9C
1729 ) { 1774 ) {
1730 tls->key_size = AES128_KEYSIZE; 1775 tls->key_size = AES128_KEYSIZE;
1731 } 1776 }
1732 if (cipherid1 <= 0x35) { 1777 if (ENABLE_FEATURE_TLS_SHA1 && cipherid1 <= 0x35) {
1733 tls->MAC_size = SHA1_OUTSIZE; 1778 tls->MAC_size = SHA1_OUTSIZE;
1734 } else 1779 } else
1735 if (cipherid1 == 0x9C /*|| cipherid1 == 0x9D*/) { 1780 if (cipherid1 == 0x9C /*|| cipherid1 == 0x9D*/) {
@@ -2227,7 +2272,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
2227 tls->min_encrypted_len_on_read = tls->MAC_size; 2272 tls->min_encrypted_len_on_read = tls->MAC_size;
2228 } else 2273 } else
2229 if (!(tls->flags & ENCRYPTION_AESGCM)) { 2274 if (!(tls->flags & ENCRYPTION_AESGCM)) {
2230 unsigned mac_blocks = (unsigned)(tls->MAC_size + AES_BLOCK_SIZE-1) / AES_BLOCK_SIZE; 2275 unsigned mac_blocks = (unsigned)(TLS_MAC_SIZE(tls) + AES_BLOCK_SIZE-1) / AES_BLOCK_SIZE;
2231 /* all incoming packets now should be encrypted and have 2276 /* all incoming packets now should be encrypted and have
2232 * at least IV + (MAC padded to blocksize): 2277 * at least IV + (MAC padded to blocksize):
2233 */ 2278 */