修改ssl_chello_parse相关函数,处理TLS Grease导致的客户端标识不准确,详见 https://security.stackexchange.com/questions/176951/google-chrome-weird-random-cipher-suite
This commit is contained in:
@@ -300,8 +300,10 @@ char * ssl_ssl_masterkey_to_str(SSL * ssl)
|
||||
char * str = NULL;
|
||||
int rv;
|
||||
unsigned char * k, * r;
|
||||
|
||||
unsigned char kbuf[48], rbuf[32];
|
||||
//https://www.openssl.org/docs/man1.1.1/man3/SSL_SESSION_get_master_key.html
|
||||
//In current versions of the TLS protocols, the length of client_random (and also server_random) is
|
||||
//always SSL3_RANDOM_SIZE bytes.
|
||||
unsigned char kbuf[48]={0}, rbuf[32]={0};//
|
||||
k = &kbuf[0];
|
||||
r = &rbuf[0];
|
||||
SSL_SESSION* sess=SSL_get0_session(ssl);
|
||||
@@ -1918,7 +1920,219 @@ static int parse_extensions(const unsigned char *buff, uint16_t buff_len, struct
|
||||
return CHELLO_PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len, int parse_cipher, enum chello_parse_result* result)
|
||||
|
||||
struct cipher_suite
|
||||
{
|
||||
uint16_t value;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
static struct cipher_suite cipher_suite_list[] =
|
||||
{
|
||||
{0xC030, "ECDHE-RSA-AES256-GCM-SHA384"},
|
||||
{0xC02C, "ECDHE-ECDSA-AES256-GCM-SHA384"},
|
||||
{0xC028, "ECDHE-RSA-AES256-SHA384"},
|
||||
{0xC024, "ECDHE-ECDSA-AES256-SHA384"},
|
||||
{0xC014, "ECDHE-RSA-AES256-SHA"},
|
||||
{0xC00A, "ECDHE-ECDSA-AES256-SHA"},
|
||||
{0x00A5, "DH-DSS-AES256-GCM-SHA384"},
|
||||
{0x00A3, "DHE-DSS-AES256-GCM-SHA384"},
|
||||
{0x00A1, "DH-RSA-AES256-GCM-SHA384"},
|
||||
{0x009F, "DHE-RSA-AES256-GCM-SHA384"},
|
||||
{0x006B, "DHE-RSA-AES256-SHA256"},
|
||||
{0x006A, "DHE-DSS-AES256-SHA256"},
|
||||
{0x0069, "DH-RSA-AES256-SHA256"},
|
||||
{0x0068, "DH-DSS-AES256-SHA256"},
|
||||
{0x0039, "DHE-RSA-AES256-SHA"},
|
||||
{0x0038, "DHE-DSS-AES256-SHA"},
|
||||
{0x0037, "DH-RSA-AES256-SHA"},
|
||||
{0x0036, "DH-DSS-AES256-SHA"},
|
||||
{0x0088, "DHE-RSA-CAMELLIA256-SHA"},
|
||||
{0x0087, "DHE-DSS-CAMELLIA256-SHA"},
|
||||
{0x0086, "DH-RSA-CAMELLIA256-SHA"},
|
||||
{0x0085, "DH-DSS-CAMELLIA256-SHA"},
|
||||
{0xC019, "AECDH-AES256-SHA"},
|
||||
{0x00A7, "ADH-AES256-GCM-SHA384"},
|
||||
{0x006D, "ADH-AES256-SHA256"},
|
||||
{0x003A, "ADH-AES256-SHA"},
|
||||
{0x0089, "ADH-CAMELLIA256-SHA"},
|
||||
{0xC032, "ECDH-RSA-AES256-GCM-SHA384"},
|
||||
{0xC02E, "ECDH-ECDSA-AES256-GCM-SHA384"},
|
||||
{0xC02A, "ECDH-RSA-AES256-SHA384"},
|
||||
{0xC026, "ECDH-ECDSA-AES256-SHA384"},
|
||||
{0xC00F, "ECDH-RSA-AES256-SHA"},
|
||||
{0xC005, "ECDH-ECDSA-AES256-SHA"},
|
||||
{0x009D, "AES256-GCM-SHA384"},
|
||||
{0x003D, "AES256-SHA256"},
|
||||
{0x0035, "AES256-SHA"},
|
||||
{0x0084, "CAMELLIA256-SHA"},
|
||||
{0x008D, "PSK-AES256-CBC-SHA"},
|
||||
{0xC02F, "ECDHE-RSA-AES128-GCM-SHA256"},
|
||||
{0xC02B, "ECDHE-ECDSA-AES128-GCM-SHA256"},
|
||||
{0xC027, "ECDHE-RSA-AES128-SHA256"},
|
||||
{0xC023, "ECDHE-ECDSA-AES128-SHA256"},
|
||||
{0xC013, "ECDHE-RSA-AES128-SHA"},
|
||||
{0xC009, "ECDHE-ECDSA-AES128-SHA"},
|
||||
{0x00A4, "DH-DSS-AES128-GCM-SHA256"},
|
||||
{0x00A2, "DHE-DSS-AES128-GCM-SHA256"},
|
||||
{0x00A0, "DH-RSA-AES128-GCM-SHA256"},
|
||||
{0x009E, "DHE-RSA-AES128-GCM-SHA256"},
|
||||
{0x0067, "DHE-RSA-AES128-SHA256"},
|
||||
{0x0040, "DHE-DSS-AES128-SHA256"},
|
||||
{0x003F, "DH-RSA-AES128-SHA256"},
|
||||
{0x003E, "DH-DSS-AES128-SHA256"},
|
||||
{0x0033, "DHE-RSA-AES128-SHA"},
|
||||
{0x0032, "DHE-DSS-AES128-SHA"},
|
||||
{0x0031, "DH-RSA-AES128-SHA"},
|
||||
{0x0030, "DH-DSS-AES128-SHA"},
|
||||
{0x009A, "DHE-RSA-SEED-SHA"},
|
||||
{0x0099, "DHE-DSS-SEED-SHA"},
|
||||
{0x0098, "DH-RSA-SEED-SHA"},
|
||||
{0x0097, "DH-DSS-SEED-SHA"},
|
||||
{0x0045, "DHE-RSA-CAMELLIA128-SHA"},
|
||||
{0x0044, "DHE-DSS-CAMELLIA128-SHA"},
|
||||
{0x0043, "DH-RSA-CAMELLIA128-SHA"},
|
||||
{0x0042, "DH-DSS-CAMELLIA128-SHA"},
|
||||
{0xC018, "AECDH-AES128-SHA"},
|
||||
{0x00A6, "ADH-AES128-GCM-SHA256"},
|
||||
{0x006C, "ADH-AES128-SHA256"},
|
||||
{0x0034, "ADH-AES128-SHA"},
|
||||
{0x009B, "ADH-SEED-SHA"},
|
||||
{0x0046, "ADH-CAMELLIA128-SHA"},
|
||||
{0xC031, "ECDH-RSA-AES128-GCM-SHA256"},
|
||||
{0xC02D, "ECDH-ECDSA-AES128-GCM-SHA256"},
|
||||
{0xC029, "ECDH-RSA-AES128-SHA256"},
|
||||
{0xC025, "ECDH-ECDSA-AES128-SHA256"},
|
||||
{0xC00E, "ECDH-RSA-AES128-SHA"},
|
||||
{0xC004, "ECDH-ECDSA-AES128-SHA"},
|
||||
{0x009C, "AES128-GCM-SHA256"},
|
||||
{0x003C, "AES128-SHA256"},
|
||||
{0x002F, "AES128-SHA"},
|
||||
{0x0096, "SEED-SHA"},
|
||||
{0x0041, "CAMELLIA128-SHA"},
|
||||
{0x008C, "PSK-AES128-CBC-SHA"},
|
||||
{0xC012, "ECDHE-RSA-DES-CBC3-SHA"},
|
||||
{0xC008, "ECDHE-ECDSA-DES-CBC3-SHA"},
|
||||
{0x0016, "EDH-RSA-DES-CBC3-SHA"},
|
||||
{0x0013, "EDH-DSS-DES-CBC3-SHA"},
|
||||
{0x0010, "DH-RSA-DES-CBC3-SHA"},
|
||||
{0x000D, "DH-DSS-DES-CBC3-SHA"},
|
||||
{0xC017, "AECDH-DES-CBC3-SHA"},
|
||||
{0x001B, "ADH-DES-CBC3-SHA"},
|
||||
{0xC00D, "ECDH-RSA-DES-CBC3-SHA"},
|
||||
{0xC003, "ECDH-ECDSA-DES-CBC3-SHA"},
|
||||
{0x000A, "DES-CBC3-SHA"},
|
||||
{0x0007, "IDEA-CBC-SHA"},
|
||||
{0x008B, "PSK-3DES-EDE-CBC-SHA"},
|
||||
{0x0021, "KRB5-IDEA-CBC-SHA"},
|
||||
{0x001F, "KRB5-DES-CBC3-SHA"},
|
||||
{0x0025, "KRB5-IDEA-CBC-MD5"},
|
||||
{0x0023, "KRB5-DES-CBC3-MD5"},
|
||||
{0xC011, "ECDHE-RSA-RC4-SHA"},
|
||||
{0xC007, "ECDHE-ECDSA-RC4-SHA"},
|
||||
{0xC016, "AECDH-RC4-SHA"},
|
||||
{0x0018, "ADH-RC4-MD5"},
|
||||
{0xC00C, "ECDH-RSA-RC4-SHA"},
|
||||
{0xC002, "ECDH-ECDSA-RC4-SHA"},
|
||||
{0x0005, "RC4-SHA"},
|
||||
{0x0004, "RC4-MD5"},
|
||||
{0x008A, "PSK-RC4-SHA"},
|
||||
{0x0020, "KRB5-RC4-SHA"},
|
||||
{0x0024, "KRB5-RC4-MD5"},
|
||||
{0xC010, "ECDHE-RSA-NULL-SHA"},
|
||||
{0xC006, "ECDHE-ECDSA-NULL-SHA"},
|
||||
{0xC015, "AECDH-NULL-SHA"},
|
||||
{0xC00B, "ECDH-RSA-NULL-SHA"},
|
||||
{0xC001, "ECDH-ECDSA-NULL-SHA"},
|
||||
{0x003B, "NULL-SHA256"},
|
||||
{0x0002, "NULL-SHA"},
|
||||
{0x0001, "NULL-MD5"}
|
||||
};
|
||||
|
||||
static struct cipher_suite cipher_suite_list_tls13[] =
|
||||
{
|
||||
{0x1301, "TLS_AES_128_GCM_SHA256"},
|
||||
{0x1302, "TLS_AES_256_GCM_SHA384"},
|
||||
{0x1303, "TLS_CHACHA20_POLY1305_SHA256"},
|
||||
{0x1304, "TLS_AES_128_CCM_SHA256"},
|
||||
{0x1305, "TLS_AES_128_CCM_8_SHA256"}
|
||||
};
|
||||
|
||||
static int cipher_suites_convert_helper(uint16_t value, char *name, size_t name_sz)
|
||||
{
|
||||
int n1 = sizeof(cipher_suite_list) / sizeof(struct cipher_suite);
|
||||
int n2 = sizeof(cipher_suite_list_tls13) / sizeof(struct cipher_suite);
|
||||
for(int i = 0; i < n1; i++)
|
||||
{
|
||||
if(value == cipher_suite_list[i].value)
|
||||
{
|
||||
if(name) memcpy(name, cipher_suite_list[i].name, strnlen(cipher_suite_list[i].name, name_sz));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < n2; i++)
|
||||
{
|
||||
if(value == cipher_suite_list_tls13[i].value)
|
||||
{
|
||||
if(name) memcpy(name, cipher_suite_list_tls13[i].name, strnlen(cipher_suite_list_tls13[i].name, name_sz));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ssl_cipher_suites_to_name(const char *source, int source_len, char *result_common, size_t sz_common, char *result_tls13, size_t sz_tls13)
|
||||
{
|
||||
int target_common_reach_max = 0;
|
||||
int target_tls13_reach_max = 0;
|
||||
char name[TFE_SYMBOL_MAX] = "";
|
||||
for(int i = 0; i < source_len - 1;)
|
||||
{
|
||||
uint16_t val = (source[i] << 8) | source[i + 1];
|
||||
memset(name, 0, sizeof(name));
|
||||
int ret = cipher_suites_convert_helper(val, name, sizeof(name));
|
||||
//target common
|
||||
if(ret == 1 && target_common_reach_max == 0)
|
||||
{
|
||||
if(strnlen(name, sizeof(name)) + strnlen(result_common, sz_common) + 1 > sz_common)
|
||||
{
|
||||
target_common_reach_max = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncat(result_common, name, sz_common);
|
||||
strncat(result_common, ":", sz_common);
|
||||
}
|
||||
}
|
||||
//result_tls13
|
||||
if(ret == 2 && target_tls13_reach_max == 0)
|
||||
{
|
||||
if(strnlen(name, sizeof(name)) + strnlen(result_tls13, sz_tls13) + 1 > sz_tls13)
|
||||
{
|
||||
target_tls13_reach_max = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncat(result_tls13, name, sz_tls13);
|
||||
strncat(result_tls13, ":", sz_tls13);
|
||||
}
|
||||
}
|
||||
i += 2;
|
||||
}
|
||||
int len1 = strnlen(result_common, sz_common);
|
||||
if(len1 > 0)
|
||||
{
|
||||
result_common[len1 - 1] = '\0';
|
||||
}
|
||||
int len2 = strnlen(result_tls13, sz_tls13);
|
||||
if(len2 > 0)
|
||||
{
|
||||
result_tls13[len2 - 1] = '\0';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len, enum chello_parse_result* result)
|
||||
{
|
||||
if(buff == NULL)
|
||||
{
|
||||
@@ -2060,13 +2274,20 @@ struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len,
|
||||
*result = CHELLO_PARSE_INVALID_FORMAT;
|
||||
return _chello;
|
||||
}
|
||||
if(parse_cipher)
|
||||
size_t i=0, j=0;
|
||||
_chello->cipher_suites = ALLOC(char, len);
|
||||
uint16_t* known_cipher=(uint16_t*)_chello->cipher_suites;
|
||||
uint16_t* raw_cipher=(uint16_t*)(buff + pos);
|
||||
for(i=0, j=0; i<len/2; i++)
|
||||
{
|
||||
char* cipher_suites = ALLOC(char, len);
|
||||
memcpy(cipher_suites, (void*)(buff + pos), len);
|
||||
_chello->cipher_suites = cipher_suites;
|
||||
_chello->cipher_suites_len = len;
|
||||
//https://security.stackexchange.com/questions/176951/google-chrome-weird-random-cipher-suite
|
||||
if(cipher_suites_convert_helper(raw_cipher[i], NULL, 0)>0)
|
||||
{
|
||||
known_cipher[j++]=raw_cipher[i];
|
||||
}
|
||||
}
|
||||
_chello->cipher_suites_len = j*2;
|
||||
|
||||
pos += len;
|
||||
|
||||
/* Compression Methods */
|
||||
@@ -2110,213 +2331,3 @@ struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len,
|
||||
}
|
||||
}
|
||||
|
||||
struct cipher_suite
|
||||
{
|
||||
uint16_t value;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
struct cipher_suite cipher_suite_list[] =
|
||||
{
|
||||
{0xC030, "ECDHE-RSA-AES256-GCM-SHA384"},
|
||||
{0xC02C, "ECDHE-ECDSA-AES256-GCM-SHA384"},
|
||||
{0xC028, "ECDHE-RSA-AES256-SHA384"},
|
||||
{0xC024, "ECDHE-ECDSA-AES256-SHA384"},
|
||||
{0xC014, "ECDHE-RSA-AES256-SHA"},
|
||||
{0xC00A, "ECDHE-ECDSA-AES256-SHA"},
|
||||
{0x00A5, "DH-DSS-AES256-GCM-SHA384"},
|
||||
{0x00A3, "DHE-DSS-AES256-GCM-SHA384"},
|
||||
{0x00A1, "DH-RSA-AES256-GCM-SHA384"},
|
||||
{0x009F, "DHE-RSA-AES256-GCM-SHA384"},
|
||||
{0x006B, "DHE-RSA-AES256-SHA256"},
|
||||
{0x006A, "DHE-DSS-AES256-SHA256"},
|
||||
{0x0069, "DH-RSA-AES256-SHA256"},
|
||||
{0x0068, "DH-DSS-AES256-SHA256"},
|
||||
{0x0039, "DHE-RSA-AES256-SHA"},
|
||||
{0x0038, "DHE-DSS-AES256-SHA"},
|
||||
{0x0037, "DH-RSA-AES256-SHA"},
|
||||
{0x0036, "DH-DSS-AES256-SHA"},
|
||||
{0x0088, "DHE-RSA-CAMELLIA256-SHA"},
|
||||
{0x0087, "DHE-DSS-CAMELLIA256-SHA"},
|
||||
{0x0086, "DH-RSA-CAMELLIA256-SHA"},
|
||||
{0x0085, "DH-DSS-CAMELLIA256-SHA"},
|
||||
{0xC019, "AECDH-AES256-SHA"},
|
||||
{0x00A7, "ADH-AES256-GCM-SHA384"},
|
||||
{0x006D, "ADH-AES256-SHA256"},
|
||||
{0x003A, "ADH-AES256-SHA"},
|
||||
{0x0089, "ADH-CAMELLIA256-SHA"},
|
||||
{0xC032, "ECDH-RSA-AES256-GCM-SHA384"},
|
||||
{0xC02E, "ECDH-ECDSA-AES256-GCM-SHA384"},
|
||||
{0xC02A, "ECDH-RSA-AES256-SHA384"},
|
||||
{0xC026, "ECDH-ECDSA-AES256-SHA384"},
|
||||
{0xC00F, "ECDH-RSA-AES256-SHA"},
|
||||
{0xC005, "ECDH-ECDSA-AES256-SHA"},
|
||||
{0x009D, "AES256-GCM-SHA384"},
|
||||
{0x003D, "AES256-SHA256"},
|
||||
{0x0035, "AES256-SHA"},
|
||||
{0x0084, "CAMELLIA256-SHA"},
|
||||
{0x008D, "PSK-AES256-CBC-SHA"},
|
||||
{0xC02F, "ECDHE-RSA-AES128-GCM-SHA256"},
|
||||
{0xC02B, "ECDHE-ECDSA-AES128-GCM-SHA256"},
|
||||
{0xC027, "ECDHE-RSA-AES128-SHA256"},
|
||||
{0xC023, "ECDHE-ECDSA-AES128-SHA256"},
|
||||
{0xC013, "ECDHE-RSA-AES128-SHA"},
|
||||
{0xC009, "ECDHE-ECDSA-AES128-SHA"},
|
||||
{0x00A4, "DH-DSS-AES128-GCM-SHA256"},
|
||||
{0x00A2, "DHE-DSS-AES128-GCM-SHA256"},
|
||||
{0x00A0, "DH-RSA-AES128-GCM-SHA256"},
|
||||
{0x009E, "DHE-RSA-AES128-GCM-SHA256"},
|
||||
{0x0067, "DHE-RSA-AES128-SHA256"},
|
||||
{0x0040, "DHE-DSS-AES128-SHA256"},
|
||||
{0x003F, "DH-RSA-AES128-SHA256"},
|
||||
{0x003E, "DH-DSS-AES128-SHA256"},
|
||||
{0x0033, "DHE-RSA-AES128-SHA"},
|
||||
{0x0032, "DHE-DSS-AES128-SHA"},
|
||||
{0x0031, "DH-RSA-AES128-SHA"},
|
||||
{0x0030, "DH-DSS-AES128-SHA"},
|
||||
{0x009A, "DHE-RSA-SEED-SHA"},
|
||||
{0x0099, "DHE-DSS-SEED-SHA"},
|
||||
{0x0098, "DH-RSA-SEED-SHA"},
|
||||
{0x0097, "DH-DSS-SEED-SHA"},
|
||||
{0x0045, "DHE-RSA-CAMELLIA128-SHA"},
|
||||
{0x0044, "DHE-DSS-CAMELLIA128-SHA"},
|
||||
{0x0043, "DH-RSA-CAMELLIA128-SHA"},
|
||||
{0x0042, "DH-DSS-CAMELLIA128-SHA"},
|
||||
{0xC018, "AECDH-AES128-SHA"},
|
||||
{0x00A6, "ADH-AES128-GCM-SHA256"},
|
||||
{0x006C, "ADH-AES128-SHA256"},
|
||||
{0x0034, "ADH-AES128-SHA"},
|
||||
{0x009B, "ADH-SEED-SHA"},
|
||||
{0x0046, "ADH-CAMELLIA128-SHA"},
|
||||
{0xC031, "ECDH-RSA-AES128-GCM-SHA256"},
|
||||
{0xC02D, "ECDH-ECDSA-AES128-GCM-SHA256"},
|
||||
{0xC029, "ECDH-RSA-AES128-SHA256"},
|
||||
{0xC025, "ECDH-ECDSA-AES128-SHA256"},
|
||||
{0xC00E, "ECDH-RSA-AES128-SHA"},
|
||||
{0xC004, "ECDH-ECDSA-AES128-SHA"},
|
||||
{0x009C, "AES128-GCM-SHA256"},
|
||||
{0x003C, "AES128-SHA256"},
|
||||
{0x002F, "AES128-SHA"},
|
||||
{0x0096, "SEED-SHA"},
|
||||
{0x0041, "CAMELLIA128-SHA"},
|
||||
{0x008C, "PSK-AES128-CBC-SHA"},
|
||||
{0xC012, "ECDHE-RSA-DES-CBC3-SHA"},
|
||||
{0xC008, "ECDHE-ECDSA-DES-CBC3-SHA"},
|
||||
{0x0016, "EDH-RSA-DES-CBC3-SHA"},
|
||||
{0x0013, "EDH-DSS-DES-CBC3-SHA"},
|
||||
{0x0010, "DH-RSA-DES-CBC3-SHA"},
|
||||
{0x000D, "DH-DSS-DES-CBC3-SHA"},
|
||||
{0xC017, "AECDH-DES-CBC3-SHA"},
|
||||
{0x001B, "ADH-DES-CBC3-SHA"},
|
||||
{0xC00D, "ECDH-RSA-DES-CBC3-SHA"},
|
||||
{0xC003, "ECDH-ECDSA-DES-CBC3-SHA"},
|
||||
{0x000A, "DES-CBC3-SHA"},
|
||||
{0x0007, "IDEA-CBC-SHA"},
|
||||
{0x008B, "PSK-3DES-EDE-CBC-SHA"},
|
||||
{0x0021, "KRB5-IDEA-CBC-SHA"},
|
||||
{0x001F, "KRB5-DES-CBC3-SHA"},
|
||||
{0x0025, "KRB5-IDEA-CBC-MD5"},
|
||||
{0x0023, "KRB5-DES-CBC3-MD5"},
|
||||
{0xC011, "ECDHE-RSA-RC4-SHA"},
|
||||
{0xC007, "ECDHE-ECDSA-RC4-SHA"},
|
||||
{0xC016, "AECDH-RC4-SHA"},
|
||||
{0x0018, "ADH-RC4-MD5"},
|
||||
{0xC00C, "ECDH-RSA-RC4-SHA"},
|
||||
{0xC002, "ECDH-ECDSA-RC4-SHA"},
|
||||
{0x0005, "RC4-SHA"},
|
||||
{0x0004, "RC4-MD5"},
|
||||
{0x008A, "PSK-RC4-SHA"},
|
||||
{0x0020, "KRB5-RC4-SHA"},
|
||||
{0x0024, "KRB5-RC4-MD5"},
|
||||
{0xC010, "ECDHE-RSA-NULL-SHA"},
|
||||
{0xC006, "ECDHE-ECDSA-NULL-SHA"},
|
||||
{0xC015, "AECDH-NULL-SHA"},
|
||||
{0xC00B, "ECDH-RSA-NULL-SHA"},
|
||||
{0xC001, "ECDH-ECDSA-NULL-SHA"},
|
||||
{0x003B, "NULL-SHA256"},
|
||||
{0x0002, "NULL-SHA"},
|
||||
{0x0001, "NULL-MD5"}
|
||||
};
|
||||
|
||||
struct cipher_suite cipher_suite_list_tls13[] =
|
||||
{
|
||||
{0x1301, "TLS_AES_128_GCM_SHA256"},
|
||||
{0x1302, "TLS_AES_256_GCM_SHA384"},
|
||||
{0x1303, "TLS_CHACHA20_POLY1305_SHA256"},
|
||||
{0x1304, "TLS_AES_128_CCM_SHA256"},
|
||||
{0x1305, "TLS_AES_128_CCM_8_SHA256"}
|
||||
};
|
||||
|
||||
int cipher_suites_convert_helper(uint16_t value, char *name)
|
||||
{
|
||||
int n1 = sizeof(cipher_suite_list) / sizeof(struct cipher_suite);
|
||||
int n2 = sizeof(cipher_suite_list_tls13) / sizeof(struct cipher_suite);
|
||||
for(int i = 0; i < n1; i++)
|
||||
{
|
||||
if(value == cipher_suite_list[i].value)
|
||||
{
|
||||
memcpy(name, cipher_suite_list[i].name, strnlen(cipher_suite_list[i].name, TFE_STRING_MAX));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < n2; i++)
|
||||
{
|
||||
if(value == cipher_suite_list_tls13[i].value)
|
||||
{
|
||||
memcpy(name, cipher_suite_list_tls13[i].name, strnlen(cipher_suite_list_tls13[i].name, TFE_STRING_MAX));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ssl_cipher_suites_convert(const char *source, int source_len, char *target_common, char *target_tls13)
|
||||
{
|
||||
int target_common_reach_max = 0;
|
||||
int target_tls13_reach_max = 0;
|
||||
for(int i = 0; i < source_len - 1;)
|
||||
{
|
||||
uint16_t val = (source[i] << 8) | source[i + 1];
|
||||
char name[TFE_SYMBOL_MAX] = "";
|
||||
int ret = cipher_suites_convert_helper(val, name);
|
||||
//target common
|
||||
if(ret == 1 && target_common_reach_max == 0)
|
||||
{
|
||||
if(strnlen(name, TFE_STRING_MAX) + strnlen(target_common, TFE_STRING_MAX) + 1 > TFE_STRING_MAX)
|
||||
{
|
||||
target_common_reach_max = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncat(target_common, name, TFE_STRING_MAX);
|
||||
strncat(target_common, ":", TFE_STRING_MAX);
|
||||
}
|
||||
}
|
||||
//target_tls13
|
||||
if(ret == 2 && target_tls13_reach_max == 0)
|
||||
{
|
||||
if(strnlen(name, TFE_STRING_MAX) + strnlen(target_tls13, TFE_STRING_MAX) + 1 > TFE_STRING_MAX)
|
||||
{
|
||||
target_tls13_reach_max = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncat(target_tls13, name, TFE_STRING_MAX);
|
||||
strncat(target_tls13, ":", TFE_STRING_MAX);
|
||||
}
|
||||
}
|
||||
i += 2;
|
||||
}
|
||||
int len1 = strnlen(target_common, TFE_STRING_MAX);
|
||||
if(len1 > 0)
|
||||
{
|
||||
target_common[len1 - 1] = '\0';
|
||||
}
|
||||
int len2 = strnlen(target_tls13, TFE_STRING_MAX);
|
||||
if(len2 > 0)
|
||||
{
|
||||
target_tls13[len2 - 1] = '\0';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user