diff options
author | jsing <> | 2020-03-13 16:04:31 +0000 |
---|---|---|
committer | jsing <> | 2020-03-13 16:04:31 +0000 |
commit | e4aa84e84fe680f7d36c8937f3d398c2e44b9d6e (patch) | |
tree | 034ea0d7da6e8552b90a2128c8036e868a075179 | |
parent | 45c61f88aabb42b7213e428bcb556df63b9b6db8 (diff) | |
download | openbsd-e4aa84e84fe680f7d36c8937f3d398c2e44b9d6e.tar.gz openbsd-e4aa84e84fe680f7d36c8937f3d398c2e44b9d6e.tar.bz2 openbsd-e4aa84e84fe680f7d36c8937f3d398c2e44b9d6e.zip |
Add regress for TLSv1.3 sequence number handling.
-rw-r--r-- | src/regress/lib/libssl/Makefile | 3 | ||||
-rw-r--r-- | src/regress/lib/libssl/record_layer/Makefile | 10 | ||||
-rw-r--r-- | src/regress/lib/libssl/record_layer/record_layer_test.c | 123 |
3 files changed, 135 insertions, 1 deletions
diff --git a/src/regress/lib/libssl/Makefile b/src/regress/lib/libssl/Makefile index 8dc92d433a..678016e050 100644 --- a/src/regress/lib/libssl/Makefile +++ b/src/regress/lib/libssl/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.36 2020/01/25 05:24:49 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.37 2020/03/13 16:04:31 jsing Exp $ |
2 | 2 | ||
3 | SUBDIR += asn1 | 3 | SUBDIR += asn1 |
4 | SUBDIR += buffer | 4 | SUBDIR += buffer |
@@ -8,6 +8,7 @@ SUBDIR += ciphers | |||
8 | SUBDIR += handshake | 8 | SUBDIR += handshake |
9 | SUBDIR += pqueue | 9 | SUBDIR += pqueue |
10 | SUBDIR += record | 10 | SUBDIR += record |
11 | SUBDIR += record_layer | ||
11 | SUBDIR += server | 12 | SUBDIR += server |
12 | SUBDIR += ssl | 13 | SUBDIR += ssl |
13 | SUBDIR += tlsext | 14 | SUBDIR += tlsext |
diff --git a/src/regress/lib/libssl/record_layer/Makefile b/src/regress/lib/libssl/record_layer/Makefile new file mode 100644 index 0000000000..66c48dd769 --- /dev/null +++ b/src/regress/lib/libssl/record_layer/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2020/03/13 16:04:31 jsing Exp $ | ||
2 | |||
3 | PROG= record_layer_test | ||
4 | LDADD= ${SSL_INT} -lcrypto | ||
5 | DPADD= ${LIBSSL} ${LIBCRYPTO} | ||
6 | WARNINGS= Yes | ||
7 | CFLAGS+= -DLIBRESSL_INTERNAL -Wall -Wundef -Werror | ||
8 | CFLAGS+= -I${.CURDIR}/../../../../lib/libssl | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/record_layer/record_layer_test.c b/src/regress/lib/libssl/record_layer/record_layer_test.c new file mode 100644 index 0000000000..d59147112c --- /dev/null +++ b/src/regress/lib/libssl/record_layer/record_layer_test.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* $OpenBSD: record_layer_test.c,v 1.1 2020/03/13 16:04:31 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <err.h> | ||
19 | #include <string.h> | ||
20 | |||
21 | #include "tls13_internal.h" | ||
22 | #include "tls13_record.h" | ||
23 | |||
24 | int tls13_record_layer_inc_seq_num(uint8_t *seq_num); | ||
25 | |||
26 | static void | ||
27 | hexdump(const unsigned char *buf, size_t len) | ||
28 | { | ||
29 | size_t i; | ||
30 | |||
31 | for (i = 1; i <= len; i++) | ||
32 | fprintf(stderr, " 0x%02x,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
33 | if (len % 8 != 0) | ||
34 | fprintf(stderr, "\n"); | ||
35 | } | ||
36 | |||
37 | struct seq_num_test { | ||
38 | uint8_t seq_num[TLS13_RECORD_SEQ_NUM_LEN]; | ||
39 | uint8_t want_num[TLS13_RECORD_SEQ_NUM_LEN]; | ||
40 | int want; | ||
41 | }; | ||
42 | |||
43 | struct seq_num_test seq_num_tests[] = { | ||
44 | { | ||
45 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, | ||
46 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, | ||
47 | .want = 1, | ||
48 | }, | ||
49 | { | ||
50 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, | ||
51 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, | ||
52 | .want = 1, | ||
53 | }, | ||
54 | { | ||
55 | .seq_num = {0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
56 | .want_num = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, | ||
57 | .want = 1, | ||
58 | }, | ||
59 | { | ||
60 | .seq_num = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}, | ||
61 | .want_num = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
62 | .want = 1, | ||
63 | }, | ||
64 | { | ||
65 | .seq_num = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
66 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, | ||
67 | .want = 0, | ||
68 | }, | ||
69 | }; | ||
70 | |||
71 | #define N_SEQ_NUM_TESTS (sizeof(seq_num_tests) / sizeof(seq_num_tests[0])) | ||
72 | |||
73 | static int | ||
74 | do_seq_num_test(size_t test_no, struct seq_num_test *snt) | ||
75 | { | ||
76 | uint8_t seq_num[TLS13_RECORD_SEQ_NUM_LEN]; | ||
77 | int failed = 1; | ||
78 | int ret; | ||
79 | |||
80 | memcpy(seq_num, snt->seq_num, sizeof(seq_num)); | ||
81 | |||
82 | if ((ret = tls13_record_layer_inc_seq_num(seq_num)) != snt->want) { | ||
83 | fprintf(stderr, "FAIL: Test %zu - got return %i, want %i\n", | ||
84 | test_no, ret, snt->want); | ||
85 | goto failure; | ||
86 | } | ||
87 | |||
88 | if (memcmp(seq_num, snt->want_num, sizeof(seq_num)) != 0) { | ||
89 | fprintf(stderr, "FAIL: Test %zu - got sequence number:\n", | ||
90 | test_no); | ||
91 | hexdump(seq_num, sizeof(seq_num)); | ||
92 | fprintf(stderr, "want:\n"); | ||
93 | hexdump(snt->want_num, sizeof(snt->want_num)); | ||
94 | goto failure; | ||
95 | } | ||
96 | |||
97 | failed = 0; | ||
98 | |||
99 | failure: | ||
100 | return failed; | ||
101 | } | ||
102 | |||
103 | static int | ||
104 | test_seq_num(void) | ||
105 | { | ||
106 | int failed = 0; | ||
107 | size_t i; | ||
108 | |||
109 | for (i = 0; i < N_SEQ_NUM_TESTS; i++) | ||
110 | failed |= do_seq_num_test(i, &seq_num_tests[i]); | ||
111 | |||
112 | return failed; | ||
113 | } | ||
114 | |||
115 | int | ||
116 | main(int argc, char **argv) | ||
117 | { | ||
118 | int failed = 0; | ||
119 | |||
120 | failed |= test_seq_num(); | ||
121 | |||
122 | return failed; | ||
123 | } | ||