Skip to content

If Handshake does not appear in the first, TLS cannot be recognized #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions sslscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down