diff options
author | jsing <> | 2021-07-03 15:54:41 +0000 |
---|---|---|
committer | jsing <> | 2021-07-03 15:54:41 +0000 |
commit | b109ab19721cd800c089654efad1a02b3692e495 (patch) | |
tree | f188dc59333894a8e8ff6448f1b27d75c3b848bb /src | |
parent | 01d3cb38351c42cd85db30d9fef1682001d52f88 (diff) | |
download | openbsd-b109ab19721cd800c089654efad1a02b3692e495.tar.gz openbsd-b109ab19721cd800c089654efad1a02b3692e495.tar.bz2 openbsd-b109ab19721cd800c089654efad1a02b3692e495.zip |
Add test that ensures ssl3_ciphers[] is sorted by cipher id.
Diffstat (limited to '')
-rw-r--r-- | src/regress/lib/libssl/ciphers/cipherstest.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/regress/lib/libssl/ciphers/cipherstest.c b/src/regress/lib/libssl/ciphers/cipherstest.c index f3bd841130..c43939d4d5 100644 --- a/src/regress/lib/libssl/ciphers/cipherstest.c +++ b/src/regress/lib/libssl/ciphers/cipherstest.c | |||
@@ -20,6 +20,9 @@ | |||
20 | #include <stdio.h> | 20 | #include <stdio.h> |
21 | #include <string.h> | 21 | #include <string.h> |
22 | 22 | ||
23 | int ssl3_num_ciphers(void); | ||
24 | const SSL_CIPHER *ssl3_get_cipher(unsigned int u); | ||
25 | |||
23 | int ssl_parse_ciphersuites(STACK_OF(SSL_CIPHER) **out_ciphers, const char *str); | 26 | int ssl_parse_ciphersuites(STACK_OF(SSL_CIPHER) **out_ciphers, const char *str); |
24 | 27 | ||
25 | static inline int | 28 | static inline int |
@@ -33,6 +36,38 @@ ssl_aes_is_accelerated(void) | |||
33 | } | 36 | } |
34 | 37 | ||
35 | static int | 38 | static int |
39 | check_cipher_order(void) | ||
40 | { | ||
41 | unsigned long id, prev_id = 0; | ||
42 | const SSL_CIPHER *cipher; | ||
43 | int num_ciphers; | ||
44 | int i; | ||
45 | |||
46 | num_ciphers = ssl3_num_ciphers(); | ||
47 | |||
48 | for (i = 1; i <= num_ciphers; i++) { | ||
49 | /* | ||
50 | * For some reason, ssl3_get_cipher() returns ciphers in | ||
51 | * reverse order. | ||
52 | */ | ||
53 | if ((cipher = ssl3_get_cipher(num_ciphers - i)) == NULL) { | ||
54 | fprintf(stderr, "FAIL: ssl3_get_cipher(%d) returned " | ||
55 | "NULL\n", i); | ||
56 | return 1; | ||
57 | } | ||
58 | if ((id = SSL_CIPHER_get_id(cipher)) <= prev_id) { | ||
59 | fprintf(stderr, "FAIL: ssl3_ciphers is not sorted by " | ||
60 | "id - cipher %d (%lx) <= cipher %d (%lx)\n", | ||
61 | i, id, i - 1, prev_id); | ||
62 | return 1; | ||
63 | } | ||
64 | prev_id = id; | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static int | ||
36 | cipher_find_test(void) | 71 | cipher_find_test(void) |
37 | { | 72 | { |
38 | STACK_OF(SSL_CIPHER) *ciphers; | 73 | STACK_OF(SSL_CIPHER) *ciphers; |
@@ -484,6 +519,8 @@ main(int argc, char **argv) | |||
484 | { | 519 | { |
485 | int failed = 0; | 520 | int failed = 0; |
486 | 521 | ||
522 | failed |= check_cipher_order(); | ||
523 | |||
487 | failed |= cipher_find_test(); | 524 | failed |= cipher_find_test(); |
488 | failed |= cipher_get_by_value_tests(); | 525 | failed |= cipher_get_by_value_tests(); |
489 | 526 | ||