This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tfe/platform/test/test_chello_parse.cpp

243 lines
11 KiB
C++
Raw Normal View History

2018-09-13 20:10:21 +08:00
#include "ssl_utils.h"
#include "tfe_utils.h"
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
char* parse_alpn(const char* alpn)
{
int size = strlen(alpn);
char* result = (char*)malloc(100);
result[0] = '\0';
int i = 0;
for(i = 0;i < size; )
{
int size1 = alpn[i];
strncat(result, alpn + i + 1, size1);
strncat(result, ", ", 2);
i += (1 + size1);
}
int size2 = strlen(result);
result[size2] = '\0';
return result;
}
int ssl2_test(){
2018-09-13 20:10:21 +08:00
//ssl2.0
unsigned char buff[] =
{
0x80, 0x77, 0x01, 0x03, 0x01, 0x00, 0x4e, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x39, 0x00, 0x00, 0x38, 0x00, 0x00, 0x35,
0x00, 0x00, 0x16, 0x00, 0x00, 0x13, 0x00, 0x00, 0x0a, 0x07,
0x00, 0xc0, 0x00, 0x00, 0x33, 0x00, 0x00, 0x32, 0x00, 0x00,
0x2f, 0x03, 0x00, 0x80, 0x00, 0x00, 0x05, 0x00, 0x00, 0x04,
0x01, 0x00, 0x80, 0x00, 0x00, 0x15, 0x00, 0x00, 0x12, 0x00,
0x00, 0x09, 0x06, 0x00, 0x40, 0x00, 0x00, 0x14, 0x00, 0x00,
0x11, 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x04, 0x00, 0x80,
0x00, 0x00, 0x03, 0x02, 0x00, 0x80, 0x00, 0x00, 0xff, 0xe2,
0xd8, 0x90, 0x3f, 0xbd, 0x26, 0x76, 0xb2, 0xf3, 0x8b, 0x1b,
0x36, 0xed, 0x29, 0x04, 0x8d, 0x72, 0x1a, 0xe7, 0xc4, 0xd5,
0xbc, 0x56, 0xb1, 0x63, 0x8e, 0x8d, 0x9e, 0x08, 0x74, 0xb9,
0x69
};
size_t buff_len = sizeof(buff) / sizeof(char);
enum chello_parse_result result;
struct ssl_chello* chello = ssl_chello_parse(buff, buff_len, 1, &result);
2018-09-13 20:10:21 +08:00
printf("-----------------------------ssl2.0 only parse version --------------------------------\n");
2018-09-14 14:09:37 +08:00
printf("result is %d\n", result);
printf("min version is %d, %d\n", chello->min_version.major, chello->min_version.minor);
2018-09-13 20:10:21 +08:00
printf("\n\n");
ssl_chello_free(chello);
chello = NULL;
}
2018-09-13 20:10:21 +08:00
int ssl3_test(){
2018-09-13 20:10:21 +08:00
//ssl3.0, no extensions
unsigned char buff1[] =
{
0x16, 0x03, 0x00, 0x00, 0x51, 0x01, 0x00, 0x00, 0x4d, 0x03,
0x00, 0x50, 0x42, 0xb2, 0x29, 0x1f, 0xcf, 0x52, 0xa0, 0x94,
0x87, 0x05, 0xe7, 0x0b, 0x63, 0x08, 0x12, 0xa2, 0x6c, 0x59,
0xf7, 0xf5, 0x72, 0x2b, 0x57, 0x14, 0xa7, 0x07, 0x95, 0xcb,
0xce, 0xe5, 0xe4, 0x00, 0x00, 0x26, 0x00, 0x04, 0x00, 0x05,
0x00, 0x2f, 0x00, 0x33, 0x00, 0x32, 0x00, 0x0a, 0xfe, 0xff,
0x00, 0x16, 0x00, 0x13, 0x00, 0x66, 0x00, 0x09, 0xfe, 0xfe,
0x00, 0x15, 0x00, 0x12, 0x00, 0x03, 0x00, 0x08, 0x00, 0x06,
0x00, 0x14, 0x00, 0x11, 0x01, 0x00
};
size_t buff1_len = sizeof(buff1) / sizeof(char);
enum chello_parse_result result1;
struct ssl_chello* chello1 = ssl_chello_parse(buff1, buff1_len, 1, &result1);
2018-09-13 20:10:21 +08:00
printf("--------------------------------ssl3.0, no extensions --------------------------------\n");
2018-09-14 14:09:37 +08:00
printf("result is %d\n", result1);
printf("min version is %d, %d\n", chello1->min_version.major, chello1->min_version.minor);
printf("max version: %d, %d\n", chello1->max_version.major, chello1->max_version.minor);
2018-09-13 20:10:21 +08:00
printf("cipher suites is %s\n", chello1->cipher_suites);
printf("\n\n");
ssl_chello_free(chello1);
chello1 = NULL;
}
2018-09-13 20:10:21 +08:00
int tls12_test(){
2018-09-13 20:10:21 +08:00
//tls1.2
unsigned char buff[] =
2018-09-13 20:10:21 +08:00
{
0x16, 0x03, 0x01, 0x00, 0xd7, 0x01, 0x00, 0x00, 0xd3, 0x03, 0x03, 0x5c, 0xe7, 0x91, 0x0d, 0x99,
0x76, 0x7d, 0x0c, 0xce, 0x84, 0xe0, 0x14, 0x91, 0x07, 0xe4, 0x71, 0x29, 0x97, 0x0a, 0x27, 0xae,
0xff, 0xe7, 0xde, 0x90, 0xd7, 0x01, 0x93, 0x8b, 0x53, 0x7f, 0x0a, 0x20, 0x45, 0x90, 0x72, 0xd8,
0xfa, 0xcf, 0x55, 0x2d, 0x87, 0x84, 0x57, 0xb6, 0xfb, 0xff, 0x3a, 0x1c, 0x00, 0x8a, 0x81, 0x27,
0xe1, 0x75, 0x1f, 0x97, 0xfd, 0xb1, 0x51, 0x0b, 0x73, 0xa4, 0xe3, 0xff, 0x00, 0x3a, 0x00, 0xff,
0xc0, 0x2c, 0xc0, 0x2b, 0xc0, 0x24, 0xc0, 0x23, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x08, 0xc0, 0x30,
0xc0, 0x2f, 0xc0, 0x28, 0xc0, 0x27, 0xc0, 0x14, 0xc0, 0x13, 0xc0, 0x12, 0x00, 0x9f, 0x00, 0x9e,
0x00, 0x6b, 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x16, 0x00, 0x9d, 0x00, 0x9c, 0x00, 0x3d,
0x00, 0x3c, 0x00, 0x35, 0x00, 0x2f, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x13,
0x00, 0x11, 0x00, 0x00, 0x0e, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x73, 0x74, 0x6e, 0x65, 0x74,
0x2e, 0x63, 0x6e, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x00,
0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x12, 0x00, 0x10, 0x04, 0x01, 0x02, 0x01, 0x05,
0x01, 0x06, 0x01, 0x04, 0x03, 0x02, 0x03, 0x05, 0x03, 0x06, 0x03, 0x00, 0x05, 0x00, 0x05, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00,
2018-09-13 20:10:21 +08:00
};
int len = sizeof(buff);
enum chello_parse_result result;
struct ssl_chello* chello = ssl_chello_parse(buff, len, 1, &result);
2018-09-13 20:10:21 +08:00
printf("---------------------------tls1.2 --------------------------------\n");
printf("result is %d\n", result);
printf("min version: %d, %d, ossl format: %x\n", chello->min_version.major, chello->min_version.minor, chello->min_version.ossl_format);
printf("max version: %d, %d, ossl format: %x\n", chello->max_version.major, chello->max_version.minor, chello->max_version.ossl_format);
unsigned char cipher_suites[1024];
memcpy(cipher_suites, chello->cipher_suites, chello->cipher_suites_len);
printf("cipher suites: \n", chello->cipher_suites);
for(int i = 0; i < chello->cipher_suites_len; i++){
printf("0x%02x ", cipher_suites[i]);
}
printf("\n");
printf("sni: %s\n", chello->sni);
if(chello->alpn == NULL){
printf("no alpn\n");
}
else{
char* alpn = parse_alpn((char*)chello->alpn);
printf("alpn: %s\n", alpn);
free(alpn);
alpn = NULL;
}
unsigned char sign_algos[1024];
if(chello->sign_algos == NULL){
printf("no signature algorithms\n");
}
else{
memcpy(sign_algos, chello->sign_algos, chello->sign_algos_len);
printf("signature algorithms is: \n");
for(int i = 0; i < chello->sign_algos_len; i++){
printf("0x%02x ", sign_algos[i]);
}
}
printf("\n");
unsigned char supported_groups[1024];
if(chello->supported_groups == NULL){
printf("no supported groups\n");
}
else{
memcpy(supported_groups, chello->supported_groups, chello->supported_groups_len);
printf("supported groups is \n", supported_groups);
for(int i = 0; i < chello->supported_groups_len; i++){
printf("0x%02x ", supported_groups[i]);
}
}
printf("\n\n");
ssl_chello_free(chello);
chello = NULL;
}
int tls13_test(){
unsigned char buff[] =
{
0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03, 0x90, 0x44, 0x3f,
0xb1, 0x87, 0x73, 0x78, 0x0d, 0xa6, 0x41, 0x77, 0x4d, 0xee, 0xf4, 0xe0, 0x98, 0x2a, 0xbf, 0x8e,
0x61, 0x51, 0xe7, 0xde, 0xee, 0xc1, 0x4a, 0x24, 0x86, 0x93, 0x0c, 0xfd, 0x03, 0x20, 0xb8, 0xcb,
0x65, 0xb4, 0x5a, 0xd7, 0x70, 0x60, 0x60, 0x59, 0x97, 0xf8, 0x0b, 0x5f, 0xe4, 0x98, 0x0c, 0x05,
0xe2, 0xc1, 0x1c, 0xd5, 0x63, 0x05, 0x81, 0xcd, 0x6f, 0xfd, 0x1c, 0x35, 0x16, 0xde, 0x00, 0x22,
0x6a, 0x6a, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2b, 0xc0, 0x2f, 0xc0, 0x2c, 0xc0, 0x30,
0xcc, 0xa9, 0xcc, 0xa8, 0xc0, 0x13, 0xc0, 0x14, 0x00, 0x9c, 0x00, 0x9d, 0x00, 0x2f, 0x00, 0x35,
0x00, 0x0a, 0x01, 0x00, 0x01, 0x91, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x1f,
0x00, 0x00, 0x1c, 0x73, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x68, 0x6b, 0x67, 0x33,
0x2d, 0x32, 0x2e, 0x78, 0x78, 0x2e, 0x66, 0x62, 0x63, 0x64, 0x6e, 0x2e, 0x6e, 0x65, 0x74, 0x00,
0x17, 0x00, 0x00, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0xda, 0xda,
0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, 0x00, 0x00,
0x00, 0x10, 0x00, 0x0e, 0x00, 0x0c, 0x02, 0x68, 0x32, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31,
0x2e, 0x31, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x14, 0x00,
0x12, 0x04, 0x03, 0x08, 0x04, 0x04, 0x01, 0x05, 0x03, 0x08, 0x05, 0x05, 0x01, 0x08, 0x06, 0x06,
0x01, 0x02, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x33, 0x00, 0x2b, 0x00, 0x29, 0xda, 0xda, 0x00,
0x01, 0x00, 0x00, 0x1d, 0x00, 0x20, 0x9a, 0x7a, 0x5b, 0xbc, 0x80, 0x71, 0x71, 0xaa, 0x36, 0xf0,
0x74, 0x91, 0x5d, 0xaf, 0x8e, 0xda, 0xa3, 0x70, 0xbf, 0x14, 0xe4, 0xd4, 0x06, 0x2a, 0x54, 0x23,
0x5c, 0x91, 0xfb, 0x78, 0x04, 0x62, 0x00, 0x2d, 0x00, 0x02, 0x01, 0x01, 0x00, 0x2b, 0x00, 0x0b,
0x0a, 0x1a, 0x1a, 0x03, 0x04, 0x03, 0x03, 0x03, 0x02, 0x03, 0x01, 0x00, 0x1b, 0x00, 0x03, 0x02,
0x00, 0x02, 0x1a, 0x1a, 0x00, 0x01, 0x00, 0x00, 0x15, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00, 0x99, 0x00, 0x74,
0x00, 0x6e, 0xe7, 0xa7, 0x7b, 0x46, 0xa1, 0x9a, 0x34, 0xb9, 0x5a, 0xf6, 0x90, 0x80, 0x1d, 0xa5,
0xb6, 0x8a, 0x5f, 0x01, 0x1a, 0x23, 0x17, 0x80, 0xe3, 0x2a, 0x93, 0x29, 0x2f, 0x74, 0x71, 0x9c,
0x74, 0x99, 0x00, 0x00, 0x00, 0x00, 0x84, 0x89, 0xb4, 0x19, 0x04, 0xf8, 0xee, 0xb1, 0x0d, 0xc5,
0xf6, 0x91, 0x4d, 0x8e, 0x2e, 0x90, 0x87, 0xb3, 0x7b, 0xce, 0xc1, 0x9b, 0xa0, 0xe3, 0x7b, 0xf7,
0x02, 0x19, 0xf0, 0xf0, 0xcd, 0xd5, 0x37, 0x96, 0xce, 0x22, 0x10, 0xbf, 0xae, 0x2b, 0x6e, 0x94,
0xa9, 0x68, 0x38, 0xd1, 0x8b, 0x17, 0x83, 0x8c, 0x14, 0xec, 0xb5, 0xcd, 0x0d, 0x4b, 0x6b, 0x8f,
0xb8, 0xc0, 0xd3, 0xf8, 0x71, 0xe8, 0xd1, 0xbc, 0xfa, 0xdf, 0x88, 0x12, 0xe8, 0x95, 0xdf, 0x93,
0x31, 0x7f, 0x35, 0x17, 0x00, 0x21, 0x20, 0xa1, 0xcd, 0x5f, 0xd3, 0xe4, 0xd5, 0xd1, 0xfa, 0x65,
0x8e, 0xed, 0x02, 0xa2, 0xc8, 0xd2, 0x12, 0xf4, 0xfd, 0x96, 0x42, 0x2c, 0xe0, 0x02, 0x52, 0x7e,
0xce, 0x90, 0x80, 0xf0, 0xc6, 0xc6, 0x42
};
int len = sizeof(buff);
enum chello_parse_result result;
struct ssl_chello* chello = ssl_chello_parse(buff, len, 1, &result);
printf("---------------------------tls1.3 --------------------------------\n");
printf("min version: %d, %d, ossl format: %x\n", chello->min_version.major, chello->min_version.minor, chello->min_version.ossl_format);
printf("max version: %d, %d, ossl format: %x\n", chello->max_version.major, chello->max_version.minor, chello->max_version.ossl_format);
unsigned char cipher_suites[1024];
memcpy(cipher_suites, chello->cipher_suites, chello->cipher_suites_len);
printf("cipher suites: \n", chello->cipher_suites);
for(int i = 0; i < chello->cipher_suites_len; i++){
printf("0x%02x ", cipher_suites[i]);
}
printf("\n");
printf("sni: %s\n", chello->sni);
char* alpn = parse_alpn((char*)chello->alpn);
2018-09-13 20:10:21 +08:00
printf("alpn: %s\n", alpn);
free(alpn);
alpn = NULL;
unsigned char sign_algos[1024];
memcpy(sign_algos, chello->sign_algos, chello->sign_algos_len);
printf("signature algorithms is: \n");
for(int i = 0; i < chello->sign_algos_len; i++){
printf("0x%02x ", sign_algos[i]);
}
printf("\n");
unsigned char supported_groups[1024];
memcpy(supported_groups, chello->supported_groups, chello->supported_groups_len);
supported_groups[chello->supported_groups_len] = '\0';
printf("supported groups is \n", supported_groups);
for(int i = 0; i < chello->supported_groups_len; i++){
printf("0x%02x ", supported_groups[i]);
}
printf("\n");
ssl_chello_free(chello);
chello = NULL;
}
int main()
{
tls12_test();
tls13_test();
2018-09-13 20:10:21 +08:00
}