diff --git a/sslscan.c b/sslscan.c index 625d396..2075e55 100644 --- a/sslscan.c +++ b/sslscan.c @@ -4779,6 +4779,16 @@ void bs_append_bs(bs *dst, bs *src) { bs_append_bytes(dst, src->buf, src->len); } +/* Returns the number of bytes in this byte string. */ +size_t bs_reset(bs *b) { + if (b == NULL) + return 0; + + b->len = 0; + + return 0; +} + /* Returns the number of bytes in this byte string. */ size_t bs_get_len(bs *b) { if (b == NULL) @@ -5287,22 +5297,26 @@ bs *getTLSHandshakeRecord(int s) { bs *tls_record = NULL; bs_new_size(&tls_record, 512); - /* Read in the first 5 bytes to get the length of the rest of the record. */ - int err = bs_read_socket(tls_record, s, 5); - if (err != 0) - goto err; + while (1) { + /* Read in the first 5 bytes to get the length of the rest of the record. */ + int err = bs_read_socket(tls_record, s, 5); + if (err != 0) + goto err; - /* Ensure that the Content Type is Handshake (22). */ - if (bs_get_byte(tls_record, 0) != 0x16) - goto err; + /* Get the length of the record. */ + unsigned short packet_len = (bs_get_byte(tls_record, 3) << 8) | bs_get_byte(tls_record, 4); + + /* Read in the rest of the record. */ + err = bs_read_socket(tls_record, s, packet_len); + if (err != 0) + goto err; - /* Get the length of the record. */ - unsigned short packet_len = (bs_get_byte(tls_record, 3) << 8) | bs_get_byte(tls_record, 4); + /* Find that the Content Type is Handshake (22). */ + if (bs_get_byte(tls_record, 0) == 0x16) + break; - /* Read in the rest of the record. */ - err = bs_read_socket(tls_record, s, packet_len); - if (err != 0) - goto err; + bs_reset(tls_record); + } return tls_record;