fix bugs
This commit is contained in:
154
platform/test/test_chello_parse.cpp
Normal file
154
platform/test/test_chello_parse.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
|
||||
#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 main()
|
||||
{
|
||||
|
||||
//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 parse_chello_result result;
|
||||
struct ssl_chello* chello = ssl_chello_parse(buff, buff_len, &result);
|
||||
printf("-----------------------------ssl2.0 only parse version --------------------------------\n");
|
||||
printf("record layer version is %d, %d\n", chello->record_layer_version.major, chello->record_layer_version.minor);
|
||||
printf("\n\n");
|
||||
ssl_chello_free(chello);
|
||||
chello = NULL;
|
||||
|
||||
//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 parse_chello_result result1;
|
||||
struct ssl_chello* chello1 = ssl_chello_parse(buff1, buff1_len, &result1);
|
||||
printf("--------------------------------ssl3.0, no extensions --------------------------------\n");
|
||||
printf("record layer version is %d, %d\n", chello1->record_layer_version.major, chello1->record_layer_version.minor);
|
||||
printf("client hello version: %d, %d\n", chello1->chello_version.major, chello1->chello_version.minor);
|
||||
printf("cipher suites is %s\n", chello1->cipher_suites);
|
||||
if(chello1->cipher_suites_tls13)
|
||||
{
|
||||
printf("cipher suites for tls1.3 is %s\n", chello1->cipher_suites_tls13);
|
||||
}
|
||||
printf("\n\n");
|
||||
ssl_chello_free(chello1);
|
||||
chello1 = NULL;
|
||||
|
||||
//tls1.2
|
||||
unsigned char buff2[] =
|
||||
{
|
||||
0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03,
|
||||
0x03, 0x30, 0x6d, 0x1d, 0xd5, 0x0d, 0xa6, 0x1e, 0x0b, 0xe6,
|
||||
0xf7, 0xf0, 0xd3, 0xfa, 0x14, 0xdc, 0x80, 0x24, 0xe5, 0x34,
|
||||
0x2d, 0x9c, 0x68, 0x6b, 0x0a, 0x40, 0x59, 0xc6, 0x2c, 0xbb,
|
||||
0xf1, 0x04, 0xee, 0x20, 0xc4, 0x33, 0x03, 0x91, 0xa9, 0x0d,
|
||||
0xfa, 0xae, 0x93, 0x9b, 0xbe, 0x22, 0x7c, 0x99, 0x5f, 0xaf,
|
||||
0xdc, 0xe1, 0x14, 0xab, 0xbc, 0x57, 0x1f, 0x7f, 0xe0, 0x5c,
|
||||
0x59, 0xe3, 0x8b, 0xaa, 0x70, 0xf8, 0x00, 0x22, 0x5a, 0x5a,
|
||||
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, 0xea, 0xea, 0x00, 0x00,
|
||||
0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00,
|
||||
0x10, 0x00, 0x00, 0x0d, 0x77, 0x77, 0x77, 0x2e, 0x62, 0x61,
|
||||
0x69, 0x64, 0x75, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x17, 0x00,
|
||||
0x00, 0x00, 0x23, 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,
|
||||
0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12,
|
||||
0x00, 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x0c, 0x02, 0x68,
|
||||
0x32, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31,
|
||||
0x75, 0x50, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00,
|
||||
0x00, 0x33, 0x00, 0x2b, 0x00, 0x29, 0xea, 0xea, 0x00, 0x01,
|
||||
0x00, 0x00, 0x1d, 0x00, 0x20, 0x1b, 0xae, 0xc9, 0x4f, 0x17,
|
||||
0x30, 0xf2, 0xec, 0x4c, 0xc1, 0xdb, 0xf7, 0xe4, 0x72, 0xad,
|
||||
0x22, 0xa8, 0xe9, 0x2c, 0x67, 0x4d, 0x8a, 0x87, 0x22, 0xd1,
|
||||
0x65, 0x2f, 0x08, 0xef, 0x01, 0xd9, 0x73, 0x00, 0x2d, 0x00,
|
||||
0x02, 0x01, 0x01, 0x00, 0x2b, 0x00, 0x0b, 0x0a, 0x1a, 0x1a,
|
||||
0x7f, 0x17, 0x03, 0x03, 0x03, 0x02, 0x03, 0x01, 0x00, 0x0a,
|
||||
0x00, 0x0a, 0x00, 0x08, 0xea, 0xea, 0x00, 0x1d, 0x00, 0x17,
|
||||
0x00, 0x18, 0x00, 0x1b, 0x00, 0x03, 0x02, 0x00, 0x02, 0xaa,
|
||||
0xaa, 0x00, 0x01, 0x00, 0x00, 0x15, 0x00, 0xc7, 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,
|
||||
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, 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, 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, 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, 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,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
size_t buff2_len = sizeof(buff2) / sizeof(char);
|
||||
enum parse_chello_result result2;
|
||||
struct ssl_chello* chello2 = ssl_chello_parse(buff2, buff2_len, &result2);
|
||||
printf("---------------------------tls1.2 --------------------------------\n");
|
||||
printf("record layer version: %d, %d\n", chello2->record_layer_version.major, chello2->record_layer_version.minor);
|
||||
printf("client hello version: %d, %d\n", chello2->chello_version.major, chello2->chello_version.minor);
|
||||
printf("cipher suites: %s\n", chello2->cipher_suites);
|
||||
printf("cipher suites for tls1.3: %s\n", chello2->cipher_suites_tls13);
|
||||
printf("sni: %s\n", chello2->sni);
|
||||
char* alpn = parse_alpn(chello2->alpn);
|
||||
printf("alpn: %s\n", alpn);
|
||||
free(alpn);
|
||||
alpn = NULL;
|
||||
printf("\n\n");
|
||||
ssl_chello_free(chello2);
|
||||
chello2 = NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user