aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-11-26 00:17:10 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-11-26 00:17:10 +0100
commitca7cdd4b0350d47445f9c02adc161ebcb41b4c20 (patch)
treef533aa7d84bee46327c978cba32d228fe58c4e55
parent838b88c044f04af07a260313f0f18ead5eb0fc6f (diff)
downloadbusybox-w32-ca7cdd4b0350d47445f9c02adc161ebcb41b4c20.tar.gz
busybox-w32-ca7cdd4b0350d47445f9c02adc161ebcb41b4c20.tar.bz2
busybox-w32-ca7cdd4b0350d47445f9c02adc161ebcb41b4c20.zip
tls: add support for 8 more cipher ids - all tested to work
function old new delta tls_handshake 2059 2116 +57 static.ciphers - 30 +30 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 87/0) Total: 87 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/tls.c204
1 files changed, 117 insertions, 87 deletions
diff --git a/networking/tls.c b/networking/tls.c
index 66d62fe3d..e76a78585 100644
--- a/networking/tls.c
+++ b/networking/tls.c
@@ -19,6 +19,10 @@
19 19
20#include "tls.h" 20#include "tls.h"
21 21
22// works against "openssl s_server -cipher NULL"
23// and against wolfssl-3.9.10-stable/examples/server/server.c:
24#define ALLOW_RSA_NULL_SHA256 0 // for testing (does everything except encrypting)
25
22//Tested against kernel.org: 26//Tested against kernel.org:
23//#define CIPHER_ID TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA // ok, recvs SERVER_KEY_EXCHANGE *** matrixssl uses this on my box 27//#define CIPHER_ID TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA // ok, recvs SERVER_KEY_EXCHANGE *** matrixssl uses this on my box
24//#define CIPHER_ID TLS_RSA_WITH_AES_256_CBC_SHA256 // ok, no SERVER_KEY_EXCHANGE 28//#define CIPHER_ID TLS_RSA_WITH_AES_256_CBC_SHA256 // ok, no SERVER_KEY_EXCHANGE
@@ -35,10 +39,6 @@
35//#define CIPHER_ID TLS_RSA_WITH_AES_256_GCM_SHA384 // ok, no SERVER_KEY_EXCHANGE 39//#define CIPHER_ID TLS_RSA_WITH_AES_256_GCM_SHA384 // ok, no SERVER_KEY_EXCHANGE
36//#define CIPHER_ID TLS_RSA_WITH_AES_128_GCM_SHA256 // ok, no SERVER_KEY_EXCHANGE 40//#define CIPHER_ID TLS_RSA_WITH_AES_128_GCM_SHA256 // ok, no SERVER_KEY_EXCHANGE
37 41
38// works against "openssl s_server -cipher NULL"
39// and against wolfssl-3.9.10-stable/examples/server/server.c:
40//#define CIPHER_ID1 TLS_RSA_WITH_NULL_SHA256 // for testing (does everything except encrypting)
41
42// works against wolfssl-3.9.10-stable/examples/server/server.c 42// works against wolfssl-3.9.10-stable/examples/server/server.c
43// works for kernel.org 43// works for kernel.org
44// does not work for cdn.kernel.org (e.g. downloading an actual tarball, not a web page) 44// does not work for cdn.kernel.org (e.g. downloading an actual tarball, not a web page)
@@ -50,41 +50,15 @@
50// ok: openssl s_client -connect cdn.kernel.org:443 -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher AES128-GCM-SHA256 50// ok: openssl s_client -connect cdn.kernel.org:443 -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher AES128-GCM-SHA256
51// ok: openssl s_client -connect cdn.kernel.org:443 -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher AES128-SHA 51// ok: openssl s_client -connect cdn.kernel.org:443 -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher AES128-SHA
52// (TLS_RSA_WITH_AES_128_CBC_SHA - in TLS 1.2 it's mandated to be always supported) 52// (TLS_RSA_WITH_AES_128_CBC_SHA - in TLS 1.2 it's mandated to be always supported)
53#define CIPHER_ID1 TLS_RSA_WITH_AES_256_CBC_SHA256 //0x003D 53//#define CIPHER_ID1 TLS_RSA_WITH_AES_256_CBC_SHA256 //0x003D
54// Works with "wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.9.5.tar.xz" 54// Works with "wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.9.5.tar.xz"
55#define CIPHER_ID2 TLS_RSA_WITH_AES_128_CBC_SHA //0x002F 55//#define CIPHER_ID2 TLS_RSA_WITH_AES_128_CBC_SHA //0x002F
56 56
57// bug #11456: 57// bug #11456:
58// ftp.openbsd.org only supports ECDHE-RSA-AESnnn-GCM-SHAnnn or ECDHE-RSA-CHACHA20-POLY1305 58// ftp.openbsd.org only supports ECDHE-RSA-AESnnn-GCM-SHAnnn or ECDHE-RSA-CHACHA20-POLY1305
59#define CIPHER_ID3 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 //0xC02F 59//#define CIPHER_ID3 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 //0xC02F
60// host is.gd accepts only ECDHE-ECDSA-foo (the simplest which works: ECDHE-ECDSA-AES128-SHA 0xC009) 60// host is.gd accepts only ECDHE-ECDSA-foo (the simplest which works: ECDHE-ECDSA-AES128-SHA 0xC009)
61#define CIPHER_ID4 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA //0xC009 61//#define CIPHER_ID4 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA //0xC009
62
63#define NUM_CIPHERS 4
64//TODO: we can support all these:
65// TLS_RSA_WITH_AES_128_CBC_SHA 0x002F
66// TLS_RSA_WITH_AES_256_CBC_SHA 0x0035
67// TLS_RSA_WITH_AES_128_CBC_SHA256 0x003C
68// TLS_RSA_WITH_AES_256_CBC_SHA256 0x003D
69// TLS_RSA_WITH_AES_128_GCM_SHA256 0x009C
70// TLS_RSA_WITH_AES_256_GCM_SHA384 0x009D
71// TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009
72// TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A
73// TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013
74// TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014
75// TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023
76////TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 - can't do SHA384 yet
77// TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027
78////TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 0xC028 - can't do SHA384 yet
79// TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B
80// TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C
81// TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F
82// TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030
83//possibly these too:
84// TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035
85// TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036
86// TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037
87////TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0xC038 - can't do SHA384 yet
88 62
89 63
90#define TLS_DEBUG 0 64#define TLS_DEBUG 0
@@ -291,7 +265,7 @@ enum {
291 GOT_CERT_RSA_KEY_ALG = 1 << 1, 265 GOT_CERT_RSA_KEY_ALG = 1 << 1,
292 GOT_CERT_ECDSA_KEY_ALG = 1 << 2, // so far unused 266 GOT_CERT_ECDSA_KEY_ALG = 1 << 2, // so far unused
293 GOT_EC_KEY = 1 << 3, 267 GOT_EC_KEY = 1 << 3,
294 ENCRYPTION_AESGCM = 1 << 4, // else AES-SHA (or NULL-SHA if CIPHER_ID1 set to allow one) 268 ENCRYPTION_AESGCM = 1 << 4, // else AES-SHA (or NULL-SHA if ALLOW_RSA_NULL_SHA256=1)
295 ENCRYPT_ON_WRITE = 1 << 5, 269 ENCRYPT_ON_WRITE = 1 << 5,
296}; 270};
297 271
@@ -676,7 +650,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
676 uint8_t padding_length; 650 uint8_t padding_length;
677 651
678 xhdr = (void*)(buf - RECHDR_LEN); 652 xhdr = (void*)(buf - RECHDR_LEN);
679 if (CIPHER_ID1 != TLS_RSA_WITH_NULL_SHA256 /* if "no encryption" can't be selected */ 653 if (!ALLOW_RSA_NULL_SHA256 /* if "no encryption" can't be selected */
680 || tls->cipher_id != TLS_RSA_WITH_NULL_SHA256 /* or if it wasn't selected */ 654 || tls->cipher_id != TLS_RSA_WITH_NULL_SHA256 /* or if it wasn't selected */
681 ) { 655 ) {
682 xhdr = (void*)(buf - RECHDR_LEN - AES_BLOCK_SIZE); /* place for IV */ 656 xhdr = (void*)(buf - RECHDR_LEN - AES_BLOCK_SIZE); /* place for IV */
@@ -734,7 +708,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
734 // -------- ----------- ---------- -------------- 708 // -------- ----------- ---------- --------------
735 // SHA HMAC-SHA1 20 20 709 // SHA HMAC-SHA1 20 20
736 // SHA256 HMAC-SHA256 32 32 710 // SHA256 HMAC-SHA256 32 32
737 if (CIPHER_ID1 == TLS_RSA_WITH_NULL_SHA256 711 if (ALLOW_RSA_NULL_SHA256
738 && tls->cipher_id == TLS_RSA_WITH_NULL_SHA256 712 && tls->cipher_id == TLS_RSA_WITH_NULL_SHA256
739 ) { 713 ) {
740 /* No encryption, only signing */ 714 /* No encryption, only signing */
@@ -1478,6 +1452,39 @@ static ALWAYS_INLINE void fill_handshake_record_hdr(void *buf, unsigned type, un
1478 1452
1479static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni) 1453static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1480{ 1454{
1455#define NUM_CIPHERS (12 + ALLOW_RSA_NULL_SHA256)
1456 static const uint8_t ciphers[] = {
1457 0x00,(1 + NUM_CIPHERS) * 2, //len16_be
1458 0x00,0xFF, //not a cipher - TLS_EMPTY_RENEGOTIATION_INFO_SCSV
1459 /* ^^^^^^ RFC 5746 Renegotiation Indication Extension - some servers will refuse to work with us otherwise */
1460 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/
1461 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/
1462 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA
1463 // 0xC0,0x14, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - openssl s_server ... -cipher ECDHE-RSA-AES256-SHA: "No ciphers enabled for max supported SSL/TLS version"
1464 0xC0,0x23, // 4 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/
1465 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1466 0xC0,0x27, // 5 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256
1467 // 0xC0,0x28, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1468 0xC0,0x2B, // 6 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - ok: wget https://is.gd/
1469 // 0xC0,0x2C, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - wget https://is.gd/: "TLS error from peer (alert code 20): bad MAC"
1470 0xC0,0x2F, // 7 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256
1471 // 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"
1472 //possibly these too:
1473 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
1474 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
1475 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
1476 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1477 0x00,0x2F, // 8 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA
1478 0x00,0x35, // 9 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA
1479 0x00,0x3C, //10 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256
1480 0x00,0x3D, //11 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256
1481 0x00,0x9C, //12 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256
1482 // 0x00,0x9D, // TLS_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher AES256-GCM-SHA384: "decryption failed or bad record mac"
1483#if ALLOW_RSA_NULL_SHA256
1484 0x00,0x3B, // TLS_RSA_WITH_NULL_SHA256
1485#endif
1486 0x01,0x00, //not a cipher - comprtypes_len, comprtype
1487 };
1481 static const uint8_t supported_groups[] = { 1488 static const uint8_t supported_groups[] = {
1482 0x00,0x0a, //extension_type: "supported_groups" 1489 0x00,0x0a, //extension_type: "supported_groups"
1483 0x00,0x04, //ext len 1490 0x00,0x04, //ext len
@@ -1502,7 +1509,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1502 uint8_t session_id_len; 1509 uint8_t session_id_len;
1503 /* uint8_t session_id[]; */ 1510 /* uint8_t session_id[]; */
1504 uint8_t cipherid_len16_hi, cipherid_len16_lo; 1511 uint8_t cipherid_len16_hi, cipherid_len16_lo;
1505 uint8_t cipherid[2 * (1 + NUM_CIPHERS)]; /* actually variable */ 1512 uint8_t cipherid[(1 + NUM_CIPHERS) * 2]; /* actually variable */
1506 uint8_t comprtypes_len; 1513 uint8_t comprtypes_len;
1507 uint8_t comprtypes[1]; /* actually variable */ 1514 uint8_t comprtypes[1]; /* actually variable */
1508 /* Extensions (SNI shown): 1515 /* Extensions (SNI shown):
@@ -1550,28 +1557,8 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1550 memset(record->rand32, 0x11, sizeof(record->rand32)); 1557 memset(record->rand32, 0x11, sizeof(record->rand32));
1551 /* record->session_id_len = 0; - already is */ 1558 /* record->session_id_len = 0; - already is */
1552 1559
1553 /* record->cipherid_len16_hi = 0; */ 1560 BUILD_BUG_ON(sizeof(ciphers) != 2 + (1 + NUM_CIPHERS) * 2 + 2);
1554 record->cipherid_len16_lo = sizeof(record->cipherid); 1561 memcpy(&record->cipherid_len16_hi, ciphers, sizeof(ciphers));
1555 /* RFC 5746 Renegotiation Indication Extension - some servers will refuse to work with us otherwise */
1556 /*record->cipherid[0] = TLS_EMPTY_RENEGOTIATION_INFO_SCSV >> 8; - zero */
1557 record->cipherid[1] = TLS_EMPTY_RENEGOTIATION_INFO_SCSV & 0xff;
1558 if ((CIPHER_ID1 >> 8) != 0) record->cipherid[2] = CIPHER_ID1 >> 8;
1559 /*************************/ record->cipherid[3] = CIPHER_ID1 & 0xff;
1560#if CIPHER_ID2
1561 if ((CIPHER_ID2 >> 8) != 0) record->cipherid[4] = CIPHER_ID2 >> 8;
1562 /*************************/ record->cipherid[5] = CIPHER_ID2 & 0xff;
1563#endif
1564#if CIPHER_ID3
1565 if ((CIPHER_ID3 >> 8) != 0) record->cipherid[6] = CIPHER_ID3 >> 8;
1566 /*************************/ record->cipherid[7] = CIPHER_ID3 & 0xff;
1567#endif
1568#if CIPHER_ID4
1569 if ((CIPHER_ID4 >> 8) != 0) record->cipherid[8] = CIPHER_ID4 >> 8;
1570 /*************************/ record->cipherid[9] = CIPHER_ID4 & 0xff;
1571#endif
1572
1573 record->comprtypes_len = 1;
1574 /* record->comprtypes[0] = 0; */
1575 1562
1576 ptr = (void*)(record + 1); 1563 ptr = (void*)(record + 1);
1577 *ptr++ = ext_len >> 8; 1564 *ptr++ = ext_len >> 8;
@@ -1626,6 +1613,7 @@ static void get_server_hello(tls_state_t *tls)
1626 1613
1627 struct server_hello *hp; 1614 struct server_hello *hp;
1628 uint8_t *cipherid; 1615 uint8_t *cipherid;
1616 uint8_t cipherid1;
1629 unsigned cipher; 1617 unsigned cipher;
1630 int len, len24; 1618 int len, len24;
1631 1619
@@ -1659,39 +1647,81 @@ static void get_server_hello(tls_state_t *tls)
1659 len24 += 32; /* what len would be if session id would be present */ 1647 len24 += 32; /* what len would be if session id would be present */
1660 } 1648 }
1661 1649
1662 if (len24 < 70 1650 if (len24 < 70)
1663// || cipherid[0] != (CIPHER_ID >> 8)
1664// || cipherid[1] != (CIPHER_ID & 0xff)
1665// || cipherid[2] != 0 /* comprtype */
1666 ) {
1667 bad_record_die(tls, "'server hello'", len); 1651 bad_record_die(tls, "'server hello'", len);
1668 }
1669 dbg("<< SERVER_HELLO\n"); 1652 dbg("<< SERVER_HELLO\n");
1670 1653
1671 memcpy(tls->hsd->client_and_server_rand32 + 32, hp->rand32, sizeof(hp->rand32)); 1654 memcpy(tls->hsd->client_and_server_rand32 + 32, hp->rand32, sizeof(hp->rand32));
1672 1655
1673 tls->cipher_id = cipher = 0x100 * cipherid[0] + cipherid[1]; 1656 /* Set up encryption params based on selected cipher */
1657#if 0
1658 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/
1659 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/
1660 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA
1661 // 0xC0,0x14, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - openssl s_server ... -cipher ECDHE-RSA-AES256-SHA: "No ciphers enabled for max supported SSL/TLS version"
1662 0xC0,0x23, // 4 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/
1663 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1664 0xC0,0x27, // 5 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256
1665 // 0xC0,0x28, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1666 0xC0,0x2B, // 6 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - ok: wget https://is.gd/
1667 // 0xC0,0x2C, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - wget https://is.gd/: "TLS error from peer (alert code 20): bad MAC"
1668 0xC0,0x2F, // 7 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256
1669 // 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"
1670 //possibly these too:
1671 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
1672 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
1673 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
1674 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1675 0x00,0x2F, // 8 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA
1676 0x00,0x35, // 9 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA
1677 0x00,0x3C, //10 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256
1678 0x00,0x3D, //11 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256
1679 0x00,0x9C, //12 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256
1680 // 0x00,0x9D, // TLS_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher AES256-GCM-SHA384: "decryption failed or bad record mac"
1681 0x00,0x3B, // TLS_RSA_WITH_NULL_SHA256
1682#endif
1683 cipherid1 = cipherid[1];
1684 tls->cipher_id = cipher = 0x100 * cipherid[0] + cipherid1;
1674 dbg("server chose cipher %04x\n", cipher); 1685 dbg("server chose cipher %04x\n", cipher);
1675 1686 tls->key_size = AES256_KEYSIZE;
1676 if (cipher == TLS_RSA_WITH_AES_128_CBC_SHA 1687 tls->MAC_size = SHA256_OUTSIZE;
1677 || cipher == TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 1688 /*tls->IV_size = 0; - already is */
1678 ) { 1689 if (cipherid[0] == 0xC0) {
1679 if (cipher == TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA) 1690 /* All C0xx are ECDHE */
1680 tls->flags |= NEED_EC_KEY; 1691 tls->flags |= NEED_EC_KEY;
1681 tls->key_size = AES128_KEYSIZE; 1692 if (cipherid1 & 1) {
1682 tls->MAC_size = SHA1_OUTSIZE; 1693 /* Odd numbered C0xx use AES128 (even ones use AES256) */
1683 } 1694 tls->key_size = AES128_KEYSIZE;
1684 else 1695 }
1685 if (cipher == TLS_RSA_WITH_AES_256_CBC_SHA256) { 1696 if (cipherid1 <= 0x14) {
1686 tls->key_size = AES256_KEYSIZE; 1697 tls->MAC_size = SHA1_OUTSIZE;
1687 tls->MAC_size = SHA256_OUTSIZE; 1698 } else
1688 } 1699 if (cipherid1 >= 0x2B && cipherid1 <= 0x30) {
1689 else { /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */ 1700 /* C02B,2C,2F,30 are AES-GCM */
1690 tls->flags |= NEED_EC_KEY | ENCRYPTION_AESGCM; 1701 tls->flags |= ENCRYPTION_AESGCM;
1691 tls->key_size = AES128_KEYSIZE; 1702 tls->MAC_size = 0;
1692 /* tls->MAC_size = 0; */ 1703 tls->IV_size = 4;
1693 tls->IV_size = 4; 1704 }
1705 } else {
1706 /* All 00xx are RSA */
1707 if (cipherid1 == 0x2F
1708 || cipherid1 == 0x3C
1709 || cipherid1 == 0x9C
1710 ) {
1711 tls->key_size = AES128_KEYSIZE;
1712 }
1713 if (cipherid1 <= 0x35) {
1714 tls->MAC_size = SHA1_OUTSIZE;
1715 } else
1716 if (cipherid1 == 0x9C || cipherid1 == 0x9D) {
1717 /* 009C,9D are AES-GCM */
1718 tls->flags |= ENCRYPTION_AESGCM;
1719 tls->MAC_size = 0;
1720 tls->IV_size = 4;
1721 }
1694 } 1722 }
1723 dbg("key_size:%u MAC_size:%u IV_size:%u\n", tls->key_size, tls->MAC_size, tls->IV_size);
1724
1695 /* Handshake hash eventually destined to FINISHED record 1725 /* Handshake hash eventually destined to FINISHED record
1696 * is sha256 regardless of cipher 1726 * is sha256 regardless of cipher
1697 * (at least for all ciphers defined by RFC5246). 1727 * (at least for all ciphers defined by RFC5246).
@@ -2171,7 +2201,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
2171 bad_record_die(tls, "switch to encrypted traffic", len); 2201 bad_record_die(tls, "switch to encrypted traffic", len);
2172 dbg("<< CHANGE_CIPHER_SPEC\n"); 2202 dbg("<< CHANGE_CIPHER_SPEC\n");
2173 2203
2174 if (CIPHER_ID1 == TLS_RSA_WITH_NULL_SHA256 2204 if (ALLOW_RSA_NULL_SHA256
2175 && tls->cipher_id == TLS_RSA_WITH_NULL_SHA256 2205 && tls->cipher_id == TLS_RSA_WITH_NULL_SHA256
2176 ) { 2206 ) {
2177 tls->min_encrypted_len_on_read = tls->MAC_size; 2207 tls->min_encrypted_len_on_read = tls->MAC_size;