diff options
Diffstat (limited to 'src/regress/lib/libssl/unit')
-rw-r--r-- | src/regress/lib/libssl/unit/Makefile | 21 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/cipher_list.c | 231 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/ssl_get_shared_ciphers.c | 478 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/ssl_methods.c | 267 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/ssl_set_alpn_protos.c | 470 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/ssl_verify_param.c | 99 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/ssl_versions.c | 922 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/tests.h | 44 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/tls_ext_alpn.c | 442 | ||||
-rw-r--r-- | src/regress/lib/libssl/unit/tls_prf.c | 182 |
10 files changed, 0 insertions, 3156 deletions
diff --git a/src/regress/lib/libssl/unit/Makefile b/src/regress/lib/libssl/unit/Makefile deleted file mode 100644 index 6a925069ca..0000000000 --- a/src/regress/lib/libssl/unit/Makefile +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.16 2023/05/24 09:15:14 tb Exp $ | ||
2 | |||
3 | PROGS += cipher_list | ||
4 | PROGS += ssl_get_shared_ciphers | ||
5 | PROGS += ssl_methods | ||
6 | PROGS += ssl_set_alpn_protos | ||
7 | PROGS += ssl_verify_param | ||
8 | PROGS += ssl_versions | ||
9 | PROGS += tls_ext_alpn | ||
10 | PROGS += tls_prf | ||
11 | |||
12 | WARNINGS= Yes | ||
13 | LDADD = ${SSL_INT} -lcrypto | ||
14 | DPADD = ${LIBSSL} ${LIBCRYPTO} | ||
15 | CFLAGS+= -DLIBRESSL_INTERNAL -Wall -Wundef -Werror | ||
16 | CFLAGS+= -DCERTSDIR=\"${.CURDIR}/../certs\" | ||
17 | CFLAGS+= -I${.CURDIR}/../../../../lib/libssl | ||
18 | |||
19 | LDADD_ssl_verify_param = ${LIBSSL} ${CRYPTO_INT} | ||
20 | |||
21 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/unit/cipher_list.c b/src/regress/lib/libssl/unit/cipher_list.c deleted file mode 100644 index c715f60e0b..0000000000 --- a/src/regress/lib/libssl/unit/cipher_list.c +++ /dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | /* $OpenBSD: cipher_list.c,v 1.14 2022/12/17 16:05:28 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2015 Doug Hogan <doug@openbsd.org> | ||
4 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* | ||
20 | * Test TLS ssl bytes (aka cipher suites) to cipher list and back. | ||
21 | * | ||
22 | * TLSv1.0 - RFC 2246 section 7.4.1.2 (ClientHello struct) | ||
23 | * TLSv1.1 - RFC 4346 section 7.4.1.2 (ClientHello struct) | ||
24 | * TLSv1.2 - RFC 5246 section 7.4.1.2 (ClientHello struct) | ||
25 | * | ||
26 | * In all of these standards, the relevant structures are: | ||
27 | * | ||
28 | * uint8 CipherSuite[2]; | ||
29 | * | ||
30 | * struct { | ||
31 | * ... | ||
32 | * CipherSuite cipher_suites<2..2^16-2> | ||
33 | * ... | ||
34 | * } ClientHello; | ||
35 | */ | ||
36 | |||
37 | #include <openssl/ssl.h> | ||
38 | |||
39 | #include <stdio.h> | ||
40 | #include <string.h> | ||
41 | |||
42 | #include "ssl_local.h" | ||
43 | |||
44 | #include "tests.h" | ||
45 | |||
46 | static uint8_t cipher_bytes[] = { | ||
47 | 0xcc, 0xa8, /* ECDHE-ECDSA-CHACHA20-POLY1305 */ | ||
48 | 0xcc, 0xa9, /* ECDHE-RSA-CHACHA20-POLY1305 */ | ||
49 | 0xcc, 0xaa, /* DHE-RSA-CHACHA20-POLY1305 */ | ||
50 | 0x00, 0x9c, /* AES128-GCM-SHA256 */ | ||
51 | 0x00, 0x3d, /* AES256-SHA256 */ | ||
52 | }; | ||
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 | |||
60 | static uint16_t cipher_values[] = { | ||
61 | 0xcca8, /* ECDHE-ECDSA-CHACHA20-POLY1305 */ | ||
62 | 0xcca9, /* ECDHE-RSA-CHACHA20-POLY1305 */ | ||
63 | 0xccaa, /* DHE-RSA-CHACHA20-POLY1305 */ | ||
64 | 0x009c, /* AES128-GCM-SHA256 */ | ||
65 | 0x003d, /* AES256-SHA256 */ | ||
66 | }; | ||
67 | |||
68 | #define N_CIPHERS (sizeof(cipher_bytes) / 2) | ||
69 | |||
70 | static int | ||
71 | ssl_bytes_to_list_alloc(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | ||
72 | { | ||
73 | SSL_CIPHER *cipher; | ||
74 | uint16_t value; | ||
75 | CBS cbs; | ||
76 | int i; | ||
77 | |||
78 | CBS_init(&cbs, cipher_bytes, sizeof(cipher_bytes)); | ||
79 | |||
80 | *ciphers = ssl_bytes_to_cipher_list(s, &cbs); | ||
81 | CHECK(*ciphers != NULL); | ||
82 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | ||
83 | for (i = 0; i < sk_SSL_CIPHER_num(*ciphers); i++) { | ||
84 | cipher = sk_SSL_CIPHER_value(*ciphers, i); | ||
85 | CHECK(cipher != NULL); | ||
86 | value = SSL_CIPHER_get_value(cipher); | ||
87 | CHECK(value == cipher_values[i]); | ||
88 | } | ||
89 | |||
90 | return 1; | ||
91 | } | ||
92 | |||
93 | static int | ||
94 | ssl_list_to_bytes_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers, | ||
95 | const uint8_t *cb, size_t cb_len) | ||
96 | { | ||
97 | CBB cbb; | ||
98 | unsigned char *buf = NULL; | ||
99 | size_t buflen, outlen; | ||
100 | int ret = 0; | ||
101 | |||
102 | /* Space for cipher bytes, plus reneg SCSV and two spare bytes. */ | ||
103 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | ||
104 | buflen = cb_len + 2 + 2; | ||
105 | CHECK((buf = calloc(1, buflen)) != NULL); | ||
106 | |||
107 | /* Clear renegotiate so it adds SCSV */ | ||
108 | s->renegotiate = 0; | ||
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)); | ||
113 | |||
114 | CHECK_GOTO(outlen > 0 && outlen == cb_len + 2); | ||
115 | CHECK_GOTO(memcmp(buf, cb, cb_len) == 0); | ||
116 | CHECK_GOTO(buf[buflen - 4] == 0x00 && buf[buflen - 3] == 0xff); | ||
117 | CHECK_GOTO(buf[buflen - 2] == 0x00 && buf[buflen - 1] == 0x00); | ||
118 | |||
119 | ret = 1; | ||
120 | |||
121 | err: | ||
122 | free(buf); | ||
123 | return ret; | ||
124 | } | ||
125 | |||
126 | static int | ||
127 | ssl_list_to_bytes_no_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers, | ||
128 | const uint8_t *cb, size_t cb_len) | ||
129 | { | ||
130 | CBB cbb; | ||
131 | unsigned char *buf = NULL; | ||
132 | size_t buflen, outlen; | ||
133 | int ret = 0; | ||
134 | |||
135 | /* Space for cipher bytes and two spare bytes */ | ||
136 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | ||
137 | buflen = cb_len + 2; | ||
138 | CHECK((buf = calloc(1, buflen)) != NULL); | ||
139 | buf[buflen - 2] = 0xfe; | ||
140 | buf[buflen - 1] = 0xab; | ||
141 | |||
142 | /* Set renegotiate so it doesn't add SCSV */ | ||
143 | s->renegotiate = 1; | ||
144 | |||
145 | CHECK_GOTO(CBB_init_fixed(&cbb, buf, buflen)); | ||
146 | CHECK_GOTO(ssl_cipher_list_to_bytes(s, *ciphers, &cbb)); | ||
147 | CHECK_GOTO(CBB_finish(&cbb, NULL, &outlen)); | ||
148 | |||
149 | CHECK_GOTO(outlen > 0 && outlen == cb_len); | ||
150 | CHECK_GOTO(memcmp(buf, cb, cb_len) == 0); | ||
151 | CHECK_GOTO(buf[buflen - 2] == 0xfe && buf[buflen - 1] == 0xab); | ||
152 | |||
153 | ret = 1; | ||
154 | |||
155 | err: | ||
156 | free(buf); | ||
157 | return ret; | ||
158 | } | ||
159 | |||
160 | static int | ||
161 | ssl_bytes_to_list_invalid(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | ||
162 | { | ||
163 | uint8_t empty_cipher_bytes[] = {0}; | ||
164 | CBS cbs; | ||
165 | |||
166 | sk_SSL_CIPHER_free(*ciphers); | ||
167 | |||
168 | /* Invalid length: CipherSuite is 2 bytes so it must be even */ | ||
169 | CBS_init(&cbs, cipher_bytes, sizeof(cipher_bytes) - 1); | ||
170 | *ciphers = ssl_bytes_to_cipher_list(s, &cbs); | ||
171 | CHECK(*ciphers == NULL); | ||
172 | |||
173 | /* Invalid length: cipher_suites must be at least 2 */ | ||
174 | CBS_init(&cbs, empty_cipher_bytes, sizeof(empty_cipher_bytes)); | ||
175 | *ciphers = ssl_bytes_to_cipher_list(s, &cbs); | ||
176 | CHECK(*ciphers == NULL); | ||
177 | |||
178 | return 1; | ||
179 | } | ||
180 | |||
181 | int | ||
182 | main(void) | ||
183 | { | ||
184 | STACK_OF(SSL_CIPHER) *ciphers = NULL; | ||
185 | SSL_CTX *ctx = NULL; | ||
186 | SSL *s = NULL; | ||
187 | int rv = 1; | ||
188 | |||
189 | SSL_library_init(); | ||
190 | |||
191 | /* Use TLSv1.2 client to get all ciphers. */ | ||
192 | CHECK_GOTO((ctx = SSL_CTX_new(TLSv1_2_client_method())) != NULL); | ||
193 | CHECK_GOTO((s = SSL_new(ctx)) != NULL); | ||
194 | SSL_set_security_level(s, 2); | ||
195 | |||
196 | if (!ssl_bytes_to_list_alloc(s, &ciphers)) | ||
197 | goto err; | ||
198 | if (!ssl_list_to_bytes_scsv(s, &ciphers, cipher_bytes, | ||
199 | sizeof(cipher_bytes))) | ||
200 | goto err; | ||
201 | if (!ssl_list_to_bytes_no_scsv(s, &ciphers, cipher_bytes, | ||
202 | sizeof(cipher_bytes))) | ||
203 | goto err; | ||
204 | if (!ssl_bytes_to_list_invalid(s, &ciphers)) | ||
205 | goto err; | ||
206 | |||
207 | sk_SSL_CIPHER_free(ciphers); | ||
208 | ciphers = NULL; | ||
209 | |||
210 | SSL_set_security_level(s, 3); | ||
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))) | ||
218 | goto err; | ||
219 | |||
220 | rv = 0; | ||
221 | |||
222 | err: | ||
223 | sk_SSL_CIPHER_free(ciphers); | ||
224 | SSL_CTX_free(ctx); | ||
225 | SSL_free(s); | ||
226 | |||
227 | if (!rv) | ||
228 | printf("PASS %s\n", __FILE__); | ||
229 | |||
230 | return rv; | ||
231 | } | ||
diff --git a/src/regress/lib/libssl/unit/ssl_get_shared_ciphers.c b/src/regress/lib/libssl/unit/ssl_get_shared_ciphers.c deleted file mode 100644 index e26f614e53..0000000000 --- a/src/regress/lib/libssl/unit/ssl_get_shared_ciphers.c +++ /dev/null | |||
@@ -1,478 +0,0 @@ | |||
1 | /* $OpenBSD: ssl_get_shared_ciphers.c,v 1.13 2024/08/31 12:47:24 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2021 Theo Buehler <tb@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 <stdint.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | |||
23 | #include <openssl/bio.h> | ||
24 | #include <openssl/crypto.h> | ||
25 | #include <openssl/err.h> | ||
26 | #include <openssl/ssl.h> | ||
27 | |||
28 | struct peer_config { | ||
29 | const char *name; | ||
30 | int server; | ||
31 | uint16_t max_version; | ||
32 | uint16_t min_version; | ||
33 | const char *ciphers; | ||
34 | }; | ||
35 | |||
36 | struct ssl_shared_ciphers_test_data { | ||
37 | const char *description; | ||
38 | struct peer_config client_config; | ||
39 | struct peer_config server_config; | ||
40 | const char *shared_ciphers; | ||
41 | const char *shared_ciphers_without_aesni; | ||
42 | }; | ||
43 | |||
44 | char *server_cert; | ||
45 | char *server_key; | ||
46 | |||
47 | static const struct ssl_shared_ciphers_test_data ssl_shared_ciphers_tests[] = { | ||
48 | { | ||
49 | .description = "TLSv1.3 defaults", | ||
50 | .client_config = { | ||
51 | .name = "client", | ||
52 | .server = 0, | ||
53 | .max_version = TLS1_3_VERSION, | ||
54 | .min_version = TLS1_3_VERSION, | ||
55 | .ciphers = | ||
56 | "TLS_AES_256_GCM_SHA384:" | ||
57 | "TLS_CHACHA20_POLY1305_SHA256:" | ||
58 | "TLS_AES_128_GCM_SHA256", | ||
59 | }, | ||
60 | .server_config = { | ||
61 | .name = "server", | ||
62 | .server = 1, | ||
63 | .max_version = TLS1_3_VERSION, | ||
64 | .min_version = TLS1_3_VERSION, | ||
65 | .ciphers = | ||
66 | "TLS_AES_256_GCM_SHA384:" | ||
67 | "TLS_CHACHA20_POLY1305_SHA256:" | ||
68 | "TLS_AES_128_GCM_SHA256", | ||
69 | }, | ||
70 | .shared_ciphers = | ||
71 | "TLS_AES_256_GCM_SHA384:" | ||
72 | "TLS_CHACHA20_POLY1305_SHA256:" | ||
73 | "TLS_AES_128_GCM_SHA256", | ||
74 | }, | ||
75 | |||
76 | { | ||
77 | .description = "TLSv1.3, client without ChaCha", | ||
78 | .client_config = { | ||
79 | .name = "client", | ||
80 | .server = 0, | ||
81 | .max_version = TLS1_3_VERSION, | ||
82 | .min_version = TLS1_3_VERSION, | ||
83 | .ciphers = | ||
84 | "TLS_AES_256_GCM_SHA384:" | ||
85 | "TLS_AES_128_GCM_SHA256", | ||
86 | }, | ||
87 | .server_config = { | ||
88 | .name = "server", | ||
89 | .server = 1, | ||
90 | .max_version = TLS1_3_VERSION, | ||
91 | .min_version = TLS1_3_VERSION, | ||
92 | .ciphers = | ||
93 | "TLS_AES_256_GCM_SHA384:" | ||
94 | "TLS_CHACHA20_POLY1305_SHA256:" | ||
95 | "TLS_AES_128_GCM_SHA256", | ||
96 | }, | ||
97 | .shared_ciphers = | ||
98 | "TLS_AES_256_GCM_SHA384:" | ||
99 | "TLS_AES_128_GCM_SHA256", | ||
100 | }, | ||
101 | |||
102 | { | ||
103 | .description = "TLSv1.2", | ||
104 | .client_config = { | ||
105 | .name = "client", | ||
106 | .server = 0, | ||
107 | .max_version = TLS1_2_VERSION, | ||
108 | .min_version = TLS1_2_VERSION, | ||
109 | .ciphers = | ||
110 | "ECDHE-RSA-AES256-GCM-SHA384:" | ||
111 | "ECDHE-ECDSA-AES256-GCM-SHA384:" | ||
112 | "ECDHE-RSA-AES256-SHA384:" | ||
113 | "ECDHE-ECDSA-AES256-SHA384:" | ||
114 | "ECDHE-RSA-AES256-SHA:" | ||
115 | "ECDHE-ECDSA-AES256-SHA", | ||
116 | }, | ||
117 | .server_config = { | ||
118 | .name = "server", | ||
119 | .server = 1, | ||
120 | .max_version = TLS1_2_VERSION, | ||
121 | .min_version = TLS1_2_VERSION, | ||
122 | .ciphers = | ||
123 | "ECDHE-RSA-AES256-GCM-SHA384:" | ||
124 | "ECDHE-ECDSA-AES256-GCM-SHA384:" | ||
125 | "ECDHE-RSA-AES256-SHA384:" | ||
126 | "ECDHE-ECDSA-AES256-SHA384:" | ||
127 | "ECDHE-RSA-AES256-SHA:" | ||
128 | "ECDHE-ECDSA-AES256-SHA", | ||
129 | }, | ||
130 | .shared_ciphers = | ||
131 | "ECDHE-RSA-AES256-GCM-SHA384:" | ||
132 | "ECDHE-ECDSA-AES256-GCM-SHA384:" | ||
133 | "ECDHE-RSA-AES256-SHA384:" | ||
134 | "ECDHE-ECDSA-AES256-SHA384:" | ||
135 | "ECDHE-RSA-AES256-SHA:" | ||
136 | "ECDHE-ECDSA-AES256-SHA", | ||
137 | }, | ||
138 | |||
139 | { | ||
140 | .description = "TLSv1.2, server without ECDSA", | ||
141 | .client_config = { | ||
142 | .name = "client", | ||
143 | .server = 0, | ||
144 | .max_version = TLS1_2_VERSION, | ||
145 | .min_version = TLS1_2_VERSION, | ||
146 | .ciphers = | ||
147 | "ECDHE-RSA-AES256-GCM-SHA384:" | ||
148 | "ECDHE-ECDSA-AES256-GCM-SHA384:" | ||
149 | "ECDHE-RSA-AES256-SHA384:" | ||
150 | "ECDHE-ECDSA-AES256-SHA384:" | ||
151 | "ECDHE-RSA-AES256-SHA:" | ||
152 | "ECDHE-ECDSA-AES256-SHA", | ||
153 | }, | ||
154 | .server_config = { | ||
155 | .name = "server", | ||
156 | .server = 1, | ||
157 | .max_version = TLS1_2_VERSION, | ||
158 | .min_version = TLS1_2_VERSION, | ||
159 | .ciphers = | ||
160 | "ECDHE-RSA-AES256-GCM-SHA384:" | ||
161 | "ECDHE-RSA-AES256-SHA384:" | ||
162 | "ECDHE-RSA-AES256-SHA", | ||
163 | }, | ||
164 | .shared_ciphers = | ||
165 | "ECDHE-RSA-AES256-GCM-SHA384:" | ||
166 | "ECDHE-RSA-AES256-SHA384:" | ||
167 | "ECDHE-RSA-AES256-SHA", | ||
168 | }, | ||
169 | |||
170 | { | ||
171 | .description = "TLSv1.3 ciphers are prepended", | ||
172 | .client_config = { | ||
173 | .name = "client", | ||
174 | .server = 0, | ||
175 | .max_version = TLS1_3_VERSION, | ||
176 | .min_version = TLS1_2_VERSION, | ||
177 | .ciphers = | ||
178 | "ECDHE-RSA-AES256-GCM-SHA384", | ||
179 | }, | ||
180 | .server_config = { | ||
181 | .name = "server", | ||
182 | .server = 1, | ||
183 | .max_version = TLS1_3_VERSION, | ||
184 | .min_version = TLS1_2_VERSION, | ||
185 | .ciphers = | ||
186 | "ECDHE-RSA-AES256-GCM-SHA384", | ||
187 | }, | ||
188 | .shared_ciphers = | ||
189 | "TLS_AES_256_GCM_SHA384:" | ||
190 | "TLS_CHACHA20_POLY1305_SHA256:" | ||
191 | "TLS_AES_128_GCM_SHA256:" | ||
192 | "ECDHE-RSA-AES256-GCM-SHA384", | ||
193 | .shared_ciphers_without_aesni = | ||
194 | "TLS_CHACHA20_POLY1305_SHA256:" | ||
195 | "TLS_AES_256_GCM_SHA384:" | ||
196 | "TLS_AES_128_GCM_SHA256:" | ||
197 | "ECDHE-RSA-AES256-GCM-SHA384", | ||
198 | }, | ||
199 | }; | ||
200 | |||
201 | static const size_t N_SHARED_CIPHERS_TESTS = | ||
202 | sizeof(ssl_shared_ciphers_tests) / sizeof(ssl_shared_ciphers_tests[0]); | ||
203 | |||
204 | static SSL_CTX * | ||
205 | peer_config_to_ssl_ctx(const struct peer_config *config) | ||
206 | { | ||
207 | SSL_CTX *ctx; | ||
208 | |||
209 | if ((ctx = SSL_CTX_new(TLS_method())) == NULL) { | ||
210 | fprintf(stderr, "SSL_CTX_new(%s) failed\n", config->name); | ||
211 | goto err; | ||
212 | } | ||
213 | if (!SSL_CTX_set_max_proto_version(ctx, config->max_version)) { | ||
214 | fprintf(stderr, "max_proto_version(%s) failed\n", config->name); | ||
215 | goto err; | ||
216 | } | ||
217 | if (!SSL_CTX_set_min_proto_version(ctx, config->min_version)) { | ||
218 | fprintf(stderr, "min_proto_version(%s) failed\n", config->name); | ||
219 | goto err; | ||
220 | } | ||
221 | if (!SSL_CTX_set_cipher_list(ctx, config->ciphers)) { | ||
222 | fprintf(stderr, "set_cipher_list(%s) failed\n", config->name); | ||
223 | goto err; | ||
224 | } | ||
225 | |||
226 | if (config->server) { | ||
227 | if (!SSL_CTX_use_certificate_file(ctx, server_cert, | ||
228 | SSL_FILETYPE_PEM)) { | ||
229 | fprintf(stderr, "use_certificate_file(%s) failed\n", | ||
230 | config->name); | ||
231 | goto err; | ||
232 | } | ||
233 | if (!SSL_CTX_use_PrivateKey_file(ctx, server_key, | ||
234 | SSL_FILETYPE_PEM)) { | ||
235 | fprintf(stderr, "use_PrivateKey_file(%s) failed\n", | ||
236 | config->name); | ||
237 | goto err; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | return ctx; | ||
242 | |||
243 | err: | ||
244 | SSL_CTX_free(ctx); | ||
245 | return NULL; | ||
246 | } | ||
247 | |||
248 | /* Connect client and server via a pair of "nonblocking" memory BIOs. */ | ||
249 | static int | ||
250 | connect_peers(SSL *client_ssl, SSL *server_ssl, const char *description) | ||
251 | { | ||
252 | BIO *client_wbio = NULL, *server_wbio = NULL; | ||
253 | int ret = 0; | ||
254 | |||
255 | if ((client_wbio = BIO_new(BIO_s_mem())) == NULL) { | ||
256 | fprintf(stderr, "%s: failed to create client BIO\n", | ||
257 | description); | ||
258 | goto err; | ||
259 | } | ||
260 | if ((server_wbio = BIO_new(BIO_s_mem())) == NULL) { | ||
261 | fprintf(stderr, "%s: failed to create server BIO\n", | ||
262 | description); | ||
263 | goto err; | ||
264 | } | ||
265 | if (BIO_set_mem_eof_return(client_wbio, -1) <= 0) { | ||
266 | fprintf(stderr, "%s: failed to set client eof return\n", | ||
267 | description); | ||
268 | goto err; | ||
269 | } | ||
270 | if (BIO_set_mem_eof_return(server_wbio, -1) <= 0) { | ||
271 | fprintf(stderr, "%s: failed to set server eof return\n", | ||
272 | description); | ||
273 | goto err; | ||
274 | } | ||
275 | |||
276 | /* Avoid double free. SSL_set_bio() takes ownership of the BIOs. */ | ||
277 | BIO_up_ref(client_wbio); | ||
278 | BIO_up_ref(server_wbio); | ||
279 | |||
280 | SSL_set_bio(client_ssl, server_wbio, client_wbio); | ||
281 | SSL_set_bio(server_ssl, client_wbio, server_wbio); | ||
282 | client_wbio = NULL; | ||
283 | server_wbio = NULL; | ||
284 | |||
285 | ret = 1; | ||
286 | |||
287 | err: | ||
288 | BIO_free(client_wbio); | ||
289 | BIO_free(server_wbio); | ||
290 | |||
291 | return ret; | ||
292 | } | ||
293 | |||
294 | static int | ||
295 | push_data_to_peer(SSL *ssl, int *ret, int (*func)(SSL *), const char *func_name, | ||
296 | const char *description) | ||
297 | { | ||
298 | int ssl_err = 0; | ||
299 | |||
300 | if (*ret == 1) | ||
301 | return 1; | ||
302 | |||
303 | /* | ||
304 | * Do SSL_connect/SSL_accept/SSL_shutdown once and loop while hitting | ||
305 | * WANT_WRITE. If done or on WANT_READ hand off to peer. | ||
306 | */ | ||
307 | |||
308 | do { | ||
309 | if ((*ret = func(ssl)) <= 0) | ||
310 | ssl_err = SSL_get_error(ssl, *ret); | ||
311 | } while (*ret <= 0 && ssl_err == SSL_ERROR_WANT_WRITE); | ||
312 | |||
313 | /* Ignore erroneous error - see SSL_shutdown(3)... */ | ||
314 | if (func == SSL_shutdown && ssl_err == SSL_ERROR_SYSCALL) | ||
315 | return 1; | ||
316 | |||
317 | if (*ret <= 0 && ssl_err != SSL_ERROR_WANT_READ) { | ||
318 | fprintf(stderr, "%s: %s failed\n", description, func_name); | ||
319 | ERR_print_errors_fp(stderr); | ||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | return 1; | ||
324 | } | ||
325 | |||
326 | /* | ||
327 | * Alternate between loops of SSL_connect() and SSL_accept() as long as only | ||
328 | * WANT_READ and WANT_WRITE situations are encountered. A function is repeated | ||
329 | * until WANT_READ is returned or it succeeds, then it's the other function's | ||
330 | * turn to make progress. Succeeds if SSL_connect() and SSL_accept() return 1. | ||
331 | */ | ||
332 | static int | ||
333 | handshake(SSL *client_ssl, SSL *server_ssl, const char *description) | ||
334 | { | ||
335 | int loops = 0, client_ret = 0, server_ret = 0; | ||
336 | |||
337 | while (loops++ < 10 && (client_ret <= 0 || server_ret <= 0)) { | ||
338 | if (!push_data_to_peer(client_ssl, &client_ret, SSL_connect, | ||
339 | "SSL_connect", description)) | ||
340 | return 0; | ||
341 | |||
342 | if (!push_data_to_peer(server_ssl, &server_ret, SSL_accept, | ||
343 | "SSL_accept", description)) | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | if (client_ret != 1 || server_ret != 1) { | ||
348 | fprintf(stderr, "%s: failed\n", __func__); | ||
349 | return 0; | ||
350 | } | ||
351 | |||
352 | return 1; | ||
353 | } | ||
354 | |||
355 | static int | ||
356 | shutdown_peers(SSL *client_ssl, SSL *server_ssl, const char *description) | ||
357 | { | ||
358 | int loops = 0, client_ret = 0, server_ret = 0; | ||
359 | |||
360 | while (loops++ < 10 && (client_ret <= 0 || server_ret <= 0)) { | ||
361 | if (!push_data_to_peer(client_ssl, &client_ret, SSL_shutdown, | ||
362 | "client shutdown", description)) | ||
363 | return 0; | ||
364 | |||
365 | if (!push_data_to_peer(server_ssl, &server_ret, SSL_shutdown, | ||
366 | "server shutdown", description)) | ||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | if (client_ret != 1 || server_ret != 1) { | ||
371 | fprintf(stderr, "%s: failed\n", __func__); | ||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | return 1; | ||
376 | } | ||
377 | |||
378 | /* from ssl_ciph.c */ | ||
379 | static inline int | ||
380 | ssl_aes_is_accelerated(void) | ||
381 | { | ||
382 | return (OPENSSL_cpu_caps() & CRYPTO_CPU_CAPS_ACCELERATED_AES) != 0; | ||
383 | } | ||
384 | |||
385 | static int | ||
386 | check_shared_ciphers(const struct ssl_shared_ciphers_test_data *test, | ||
387 | const char *got) | ||
388 | { | ||
389 | const char *want = test->shared_ciphers; | ||
390 | int failed; | ||
391 | |||
392 | if (!ssl_aes_is_accelerated() && | ||
393 | test->shared_ciphers_without_aesni != NULL) | ||
394 | want = test->shared_ciphers_without_aesni; | ||
395 | |||
396 | failed = strcmp(want, got); | ||
397 | |||
398 | if (failed) | ||
399 | fprintf(stderr, "%s: want \"%s\", got \"%s\"\n", | ||
400 | test->description, want, got); | ||
401 | |||
402 | return failed; | ||
403 | } | ||
404 | |||
405 | static int | ||
406 | test_get_shared_ciphers(const struct ssl_shared_ciphers_test_data *test) | ||
407 | { | ||
408 | SSL_CTX *client_ctx = NULL, *server_ctx = NULL; | ||
409 | SSL *client_ssl = NULL, *server_ssl = NULL; | ||
410 | char buf[4096]; | ||
411 | int failed = 1; | ||
412 | |||
413 | if ((client_ctx = peer_config_to_ssl_ctx(&test->client_config)) == NULL) | ||
414 | goto err; | ||
415 | if ((server_ctx = peer_config_to_ssl_ctx(&test->server_config)) == NULL) | ||
416 | goto err; | ||
417 | |||
418 | if ((client_ssl = SSL_new(client_ctx)) == NULL) { | ||
419 | fprintf(stderr, "%s: failed to create client SSL\n", | ||
420 | test->description); | ||
421 | goto err; | ||
422 | } | ||
423 | if ((server_ssl = SSL_new(server_ctx)) == NULL) { | ||
424 | fprintf(stderr, "%s: failed to create server SSL\n", | ||
425 | test->description); | ||
426 | goto err; | ||
427 | } | ||
428 | |||
429 | if (!connect_peers(client_ssl, server_ssl, test->description)) | ||
430 | goto err; | ||
431 | |||
432 | if (!handshake(client_ssl, server_ssl, test->description)) | ||
433 | goto err; | ||
434 | |||
435 | if (SSL_get_shared_ciphers(server_ssl, buf, sizeof(buf)) == NULL) { | ||
436 | fprintf(stderr, "%s: failed to get shared ciphers\n", | ||
437 | test->description); | ||
438 | goto err; | ||
439 | } | ||
440 | |||
441 | if (!shutdown_peers(client_ssl, server_ssl, test->description)) | ||
442 | goto err; | ||
443 | |||
444 | failed = check_shared_ciphers(test, buf); | ||
445 | |||
446 | err: | ||
447 | SSL_CTX_free(client_ctx); | ||
448 | SSL_CTX_free(server_ctx); | ||
449 | SSL_free(client_ssl); | ||
450 | SSL_free(server_ssl); | ||
451 | |||
452 | return failed; | ||
453 | } | ||
454 | |||
455 | int | ||
456 | main(int argc, char **argv) | ||
457 | { | ||
458 | size_t i; | ||
459 | int failed = 0; | ||
460 | |||
461 | if (asprintf(&server_cert, "%s/server1-rsa.pem", CERTSDIR) == -1) { | ||
462 | fprintf(stderr, "asprintf server_cert failed\n"); | ||
463 | failed = 1; | ||
464 | goto err; | ||
465 | } | ||
466 | server_key = server_cert; | ||
467 | |||
468 | for (i = 0; i < N_SHARED_CIPHERS_TESTS; i++) | ||
469 | failed |= test_get_shared_ciphers(&ssl_shared_ciphers_tests[i]); | ||
470 | |||
471 | if (failed == 0) | ||
472 | printf("PASS %s\n", __FILE__); | ||
473 | |||
474 | err: | ||
475 | free(server_cert); | ||
476 | |||
477 | return failed; | ||
478 | } | ||
diff --git a/src/regress/lib/libssl/unit/ssl_methods.c b/src/regress/lib/libssl/unit/ssl_methods.c deleted file mode 100644 index 0fc33a406c..0000000000 --- a/src/regress/lib/libssl/unit/ssl_methods.c +++ /dev/null | |||
@@ -1,267 +0,0 @@ | |||
1 | /* $OpenBSD: ssl_methods.c,v 1.4 2021/04/04 20:21:43 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020 Theo Buehler <tb@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 <stdio.h> | ||
19 | |||
20 | #include <openssl/ssl.h> | ||
21 | |||
22 | struct ssl_method_test_data { | ||
23 | const SSL_METHOD *(*method)(void); | ||
24 | const char *name; | ||
25 | int server; | ||
26 | int dtls; | ||
27 | }; | ||
28 | |||
29 | struct ssl_method_test_data ssl_method_tests[] = { | ||
30 | { | ||
31 | .method = SSLv23_method, | ||
32 | .name = "SSLv23_method", | ||
33 | .server = 1, | ||
34 | .dtls = 0, | ||
35 | }, | ||
36 | { | ||
37 | .method = SSLv23_server_method, | ||
38 | .name = "SSLv23_server_method", | ||
39 | .server = 1, | ||
40 | .dtls = 0, | ||
41 | }, | ||
42 | { | ||
43 | .method = SSLv23_client_method, | ||
44 | .name = "SSLv23_client_method", | ||
45 | .server = 0, | ||
46 | .dtls = 0, | ||
47 | }, | ||
48 | |||
49 | { | ||
50 | .method = TLSv1_method, | ||
51 | .name = "TLSv1_method", | ||
52 | .server = 1, | ||
53 | .dtls = 0, | ||
54 | }, | ||
55 | { | ||
56 | .method = TLSv1_server_method, | ||
57 | .name = "TLSv1_server_method", | ||
58 | .server = 1, | ||
59 | .dtls = 0, | ||
60 | }, | ||
61 | { | ||
62 | .method = TLSv1_client_method, | ||
63 | .name = "TLSv1_client_method", | ||
64 | .server = 0, | ||
65 | .dtls = 0, | ||
66 | }, | ||
67 | |||
68 | { | ||
69 | .method = TLSv1_1_method, | ||
70 | .name = "TLSv1_1_method", | ||
71 | .server = 1, | ||
72 | .dtls = 0, | ||
73 | }, | ||
74 | { | ||
75 | .method = TLSv1_1_server_method, | ||
76 | .name = "TLSv1_1_server_method", | ||
77 | .server = 1, | ||
78 | .dtls = 0, | ||
79 | }, | ||
80 | { | ||
81 | .method = TLSv1_1_client_method, | ||
82 | .name = "TLSv1_1_client_method", | ||
83 | .server = 0, | ||
84 | .dtls = 0, | ||
85 | }, | ||
86 | |||
87 | { | ||
88 | .method = TLSv1_2_method, | ||
89 | .name = "TLSv1_2_method", | ||
90 | .server = 1, | ||
91 | .dtls = 0, | ||
92 | }, | ||
93 | { | ||
94 | .method = TLSv1_2_server_method, | ||
95 | .name = "TLSv1_2_server_method", | ||
96 | .server = 1, | ||
97 | .dtls = 0, | ||
98 | }, | ||
99 | { | ||
100 | .method = TLSv1_2_client_method, | ||
101 | .name = "TLSv1_2_client_method", | ||
102 | .server = 0, | ||
103 | .dtls = 0, | ||
104 | }, | ||
105 | |||
106 | { | ||
107 | .method = TLS_method, | ||
108 | .name = "TLS_method", | ||
109 | .server = 1, | ||
110 | .dtls = 0, | ||
111 | }, | ||
112 | { | ||
113 | .method = TLS_server_method, | ||
114 | .name = "TLS_server_method", | ||
115 | .server = 1, | ||
116 | .dtls = 0, | ||
117 | }, | ||
118 | { | ||
119 | .method = TLS_client_method, | ||
120 | .name = "TLS_client_method", | ||
121 | .server = 0, | ||
122 | .dtls = 0, | ||
123 | }, | ||
124 | |||
125 | { | ||
126 | .method = DTLSv1_method, | ||
127 | .name = "DTLSv1_method", | ||
128 | .server = 1, | ||
129 | .dtls = 1, | ||
130 | }, | ||
131 | { | ||
132 | .method = DTLSv1_server_method, | ||
133 | .name = "DTLSv1_server_method", | ||
134 | .server = 1, | ||
135 | .dtls = 1, | ||
136 | }, | ||
137 | { | ||
138 | .method = DTLSv1_client_method, | ||
139 | .name = "DTLSv1_client_method", | ||
140 | .server = 0, | ||
141 | .dtls = 1, | ||
142 | }, | ||
143 | |||
144 | { | ||
145 | .method = DTLSv1_2_method, | ||
146 | .name = "DTLSv1_2_method", | ||
147 | .server = 1, | ||
148 | .dtls = 1, | ||
149 | }, | ||
150 | { | ||
151 | .method = DTLSv1_2_server_method, | ||
152 | .name = "DTLSv1_2_server_method", | ||
153 | .server = 1, | ||
154 | .dtls = 1, | ||
155 | }, | ||
156 | { | ||
157 | .method = DTLSv1_2_client_method, | ||
158 | .name = "DTLSv1_2_client_method", | ||
159 | .server = 0, | ||
160 | .dtls = 1, | ||
161 | }, | ||
162 | |||
163 | { | ||
164 | .method = DTLS_method, | ||
165 | .name = "DTLS_method", | ||
166 | .server = 1, | ||
167 | .dtls = 1, | ||
168 | }, | ||
169 | { | ||
170 | .method = DTLS_server_method, | ||
171 | .name = "DTLS_server_method", | ||
172 | .server = 1, | ||
173 | .dtls = 1, | ||
174 | }, | ||
175 | { | ||
176 | .method = DTLS_client_method, | ||
177 | .name = "DTLS_client_method", | ||
178 | .server = 0, | ||
179 | .dtls = 1, | ||
180 | }, | ||
181 | }; | ||
182 | |||
183 | #define N_METHOD_TESTS (sizeof(ssl_method_tests) / sizeof(ssl_method_tests[0])) | ||
184 | |||
185 | int test_client_or_server_method(struct ssl_method_test_data *); | ||
186 | int test_dtls_method(struct ssl_method_test_data *); | ||
187 | |||
188 | int | ||
189 | test_client_or_server_method(struct ssl_method_test_data *testcase) | ||
190 | { | ||
191 | SSL_CTX *ssl_ctx; | ||
192 | SSL *ssl = NULL; | ||
193 | int failed = 1; | ||
194 | |||
195 | if ((ssl_ctx = SSL_CTX_new(testcase->method())) == NULL) { | ||
196 | fprintf(stderr, "SSL_CTX_new returned NULL\n"); | ||
197 | goto err; | ||
198 | } | ||
199 | |||
200 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
201 | fprintf(stderr, "SSL_new returned NULL\n"); | ||
202 | goto err; | ||
203 | } | ||
204 | |||
205 | if (SSL_is_server(ssl) != testcase->server) { | ||
206 | fprintf(stderr, "%s: SSL_is_server: want %d, got %d\n", | ||
207 | testcase->name, testcase->server, SSL_is_server(ssl)); | ||
208 | goto err; | ||
209 | } | ||
210 | |||
211 | failed = 0; | ||
212 | |||
213 | err: | ||
214 | SSL_free(ssl); | ||
215 | SSL_CTX_free(ssl_ctx); | ||
216 | |||
217 | return failed; | ||
218 | } | ||
219 | |||
220 | int | ||
221 | test_dtls_method(struct ssl_method_test_data *testcase) | ||
222 | { | ||
223 | SSL_CTX *ssl_ctx; | ||
224 | SSL *ssl = NULL; | ||
225 | int failed = 1; | ||
226 | |||
227 | if ((ssl_ctx = SSL_CTX_new(testcase->method())) == NULL) { | ||
228 | fprintf(stderr, "SSL_CTX_new returned NULL\n"); | ||
229 | goto err; | ||
230 | } | ||
231 | |||
232 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
233 | fprintf(stderr, "SSL_new returned NULL\n"); | ||
234 | goto err; | ||
235 | } | ||
236 | |||
237 | if (SSL_is_dtls(ssl) != testcase->dtls) { | ||
238 | fprintf(stderr, "%s: SSL_is_dtls: want %d, got %d\n", | ||
239 | testcase->name, testcase->dtls, SSL_is_dtls(ssl)); | ||
240 | goto err; | ||
241 | } | ||
242 | |||
243 | failed = 0; | ||
244 | |||
245 | err: | ||
246 | SSL_free(ssl); | ||
247 | SSL_CTX_free(ssl_ctx); | ||
248 | |||
249 | return failed; | ||
250 | } | ||
251 | |||
252 | int | ||
253 | main(int argc, char **argv) | ||
254 | { | ||
255 | size_t i; | ||
256 | int failed = 0; | ||
257 | |||
258 | for (i = 0; i < N_METHOD_TESTS; i++) { | ||
259 | failed |= test_client_or_server_method(&ssl_method_tests[i]); | ||
260 | failed |= test_dtls_method(&ssl_method_tests[i]); | ||
261 | } | ||
262 | |||
263 | if (failed == 0) | ||
264 | printf("PASS %s\n", __FILE__); | ||
265 | |||
266 | return failed; | ||
267 | } | ||
diff --git a/src/regress/lib/libssl/unit/ssl_set_alpn_protos.c b/src/regress/lib/libssl/unit/ssl_set_alpn_protos.c deleted file mode 100644 index d8447c8999..0000000000 --- a/src/regress/lib/libssl/unit/ssl_set_alpn_protos.c +++ /dev/null | |||
@@ -1,470 +0,0 @@ | |||
1 | /* $OpenBSD: ssl_set_alpn_protos.c,v 1.4 2024/07/11 13:51:47 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2022 Theo Buehler <tb@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 <stdio.h> | ||
20 | |||
21 | #include <openssl/ssl.h> | ||
22 | |||
23 | static void | ||
24 | hexdump(const unsigned char *buf, size_t len) | ||
25 | { | ||
26 | size_t i; | ||
27 | |||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "(null), len %zu\n", len); | ||
30 | return; | ||
31 | } | ||
32 | for (i = 1; i <= len; i++) | ||
33 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
34 | if (len % 8) | ||
35 | fprintf(stderr, "\n"); | ||
36 | } | ||
37 | |||
38 | struct alpn_test { | ||
39 | const char *description; | ||
40 | const uint8_t protocols[24]; | ||
41 | size_t protocols_len; | ||
42 | int ret; | ||
43 | }; | ||
44 | |||
45 | static const struct alpn_test alpn_tests[] = { | ||
46 | { | ||
47 | .description = "valid protocol list", | ||
48 | .protocols = { | ||
49 | 6, 's', 'p', 'd', 'y', '/', '1', | ||
50 | 8, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
51 | }, | ||
52 | .protocols_len = 16, | ||
53 | .ret = 0, | ||
54 | }, | ||
55 | { | ||
56 | .description = "zero length protocol", | ||
57 | .protocols = { | ||
58 | 0, | ||
59 | }, | ||
60 | .protocols_len = 1, | ||
61 | .ret = 1, | ||
62 | }, | ||
63 | { | ||
64 | .description = "zero length protocol at start", | ||
65 | .protocols = { | ||
66 | 0, | ||
67 | 8, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
68 | 6, 's', 'p', 'd', 'y', '/', '1', | ||
69 | }, | ||
70 | .protocols_len = 17, | ||
71 | .ret = 1, | ||
72 | }, | ||
73 | { | ||
74 | .description = "zero length protocol embedded", | ||
75 | .protocols = { | ||
76 | 8, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
77 | 0, | ||
78 | 6, 's', 'p', 'd', 'y', '/', '1', | ||
79 | }, | ||
80 | .protocols_len = 17, | ||
81 | .ret = 1, | ||
82 | }, | ||
83 | { | ||
84 | .description = "zero length protocol at end", | ||
85 | .protocols = { | ||
86 | 8, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
87 | 6, 's', 'p', 'd', 'y', '/', '1', | ||
88 | 0, | ||
89 | }, | ||
90 | .protocols_len = 17, | ||
91 | .ret = 1, | ||
92 | }, | ||
93 | { | ||
94 | .description = "protocol length too short", | ||
95 | .protocols = { | ||
96 | 6, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
97 | }, | ||
98 | .protocols_len = 9, | ||
99 | .ret = 1, | ||
100 | }, | ||
101 | { | ||
102 | .description = "protocol length too long", | ||
103 | .protocols = { | ||
104 | 8, 's', 'p', 'd', 'y', '/', '1', | ||
105 | }, | ||
106 | .protocols_len = 7, | ||
107 | .ret = 1, | ||
108 | }, | ||
109 | }; | ||
110 | |||
111 | static const size_t N_ALPN_TESTS = sizeof(alpn_tests) / sizeof(alpn_tests[0]); | ||
112 | |||
113 | static int | ||
114 | test_ssl_set_alpn_protos(const struct alpn_test *tc) | ||
115 | { | ||
116 | SSL_CTX *ctx; | ||
117 | SSL *ssl; | ||
118 | int ret; | ||
119 | int failed = 0; | ||
120 | |||
121 | if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
122 | errx(1, "SSL_CTX_new"); | ||
123 | |||
124 | ret = SSL_CTX_set_alpn_protos(ctx, tc->protocols, tc->protocols_len); | ||
125 | if (ret != tc->ret) { | ||
126 | warnx("%s: setting on SSL_CTX: want %d, got %d", | ||
127 | tc->description, tc->ret, ret); | ||
128 | failed = 1; | ||
129 | } | ||
130 | |||
131 | if ((ssl = SSL_new(ctx)) == NULL) | ||
132 | errx(1, "SSL_new"); | ||
133 | |||
134 | ret = SSL_set_alpn_protos(ssl, tc->protocols, tc->protocols_len); | ||
135 | if (ret != tc->ret) { | ||
136 | warnx("%s: setting on SSL: want %d, got %d", | ||
137 | tc->description, tc->ret, ret); | ||
138 | failed = 1; | ||
139 | } | ||
140 | |||
141 | SSL_CTX_free(ctx); | ||
142 | SSL_free(ssl); | ||
143 | |||
144 | return failed; | ||
145 | } | ||
146 | |||
147 | static int | ||
148 | test_ssl_set_alpn_protos_edge_cases(void) | ||
149 | { | ||
150 | SSL_CTX *ctx; | ||
151 | SSL *ssl; | ||
152 | const uint8_t valid[] = { | ||
153 | 6, 's', 'p', 'd', 'y', '/', '3', | ||
154 | 8, 'h', 't', 't', 'p', '/', '1', '.', '1', | ||
155 | }; | ||
156 | int failed = 0; | ||
157 | |||
158 | if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
159 | errx(1, "SSL_CTX_new"); | ||
160 | |||
161 | if (SSL_CTX_set_alpn_protos(ctx, valid, sizeof(valid)) != 0) { | ||
162 | warnx("setting valid protocols on SSL_CTX failed"); | ||
163 | failed = 1; | ||
164 | } | ||
165 | if (SSL_CTX_set_alpn_protos(ctx, NULL, 0) != 0) { | ||
166 | warnx("setting 'NULL, 0' on SSL_CTX failed"); | ||
167 | failed = 1; | ||
168 | } | ||
169 | if (SSL_CTX_set_alpn_protos(ctx, valid, 0) != 0) { | ||
170 | warnx("setting 'valid, 0' on SSL_CTX failed"); | ||
171 | failed = 1; | ||
172 | } | ||
173 | if (SSL_CTX_set_alpn_protos(ctx, NULL, 43) != 0) { | ||
174 | warnx("setting 'NULL, 43' on SSL_CTX failed"); | ||
175 | failed = 1; | ||
176 | } | ||
177 | |||
178 | if ((ssl = SSL_new(ctx)) == NULL) | ||
179 | errx(1, "SSL_new"); | ||
180 | |||
181 | if (SSL_set_alpn_protos(ssl, valid, sizeof(valid)) != 0) { | ||
182 | warnx("setting valid protocols on SSL failed"); | ||
183 | failed = 1; | ||
184 | } | ||
185 | if (SSL_set_alpn_protos(ssl, NULL, 0) != 0) { | ||
186 | warnx("setting 'NULL, 0' on SSL failed"); | ||
187 | failed = 1; | ||
188 | } | ||
189 | if (SSL_set_alpn_protos(ssl, valid, 0) != 0) { | ||
190 | warnx("setting 'valid, 0' on SSL failed"); | ||
191 | failed = 1; | ||
192 | } | ||
193 | if (SSL_set_alpn_protos(ssl, NULL, 43) != 0) { | ||
194 | warnx("setting 'NULL, 43' on SSL failed"); | ||
195 | failed = 1; | ||
196 | } | ||
197 | |||
198 | SSL_CTX_free(ctx); | ||
199 | SSL_free(ssl); | ||
200 | |||
201 | return failed; | ||
202 | } | ||
203 | |||
204 | static const struct select_next_proto_test { | ||
205 | const unsigned char *peer_list; | ||
206 | size_t peer_list_len; | ||
207 | const unsigned char *supported_list; | ||
208 | size_t supported_list_len; | ||
209 | int want_ret; | ||
210 | const unsigned char *want_out; | ||
211 | unsigned char want_out_len; /* yes, unsigned char */ | ||
212 | } select_next_proto_tests[] = { | ||
213 | { | ||
214 | .peer_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
215 | .peer_list_len = 6, | ||
216 | .supported_list = "\x01" "a", | ||
217 | .supported_list_len = 2, | ||
218 | .want_ret = OPENSSL_NPN_NEGOTIATED, | ||
219 | .want_out = "a", | ||
220 | .want_out_len = 1, | ||
221 | }, | ||
222 | { | ||
223 | .peer_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
224 | .peer_list_len = 6, | ||
225 | .supported_list = "\x02" "aa" "\x01" "b" "\x01" "c", | ||
226 | .supported_list_len = 7, | ||
227 | .want_ret = OPENSSL_NPN_NEGOTIATED, | ||
228 | .want_out = "b", | ||
229 | .want_out_len = 1, | ||
230 | }, | ||
231 | { | ||
232 | /* Use peer preference. */ | ||
233 | .peer_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
234 | .peer_list_len = 6, | ||
235 | .supported_list = "\x01" "c" "\x01" "b" "\x01" "a", | ||
236 | .supported_list_len = 6, | ||
237 | .want_ret = OPENSSL_NPN_NEGOTIATED, | ||
238 | .want_out = "a", | ||
239 | .want_out_len = 1, | ||
240 | }, | ||
241 | { | ||
242 | /* Again peer preference wins. */ | ||
243 | .peer_list = "\x01" "a" "\x03" "bbb" "\x02" "cc", | ||
244 | .peer_list_len = 9, | ||
245 | .supported_list = "\x01" "z" "\x02" "cc" "\x03" "bbb", | ||
246 | .supported_list_len = 9, | ||
247 | .want_ret = OPENSSL_NPN_NEGOTIATED, | ||
248 | .want_out = "bbb", | ||
249 | .want_out_len = 3, | ||
250 | }, | ||
251 | { | ||
252 | /* No overlap fails with first supported protocol. */ | ||
253 | .peer_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
254 | .peer_list_len = 6, | ||
255 | .supported_list = "\x01" "z" "\x01" "y", | ||
256 | .supported_list_len = 4, | ||
257 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
258 | .want_out = "z", | ||
259 | .want_out_len = 1, | ||
260 | }, | ||
261 | { | ||
262 | /* No peer protocols fails cleanly. */ | ||
263 | .peer_list = "", | ||
264 | .peer_list_len = 0, | ||
265 | .supported_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
266 | .supported_list_len = 6, | ||
267 | .want_out = "a", | ||
268 | .want_out_len = 1, | ||
269 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
270 | }, | ||
271 | { | ||
272 | /* NULL peer protocols fails cleanly. */ | ||
273 | .peer_list = NULL, | ||
274 | .peer_list_len = 0, | ||
275 | .supported_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
276 | .supported_list_len = 6, | ||
277 | .want_out = "a", | ||
278 | .want_out_len = 1, | ||
279 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
280 | }, | ||
281 | { | ||
282 | /* Malformed peer protocols fails cleanly. */ | ||
283 | .peer_list = "\x00", | ||
284 | .peer_list_len = 1, | ||
285 | .supported_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
286 | .supported_list_len = 6, | ||
287 | .want_out = "a", | ||
288 | .want_out_len = 1, | ||
289 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
290 | }, | ||
291 | { | ||
292 | /* Malformed peer protocols fails cleanly. */ | ||
293 | .peer_list = "\x01" "a" "\x03" "bb", | ||
294 | .peer_list_len = 5, | ||
295 | .supported_list = "\x01" "a" "\x01" "b" "\x01" "c", | ||
296 | .supported_list_len = 6, | ||
297 | .want_out = "a", | ||
298 | .want_out_len = 1, | ||
299 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
300 | }, | ||
301 | { | ||
302 | /* Empty supported list fails cleanly. */ | ||
303 | .peer_list = "\x01" "a", | ||
304 | .peer_list_len = 2, | ||
305 | .supported_list = "", | ||
306 | .supported_list_len = 0, | ||
307 | .want_out = NULL, | ||
308 | .want_out_len = 0, | ||
309 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
310 | }, | ||
311 | { | ||
312 | /* NULL supported list fails cleanly. */ | ||
313 | .peer_list = "\x01" "a", | ||
314 | .peer_list_len = 2, | ||
315 | .supported_list = NULL, | ||
316 | .supported_list_len = 0, | ||
317 | .want_out = NULL, | ||
318 | .want_out_len = 0, | ||
319 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
320 | }, | ||
321 | { | ||
322 | /* Malformed supported list fails cleanly. */ | ||
323 | .peer_list = "\x01" "a", | ||
324 | .peer_list_len = 2, | ||
325 | .supported_list = "\x01" "a" "\x02" "bb" "\x03" "cc" "\x04" "ddd", | ||
326 | .supported_list_len = 12, | ||
327 | .want_out = NULL, | ||
328 | .want_out_len = 0, | ||
329 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
330 | }, | ||
331 | { | ||
332 | /* Malformed client list fails cleanly. */ | ||
333 | .peer_list = "\x01" "a", | ||
334 | .peer_list_len = 2, | ||
335 | .supported_list = "\x01" "a" "\x02" "bb" "\x00" "\x03" "ddd", | ||
336 | .supported_list_len = 10, | ||
337 | .want_out = NULL, | ||
338 | .want_out_len = 0, | ||
339 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
340 | }, | ||
341 | |||
342 | /* | ||
343 | * Some non-toy examples. | ||
344 | */ | ||
345 | |||
346 | { | ||
347 | .peer_list = "\x08" "http/1.1" "\x06" "spdy/1", | ||
348 | .peer_list_len = 16, | ||
349 | .supported_list = "\x08" "http/2.0" "\x08" "http/1.1", | ||
350 | .supported_list_len = 18, | ||
351 | .want_out = "http/1.1", | ||
352 | .want_out_len = 8, | ||
353 | .want_ret = OPENSSL_NPN_NEGOTIATED, | ||
354 | }, | ||
355 | { | ||
356 | .peer_list = "\x08" "http/2.0" "\x06" "spdy/1", | ||
357 | .peer_list_len = 16, | ||
358 | .supported_list = "\x08" "http/1.0" "\x08" "http/1.1", | ||
359 | .supported_list_len = 18, | ||
360 | .want_out = "http/1.0", | ||
361 | .want_out_len = 8, | ||
362 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
363 | }, | ||
364 | { | ||
365 | .peer_list = "\x08" "http/1.1" "\x08" "http/1.0", | ||
366 | .peer_list_len = 18, | ||
367 | .supported_list = "\x08" "http/1.0" "\x08" "http/1.1", | ||
368 | .supported_list_len = 18, | ||
369 | .want_out = "http/1.1", | ||
370 | .want_out_len = 8, | ||
371 | .want_ret = OPENSSL_NPN_NEGOTIATED, | ||
372 | }, | ||
373 | { | ||
374 | /* Peer list malformed. */ | ||
375 | .peer_list = "\x08" "http/1.1" "\x07" "http/1.0", | ||
376 | .peer_list_len = 18, | ||
377 | .supported_list = "\x08" "http/1.0" "\x08" "http/1.1", | ||
378 | .supported_list_len = 18, | ||
379 | .want_out = "http/1.0", | ||
380 | .want_out_len = 8, | ||
381 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
382 | }, | ||
383 | { | ||
384 | /* Peer list malformed. */ | ||
385 | .peer_list = "\x07" "http/1.1" "\x08" "http/1.0", | ||
386 | .peer_list_len = 18, | ||
387 | .supported_list = "\x08" "http/1.0" "\x08" "http/1.1", | ||
388 | .supported_list_len = 18, | ||
389 | .want_out = "http/1.0", | ||
390 | .want_out_len = 8, | ||
391 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
392 | }, | ||
393 | { | ||
394 | /* Supported list has trailing bytes. */ | ||
395 | .peer_list = "\x08" "http/1.1" "\x08" "http/1.0", | ||
396 | .peer_list_len = 18, | ||
397 | .supported_list = "\x08" "http/1.0" "\x07" "http/1.1", | ||
398 | .supported_list_len = 18, | ||
399 | .want_out = NULL, | ||
400 | .want_out_len = 0, | ||
401 | .want_ret = OPENSSL_NPN_NO_OVERLAP, | ||
402 | }, | ||
403 | }; | ||
404 | |||
405 | #define N_SELECT_NEXT_PROTO_TESTS \ | ||
406 | (sizeof(select_next_proto_tests) / sizeof(select_next_proto_tests[0])) | ||
407 | |||
408 | static int | ||
409 | select_next_proto_testcase(const struct select_next_proto_test *test) | ||
410 | { | ||
411 | unsigned char *out; | ||
412 | unsigned char out_len; | ||
413 | int ret; | ||
414 | int failed = 0; | ||
415 | |||
416 | ret = SSL_select_next_proto(&out, &out_len, test->peer_list, | ||
417 | test->peer_list_len, test->supported_list, test->supported_list_len); | ||
418 | |||
419 | if (ret != test->want_ret || out_len != test->want_out_len || | ||
420 | (out == NULL && test->want_out != NULL) || | ||
421 | (out != NULL && test->want_out == NULL) || | ||
422 | (out != NULL && test->want_out != NULL && | ||
423 | memcmp(out, test->want_out, out_len) != 0)) { | ||
424 | fprintf(stderr, "FAIL: ret: %u (want %u), out_len: %u (want %u)\n", | ||
425 | ret, test->want_ret, out_len, test->want_out_len); | ||
426 | fprintf(stderr, "\ngot:\n"); | ||
427 | hexdump(out, out_len); | ||
428 | fprintf(stderr, "\nwant:\n"); | ||
429 | hexdump(test->want_out, test->want_out_len); | ||
430 | fprintf(stderr, "\nserver:\n"); | ||
431 | hexdump(test->peer_list, test->peer_list_len); | ||
432 | fprintf(stderr, "\nclient:\n"); | ||
433 | hexdump(test->supported_list, test->supported_list_len); | ||
434 | fprintf(stderr, "\n"); | ||
435 | failed = 1; | ||
436 | } | ||
437 | |||
438 | return failed; | ||
439 | } | ||
440 | |||
441 | static int | ||
442 | test_ssl_select_next_proto(void) | ||
443 | { | ||
444 | size_t i; | ||
445 | int failed = 0; | ||
446 | |||
447 | for (i = 0; i < N_SELECT_NEXT_PROTO_TESTS; i++) | ||
448 | failed |= select_next_proto_testcase(&select_next_proto_tests[i]); | ||
449 | |||
450 | return failed; | ||
451 | } | ||
452 | |||
453 | int | ||
454 | main(void) | ||
455 | { | ||
456 | size_t i; | ||
457 | int failed = 0; | ||
458 | |||
459 | for (i = 0; i < N_ALPN_TESTS; i++) | ||
460 | failed |= test_ssl_set_alpn_protos(&alpn_tests[i]); | ||
461 | |||
462 | failed |= test_ssl_set_alpn_protos_edge_cases(); | ||
463 | |||
464 | failed |= test_ssl_select_next_proto(); | ||
465 | |||
466 | if (!failed) | ||
467 | printf("PASS %s\n", __FILE__); | ||
468 | |||
469 | return failed; | ||
470 | } | ||
diff --git a/src/regress/lib/libssl/unit/ssl_verify_param.c b/src/regress/lib/libssl/unit/ssl_verify_param.c deleted file mode 100644 index cdb52c56a8..0000000000 --- a/src/regress/lib/libssl/unit/ssl_verify_param.c +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | /* $OpenBSD: ssl_verify_param.c,v 1.1 2023/05/24 08:54:59 tb Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2023 Theo Buehler <tb@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <err.h> | ||
20 | #include <stdio.h> | ||
21 | |||
22 | #include <openssl/ssl.h> | ||
23 | #include <openssl/x509v3.h> | ||
24 | |||
25 | unsigned int X509_VERIFY_PARAM_get_hostflags(X509_VERIFY_PARAM *param); | ||
26 | |||
27 | static int | ||
28 | ssl_verify_param_flags_inherited(void) | ||
29 | { | ||
30 | SSL_CTX *ssl_ctx = NULL; | ||
31 | SSL *ssl = NULL; | ||
32 | X509_VERIFY_PARAM *param; | ||
33 | unsigned int defaultflags = 0; | ||
34 | unsigned int newflags = X509_CHECK_FLAG_NEVER_CHECK_SUBJECT; | ||
35 | unsigned int flags; | ||
36 | int failed = 1; | ||
37 | |||
38 | if ((ssl_ctx = SSL_CTX_new(TLS_method())) == NULL) | ||
39 | errx(1, "SSL_CTX_new"); | ||
40 | |||
41 | if ((param = SSL_CTX_get0_param(ssl_ctx)) == NULL) { | ||
42 | fprintf(stderr, "FAIL: no verify param on ssl_ctx\n"); | ||
43 | goto failure; | ||
44 | } | ||
45 | |||
46 | if ((flags = X509_VERIFY_PARAM_get_hostflags(param)) != defaultflags) { | ||
47 | fprintf(stderr, "FAIL: SSL_CTX default hostflags, " | ||
48 | "want: %x, got: %x\n", defaultflags, flags); | ||
49 | goto failure; | ||
50 | } | ||
51 | |||
52 | X509_VERIFY_PARAM_set_hostflags(param, newflags); | ||
53 | |||
54 | if ((flags = X509_VERIFY_PARAM_get_hostflags(param)) != newflags) { | ||
55 | fprintf(stderr, "FAIL: SSL_CTX new hostflags, " | ||
56 | "want: %x, got: %x\n", newflags, flags); | ||
57 | goto failure; | ||
58 | } | ||
59 | |||
60 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
61 | errx(1, "SSL_new"); | ||
62 | |||
63 | if ((param = SSL_get0_param(ssl)) == NULL) { | ||
64 | fprintf(stderr, "FAIL: no verify param on ssl\n"); | ||
65 | goto failure; | ||
66 | } | ||
67 | |||
68 | if ((flags = X509_VERIFY_PARAM_get_hostflags(param)) != newflags) { | ||
69 | fprintf(stderr, "FAIL: SSL inherited hostflags, " | ||
70 | "want: %x, got: %x\n", newflags, flags); | ||
71 | goto failure; | ||
72 | } | ||
73 | |||
74 | SSL_set_hostflags(ssl, defaultflags); | ||
75 | |||
76 | if ((flags = X509_VERIFY_PARAM_get_hostflags(param)) != defaultflags) { | ||
77 | fprintf(stderr, "FAIL: SSL set hostflags, " | ||
78 | "want: %x, got: %x\n", defaultflags, flags); | ||
79 | goto failure; | ||
80 | } | ||
81 | |||
82 | failed = 0; | ||
83 | |||
84 | failure: | ||
85 | SSL_CTX_free(ssl_ctx); | ||
86 | SSL_free(ssl); | ||
87 | |||
88 | return failed; | ||
89 | } | ||
90 | |||
91 | int | ||
92 | main(void) | ||
93 | { | ||
94 | int failed = 0; | ||
95 | |||
96 | failed |= ssl_verify_param_flags_inherited(); | ||
97 | |||
98 | return failed; | ||
99 | } | ||
diff --git a/src/regress/lib/libssl/unit/ssl_versions.c b/src/regress/lib/libssl/unit/ssl_versions.c deleted file mode 100644 index ebfe8d2c28..0000000000 --- a/src/regress/lib/libssl/unit/ssl_versions.c +++ /dev/null | |||
@@ -1,922 +0,0 @@ | |||
1 | /* $OpenBSD: ssl_versions.c,v 1.20 2023/07/02 17:21:33 beck Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2016, 2017 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 <openssl/ssl.h> | ||
19 | |||
20 | #include "ssl_local.h" | ||
21 | |||
22 | struct version_range_test { | ||
23 | const long options; | ||
24 | const uint16_t minver; | ||
25 | const uint16_t maxver; | ||
26 | const uint16_t want_minver; | ||
27 | const uint16_t want_maxver; | ||
28 | }; | ||
29 | |||
30 | static struct version_range_test version_range_tests[] = { | ||
31 | { | ||
32 | .options = 0, | ||
33 | .minver = TLS1_VERSION, | ||
34 | .maxver = TLS1_3_VERSION, | ||
35 | .want_minver = TLS1_2_VERSION, | ||
36 | .want_maxver = TLS1_3_VERSION, | ||
37 | }, | ||
38 | { | ||
39 | .options = 0, | ||
40 | .minver = TLS1_VERSION, | ||
41 | .maxver = TLS1_2_VERSION, | ||
42 | .want_minver = TLS1_2_VERSION, | ||
43 | .want_maxver = TLS1_2_VERSION, | ||
44 | }, | ||
45 | { | ||
46 | .options = SSL_OP_NO_TLSv1, | ||
47 | .minver = TLS1_VERSION, | ||
48 | .maxver = TLS1_2_VERSION, | ||
49 | .want_minver = TLS1_2_VERSION, | ||
50 | .want_maxver = TLS1_2_VERSION, | ||
51 | }, | ||
52 | { | ||
53 | .options = SSL_OP_NO_TLSv1_3, | ||
54 | .minver = TLS1_VERSION, | ||
55 | .maxver = TLS1_3_VERSION, | ||
56 | .want_minver = TLS1_2_VERSION, | ||
57 | .want_maxver = TLS1_2_VERSION, | ||
58 | }, | ||
59 | { | ||
60 | .options = SSL_OP_NO_TLSv1_2, | ||
61 | .minver = TLS1_VERSION, | ||
62 | .maxver = TLS1_2_VERSION, | ||
63 | .want_minver = 0, | ||
64 | .want_maxver = 0, | ||
65 | }, | ||
66 | { | ||
67 | .options = SSL_OP_NO_TLSv1_1, | ||
68 | .minver = TLS1_VERSION, | ||
69 | .maxver = TLS1_2_VERSION, | ||
70 | .want_minver = TLS1_2_VERSION, | ||
71 | .want_maxver = TLS1_2_VERSION, | ||
72 | }, | ||
73 | { | ||
74 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1, | ||
75 | .minver = TLS1_VERSION, | ||
76 | .maxver = TLS1_2_VERSION, | ||
77 | .want_minver = TLS1_2_VERSION, | ||
78 | .want_maxver = TLS1_2_VERSION, | ||
79 | }, | ||
80 | { | ||
81 | .options = SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
82 | .minver = TLS1_VERSION, | ||
83 | .maxver = TLS1_2_VERSION, | ||
84 | .want_minver = 0, | ||
85 | .want_maxver = 0, | ||
86 | }, | ||
87 | { | ||
88 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_2, | ||
89 | .minver = TLS1_VERSION, | ||
90 | .maxver = TLS1_2_VERSION, | ||
91 | .want_minver = 0, | ||
92 | .want_maxver = 0, | ||
93 | }, | ||
94 | { | ||
95 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
96 | SSL_OP_NO_TLSv1_2, | ||
97 | .minver = TLS1_VERSION, | ||
98 | .maxver = TLS1_2_VERSION, | ||
99 | .want_minver = 0, | ||
100 | .want_maxver = 0, | ||
101 | }, | ||
102 | { | ||
103 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
104 | SSL_OP_NO_TLSv1_2, | ||
105 | .minver = TLS1_VERSION, | ||
106 | .maxver = TLS1_3_VERSION, | ||
107 | .want_minver = TLS1_3_VERSION, | ||
108 | .want_maxver = TLS1_3_VERSION, | ||
109 | }, | ||
110 | { | ||
111 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
112 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3, | ||
113 | .minver = TLS1_VERSION, | ||
114 | .maxver = TLS1_3_VERSION, | ||
115 | .want_minver = 0, | ||
116 | .want_maxver = 0, | ||
117 | }, | ||
118 | { | ||
119 | .options = 0, | ||
120 | .minver = TLS1_VERSION, | ||
121 | .maxver = TLS1_2_VERSION, | ||
122 | .want_minver = TLS1_2_VERSION, | ||
123 | .want_maxver = TLS1_2_VERSION, | ||
124 | }, | ||
125 | { | ||
126 | .options = 0, | ||
127 | .minver = TLS1_1_VERSION, | ||
128 | .maxver = TLS1_2_VERSION, | ||
129 | .want_minver = TLS1_2_VERSION, | ||
130 | .want_maxver = TLS1_2_VERSION, | ||
131 | }, | ||
132 | { | ||
133 | .options = 0, | ||
134 | .minver = TLS1_2_VERSION, | ||
135 | .maxver = TLS1_2_VERSION, | ||
136 | .want_minver = TLS1_2_VERSION, | ||
137 | .want_maxver = TLS1_2_VERSION, | ||
138 | }, | ||
139 | { | ||
140 | .options = 0, | ||
141 | .minver = TLS1_VERSION, | ||
142 | .maxver = TLS1_3_VERSION, | ||
143 | .want_minver = TLS1_2_VERSION, | ||
144 | .want_maxver = TLS1_3_VERSION, | ||
145 | }, | ||
146 | { | ||
147 | .options = 0, | ||
148 | .minver = TLS1_1_VERSION, | ||
149 | .maxver = TLS1_3_VERSION, | ||
150 | .want_minver = TLS1_2_VERSION, | ||
151 | .want_maxver = TLS1_3_VERSION, | ||
152 | }, | ||
153 | { | ||
154 | .options = 0, | ||
155 | .minver = TLS1_2_VERSION, | ||
156 | .maxver = TLS1_3_VERSION, | ||
157 | .want_minver = TLS1_2_VERSION, | ||
158 | .want_maxver = TLS1_3_VERSION, | ||
159 | }, | ||
160 | { | ||
161 | .options = 0, | ||
162 | .minver = TLS1_3_VERSION, | ||
163 | .maxver = TLS1_3_VERSION, | ||
164 | .want_minver = TLS1_3_VERSION, | ||
165 | .want_maxver = TLS1_3_VERSION, | ||
166 | }, | ||
167 | { | ||
168 | .options = 0, | ||
169 | .minver = TLS1_VERSION, | ||
170 | .maxver = TLS1_1_VERSION, | ||
171 | .want_minver = 0, | ||
172 | .want_maxver = 0, | ||
173 | }, | ||
174 | { | ||
175 | .options = 0, | ||
176 | .minver = TLS1_VERSION, | ||
177 | .maxver = TLS1_VERSION, | ||
178 | .want_minver = 0, | ||
179 | .want_maxver = 0, | ||
180 | }, | ||
181 | }; | ||
182 | |||
183 | #define N_VERSION_RANGE_TESTS \ | ||
184 | (sizeof(version_range_tests) / sizeof(*version_range_tests)) | ||
185 | |||
186 | static int | ||
187 | test_ssl_enabled_version_range(void) | ||
188 | { | ||
189 | struct version_range_test *vrt; | ||
190 | uint16_t minver, maxver; | ||
191 | SSL_CTX *ssl_ctx = NULL; | ||
192 | SSL *ssl = NULL; | ||
193 | int failed = 1; | ||
194 | size_t i; | ||
195 | |||
196 | fprintf(stderr, "INFO: starting enabled version range tests...\n"); | ||
197 | |||
198 | if ((ssl_ctx = SSL_CTX_new(TLS_method())) == NULL) { | ||
199 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
200 | goto failure; | ||
201 | } | ||
202 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
203 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
204 | goto failure; | ||
205 | } | ||
206 | |||
207 | failed = 0; | ||
208 | |||
209 | for (i = 0; i < N_VERSION_RANGE_TESTS; i++) { | ||
210 | vrt = &version_range_tests[i]; | ||
211 | |||
212 | SSL_clear_options(ssl, SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
213 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3); | ||
214 | SSL_set_options(ssl, vrt->options); | ||
215 | |||
216 | minver = maxver = 0xffff; | ||
217 | ssl->min_tls_version = vrt->minver; | ||
218 | ssl->max_tls_version = vrt->maxver; | ||
219 | |||
220 | if (ssl_enabled_tls_version_range(ssl, &minver, &maxver) != 1) { | ||
221 | if (vrt->want_minver != 0 || vrt->want_maxver != 0) { | ||
222 | fprintf(stderr, "FAIL: test %zu - failed but " | ||
223 | "wanted non-zero versions\n", i); | ||
224 | failed++; | ||
225 | } | ||
226 | continue; | ||
227 | } | ||
228 | if (minver != vrt->want_minver) { | ||
229 | fprintf(stderr, "FAIL: test %zu - got minver %x, " | ||
230 | "want %x\n", i, minver, vrt->want_minver); | ||
231 | failed++; | ||
232 | } | ||
233 | if (maxver != vrt->want_maxver) { | ||
234 | fprintf(stderr, "FAIL: test %zu - got maxver %x, " | ||
235 | "want %x\n", i, maxver, vrt->want_maxver); | ||
236 | failed++; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | failure: | ||
241 | SSL_CTX_free(ssl_ctx); | ||
242 | SSL_free(ssl); | ||
243 | |||
244 | return (failed); | ||
245 | } | ||
246 | |||
247 | struct shared_version_test { | ||
248 | const SSL_METHOD *(*ssl_method)(void); | ||
249 | const long options; | ||
250 | const uint16_t minver; | ||
251 | const uint16_t maxver; | ||
252 | const uint16_t peerver; | ||
253 | const uint16_t want_maxver; | ||
254 | }; | ||
255 | |||
256 | static struct shared_version_test shared_version_tests[] = { | ||
257 | { | ||
258 | .ssl_method = TLS_method, | ||
259 | .options = 0, | ||
260 | .minver = TLS1_VERSION, | ||
261 | .maxver = TLS1_2_VERSION, | ||
262 | .peerver = SSL2_VERSION, | ||
263 | .want_maxver = 0, | ||
264 | }, | ||
265 | { | ||
266 | .ssl_method = TLS_method, | ||
267 | .options = 0, | ||
268 | .minver = TLS1_VERSION, | ||
269 | .maxver = TLS1_2_VERSION, | ||
270 | .peerver = SSL3_VERSION, | ||
271 | .want_maxver = 0, | ||
272 | }, | ||
273 | { | ||
274 | .ssl_method = TLS_method, | ||
275 | .options = 0, | ||
276 | .minver = TLS1_VERSION, | ||
277 | .maxver = TLS1_2_VERSION, | ||
278 | .peerver = TLS1_VERSION, | ||
279 | .want_maxver = 0, | ||
280 | }, | ||
281 | { | ||
282 | .ssl_method = TLS_method, | ||
283 | .options = 0, | ||
284 | .minver = TLS1_VERSION, | ||
285 | .maxver = TLS1_2_VERSION, | ||
286 | .peerver = TLS1_1_VERSION, | ||
287 | .want_maxver = 0, | ||
288 | }, | ||
289 | { | ||
290 | .ssl_method = TLS_method, | ||
291 | .options = 0, | ||
292 | .minver = TLS1_VERSION, | ||
293 | .maxver = TLS1_2_VERSION, | ||
294 | .peerver = TLS1_2_VERSION, | ||
295 | .want_maxver = TLS1_2_VERSION, | ||
296 | }, | ||
297 | { | ||
298 | .ssl_method = TLS_method, | ||
299 | .options = 0, | ||
300 | .minver = TLS1_VERSION, | ||
301 | .maxver = TLS1_2_VERSION, | ||
302 | .peerver = TLS1_3_VERSION, | ||
303 | .want_maxver = TLS1_2_VERSION, | ||
304 | }, | ||
305 | { | ||
306 | .ssl_method = TLS_method, | ||
307 | .options = 0, | ||
308 | .minver = TLS1_VERSION, | ||
309 | .maxver = TLS1_2_VERSION, | ||
310 | .peerver = 0x7f12, | ||
311 | .want_maxver = TLS1_2_VERSION, | ||
312 | }, | ||
313 | { | ||
314 | .ssl_method = TLS_method, | ||
315 | .options = SSL_OP_NO_TLSv1_2, | ||
316 | .minver = TLS1_VERSION, | ||
317 | .maxver = TLS1_2_VERSION, | ||
318 | .peerver = TLS1_2_VERSION, | ||
319 | .want_maxver = 0, | ||
320 | }, | ||
321 | { | ||
322 | .ssl_method = TLS_method, | ||
323 | .options = SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
324 | .minver = TLS1_VERSION, | ||
325 | .maxver = TLS1_2_VERSION, | ||
326 | .peerver = TLS1_2_VERSION, | ||
327 | .want_maxver = 0, | ||
328 | }, | ||
329 | { | ||
330 | .ssl_method = TLS_method, | ||
331 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
332 | .minver = TLS1_VERSION, | ||
333 | .maxver = TLS1_2_VERSION, | ||
334 | .peerver = TLS1_2_VERSION, | ||
335 | .want_maxver = 0, | ||
336 | }, | ||
337 | { | ||
338 | .ssl_method = TLS_method, | ||
339 | .options = SSL_OP_NO_TLSv1, | ||
340 | .minver = TLS1_VERSION, | ||
341 | .maxver = TLS1_2_VERSION, | ||
342 | .peerver = TLS1_1_VERSION, | ||
343 | .want_maxver = 0, | ||
344 | }, | ||
345 | { | ||
346 | .ssl_method = TLS_method, | ||
347 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1, | ||
348 | .minver = TLS1_VERSION, | ||
349 | .maxver = TLS1_2_VERSION, | ||
350 | .peerver = TLS1_1_VERSION, | ||
351 | .want_maxver = 0, | ||
352 | }, | ||
353 | { | ||
354 | .ssl_method = TLS_method, | ||
355 | .options = SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
356 | .minver = TLS1_VERSION, | ||
357 | .maxver = TLS1_2_VERSION, | ||
358 | .peerver = TLS1_1_VERSION, | ||
359 | .want_maxver = 0, | ||
360 | }, | ||
361 | { | ||
362 | .ssl_method = TLS_method, | ||
363 | .options = SSL_OP_NO_TLSv1, | ||
364 | .minver = TLS1_VERSION, | ||
365 | .maxver = TLS1_2_VERSION, | ||
366 | .peerver = TLS1_VERSION, | ||
367 | .want_maxver = 0, | ||
368 | }, | ||
369 | { | ||
370 | .ssl_method = TLS_method, | ||
371 | .options = 0, | ||
372 | .minver = TLS1_VERSION, | ||
373 | .maxver = TLS1_1_VERSION, | ||
374 | .peerver = TLS1_2_VERSION, | ||
375 | .want_maxver = 0, | ||
376 | }, | ||
377 | { | ||
378 | .ssl_method = TLS_method, | ||
379 | .options = 0, | ||
380 | .minver = TLS1_VERSION, | ||
381 | .maxver = TLS1_VERSION, | ||
382 | .peerver = TLS1_2_VERSION, | ||
383 | .want_maxver = 0, | ||
384 | }, | ||
385 | { | ||
386 | .ssl_method = TLSv1_method, | ||
387 | .options = 0, | ||
388 | .minver = TLS1_VERSION, | ||
389 | .maxver = TLS1_2_VERSION, | ||
390 | .peerver = TLS1_VERSION, | ||
391 | .want_maxver = 0, | ||
392 | }, | ||
393 | { | ||
394 | .ssl_method = TLSv1_method, | ||
395 | .options = 0, | ||
396 | .minver = TLS1_1_VERSION, | ||
397 | .maxver = TLS1_2_VERSION, | ||
398 | .peerver = TLS1_VERSION, | ||
399 | .want_maxver = 0, | ||
400 | }, | ||
401 | { | ||
402 | .ssl_method = TLSv1_1_method, | ||
403 | .options = 0, | ||
404 | .minver = TLS1_VERSION, | ||
405 | .maxver = TLS1_2_VERSION, | ||
406 | .peerver = TLS1_1_VERSION, | ||
407 | .want_maxver = 0, | ||
408 | }, | ||
409 | { | ||
410 | .ssl_method = DTLS_method, | ||
411 | .options = 0, | ||
412 | .minver = TLS1_1_VERSION, | ||
413 | .maxver = TLS1_2_VERSION, | ||
414 | .peerver = DTLS1_VERSION, | ||
415 | .want_maxver = 0, | ||
416 | }, | ||
417 | { | ||
418 | .ssl_method = DTLS_method, | ||
419 | .options = 0, | ||
420 | .minver = TLS1_1_VERSION, | ||
421 | .maxver = TLS1_2_VERSION, | ||
422 | .peerver = DTLS1_2_VERSION, | ||
423 | .want_maxver = DTLS1_2_VERSION, | ||
424 | }, | ||
425 | { | ||
426 | .ssl_method = DTLS_method, | ||
427 | .options = 0, | ||
428 | .minver = TLS1_1_VERSION, | ||
429 | .maxver = TLS1_2_VERSION, | ||
430 | .peerver = 0xfefc, /* DTLSv1.3, probably. */ | ||
431 | .want_maxver = DTLS1_2_VERSION, | ||
432 | }, | ||
433 | { | ||
434 | .ssl_method = DTLSv1_method, | ||
435 | .options = 0, | ||
436 | .minver = TLS1_1_VERSION, | ||
437 | .maxver = TLS1_1_VERSION, | ||
438 | .peerver = DTLS1_2_VERSION, | ||
439 | .want_maxver = 0, | ||
440 | }, | ||
441 | { | ||
442 | .ssl_method = DTLSv1_2_method, | ||
443 | .options = 0, | ||
444 | .minver = TLS1_2_VERSION, | ||
445 | .maxver = TLS1_2_VERSION, | ||
446 | .peerver = DTLS1_2_VERSION, | ||
447 | .want_maxver = DTLS1_2_VERSION, | ||
448 | }, | ||
449 | { | ||
450 | .ssl_method = DTLSv1_method, | ||
451 | .options = 0, | ||
452 | .minver = TLS1_1_VERSION, | ||
453 | .maxver = TLS1_1_VERSION, | ||
454 | .peerver = TLS1_2_VERSION, | ||
455 | .want_maxver = 0, | ||
456 | }, | ||
457 | { | ||
458 | .ssl_method = DTLS_method, | ||
459 | .options = SSL_OP_NO_DTLSv1, | ||
460 | .minver = TLS1_1_VERSION, | ||
461 | .maxver = TLS1_2_VERSION, | ||
462 | .peerver = DTLS1_VERSION, | ||
463 | .want_maxver = 0, | ||
464 | }, | ||
465 | { | ||
466 | .ssl_method = DTLS_method, | ||
467 | .options = SSL_OP_NO_DTLSv1, | ||
468 | .minver = TLS1_1_VERSION, | ||
469 | .maxver = TLS1_2_VERSION, | ||
470 | .peerver = DTLS1_2_VERSION, | ||
471 | .want_maxver = DTLS1_2_VERSION, | ||
472 | }, | ||
473 | { | ||
474 | .ssl_method = DTLS_method, | ||
475 | .options = SSL_OP_NO_DTLSv1_2, | ||
476 | .minver = TLS1_1_VERSION, | ||
477 | .maxver = TLS1_2_VERSION, | ||
478 | .peerver = DTLS1_2_VERSION, | ||
479 | .want_maxver = 0, | ||
480 | }, | ||
481 | }; | ||
482 | |||
483 | #define N_SHARED_VERSION_TESTS \ | ||
484 | (sizeof(shared_version_tests) / sizeof(*shared_version_tests)) | ||
485 | |||
486 | static int | ||
487 | test_ssl_max_shared_version(void) | ||
488 | { | ||
489 | struct shared_version_test *svt; | ||
490 | SSL_CTX *ssl_ctx = NULL; | ||
491 | SSL *ssl = NULL; | ||
492 | uint16_t maxver; | ||
493 | int failed = 0; | ||
494 | size_t i; | ||
495 | |||
496 | failed = 0; | ||
497 | |||
498 | fprintf(stderr, "INFO: starting max shared version tests...\n"); | ||
499 | |||
500 | for (i = 0; i < N_SHARED_VERSION_TESTS; i++) { | ||
501 | svt = &shared_version_tests[i]; | ||
502 | |||
503 | if ((ssl_ctx = SSL_CTX_new(svt->ssl_method())) == NULL) { | ||
504 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
505 | failed++; | ||
506 | goto err; | ||
507 | } | ||
508 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
509 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
510 | failed++; | ||
511 | goto err; | ||
512 | } | ||
513 | |||
514 | SSL_clear_options(ssl, SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
515 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3); | ||
516 | SSL_set_options(ssl, svt->options); | ||
517 | |||
518 | maxver = 0; | ||
519 | ssl->min_tls_version = svt->minver; | ||
520 | ssl->max_tls_version = svt->maxver; | ||
521 | |||
522 | if (!ssl_max_shared_version(ssl, svt->peerver, &maxver)) { | ||
523 | if (svt->want_maxver != 0) { | ||
524 | fprintf(stderr, "FAIL: test %zu - failed but " | ||
525 | "wanted non-zero shared version (peer %x)\n", | ||
526 | i, svt->peerver); | ||
527 | failed++; | ||
528 | } | ||
529 | SSL_CTX_free(ssl_ctx); | ||
530 | SSL_free(ssl); | ||
531 | ssl_ctx = NULL; | ||
532 | ssl = NULL; | ||
533 | continue; | ||
534 | } | ||
535 | if (maxver != svt->want_maxver) { | ||
536 | fprintf(stderr, "FAIL: test %zu - got shared " | ||
537 | "version %x, want %x\n", i, maxver, | ||
538 | svt->want_maxver); | ||
539 | failed++; | ||
540 | } | ||
541 | |||
542 | SSL_CTX_free(ssl_ctx); | ||
543 | SSL_free(ssl); | ||
544 | ssl_ctx = NULL; | ||
545 | ssl = NULL; | ||
546 | } | ||
547 | |||
548 | err: | ||
549 | SSL_CTX_free(ssl_ctx); | ||
550 | SSL_free(ssl); | ||
551 | |||
552 | return (failed); | ||
553 | } | ||
554 | |||
555 | struct min_max_version_test { | ||
556 | const SSL_METHOD *(*ssl_method)(void); | ||
557 | const uint16_t minver; | ||
558 | const uint16_t maxver; | ||
559 | const uint16_t want_minver; | ||
560 | const uint16_t want_maxver; | ||
561 | const int want_min_fail; | ||
562 | const int want_max_fail; | ||
563 | }; | ||
564 | |||
565 | static struct min_max_version_test min_max_version_tests[] = { | ||
566 | { | ||
567 | .ssl_method = TLS_method, | ||
568 | .minver = 0, | ||
569 | .maxver = 0, | ||
570 | .want_minver = 0, | ||
571 | .want_maxver = 0, | ||
572 | }, | ||
573 | { | ||
574 | .ssl_method = TLS_method, | ||
575 | .minver = TLS1_VERSION, | ||
576 | .maxver = 0, | ||
577 | .want_minver = TLS1_VERSION, | ||
578 | .want_maxver = 0, | ||
579 | }, | ||
580 | { | ||
581 | .ssl_method = TLS_method, | ||
582 | .minver = 0, | ||
583 | .maxver = TLS1_2_VERSION, | ||
584 | .want_minver = 0, | ||
585 | .want_maxver = TLS1_2_VERSION, | ||
586 | }, | ||
587 | { | ||
588 | .ssl_method = TLS_method, | ||
589 | .minver = 0, | ||
590 | .maxver = TLS1_3_VERSION, | ||
591 | .want_minver = 0, | ||
592 | .want_maxver = TLS1_3_VERSION, | ||
593 | }, | ||
594 | { | ||
595 | .ssl_method = TLS_method, | ||
596 | .minver = TLS1_VERSION, | ||
597 | .maxver = TLS1_2_VERSION, | ||
598 | .want_minver = TLS1_VERSION, | ||
599 | .want_maxver = TLS1_2_VERSION, | ||
600 | }, | ||
601 | { | ||
602 | .ssl_method = TLS_method, | ||
603 | .minver = TLS1_1_VERSION, | ||
604 | .maxver = 0, | ||
605 | .want_minver = TLS1_1_VERSION, | ||
606 | .want_maxver = 0, | ||
607 | }, | ||
608 | { | ||
609 | .ssl_method = TLS_method, | ||
610 | .minver = TLS1_2_VERSION, | ||
611 | .maxver = 0, | ||
612 | .want_minver = TLS1_2_VERSION, | ||
613 | .want_maxver = 0, | ||
614 | }, | ||
615 | { | ||
616 | .ssl_method = TLS_method, | ||
617 | .minver = 0x0300, | ||
618 | .maxver = 0, | ||
619 | .want_minver = TLS1_VERSION, | ||
620 | .want_maxver = 0, | ||
621 | }, | ||
622 | { | ||
623 | .ssl_method = TLS_method, | ||
624 | .minver = 0x0305, | ||
625 | .maxver = 0, | ||
626 | .want_min_fail = 1, | ||
627 | }, | ||
628 | { | ||
629 | .ssl_method = TLS_method, | ||
630 | .minver = 0, | ||
631 | .maxver = 0x0305, | ||
632 | .want_minver = 0, | ||
633 | .want_maxver = TLS1_3_VERSION, | ||
634 | }, | ||
635 | { | ||
636 | .ssl_method = TLS_method, | ||
637 | .minver = 0, | ||
638 | .maxver = TLS1_1_VERSION, | ||
639 | .want_minver = 0, | ||
640 | .want_maxver = TLS1_1_VERSION, | ||
641 | }, | ||
642 | { | ||
643 | .ssl_method = TLS_method, | ||
644 | .minver = 0, | ||
645 | .maxver = TLS1_VERSION, | ||
646 | .want_minver = 0, | ||
647 | .want_maxver = TLS1_VERSION, | ||
648 | }, | ||
649 | { | ||
650 | .ssl_method = TLS_method, | ||
651 | .minver = 0, | ||
652 | .maxver = 0x0300, | ||
653 | .want_max_fail = 1, | ||
654 | }, | ||
655 | { | ||
656 | .ssl_method = TLS_method, | ||
657 | .minver = TLS1_2_VERSION, | ||
658 | .maxver = TLS1_1_VERSION, | ||
659 | .want_minver = TLS1_2_VERSION, | ||
660 | .want_maxver = 0, | ||
661 | .want_max_fail = 1, | ||
662 | }, | ||
663 | { | ||
664 | .ssl_method = TLSv1_1_method, | ||
665 | .minver = 0, | ||
666 | .maxver = 0, | ||
667 | .want_minver = 0, | ||
668 | .want_maxver = 0, | ||
669 | }, | ||
670 | { | ||
671 | .ssl_method = TLSv1_1_method, | ||
672 | .minver = TLS1_VERSION, | ||
673 | .maxver = TLS1_2_VERSION, | ||
674 | .want_minver = TLS1_1_VERSION, | ||
675 | .want_maxver = TLS1_1_VERSION, | ||
676 | }, | ||
677 | { | ||
678 | .ssl_method = TLSv1_1_method, | ||
679 | .minver = TLS1_2_VERSION, | ||
680 | .maxver = 0, | ||
681 | .want_minver = 0, | ||
682 | .want_maxver = 0, | ||
683 | .want_min_fail = 1, | ||
684 | }, | ||
685 | { | ||
686 | .ssl_method = TLSv1_1_method, | ||
687 | .minver = 0, | ||
688 | .maxver = TLS1_VERSION, | ||
689 | .want_minver = 0, | ||
690 | .want_maxver = 0, | ||
691 | .want_max_fail = 1, | ||
692 | }, | ||
693 | { | ||
694 | .ssl_method = DTLS_method, | ||
695 | .minver = 0, | ||
696 | .maxver = 0, | ||
697 | .want_minver = 0, | ||
698 | .want_maxver = 0, | ||
699 | }, | ||
700 | { | ||
701 | .ssl_method = DTLS_method, | ||
702 | .minver = 0, | ||
703 | .maxver = DTLS1_VERSION, | ||
704 | .want_minver = 0, | ||
705 | .want_maxver = DTLS1_VERSION, | ||
706 | }, | ||
707 | { | ||
708 | .ssl_method = DTLS_method, | ||
709 | .minver = DTLS1_VERSION, | ||
710 | .maxver = 0, | ||
711 | .want_minver = DTLS1_VERSION, | ||
712 | .want_maxver = 0, | ||
713 | }, | ||
714 | { | ||
715 | .ssl_method = DTLS_method, | ||
716 | .minver = DTLS1_VERSION, | ||
717 | .maxver = DTLS1_2_VERSION, | ||
718 | .want_minver = DTLS1_VERSION, | ||
719 | .want_maxver = DTLS1_2_VERSION, | ||
720 | }, | ||
721 | { | ||
722 | .ssl_method = DTLSv1_method, | ||
723 | .minver = 0, | ||
724 | .maxver = 0, | ||
725 | .want_minver = 0, | ||
726 | .want_maxver = 0, | ||
727 | }, | ||
728 | { | ||
729 | .ssl_method = DTLSv1_method, | ||
730 | .minver = DTLS1_VERSION, | ||
731 | .maxver = 0, | ||
732 | .want_minver = DTLS1_VERSION, | ||
733 | .want_maxver = 0, | ||
734 | }, | ||
735 | { | ||
736 | .ssl_method = DTLSv1_method, | ||
737 | .minver = 0, | ||
738 | .maxver = DTLS1_VERSION, | ||
739 | .want_minver = 0, | ||
740 | .want_maxver = DTLS1_VERSION, | ||
741 | }, | ||
742 | { | ||
743 | .ssl_method = DTLSv1_method, | ||
744 | .minver = 0, | ||
745 | .maxver = DTLS1_2_VERSION, | ||
746 | .want_minver = 0, | ||
747 | .want_maxver = DTLS1_VERSION, | ||
748 | }, | ||
749 | { | ||
750 | .ssl_method = DTLSv1_method, | ||
751 | .minver = TLS1_VERSION, | ||
752 | .maxver = TLS1_2_VERSION, | ||
753 | .want_minver = 0, | ||
754 | .want_maxver = 0, | ||
755 | .want_min_fail = 1, | ||
756 | .want_max_fail = 1, | ||
757 | }, | ||
758 | }; | ||
759 | |||
760 | #define N_MIN_MAX_VERSION_TESTS \ | ||
761 | (sizeof(min_max_version_tests) / sizeof(*min_max_version_tests)) | ||
762 | |||
763 | static int | ||
764 | test_ssl_min_max_version(void) | ||
765 | { | ||
766 | struct min_max_version_test *mmvt; | ||
767 | SSL_CTX *ssl_ctx = NULL; | ||
768 | SSL *ssl = NULL; | ||
769 | int failed = 0; | ||
770 | size_t i; | ||
771 | |||
772 | failed = 0; | ||
773 | |||
774 | fprintf(stderr, "INFO: starting min max version tests...\n"); | ||
775 | |||
776 | for (i = 0; i < N_MIN_MAX_VERSION_TESTS; i++) { | ||
777 | mmvt = &min_max_version_tests[i]; | ||
778 | |||
779 | if ((ssl_ctx = SSL_CTX_new(mmvt->ssl_method())) == NULL) { | ||
780 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
781 | return 1; | ||
782 | } | ||
783 | |||
784 | if (!SSL_CTX_set_min_proto_version(ssl_ctx, mmvt->minver)) { | ||
785 | if (!mmvt->want_min_fail) { | ||
786 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
787 | "SSL_CTX min version\n", i); | ||
788 | failed++; | ||
789 | } | ||
790 | goto next; | ||
791 | } | ||
792 | if (!SSL_CTX_set_max_proto_version(ssl_ctx, mmvt->maxver)) { | ||
793 | if (!mmvt->want_max_fail) { | ||
794 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
795 | "SSL_CTX min version\n", i); | ||
796 | failed++; | ||
797 | } | ||
798 | goto next; | ||
799 | } | ||
800 | |||
801 | if (mmvt->want_min_fail) { | ||
802 | fprintf(stderr, "FAIL: test %zu - successfully set " | ||
803 | "SSL_CTX min version, should have failed\n", i); | ||
804 | failed++; | ||
805 | goto next; | ||
806 | } | ||
807 | if (mmvt->want_max_fail) { | ||
808 | fprintf(stderr, "FAIL: test %zu - successfully set " | ||
809 | "SSL_CTX max version, should have failed\n", i); | ||
810 | failed++; | ||
811 | goto next; | ||
812 | } | ||
813 | |||
814 | if (SSL_CTX_get_min_proto_version(ssl_ctx) != mmvt->want_minver) { | ||
815 | fprintf(stderr, "FAIL: test %zu - got SSL_CTX min " | ||
816 | "version 0x%x, want 0x%x\n", i, | ||
817 | SSL_CTX_get_min_proto_version(ssl_ctx), mmvt->want_minver); | ||
818 | failed++; | ||
819 | goto next; | ||
820 | } | ||
821 | if (SSL_CTX_get_max_proto_version(ssl_ctx) != mmvt->want_maxver) { | ||
822 | fprintf(stderr, "FAIL: test %zu - got SSL_CTX max " | ||
823 | "version 0x%x, want 0x%x\n", i, | ||
824 | SSL_CTX_get_max_proto_version(ssl_ctx), mmvt->want_maxver); | ||
825 | failed++; | ||
826 | goto next; | ||
827 | } | ||
828 | |||
829 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
830 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
831 | return 1; | ||
832 | } | ||
833 | |||
834 | if (SSL_get_min_proto_version(ssl) != mmvt->want_minver) { | ||
835 | fprintf(stderr, "FAIL: test %zu - initial SSL min " | ||
836 | "version 0x%x, want 0x%x\n", i, | ||
837 | SSL_get_min_proto_version(ssl), mmvt->want_minver); | ||
838 | failed++; | ||
839 | goto next; | ||
840 | } | ||
841 | if (SSL_get_max_proto_version(ssl) != mmvt->want_maxver) { | ||
842 | fprintf(stderr, "FAIL: test %zu - initial SSL max " | ||
843 | "version 0x%x, want 0x%x\n", i, | ||
844 | SSL_get_max_proto_version(ssl), mmvt->want_maxver); | ||
845 | failed++; | ||
846 | goto next; | ||
847 | } | ||
848 | |||
849 | if (!SSL_set_min_proto_version(ssl, mmvt->minver)) { | ||
850 | if (mmvt->want_min_fail) { | ||
851 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
852 | "SSL min version\n", i); | ||
853 | failed++; | ||
854 | } | ||
855 | goto next; | ||
856 | } | ||
857 | if (!SSL_set_max_proto_version(ssl, mmvt->maxver)) { | ||
858 | if (mmvt->want_max_fail) { | ||
859 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
860 | "SSL min version\n", i); | ||
861 | failed++; | ||
862 | } | ||
863 | goto next; | ||
864 | } | ||
865 | |||
866 | if (mmvt->want_min_fail) { | ||
867 | fprintf(stderr, "FAIL: test %zu - successfully set SSL " | ||
868 | "min version, should have failed\n", i); | ||
869 | failed++; | ||
870 | goto next; | ||
871 | } | ||
872 | if (mmvt->want_max_fail) { | ||
873 | fprintf(stderr, "FAIL: test %zu - successfully set SSL " | ||
874 | "max version, should have failed\n", i); | ||
875 | failed++; | ||
876 | goto next; | ||
877 | } | ||
878 | |||
879 | if (SSL_get_min_proto_version(ssl) != mmvt->want_minver) { | ||
880 | fprintf(stderr, "FAIL: test %zu - got SSL min " | ||
881 | "version 0x%x, want 0x%x\n", i, | ||
882 | SSL_get_min_proto_version(ssl), mmvt->want_minver); | ||
883 | failed++; | ||
884 | goto next; | ||
885 | } | ||
886 | if (SSL_get_max_proto_version(ssl) != mmvt->want_maxver) { | ||
887 | fprintf(stderr, "FAIL: test %zu - got SSL max " | ||
888 | "version 0x%x, want 0x%x\n", i, | ||
889 | SSL_get_max_proto_version(ssl), mmvt->want_maxver); | ||
890 | failed++; | ||
891 | goto next; | ||
892 | } | ||
893 | |||
894 | next: | ||
895 | SSL_CTX_free(ssl_ctx); | ||
896 | SSL_free(ssl); | ||
897 | |||
898 | ssl_ctx = NULL; | ||
899 | ssl = NULL; | ||
900 | } | ||
901 | |||
902 | return (failed); | ||
903 | } | ||
904 | |||
905 | int | ||
906 | main(int argc, char **argv) | ||
907 | { | ||
908 | int failed = 0; | ||
909 | |||
910 | SSL_library_init(); | ||
911 | |||
912 | /* XXX - Test ssl_supported_version_range() */ | ||
913 | |||
914 | failed |= test_ssl_enabled_version_range(); | ||
915 | failed |= test_ssl_max_shared_version(); | ||
916 | failed |= test_ssl_min_max_version(); | ||
917 | |||
918 | if (failed == 0) | ||
919 | printf("PASS %s\n", __FILE__); | ||
920 | |||
921 | return (failed); | ||
922 | } | ||
diff --git a/src/regress/lib/libssl/unit/tests.h b/src/regress/lib/libssl/unit/tests.h deleted file mode 100644 index 287816946a..0000000000 --- a/src/regress/lib/libssl/unit/tests.h +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | /* $OpenBSD: tests.h,v 1.1 2015/06/27 23:35:52 doug Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2015 Doug Hogan <doug@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 | #ifndef LIBRESSL_REGRESS_TESTS_H__ | ||
19 | #define LIBRESSL_REGRESS_TESTS_H__ 1 | ||
20 | |||
21 | /* Ugly macros that are useful for regression tests. */ | ||
22 | |||
23 | #define SKIP(a) do { \ | ||
24 | printf("Skipping test in %s [%s:%d]\n", __func__, __FILE__, \ | ||
25 | __LINE__); \ | ||
26 | } while (0) | ||
27 | |||
28 | #define CHECK(a) do { \ | ||
29 | if (!(a)) { \ | ||
30 | printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ | ||
31 | __LINE__); \ | ||
32 | return 0; \ | ||
33 | } \ | ||
34 | } while (0) | ||
35 | |||
36 | #define CHECK_GOTO(a) do { \ | ||
37 | if (!(a)) { \ | ||
38 | printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ | ||
39 | __LINE__); \ | ||
40 | goto err; \ | ||
41 | } \ | ||
42 | } while (0) | ||
43 | |||
44 | #endif /* LIBRESSL_REGRESS_TESTS_H__ */ | ||
diff --git a/src/regress/lib/libssl/unit/tls_ext_alpn.c b/src/regress/lib/libssl/unit/tls_ext_alpn.c deleted file mode 100644 index d00f3efb5f..0000000000 --- a/src/regress/lib/libssl/unit/tls_ext_alpn.c +++ /dev/null | |||
@@ -1,442 +0,0 @@ | |||
1 | /* $OpenBSD: tls_ext_alpn.c,v 1.9 2022/11/26 16:08:57 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2015 Doug Hogan <doug@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 | /* | ||
19 | * Test TLS extension Application-Layer Protocol Negotiation (RFC 7301). | ||
20 | */ | ||
21 | #include <stdio.h> | ||
22 | #include <openssl/ssl.h> | ||
23 | |||
24 | #include "ssl_local.h" | ||
25 | #include "ssl_tlsext.h" | ||
26 | |||
27 | #include "tests.h" | ||
28 | |||
29 | /* | ||
30 | * In the ProtocolNameList, ProtocolNames must not include empty strings and | ||
31 | * byte strings must not be truncated. | ||
32 | * | ||
33 | * This uses some of the IANA approved protocol names from: | ||
34 | * http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml | ||
35 | */ | ||
36 | |||
37 | /* Valid for client and server since it only has one name. */ | ||
38 | static uint8_t proto_single[] = { | ||
39 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
40 | 0x00, 0x0f, /* len */ | ||
41 | /* ExtensionType extension_type */ | ||
42 | 0x00, 0x10, /* ALPN */ | ||
43 | /* opaque extension_data<0..2^16-1> */ | ||
44 | 0x00, 0x0b, /* len */ | ||
45 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
46 | 0x00, 0x09, /* len of all names */ | ||
47 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
48 | 0x08, /* len */ | ||
49 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 | ||
50 | }; | ||
51 | |||
52 | /* Valid for client, but NOT server. Server must have exactly one name. */ | ||
53 | static uint8_t proto_multiple1[] = { | ||
54 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
55 | 0x00, 0x19, /* len */ | ||
56 | /* ExtensionType extension_type */ | ||
57 | 0x00, 0x10, /* ALPN */ | ||
58 | /* opaque extension_data<0..2^16-1> */ | ||
59 | 0x00, 0x15, /* len */ | ||
60 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
61 | 0x00, 0x13, /* len of all names */ | ||
62 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
63 | 0x08, /* len */ | ||
64 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
65 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
66 | 0x09, /* len */ | ||
67 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
68 | }; | ||
69 | |||
70 | /* Valid for client, but NOT server. Server must have exactly one name. */ | ||
71 | static uint8_t proto_multiple2[] = { | ||
72 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
73 | 0x00, 0x1c, /* len */ | ||
74 | /* ExtensionType extension_type */ | ||
75 | 0x00, 0x10, /* ALPN */ | ||
76 | /* opaque extension_data<0..2^16-1> */ | ||
77 | 0x00, 0x18, /* len */ | ||
78 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
79 | 0x00, 0x16, /* len of all names */ | ||
80 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
81 | 0x08, /* len */ | ||
82 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
83 | /* opaque ProtocolName<1..2^8-1> -- 'h2' */ | ||
84 | 0x02, /* len */ | ||
85 | 0x68, 0x32, | ||
86 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
87 | 0x09, /* len */ | ||
88 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
89 | }; | ||
90 | |||
91 | /* Valid for client, but NOT server. Server must have exactly one name. */ | ||
92 | static uint8_t proto_multiple3[] = { | ||
93 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
94 | 0x00, 0x20, /* len */ | ||
95 | /* ExtensionType extension_type */ | ||
96 | 0x00, 0x10, /* ALPN */ | ||
97 | /* opaque extension_data<0..2^16-1> */ | ||
98 | 0x00, 0x1c, /* len */ | ||
99 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
100 | 0x00, 0x1a, /* len of all names */ | ||
101 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
102 | 0x08, /* len */ | ||
103 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
104 | /* opaque ProtocolName<1..2^8-1> -- 'h2' */ | ||
105 | 0x02, /* len */ | ||
106 | 0x68, 0x32, | ||
107 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
108 | 0x09, /* len */ | ||
109 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e, | ||
110 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
111 | 0x03, /* len */ | ||
112 | 0x68, 0x32, 0x63 | ||
113 | }; | ||
114 | |||
115 | static uint8_t proto_empty[] = { | ||
116 | /* Extension extensions<0..2^16-1> -- All TLS extensions. */ | ||
117 | 0x00, 0x00, /* none present. */ | ||
118 | }; | ||
119 | |||
120 | /* Invalid for both client and server. Length is wrong. */ | ||
121 | static uint8_t proto_invalid_len1[] = { | ||
122 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
123 | 0x00, 0x0a, /* len */ | ||
124 | /* ExtensionType extension_type */ | ||
125 | 0x00, 0x10, /* ALPN */ | ||
126 | /* opaque extension_data<0..2^16-1> */ | ||
127 | 0x00, 0x06, /* len */ | ||
128 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
129 | 0x00, 0x04, /* len of all names */ | ||
130 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
131 | 0x04, /* XXX len too large */ | ||
132 | 0x68, 0x32, 0x63 | ||
133 | }; | ||
134 | static uint8_t proto_invalid_len2[] = { | ||
135 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
136 | 0x00, 0x0a, /* len */ | ||
137 | /* ExtensionType extension_type */ | ||
138 | 0x00, 0x10, /* ALPN */ | ||
139 | /* opaque extension_data<0..2^16-1> */ | ||
140 | 0x00, 0x06, /* len */ | ||
141 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
142 | 0x00, 0x04, /* len of all names */ | ||
143 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
144 | 0x02, /* XXX len too small */ | ||
145 | 0x68, 0x32, 0x63 | ||
146 | }; | ||
147 | static uint8_t proto_invalid_len3[] = { | ||
148 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
149 | 0x00, 0x0a, /* len */ | ||
150 | /* ExtensionType extension_type */ | ||
151 | 0x00, 0x10, /* ALPN */ | ||
152 | /* opaque extension_data<0..2^16-1> */ | ||
153 | 0x00, 0x06, /* len */ | ||
154 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
155 | 0x00, 0x03, /* XXX len too small */ | ||
156 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
157 | 0x03, /* len */ | ||
158 | 0x68, 0x32, 0x63 | ||
159 | }; | ||
160 | static uint8_t proto_invalid_len4[] = { | ||
161 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
162 | 0x00, 0x0a, /* len */ | ||
163 | /* ExtensionType extension_type */ | ||
164 | 0x00, 0x10, /* ALPN */ | ||
165 | /* opaque extension_data<0..2^16-1> */ | ||
166 | 0x00, 0x06, /* len */ | ||
167 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
168 | 0x00, 0x06, /* XXX len too large */ | ||
169 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
170 | 0x03, /* len */ | ||
171 | 0x68, 0x32, 0x63 | ||
172 | }; | ||
173 | static uint8_t proto_invalid_len5[] = { | ||
174 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
175 | 0x00, 0x0a, /* len */ | ||
176 | /* ExtensionType extension_type */ | ||
177 | 0x00, 0x10, /* ALPN */ | ||
178 | /* opaque extension_data<0..2^16-1> */ | ||
179 | 0x01, 0x08, /* XXX len too large */ | ||
180 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
181 | 0x00, 0x04, /* len */ | ||
182 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
183 | 0x03, /* len */ | ||
184 | 0x68, 0x32, 0x63 | ||
185 | }; | ||
186 | static uint8_t proto_invalid_len6[] = { | ||
187 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
188 | 0x00, 0x0a, /* len */ | ||
189 | /* ExtensionType extension_type */ | ||
190 | 0x00, 0x10, /* ALPN */ | ||
191 | /* opaque extension_data<0..2^16-1> */ | ||
192 | 0x00, 0x05, /* XXX len too small */ | ||
193 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
194 | 0x00, 0x04, /* len */ | ||
195 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
196 | 0x03, /* len */ | ||
197 | 0x68, 0x32, 0x63 | ||
198 | }; | ||
199 | static uint8_t proto_invalid_len7[] = { | ||
200 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
201 | 0x00, 0x06, /* XXX len too small */ | ||
202 | /* ExtensionType extension_type */ | ||
203 | 0x00, 0x10, /* ALPN */ | ||
204 | /* opaque extension_data<0..2^16-1> */ | ||
205 | 0x00, 0x06, /* len */ | ||
206 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
207 | 0x00, 0x04, /* len */ | ||
208 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
209 | 0x03, /* len */ | ||
210 | 0x68, 0x32, 0x63 | ||
211 | }; | ||
212 | static uint8_t proto_invalid_len8[] = { | ||
213 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
214 | 0x00, 0x0b, /* XXX len too large */ | ||
215 | /* ExtensionType extension_type */ | ||
216 | 0x00, 0x10, /* ALPN */ | ||
217 | /* opaque extension_data<0..2^16-1> */ | ||
218 | 0x00, 0x06, /* len */ | ||
219 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
220 | 0x00, 0x04, /* len */ | ||
221 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
222 | 0x03, /* len */ | ||
223 | 0x68, 0x32, 0x63 | ||
224 | }; | ||
225 | |||
226 | /* Invalid for client and server since it is missing data. */ | ||
227 | static uint8_t proto_invalid_missing1[] = { | ||
228 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
229 | 0x00, 0x0a, /* len */ | ||
230 | /* ExtensionType extension_type */ | ||
231 | 0x00, 0x10, /* ALPN */ | ||
232 | /* opaque extension_data<0..2^16-1> */ | ||
233 | 0x00, 0x06, /* len */ | ||
234 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
235 | 0x00, 0x04, /* len of all names */ | ||
236 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
237 | /* XXX missing */ | ||
238 | }; | ||
239 | static uint8_t proto_invalid_missing2[] = { | ||
240 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
241 | 0x00, 0x0a, /* len */ | ||
242 | /* ExtensionType extension_type */ | ||
243 | 0x00, 0x10, /* ALPN */ | ||
244 | /* opaque extension_data<0..2^16-1> */ | ||
245 | 0x00, 0x00, /* XXX missing name list */ | ||
246 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
247 | }; | ||
248 | static uint8_t proto_invalid_missing3[] = { | ||
249 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
250 | 0x00, 0x0a, /* len */ | ||
251 | /* ExtensionType extension_type */ | ||
252 | 0x00, 0x10, /* ALPN */ | ||
253 | /* opaque extension_data<0..2^16-1> */ | ||
254 | 0x00, 0x02, /* XXX size is sufficient but missing data for name list */ | ||
255 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
256 | }; | ||
257 | static uint8_t proto_invalid_missing4[] = { | ||
258 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
259 | 0x00, 0x0a, /* len */ | ||
260 | /* ExtensionType extension_type */ | ||
261 | 0x00, 0x10, /* ALPN */ | ||
262 | /* opaque extension_data<0..2^16-1> */ | ||
263 | /* XXX missing */ | ||
264 | }; | ||
265 | static uint8_t proto_invalid_missing5[] = { | ||
266 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
267 | 0x00, 0x1c, /* len */ | ||
268 | /* ExtensionType extension_type */ | ||
269 | 0x00, 0x10, /* ALPN */ | ||
270 | /* opaque extension_data<0..2^16-1> */ | ||
271 | 0x00, 0x18, /* len */ | ||
272 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
273 | 0x00, 0x16, /* len of all names */ | ||
274 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
275 | 0x08, /* len */ | ||
276 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
277 | /* opaque ProtocolName<1..2^8-1> -- 'h2' */ | ||
278 | 0x02, /* len */ | ||
279 | 0x68, 0x32, | ||
280 | /* XXX missing name */ | ||
281 | }; | ||
282 | static uint8_t proto_invalid_missing6[] = { | ||
283 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
284 | 0x00, 0x07, /* len */ | ||
285 | /* ExtensionType extension_type */ | ||
286 | 0x00, 0x10, /* ALPN */ | ||
287 | /* opaque extension_data<0..2^16-1> */ | ||
288 | 0x00, 0x03, /* len */ | ||
289 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
290 | 0x00, 0x01, /* XXX len must be at least 2 */ | ||
291 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
292 | 0x00, /* XXX len cannot be 0 */ | ||
293 | }; | ||
294 | static uint8_t proto_invalid_missing7[] = { | ||
295 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
296 | 0x00, 0x07, /* len */ | ||
297 | /* ExtensionType extension_type */ | ||
298 | 0x00, 0x10, /* ALPN */ | ||
299 | /* opaque extension_data<0..2^16-1> */ | ||
300 | 0x00, 0x03, /* len */ | ||
301 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
302 | 0x00, 0x02, /* XXX len is at least 2 but not correct. */ | ||
303 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
304 | 0x00, /* XXX len cannot be 0 */ | ||
305 | }; | ||
306 | static uint8_t proto_invalid_missing8[] = { | ||
307 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
308 | 0x00, 0x01, /* len */ | ||
309 | /* ExtensionType extension_type */ | ||
310 | 0x00, /* XXX need a 2 byte type */ | ||
311 | }; | ||
312 | static uint8_t proto_invalid_missing9[] = { | ||
313 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
314 | 0x0a, /* XXX need a 2 byte len */ | ||
315 | }; | ||
316 | |||
317 | |||
318 | #define CHECK_BOTH(c_val, s_val, proto) do { \ | ||
319 | { \ | ||
320 | CBS cbs; \ | ||
321 | int al; \ | ||
322 | \ | ||
323 | CBS_init(&cbs, proto, sizeof(proto)); \ | ||
324 | CHECK(c_val == tlsext_server_parse(s, SSL_TLSEXT_MSG_CH, &cbs, &al)); \ | ||
325 | CBS_init(&cbs, proto, sizeof(proto)); \ | ||
326 | CHECK(s_val == tlsext_client_parse(s, SSL_TLSEXT_MSG_SH, &cbs, &al)); \ | ||
327 | } \ | ||
328 | } while (0) | ||
329 | |||
330 | static int dummy_alpn_cb(SSL *ssl, const unsigned char **out, | ||
331 | unsigned char *outlen, const unsigned char *in, unsigned int inlen, | ||
332 | void *arg); | ||
333 | |||
334 | static int | ||
335 | check_valid_alpn(SSL *s) | ||
336 | { | ||
337 | const uint8_t str[] = { | ||
338 | 0x08, /* len */ | ||
339 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 /* http/1.1 */ | ||
340 | }; | ||
341 | |||
342 | /* Setup in order to test ALPN. */ | ||
343 | CHECK(! SSL_set_alpn_protos(s, str, 9)); | ||
344 | SSL_CTX_set_alpn_select_cb(s->ctx, dummy_alpn_cb, NULL); | ||
345 | |||
346 | /* Prerequisites to test these. */ | ||
347 | CHECK(s->alpn_client_proto_list != NULL); | ||
348 | CHECK(s->ctx->alpn_select_cb != NULL); | ||
349 | //CHECK(s->s3->tmp.finish_md_len == 0); | ||
350 | |||
351 | CHECK_BOTH(1, 1, proto_single); | ||
352 | CHECK_BOTH(1, 1, proto_empty); | ||
353 | |||
354 | /* Multiple protocol names are only valid for client */ | ||
355 | CHECK_BOTH(1, 0, proto_multiple1); | ||
356 | CHECK_BOTH(1, 0, proto_multiple2); | ||
357 | CHECK_BOTH(1, 0, proto_multiple3); | ||
358 | |||
359 | return 1; | ||
360 | } | ||
361 | |||
362 | /* | ||
363 | * Some of the IANA approved IDs from: | ||
364 | * http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml | ||
365 | */ | ||
366 | static int | ||
367 | check_invalid_alpn(SSL *s) | ||
368 | { | ||
369 | const uint8_t str[] = { | ||
370 | 0x08, /* len */ | ||
371 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 /* http/1.1 */ | ||
372 | }; | ||
373 | |||
374 | /* Setup in order to test ALPN. */ | ||
375 | CHECK(! SSL_set_alpn_protos(s, str, 9)); | ||
376 | SSL_CTX_set_alpn_select_cb(s->ctx, dummy_alpn_cb, NULL); | ||
377 | |||
378 | /* Prerequisites to test these. */ | ||
379 | CHECK(s->alpn_client_proto_list != NULL); | ||
380 | CHECK(s->ctx->alpn_select_cb != NULL); | ||
381 | //CHECK(s->s3->tmp.finish_md_len == 0); | ||
382 | |||
383 | /* None of these are valid for client or server */ | ||
384 | CHECK_BOTH(0, 0, proto_invalid_len1); | ||
385 | CHECK_BOTH(0, 0, proto_invalid_len2); | ||
386 | CHECK_BOTH(0, 0, proto_invalid_len3); | ||
387 | CHECK_BOTH(0, 0, proto_invalid_len4); | ||
388 | CHECK_BOTH(0, 0, proto_invalid_len5); | ||
389 | CHECK_BOTH(0, 0, proto_invalid_len6); | ||
390 | CHECK_BOTH(0, 0, proto_invalid_len7); | ||
391 | CHECK_BOTH(0, 0, proto_invalid_len8); | ||
392 | CHECK_BOTH(0, 0, proto_invalid_missing1); | ||
393 | CHECK_BOTH(0, 0, proto_invalid_missing2); | ||
394 | CHECK_BOTH(0, 0, proto_invalid_missing3); | ||
395 | CHECK_BOTH(0, 0, proto_invalid_missing4); | ||
396 | CHECK_BOTH(0, 0, proto_invalid_missing5); | ||
397 | CHECK_BOTH(0, 0, proto_invalid_missing6); | ||
398 | CHECK_BOTH(0, 0, proto_invalid_missing7); | ||
399 | CHECK_BOTH(0, 0, proto_invalid_missing8); | ||
400 | CHECK_BOTH(0, 0, proto_invalid_missing9); | ||
401 | |||
402 | return 1; | ||
403 | } | ||
404 | |||
405 | int | ||
406 | dummy_alpn_cb(SSL *ssl __attribute__((unused)), const unsigned char **out, | ||
407 | unsigned char *outlen, const unsigned char *in, unsigned int inlen, | ||
408 | void *arg __attribute__((unused))) | ||
409 | { | ||
410 | *out = in; | ||
411 | *outlen = (unsigned char)inlen; | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | int | ||
417 | main(void) | ||
418 | { | ||
419 | SSL_CTX *ctx = NULL; | ||
420 | SSL *s = NULL; | ||
421 | int rv = 1; | ||
422 | |||
423 | SSL_library_init(); | ||
424 | |||
425 | CHECK_GOTO((ctx = SSL_CTX_new(TLSv1_2_client_method())) != NULL); | ||
426 | CHECK_GOTO((s = SSL_new(ctx)) != NULL); | ||
427 | |||
428 | if (!check_valid_alpn(s)) | ||
429 | goto err; | ||
430 | if (!check_invalid_alpn(s)) | ||
431 | goto err; | ||
432 | |||
433 | rv = 0; | ||
434 | |||
435 | err: | ||
436 | SSL_CTX_free(ctx); | ||
437 | SSL_free(s); | ||
438 | |||
439 | if (!rv) | ||
440 | printf("PASS %s\n", __FILE__); | ||
441 | return rv; | ||
442 | } | ||
diff --git a/src/regress/lib/libssl/unit/tls_prf.c b/src/regress/lib/libssl/unit/tls_prf.c deleted file mode 100644 index 8cb17cb057..0000000000 --- a/src/regress/lib/libssl/unit/tls_prf.c +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | /* $OpenBSD: tls_prf.c,v 1.11 2024/07/16 14:38:59 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2017 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 | |||
20 | #include "ssl_local.h" | ||
21 | |||
22 | int tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len, | ||
23 | const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len, | ||
24 | const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len, | ||
25 | const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len); | ||
26 | |||
27 | #define TLS_PRF_OUT_LEN 128 | ||
28 | |||
29 | struct tls_prf_test { | ||
30 | const unsigned char *desc; | ||
31 | const SSL_METHOD *(*ssl_method)(void); | ||
32 | const uint16_t cipher_value; | ||
33 | const unsigned char out[TLS_PRF_OUT_LEN]; | ||
34 | }; | ||
35 | |||
36 | static const struct tls_prf_test tls_prf_tests[] = { | ||
37 | { | ||
38 | .desc = "SHA256", | ||
39 | .ssl_method = TLSv1_2_method, | ||
40 | .cipher_value = 0x0033, | ||
41 | .out = { | ||
42 | 0x37, 0xa7, 0x06, 0x71, 0x6e, 0x19, 0x19, 0xda, | ||
43 | 0x23, 0x8c, 0xcc, 0xb4, 0x2f, 0x31, 0x64, 0x9d, | ||
44 | 0x05, 0x29, 0x1c, 0x33, 0x7e, 0x09, 0x1b, 0x0c, | ||
45 | 0x0e, 0x23, 0xc1, 0xb0, 0x40, 0xcc, 0x31, 0xf7, | ||
46 | 0x55, 0x66, 0x68, 0xd9, 0xa8, 0xae, 0x74, 0x75, | ||
47 | 0xf3, 0x46, 0xe9, 0x3a, 0x54, 0x9d, 0xe0, 0x8b, | ||
48 | 0x7e, 0x6c, 0x63, 0x1c, 0xfa, 0x2f, 0xfd, 0xc9, | ||
49 | 0xd3, 0xf1, 0xd3, 0xfe, 0x7b, 0x9e, 0x14, 0x95, | ||
50 | 0xb5, 0xd0, 0xad, 0x9b, 0xee, 0x78, 0x8c, 0x83, | ||
51 | 0x18, 0x58, 0x7e, 0xa2, 0x23, 0xc1, 0x8b, 0x62, | ||
52 | 0x94, 0x12, 0xcb, 0xb6, 0x60, 0x69, 0x32, 0xfe, | ||
53 | 0x98, 0x0e, 0x93, 0xb0, 0x8e, 0x5c, 0xfb, 0x6e, | ||
54 | 0xdb, 0x9a, 0xc2, 0x9f, 0x8c, 0x5c, 0x43, 0x19, | ||
55 | 0xeb, 0x4a, 0x52, 0xad, 0x62, 0x2b, 0xdd, 0x9f, | ||
56 | 0xa3, 0x74, 0xa6, 0x96, 0x61, 0x4d, 0x98, 0x40, | ||
57 | 0x63, 0xa6, 0xd4, 0xbb, 0x17, 0x11, 0x75, 0xed, | ||
58 | }, | ||
59 | }, | ||
60 | { | ||
61 | .desc = "SHA384", | ||
62 | .ssl_method = TLSv1_2_method, | ||
63 | .cipher_value = 0x009d, | ||
64 | .out = { | ||
65 | 0x00, 0x93, 0xc3, 0xfd, 0xa7, 0xbb, 0xdc, 0x5b, | ||
66 | 0x13, 0x3a, 0xe6, 0x8b, 0x1b, 0xac, 0xf3, 0xfb, | ||
67 | 0x3c, 0x9a, 0x78, 0xf6, 0x19, 0xf0, 0x13, 0x0f, | ||
68 | 0x0d, 0x01, 0x9d, 0xdf, 0x0a, 0x28, 0x38, 0xce, | ||
69 | 0x1a, 0x9b, 0x43, 0xbe, 0x56, 0x12, 0xa7, 0x16, | ||
70 | 0x58, 0xe1, 0x8a, 0xe4, 0xc5, 0xbb, 0x10, 0x4c, | ||
71 | 0x3a, 0xf3, 0x7f, 0xd3, 0xdb, 0xe4, 0xe0, 0x3d, | ||
72 | 0xcc, 0x83, 0xca, 0xf0, 0xf9, 0x69, 0xcc, 0x70, | ||
73 | 0x83, 0x32, 0xf6, 0xfc, 0x81, 0x80, 0x02, 0xe8, | ||
74 | 0x31, 0x1e, 0x7c, 0x3b, 0x34, 0xf7, 0x34, 0xd1, | ||
75 | 0xcf, 0x2a, 0xc4, 0x36, 0x2f, 0xe9, 0xaa, 0x7f, | ||
76 | 0x6d, 0x1f, 0x5e, 0x0e, 0x39, 0x05, 0x15, 0xe1, | ||
77 | 0xa2, 0x9a, 0x4d, 0x97, 0x8c, 0x62, 0x46, 0xf1, | ||
78 | 0x87, 0x65, 0xd8, 0xe9, 0x14, 0x11, 0xa6, 0x48, | ||
79 | 0xd7, 0x0e, 0x6e, 0x70, 0xad, 0xfb, 0x3f, 0x36, | ||
80 | 0x05, 0x76, 0x4b, 0xe4, 0x28, 0x50, 0x4a, 0xf2, | ||
81 | }, | ||
82 | }, | ||
83 | }; | ||
84 | |||
85 | #define N_TLS_PRF_TESTS \ | ||
86 | (sizeof(tls_prf_tests) / sizeof(*tls_prf_tests)) | ||
87 | |||
88 | #define TLS_PRF_SEED1 "tls prf seed 1" | ||
89 | #define TLS_PRF_SEED2 "tls prf seed 2" | ||
90 | #define TLS_PRF_SEED3 "tls prf seed 3" | ||
91 | #define TLS_PRF_SEED4 "tls prf seed 4" | ||
92 | #define TLS_PRF_SEED5 "tls prf seed 5" | ||
93 | #define TLS_PRF_SECRET "tls prf secretz" | ||
94 | |||
95 | static void | ||
96 | hexdump(const unsigned char *buf, size_t len) | ||
97 | { | ||
98 | size_t i; | ||
99 | |||
100 | for (i = 1; i <= len; i++) | ||
101 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
102 | |||
103 | fprintf(stderr, "\n"); | ||
104 | } | ||
105 | |||
106 | static int | ||
107 | do_tls_prf_test(int test_no, const struct tls_prf_test *tpt) | ||
108 | { | ||
109 | unsigned char *out = NULL; | ||
110 | const SSL_CIPHER *cipher; | ||
111 | SSL_CTX *ssl_ctx = NULL; | ||
112 | SSL *ssl = NULL; | ||
113 | int failure = 1; | ||
114 | int len; | ||
115 | |||
116 | fprintf(stderr, "Test %d - %s\n", test_no, tpt->desc); | ||
117 | |||
118 | if ((out = malloc(TLS_PRF_OUT_LEN)) == NULL) | ||
119 | errx(1, "failed to allocate out"); | ||
120 | |||
121 | if ((ssl_ctx = SSL_CTX_new(tpt->ssl_method())) == NULL) | ||
122 | errx(1, "failed to create SSL context"); | ||
123 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
124 | errx(1, "failed to create SSL context"); | ||
125 | |||
126 | if ((cipher = ssl3_get_cipher_by_value(tpt->cipher_value)) == NULL) { | ||
127 | fprintf(stderr, "FAIL: no cipher %hx\n", tpt->cipher_value); | ||
128 | goto failure; | ||
129 | } | ||
130 | |||
131 | ssl->s3->hs.cipher = cipher; | ||
132 | |||
133 | for (len = 1; len <= TLS_PRF_OUT_LEN; len++) { | ||
134 | memset(out, 'A', TLS_PRF_OUT_LEN); | ||
135 | |||
136 | if (tls1_PRF(ssl, TLS_PRF_SECRET, sizeof(TLS_PRF_SECRET), | ||
137 | TLS_PRF_SEED1, sizeof(TLS_PRF_SEED1), TLS_PRF_SEED2, | ||
138 | sizeof(TLS_PRF_SEED2), TLS_PRF_SEED3, sizeof(TLS_PRF_SEED3), | ||
139 | TLS_PRF_SEED4, sizeof(TLS_PRF_SEED4), TLS_PRF_SEED5, | ||
140 | sizeof(TLS_PRF_SEED5), out, len) != 1) { | ||
141 | fprintf(stderr, "FAIL: tls_PRF failed for len %d\n", | ||
142 | len); | ||
143 | goto failure; | ||
144 | } | ||
145 | |||
146 | if (memcmp(out, tpt->out, len) != 0) { | ||
147 | fprintf(stderr, "FAIL: tls_PRF output differs for " | ||
148 | "len %d\n", len); | ||
149 | fprintf(stderr, "output:\n"); | ||
150 | hexdump(out, TLS_PRF_OUT_LEN); | ||
151 | fprintf(stderr, "test data:\n"); | ||
152 | hexdump(tpt->out, TLS_PRF_OUT_LEN); | ||
153 | fprintf(stderr, "\n"); | ||
154 | goto failure; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | failure = 0; | ||
159 | |||
160 | failure: | ||
161 | SSL_free(ssl); | ||
162 | SSL_CTX_free(ssl_ctx); | ||
163 | |||
164 | free(out); | ||
165 | |||
166 | return failure; | ||
167 | } | ||
168 | |||
169 | int | ||
170 | main(int argc, char **argv) | ||
171 | { | ||
172 | int failed = 0; | ||
173 | size_t i; | ||
174 | |||
175 | SSL_library_init(); | ||
176 | SSL_load_error_strings(); | ||
177 | |||
178 | for (i = 0; i < N_TLS_PRF_TESTS; i++) | ||
179 | failed |= do_tls_prf_test(i, &tls_prf_tests[i]); | ||
180 | |||
181 | return failed; | ||
182 | } | ||