diff options
author | Emilia Kasper <emilia@openssl.org> | 2015-08-18 12:29:36 +0200 |
---|---|---|
committer | Emilia Kasper <emilia@openssl.org> | 2015-08-26 13:25:48 +0200 |
commit | ec30e8566e43d888ab1d7cf01749a979896bb3d9 (patch) | |
tree | e52f8eb666128af5d2269f3a4b03412b410e4094 /test/packettest.c | |
parent | 9cc3e8f1f2b9e9c36a2f61e914bc9711c35568b6 (diff) | |
download | openssl-ec30e8566e43d888ab1d7cf01749a979896bb3d9.tar.gz |
PACKET: add methods for reading length-prefixed TLS vectors.
Rewrite ssl3_get_client_hello to use the new methods.
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'test/packettest.c')
-rw-r--r-- | test/packettest.c | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/test/packettest.c b/test/packettest.c index c3ac53bcb0..b3f7bbb19e 100644 --- a/test/packettest.c +++ b/test/packettest.c @@ -281,6 +281,85 @@ static int test_PACKET_buf_init() return 1; } +static int test_PACKET_get_length_prefixed_1() +{ + unsigned char buf[BUF_LEN]; + const size_t len = 16; + unsigned int i; + PACKET pkt, short_pkt, subpkt; + + buf[0] = len; + for (i = 1; i < BUF_LEN; i++) { + buf[i] = (i * 2) & 0xff; + } + + if ( !PACKET_buf_init(&pkt, buf, BUF_LEN) + || !PACKET_buf_init(&short_pkt, buf, len) + || !PACKET_get_length_prefixed_1(&pkt, &subpkt) + || PACKET_remaining(&subpkt) != len + || !PACKET_get_net_2(&subpkt, &i) + || i != 0x0204 + || PACKET_get_length_prefixed_1(&short_pkt, &subpkt) + || PACKET_remaining(&short_pkt) != len) { + fprintf(stderr, "test_PACKET_get_length_prefixed_1() failed\n"); + return 0; + } + + return 1; +} + +static int test_PACKET_get_length_prefixed_2() +{ + unsigned char buf[1024]; + const size_t len = 516; /* 0x0204 */ + unsigned int i; + PACKET pkt, short_pkt, subpkt; + + for (i = 1; i <= 1024; i++) { + buf[i-1] = (i * 2) & 0xff; + } + + if ( !PACKET_buf_init(&pkt, buf, 1024) + || !PACKET_buf_init(&short_pkt, buf, len) + || !PACKET_get_length_prefixed_2(&pkt, &subpkt) + || PACKET_remaining(&subpkt) != len + || !PACKET_get_net_2(&subpkt, &i) + || i != 0x0608 + || PACKET_get_length_prefixed_2(&short_pkt, &subpkt) + || PACKET_remaining(&short_pkt) != len) { + fprintf(stderr, "test_PACKET_get_length_prefixed_2() failed\n"); + return 0; + } + + return 1; +} + +static int test_PACKET_get_length_prefixed_3() +{ + unsigned char buf[1024]; + const size_t len = 516; /* 0x000204 */ + unsigned int i; + PACKET pkt, short_pkt, subpkt; + + for (i = 0; i < 1024; i++) { + buf[i] = (i * 2) & 0xff; + } + + if ( !PACKET_buf_init(&pkt, buf, 1024) + || !PACKET_buf_init(&short_pkt, buf, len) + || !PACKET_get_length_prefixed_3(&pkt, &subpkt) + || PACKET_remaining(&subpkt) != len + || !PACKET_get_net_2(&subpkt, &i) + || i != 0x0608 + || PACKET_get_length_prefixed_3(&short_pkt, &subpkt) + || PACKET_remaining(&short_pkt) != len) { + fprintf(stderr, "test_PACKET_get_length_prefixed_3() failed\n"); + return 0; + } + + return 1; +} + int main(int argc, char **argv) { unsigned char buf[BUF_LEN]; @@ -309,7 +388,10 @@ int main(int argc, char **argv) || !test_PACKET_get_sub_packet(&pkt, start) || !test_PACKET_get_bytes(&pkt, start) || !test_PACKET_copy_bytes(&pkt, start) - || !test_PACKET_move_funcs(&pkt, start)) { + || !test_PACKET_move_funcs(&pkt, start) + || !test_PACKET_get_length_prefixed_1() + || !test_PACKET_get_length_prefixed_2() + || !test_PACKET_get_length_prefixed_3()) { return 1; } printf("PASS\n"); |