Skip to content

Commit 6676c44

Browse files
committed
Add test that ensures ssl3_ciphers[] is sorted by cipher id.
1 parent f3e6074 commit 6676c44

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

regress/lib/libssl/ciphers/cipherstest.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <stdio.h>
2121
#include <string.h>
2222

23+
int ssl3_num_ciphers(void);
24+
const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
25+
2326
int ssl_parse_ciphersuites(STACK_OF(SSL_CIPHER) **out_ciphers, const char *str);
2427

2528
static inline int
@@ -32,6 +35,38 @@ ssl_aes_is_accelerated(void)
3235
#endif
3336
}
3437

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+
3570
static int
3671
cipher_find_test(void)
3772
{
@@ -484,6 +519,8 @@ main(int argc, char **argv)
484519
{
485520
int failed = 0;
486521

522+
failed |= check_cipher_order();
523+
487524
failed |= cipher_find_test();
488525
failed |= cipher_get_by_value_tests();
489526

0 commit comments

Comments
 (0)