diff options
| author | jsing <> | 2021-03-29 16:22:02 +0000 |
|---|---|---|
| committer | jsing <> | 2021-03-29 16:22:02 +0000 |
| commit | f431352ee52eb3d8093a86cdc439cd6faf807ca7 (patch) | |
| tree | 7360af42af38c05a40c710f9e2b6d3fcc0acbc17 | |
| parent | 84b53cb9086e02b898c2ed561177d37a66d2e659 (diff) | |
| download | openbsd-f431352ee52eb3d8093a86cdc439cd6faf807ca7.tar.gz openbsd-f431352ee52eb3d8093a86cdc439cd6faf807ca7.tar.bz2 openbsd-f431352ee52eb3d8093a86cdc439cd6faf807ca7.zip | |
Add regress coverage for TLSv1.2 record number increment.
| -rw-r--r-- | src/regress/lib/libssl/record_layer/record_layer_test.c | 159 |
1 files changed, 151 insertions, 8 deletions
diff --git a/src/regress/lib/libssl/record_layer/record_layer_test.c b/src/regress/lib/libssl/record_layer/record_layer_test.c index 8071c1dabd..4e75ba4a25 100644 --- a/src/regress/lib/libssl/record_layer/record_layer_test.c +++ b/src/regress/lib/libssl/record_layer/record_layer_test.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: record_layer_test.c,v 1.3 2020/03/16 15:13:15 tb Exp $ */ | 1 | /* $OpenBSD: record_layer_test.c,v 1.4 2021/03/29 16:22:02 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -18,9 +18,12 @@ | |||
| 18 | #include <err.h> | 18 | #include <err.h> |
| 19 | #include <string.h> | 19 | #include <string.h> |
| 20 | 20 | ||
| 21 | #include "ssl_locl.h" | ||
| 21 | #include "tls13_internal.h" | 22 | #include "tls13_internal.h" |
| 22 | #include "tls13_record.h" | 23 | #include "tls13_record.h" |
| 23 | 24 | ||
| 25 | int tls12_record_layer_inc_seq_num(struct tls12_record_layer *rl, | ||
| 26 | uint8_t *seq_num); | ||
| 24 | int tls13_record_layer_inc_seq_num(uint8_t *seq_num); | 27 | int tls13_record_layer_inc_seq_num(uint8_t *seq_num); |
| 25 | 28 | ||
| 26 | static void | 29 | static void |
| @@ -40,7 +43,83 @@ struct seq_num_test { | |||
| 40 | int want; | 43 | int want; |
| 41 | }; | 44 | }; |
| 42 | 45 | ||
| 43 | struct seq_num_test seq_num_tests[] = { | 46 | struct seq_num_test seq_num_dtls_tests[] = { |
| 47 | { | ||
| 48 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, | ||
| 49 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, | ||
| 50 | .want = 1, | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, | ||
| 54 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, | ||
| 55 | .want = 1, | ||
| 56 | }, | ||
| 57 | { | ||
| 58 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe}, | ||
| 59 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff}, | ||
| 60 | .want = 1, | ||
| 61 | }, | ||
| 62 | { | ||
| 63 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff}, | ||
| 64 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}, | ||
| 65 | .want = 1, | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}, | ||
| 69 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}, | ||
| 70 | .want = 1, | ||
| 71 | }, | ||
| 72 | { | ||
| 73 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff}, | ||
| 74 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00}, | ||
| 75 | .want = 1, | ||
| 76 | }, | ||
| 77 | { | ||
| 78 | .seq_num = {0xab, 0xcd, 0xef, 0x00, 0xfe, 0xff, 0xff, 0xff}, | ||
| 79 | .want_num = {0xab, 0xcd, 0xef, 0x00, 0xff, 0x00, 0x00, 0x00}, | ||
| 80 | .want = 1, | ||
| 81 | }, | ||
| 82 | { | ||
| 83 | .seq_num = {0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 84 | .want_num = {0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 85 | .want = 0, | ||
| 86 | }, | ||
| 87 | { | ||
| 88 | .seq_num = {0x01, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 89 | .want_num = {0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}, | ||
| 90 | .want = 1, | ||
| 91 | }, | ||
| 92 | { | ||
| 93 | .seq_num = {0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}, | ||
| 94 | .want_num = {0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 95 | .want = 1, | ||
| 96 | }, | ||
| 97 | { | ||
| 98 | .seq_num = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, | ||
| 99 | .want_num = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, | ||
| 100 | .want = 1, | ||
| 101 | }, | ||
| 102 | { | ||
| 103 | .seq_num = {0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 104 | .want_num = {0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 105 | .want = 0, | ||
| 106 | }, | ||
| 107 | { | ||
| 108 | .seq_num = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}, | ||
| 109 | .want_num = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 110 | .want = 1, | ||
| 111 | }, | ||
| 112 | { | ||
| 113 | .seq_num = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 114 | .want_num = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, | ||
| 115 | .want = 0, | ||
| 116 | }, | ||
| 117 | }; | ||
| 118 | |||
| 119 | #define N_SEQ_NUM_DTLS_TESTS \ | ||
| 120 | (sizeof(seq_num_dtls_tests) / sizeof(seq_num_dtls_tests[0])) | ||
| 121 | |||
| 122 | struct seq_num_test seq_num_tls_tests[] = { | ||
| 44 | { | 123 | { |
| 45 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, | 124 | .seq_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, |
| 46 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, | 125 | .want_num = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, |
| @@ -108,10 +187,71 @@ struct seq_num_test seq_num_tests[] = { | |||
| 108 | }, | 187 | }, |
| 109 | }; | 188 | }; |
| 110 | 189 | ||
| 111 | #define N_SEQ_NUM_TESTS (sizeof(seq_num_tests) / sizeof(seq_num_tests[0])) | 190 | #define N_SEQ_NUM_TLS_TESTS \ |
| 191 | (sizeof(seq_num_tls_tests) / sizeof(seq_num_tls_tests[0])) | ||
| 192 | |||
| 193 | #ifndef TLS12_RECORD_SEQ_NUM_LEN | ||
| 194 | #define TLS12_RECORD_SEQ_NUM_LEN 8 | ||
| 195 | #endif | ||
| 196 | |||
| 197 | static int | ||
| 198 | do_seq_num_test_tls12(size_t test_no, int dtls, struct seq_num_test *snt) | ||
| 199 | { | ||
| 200 | uint8_t seq_num[TLS12_RECORD_SEQ_NUM_LEN]; | ||
| 201 | struct tls12_record_layer *rl; | ||
| 202 | int failed = 1; | ||
| 203 | int ret; | ||
| 204 | |||
| 205 | if ((rl = tls12_record_layer_new()) == NULL) | ||
| 206 | errx(1, "tls12_record_layer_new"); | ||
| 207 | |||
| 208 | if (dtls) | ||
| 209 | tls12_record_layer_set_version(rl, DTLS1_2_VERSION); | ||
| 210 | |||
| 211 | memcpy(seq_num, snt->seq_num, sizeof(seq_num)); | ||
| 212 | |||
| 213 | if ((ret = tls12_record_layer_inc_seq_num(rl, seq_num)) != snt->want) { | ||
| 214 | fprintf(stderr, "FAIL: Test %zu - got return %i, want %i\n", | ||
| 215 | test_no, ret, snt->want); | ||
| 216 | goto failure; | ||
| 217 | } | ||
| 218 | |||
| 219 | if (memcmp(seq_num, snt->want_num, sizeof(seq_num)) != 0) { | ||
| 220 | fprintf(stderr, "FAIL: Test %zu - got sequence number:\n", | ||
| 221 | test_no); | ||
| 222 | hexdump(seq_num, sizeof(seq_num)); | ||
| 223 | fprintf(stderr, "want:\n"); | ||
| 224 | hexdump(snt->want_num, sizeof(snt->want_num)); | ||
| 225 | goto failure; | ||
| 226 | } | ||
| 227 | |||
| 228 | failed = 0; | ||
| 229 | |||
| 230 | failure: | ||
| 231 | tls12_record_layer_free(rl); | ||
| 232 | |||
| 233 | return failed; | ||
| 234 | } | ||
| 112 | 235 | ||
| 113 | static int | 236 | static int |
| 114 | do_seq_num_test(size_t test_no, struct seq_num_test *snt) | 237 | test_seq_num_tls12(void) |
| 238 | { | ||
| 239 | int failed = 0; | ||
| 240 | size_t i; | ||
| 241 | |||
| 242 | fprintf(stderr, "Running TLSv1.2 sequence number tests...\n"); | ||
| 243 | for (i = 0; i < N_SEQ_NUM_TLS_TESTS; i++) | ||
| 244 | failed |= do_seq_num_test_tls12(i, 0, &seq_num_tls_tests[i]); | ||
| 245 | |||
| 246 | fprintf(stderr, "Running DTLSv1.2 sequence number tests...\n"); | ||
| 247 | for (i = 0; i < N_SEQ_NUM_DTLS_TESTS; i++) | ||
| 248 | failed |= do_seq_num_test_tls12(i, 1, &seq_num_dtls_tests[i]); | ||
| 249 | |||
| 250 | return failed; | ||
| 251 | } | ||
| 252 | |||
| 253 | static int | ||
| 254 | do_seq_num_test_tls13(size_t test_no, struct seq_num_test *snt) | ||
| 115 | { | 255 | { |
| 116 | uint8_t seq_num[TLS13_RECORD_SEQ_NUM_LEN]; | 256 | uint8_t seq_num[TLS13_RECORD_SEQ_NUM_LEN]; |
| 117 | int failed = 1; | 257 | int failed = 1; |
| @@ -141,13 +281,15 @@ do_seq_num_test(size_t test_no, struct seq_num_test *snt) | |||
| 141 | } | 281 | } |
| 142 | 282 | ||
| 143 | static int | 283 | static int |
| 144 | test_seq_num(void) | 284 | test_seq_num_tls13(void) |
| 145 | { | 285 | { |
| 146 | int failed = 0; | 286 | int failed = 0; |
| 147 | size_t i; | 287 | size_t i; |
| 148 | 288 | ||
| 149 | for (i = 0; i < N_SEQ_NUM_TESTS; i++) | 289 | fprintf(stderr, "Running TLSv1.3 sequence number tests...\n"); |
| 150 | failed |= do_seq_num_test(i, &seq_num_tests[i]); | 290 | |
| 291 | for (i = 0; i < N_SEQ_NUM_TLS_TESTS; i++) | ||
| 292 | failed |= do_seq_num_test_tls13(i, &seq_num_tls_tests[i]); | ||
| 151 | 293 | ||
| 152 | return failed; | 294 | return failed; |
| 153 | } | 295 | } |
| @@ -157,7 +299,8 @@ main(int argc, char **argv) | |||
| 157 | { | 299 | { |
| 158 | int failed = 0; | 300 | int failed = 0; |
| 159 | 301 | ||
| 160 | failed |= test_seq_num(); | 302 | failed |= test_seq_num_tls12(); |
| 303 | failed |= test_seq_num_tls13(); | ||
| 161 | 304 | ||
| 162 | return failed; | 305 | return failed; |
| 163 | } | 306 | } |
