diff --git a/platform/include/internal/ssl_utils.h b/platform/include/internal/ssl_utils.h index 4bd1377..6f4aea9 100644 --- a/platform/include/internal/ssl_utils.h +++ b/platform/include/internal/ssl_utils.h @@ -181,9 +181,9 @@ char * ssl_wildcardify(const char *); enum parse_chello_result { - PARSE_CHELLO_INVALID_FORMAT = 0, - PARSE_CHELLO_NOT_ENOUGH_BUFF, - PARSE_CHELLO_SUCCESS + PARSE_CHELLO_SUCCESS = 0, + PARSE_CHELLO_INVALID_FORMAT = -1, + PARSE_CHELLO_NOT_ENOUGH_BUFF = -2 }; struct ssl_version @@ -194,8 +194,8 @@ struct ssl_version struct ssl_chello { - struct ssl_version record_layer_version; - struct ssl_version chello_version; + struct ssl_version min_version; + struct ssl_version max_version; char* sni; char* alpn; char* cipher_suites; diff --git a/platform/src/ssl_utils.cc b/platform/src/ssl_utils.cc index 17bf877..b3a4358 100644 --- a/platform/src/ssl_utils.cc +++ b/platform/src/ssl_utils.cc @@ -1941,7 +1941,7 @@ struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len, if(buff[0] == 0x80) { struct ssl_chello* _chello = (struct ssl_chello*)ALLOC(struct ssl_chello, 1); - _chello->record_layer_version.major = 0x02; + _chello->min_version.major = 0x02; if(buff_len < 2) { *result = PARSE_CHELLO_NOT_ENOUGH_BUFF; @@ -1973,8 +1973,8 @@ struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len, *result = PARSE_CHELLO_INVALID_FORMAT; return _chello; } - _chello->chello_version.major = buff[pos]; - _chello->chello_version.minor = buff[pos + 1]; + _chello->max_version.major = buff[pos]; + _chello->max_version.minor = buff[pos + 1]; *result = PARSE_CHELLO_SUCCESS; return _chello; } @@ -1991,10 +1991,10 @@ struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len, return NULL; } struct ssl_chello* _chello = (struct ssl_chello*)ALLOC(struct ssl_chello, 1); - _chello->record_layer_version.major = buff[1]; - _chello->record_layer_version.minor = buff[2]; - _chello->chello_version.major = -1; - _chello->chello_version.minor = -1; + _chello->min_version.major = buff[1]; + _chello->min_version.minor = buff[2]; + _chello->max_version.major = -1; + _chello->max_version.minor = -1; _chello->sni = NULL; _chello->alpn = NULL; _chello->cipher_suites = NULL; @@ -2024,8 +2024,8 @@ struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len, *result = PARSE_CHELLO_INVALID_FORMAT; return _chello; } - _chello->chello_version.major = buff[pos]; - _chello->chello_version.minor = buff[pos+1]; + _chello->max_version.major = buff[pos]; + _chello->max_version.minor = buff[pos+1]; pos += 34; /* Session ID */ if (pos + 1 > buff_len) @@ -2070,7 +2070,7 @@ struct ssl_chello* ssl_chello_parse(const unsigned char* buff, size_t buff_len, len = (size_t)buff[pos]; pos += 1 + len; /* ssl 3.0, no extensions */ - if(_chello->record_layer_version.major == 3 && _chello->record_layer_version.minor == 0) + if(_chello->min_version.major == 3 && _chello->min_version.minor == 0) { if(pos == buff_len) { diff --git a/platform/test/test_chello_parse.cpp b/platform/test/test_chello_parse.cpp index ab793a6..cff41db 100644 --- a/platform/test/test_chello_parse.cpp +++ b/platform/test/test_chello_parse.cpp @@ -46,7 +46,8 @@ int main() 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("result is %d\n", result); + printf("min version is %d, %d\n", chello->min_version.major, chello->min_version.minor); printf("\n\n"); ssl_chello_free(chello); chello = NULL; @@ -68,8 +69,9 @@ int main() 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("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); printf("cipher suites is %s\n", chello1->cipher_suites); if(chello1->cipher_suites_tls13) { @@ -139,8 +141,9 @@ int main() 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("result is %d\n", result2); + printf("min version: %d, %d\n", chello2->min_version.major, chello2->min_version.minor); + printf("max version: %d, %d\n", chello2->max_version.major, chello2->max_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);