diff options
author | jsing <> | 2022-12-17 16:05:28 +0000 |
---|---|---|
committer | jsing <> | 2022-12-17 16:05:28 +0000 |
commit | df2ca82e06a75275e3bc983f48d1bb6f80cefdc5 (patch) | |
tree | 19550fcf03fe94e5d0b150aa340f575dd308b9bc | |
parent | a9f292ba0c26c0212f3cee4f53591dbdec7ee05c (diff) | |
download | openbsd-df2ca82e06a75275e3bc983f48d1bb6f80cefdc5.tar.gz openbsd-df2ca82e06a75275e3bc983f48d1bb6f80cefdc5.tar.bz2 openbsd-df2ca82e06a75275e3bc983f48d1bb6f80cefdc5.zip |
Revise cipher list regress coverage of SSL_set_security_level().
A SSL_set_security_level() call was added to the cipher list regress, which
expects a failure - however, it should succeed and fails for a completely
unrelated reason. Rework this regress so that it actually passes and tests
for the expected behaviour.
-rw-r--r-- | src/regress/lib/libssl/unit/cipher_list.c | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/src/regress/lib/libssl/unit/cipher_list.c b/src/regress/lib/libssl/unit/cipher_list.c index a63c5ae69f..c715f60e0b 100644 --- a/src/regress/lib/libssl/unit/cipher_list.c +++ b/src/regress/lib/libssl/unit/cipher_list.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cipher_list.c,v 1.13 2022/11/26 16:08:57 tb Exp $ */ | 1 | /* $OpenBSD: cipher_list.c,v 1.14 2022/12/17 16:05:28 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2015 Doug Hogan <doug@openbsd.org> | 3 | * Copyright (c) 2015 Doug Hogan <doug@openbsd.org> |
4 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> |
@@ -51,6 +51,12 @@ static uint8_t cipher_bytes[] = { | |||
51 | 0x00, 0x3d, /* AES256-SHA256 */ | 51 | 0x00, 0x3d, /* AES256-SHA256 */ |
52 | }; | 52 | }; |
53 | 53 | ||
54 | static uint8_t cipher_bytes_seclevel3[] = { | ||
55 | 0xcc, 0xa8, /* ECDHE-ECDSA-CHACHA20-POLY1305 */ | ||
56 | 0xcc, 0xa9, /* ECDHE-RSA-CHACHA20-POLY1305 */ | ||
57 | 0xcc, 0xaa, /* DHE-RSA-CHACHA20-POLY1305 */ | ||
58 | }; | ||
59 | |||
54 | static uint16_t cipher_values[] = { | 60 | static uint16_t cipher_values[] = { |
55 | 0xcca8, /* ECDHE-ECDSA-CHACHA20-POLY1305 */ | 61 | 0xcca8, /* ECDHE-ECDSA-CHACHA20-POLY1305 */ |
56 | 0xcca9, /* ECDHE-RSA-CHACHA20-POLY1305 */ | 62 | 0xcca9, /* ECDHE-RSA-CHACHA20-POLY1305 */ |
@@ -85,7 +91,8 @@ ssl_bytes_to_list_alloc(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | |||
85 | } | 91 | } |
86 | 92 | ||
87 | static int | 93 | static int |
88 | ssl_list_to_bytes_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | 94 | ssl_list_to_bytes_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers, |
95 | const uint8_t *cb, size_t cb_len) | ||
89 | { | 96 | { |
90 | CBB cbb; | 97 | CBB cbb; |
91 | unsigned char *buf = NULL; | 98 | unsigned char *buf = NULL; |
@@ -94,27 +101,31 @@ ssl_list_to_bytes_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | |||
94 | 101 | ||
95 | /* Space for cipher bytes, plus reneg SCSV and two spare bytes. */ | 102 | /* Space for cipher bytes, plus reneg SCSV and two spare bytes. */ |
96 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | 103 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); |
97 | buflen = sizeof(cipher_bytes) + 2 + 2; | 104 | buflen = cb_len + 2 + 2; |
98 | CHECK((buf = calloc(1, buflen)) != NULL); | 105 | CHECK((buf = calloc(1, buflen)) != NULL); |
99 | 106 | ||
100 | CHECK(CBB_init_fixed(&cbb, buf, buflen)); | 107 | /* Clear renegotiate so it adds SCSV */ |
101 | CHECK(ssl_cipher_list_to_bytes(s, *ciphers, &cbb)); | 108 | s->renegotiate = 0; |
102 | CHECK(CBB_finish(&cbb, NULL, &outlen)); | 109 | |
110 | CHECK_GOTO(CBB_init_fixed(&cbb, buf, buflen)); | ||
111 | CHECK_GOTO(ssl_cipher_list_to_bytes(s, *ciphers, &cbb)); | ||
112 | CHECK_GOTO(CBB_finish(&cbb, NULL, &outlen)); | ||
103 | 113 | ||
104 | CHECK_GOTO(outlen > 0 && outlen == buflen - 2); | 114 | CHECK_GOTO(outlen > 0 && outlen == cb_len + 2); |
105 | CHECK_GOTO(memcmp(buf, cipher_bytes, sizeof(cipher_bytes)) == 0); | 115 | CHECK_GOTO(memcmp(buf, cb, cb_len) == 0); |
106 | CHECK_GOTO(buf[buflen - 4] == 0x00 && buf[buflen - 3] == 0xff); | 116 | CHECK_GOTO(buf[buflen - 4] == 0x00 && buf[buflen - 3] == 0xff); |
107 | CHECK_GOTO(buf[buflen - 2] == 0x00 && buf[buflen - 1] == 0x00); | 117 | CHECK_GOTO(buf[buflen - 2] == 0x00 && buf[buflen - 1] == 0x00); |
108 | 118 | ||
109 | ret = 1; | 119 | ret = 1; |
110 | 120 | ||
111 | err: | 121 | err: |
112 | free(buf); | 122 | free(buf); |
113 | return ret; | 123 | return ret; |
114 | } | 124 | } |
115 | 125 | ||
116 | static int | 126 | static int |
117 | ssl_list_to_bytes_no_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | 127 | ssl_list_to_bytes_no_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers, |
128 | const uint8_t *cb, size_t cb_len) | ||
118 | { | 129 | { |
119 | CBB cbb; | 130 | CBB cbb; |
120 | unsigned char *buf = NULL; | 131 | unsigned char *buf = NULL; |
@@ -123,7 +134,7 @@ ssl_list_to_bytes_no_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | |||
123 | 134 | ||
124 | /* Space for cipher bytes and two spare bytes */ | 135 | /* Space for cipher bytes and two spare bytes */ |
125 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | 136 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); |
126 | buflen = sizeof(cipher_bytes) + 2; | 137 | buflen = cb_len + 2; |
127 | CHECK((buf = calloc(1, buflen)) != NULL); | 138 | CHECK((buf = calloc(1, buflen)) != NULL); |
128 | buf[buflen - 2] = 0xfe; | 139 | buf[buflen - 2] = 0xfe; |
129 | buf[buflen - 1] = 0xab; | 140 | buf[buflen - 1] = 0xab; |
@@ -131,17 +142,17 @@ ssl_list_to_bytes_no_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | |||
131 | /* Set renegotiate so it doesn't add SCSV */ | 142 | /* Set renegotiate so it doesn't add SCSV */ |
132 | s->renegotiate = 1; | 143 | s->renegotiate = 1; |
133 | 144 | ||
134 | CHECK(CBB_init_fixed(&cbb, buf, buflen)); | 145 | CHECK_GOTO(CBB_init_fixed(&cbb, buf, buflen)); |
135 | CHECK(ssl_cipher_list_to_bytes(s, *ciphers, &cbb)); | 146 | CHECK_GOTO(ssl_cipher_list_to_bytes(s, *ciphers, &cbb)); |
136 | CHECK(CBB_finish(&cbb, NULL, &outlen)); | 147 | CHECK_GOTO(CBB_finish(&cbb, NULL, &outlen)); |
137 | 148 | ||
138 | CHECK_GOTO(outlen > 0 && outlen == buflen - 2); | 149 | CHECK_GOTO(outlen > 0 && outlen == cb_len); |
139 | CHECK_GOTO(memcmp(buf, cipher_bytes, sizeof(cipher_bytes)) == 0); | 150 | CHECK_GOTO(memcmp(buf, cb, cb_len) == 0); |
140 | CHECK_GOTO(buf[buflen - 2] == 0xfe && buf[buflen - 1] == 0xab); | 151 | CHECK_GOTO(buf[buflen - 2] == 0xfe && buf[buflen - 1] == 0xab); |
141 | 152 | ||
142 | ret = 1; | 153 | ret = 1; |
143 | 154 | ||
144 | err: | 155 | err: |
145 | free(buf); | 156 | free(buf); |
146 | return ret; | 157 | return ret; |
147 | } | 158 | } |
@@ -184,20 +195,31 @@ main(void) | |||
184 | 195 | ||
185 | if (!ssl_bytes_to_list_alloc(s, &ciphers)) | 196 | if (!ssl_bytes_to_list_alloc(s, &ciphers)) |
186 | goto err; | 197 | goto err; |
187 | if (!ssl_list_to_bytes_scsv(s, &ciphers)) | 198 | if (!ssl_list_to_bytes_scsv(s, &ciphers, cipher_bytes, |
199 | sizeof(cipher_bytes))) | ||
188 | goto err; | 200 | goto err; |
189 | if (!ssl_list_to_bytes_no_scsv(s, &ciphers)) | 201 | if (!ssl_list_to_bytes_no_scsv(s, &ciphers, cipher_bytes, |
202 | sizeof(cipher_bytes))) | ||
190 | goto err; | 203 | goto err; |
191 | if (!ssl_bytes_to_list_invalid(s, &ciphers)) | 204 | if (!ssl_bytes_to_list_invalid(s, &ciphers)) |
192 | goto err; | 205 | goto err; |
193 | 206 | ||
207 | sk_SSL_CIPHER_free(ciphers); | ||
208 | ciphers = NULL; | ||
209 | |||
194 | SSL_set_security_level(s, 3); | 210 | SSL_set_security_level(s, 3); |
195 | if (ssl_list_to_bytes_scsv(s, &ciphers)) | 211 | if (!ssl_bytes_to_list_alloc(s, &ciphers)) |
212 | goto err; | ||
213 | if (!ssl_list_to_bytes_scsv(s, &ciphers, cipher_bytes_seclevel3, | ||
214 | sizeof(cipher_bytes_seclevel3))) | ||
215 | goto err; | ||
216 | if (!ssl_list_to_bytes_no_scsv(s, &ciphers, cipher_bytes_seclevel3, | ||
217 | sizeof(cipher_bytes_seclevel3))) | ||
196 | goto err; | 218 | goto err; |
197 | 219 | ||
198 | rv = 0; | 220 | rv = 0; |
199 | 221 | ||
200 | err: | 222 | err: |
201 | sk_SSL_CIPHER_free(ciphers); | 223 | sk_SSL_CIPHER_free(ciphers); |
202 | SSL_CTX_free(ctx); | 224 | SSL_CTX_free(ctx); |
203 | SSL_free(s); | 225 | SSL_free(s); |