Debian Codegraph @

crt/s2n/tests/integrationv2/configuration.py

raw symbols SCIP
1 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 # SPDX-License-Identifier: Apache-2.0
3 import collections
4
5 from common import Certificates, Ciphers, Curves, Protocols, AvailablePorts
6 from constants import TEST_SNI_CERT_DIRECTORY
7 from providers import S2N, OpenSSL, JavaSSL
8
9
10 # The boolean configuration will let a test run for True and False
11 # for some value. For example, using the insecure flag.
12 BOOLEAN = [True, False]
13
14
15 # List of all protocols to be tested
16 PROTOCOLS = [
17 Protocols.TLS13,
18 Protocols.TLS12,
19 Protocols.TLS11,
20 Protocols.TLS10,
21 Protocols.SSLv3,
22 ]
23
24
25 # List of providers that will be tested.
26 PROVIDERS = [S2N, OpenSSL, JavaSSL]
27
28
29 # List of binary TLS13 settings
30 TLS13 = [True, False]
31
32
33 # List of all curves that will be tested.
34 ALL_TEST_CURVES = [Curves.X25519, Curves.P256, Curves.P384, Curves.P521]
35
36
37 # List of all certificates that will be tested.
38 ALL_TEST_CERTS = [
39 Certificates.RSA_1024_SHA256,
40 Certificates.RSA_1024_SHA384,
41 Certificates.RSA_1024_SHA512,
42 Certificates.RSA_2048_SHA256,
43 Certificates.RSA_2048_SHA384,
44 Certificates.RSA_2048_SHA512,
45 Certificates.RSA_3072_SHA256,
46 Certificates.RSA_3072_SHA384,
47 Certificates.RSA_3072_SHA512,
48 Certificates.RSA_4096_SHA256,
49 Certificates.RSA_4096_SHA384,
50 Certificates.RSA_4096_SHA512,
51 Certificates.ECDSA_256,
52 Certificates.ECDSA_384,
53 Certificates.ECDSA_521,
54 Certificates.RSA_PSS_2048_SHA256,
55 ]
56
57
58 # List of certificates which enable all cipher suites
59 MINIMAL_TEST_CERTS = [
60 Certificates.RSA_2048_SHA512,
61 Certificates.RSA_4096_SHA256,
62 Certificates.ECDSA_256,
63 Certificates.ECDSA_384,
64 Certificates.RSA_PSS_2048_SHA256,
65 Certificates.ECDSA_521,
66 ]
67
68
69 # List of all ciphers that will be tested.
70 ALL_TEST_CIPHERS = [
71 Ciphers.DHE_RSA_AES128_SHA,
72 Ciphers.DHE_RSA_AES256_SHA,
73 Ciphers.DHE_RSA_AES128_SHA256,
74 Ciphers.DHE_RSA_AES256_SHA256,
75 Ciphers.DHE_RSA_AES128_GCM_SHA256,
76 Ciphers.DHE_RSA_AES256_GCM_SHA384,
77 Ciphers.DHE_RSA_CHACHA20_POLY1305,
78 Ciphers.AES128_SHA,
79 Ciphers.AES256_SHA,
80 Ciphers.AES128_SHA256,
81 Ciphers.AES256_SHA256,
82 Ciphers.AES128_GCM_SHA256,
83 Ciphers.AES256_GCM_SHA384,
84 Ciphers.ECDHE_ECDSA_AES128_GCM_SHA256,
85 Ciphers.ECDHE_ECDSA_AES256_GCM_SHA384,
86 Ciphers.ECDHE_ECDSA_AES128_SHA256,
87 Ciphers.ECDHE_ECDSA_AES256_SHA384,
88 Ciphers.ECDHE_ECDSA_AES128_SHA,
89 Ciphers.ECDHE_ECDSA_AES256_SHA,
90 Ciphers.ECDHE_ECDSA_CHACHA20_POLY1305,
91 Ciphers.ECDHE_RSA_AES128_SHA,
92 Ciphers.ECDHE_RSA_AES256_SHA,
93 Ciphers.ECDHE_RSA_AES128_SHA256,
94 Ciphers.ECDHE_RSA_AES256_SHA384,
95 Ciphers.ECDHE_RSA_AES128_GCM_SHA256,
96 Ciphers.ECDHE_RSA_AES256_GCM_SHA384,
97 Ciphers.ECDHE_RSA_CHACHA20_POLY1305,
98 Ciphers.CHACHA20_POLY1305_SHA256,
99 ]
100
101 # List of ciphers containing a small variety of symmetric ciphers
102 # with a small variety of auth methods.
103 MINIMAL_TEST_CIPHERS = [
104 Ciphers.DHE_RSA_AES128_SHA,
105 Ciphers.AES256_SHA,
106 Ciphers.ECDHE_ECDSA_AES128_GCM_SHA256,
107 Ciphers.ECDHE_RSA_AES256_GCM_SHA384,
108 Ciphers.ECDHE_RSA_CHACHA20_POLY1305,
109 Ciphers.CHACHA20_POLY1305_SHA256,
110 Ciphers.AES256_GCM_SHA384,
111 ]
112
113 # List of TLS13 Ciphers
114 TLS13_CIPHERS = [
115 Ciphers.CHACHA20_POLY1305_SHA256,
116 Ciphers.AES128_GCM_SHA256,
117 Ciphers.AES256_GCM_SHA384,
118 ]
119
120 S2N_TEST_POLICIES = [
121 Ciphers.SECURITY_POLICY_DEFAULT,
122 Ciphers.SECURITY_POLICY_DEFAULT_TLS12,
123 Ciphers.SECURITY_POLICY_DEFAULT_TLS13,
124 ]
125
126
127 # List of ports available to tests.
128 available_ports = AvailablePorts()
129
130
131 # Server certificates used to test matching domain names client with server_name
132 # ( cert_path, private_key_path, domains[] )
133 SNI_CERTS = {
134 "alligator": (
135 TEST_SNI_CERT_DIRECTORY + "alligator_cert.pem",
136 TEST_SNI_CERT_DIRECTORY + "alligator_key.pem",
137 ["www.alligator.com"],
138 ),
139 "second_alligator_rsa": (
140 TEST_SNI_CERT_DIRECTORY + "second_alligator_rsa_cert.pem",
141 TEST_SNI_CERT_DIRECTORY + "second_alligator_rsa_key.pem",
142 ["www.alligator.com"],
143 ),
144 "alligator_ecdsa": (
145 TEST_SNI_CERT_DIRECTORY + "alligator_ecdsa_cert.pem",
146 TEST_SNI_CERT_DIRECTORY + "alligator_ecdsa_key.pem",
147 ["www.alligator.com"],
148 ),
149 "beaver": (
150 TEST_SNI_CERT_DIRECTORY + "beaver_cert.pem",
151 TEST_SNI_CERT_DIRECTORY + "beaver_key.pem",
152 ["www.beaver.com"],
153 ),
154 "many_animals": (
155 TEST_SNI_CERT_DIRECTORY + "many_animal_sans_rsa_cert.pem",
156 TEST_SNI_CERT_DIRECTORY + "many_animal_sans_rsa_key.pem",
157 [
158 "www.catfish.com",
159 "www.dolphin.com",
160 "www.elephant.com",
161 "www.falcon.com",
162 "www.gorilla.com",
163 "www.horse.com",
164 "www.impala.com",
165 # "Simple hostname"
166 "Jackal",
167 "k.e.e.l.b.i.l.l.e.d.t.o.u.c.a.n",
168 # SAN on this cert is actually "ladybug.ladybug"
169 # Verify case insensitivity works as expected.
170 "LADYBUG.LADYBUG",
171 "com.penguin.macaroni",
172 ],
173 ),
174 "narwhal_cn": (
175 TEST_SNI_CERT_DIRECTORY + "narwhal_cn_cert.pem",
176 TEST_SNI_CERT_DIRECTORY + "narwhal_cn_key.pem",
177 ["www.narwhal.com"],
178 ),
179 "octopus_cn_platypus_san": (
180 TEST_SNI_CERT_DIRECTORY + "octopus_cn_platypus_san_cert.pem",
181 TEST_SNI_CERT_DIRECTORY + "octopus_cn_platypus_san_key.pem",
182 ["www.platypus.com"],
183 ),
184 "quail_cn_rattlesnake_cn": (
185 TEST_SNI_CERT_DIRECTORY + "quail_cn_rattlesnake_cn_cert.pem",
186 TEST_SNI_CERT_DIRECTORY + "quail_cn_rattlesnake_cn_key.pem",
187 ["www.quail.com", "www.rattlesnake.com"],
188 ),
189 "many_animals_mixed_case": (
190 TEST_SNI_CERT_DIRECTORY + "many_animal_sans_mixed_case_rsa_cert.pem",
191 TEST_SNI_CERT_DIRECTORY + "many_animal_sans_mixed_case_rsa_key.pem",
192 [
193 "alligator.com",
194 "beaver.com",
195 "catFish.com",
196 "WWW.dolphin.COM",
197 "www.ELEPHANT.com",
198 "www.Falcon.Com",
199 "WWW.gorilla.COM",
200 "www.horse.com",
201 "WWW.IMPALA.COM",
202 "WwW.jAcKaL.cOm",
203 ],
204 ),
205 "embedded_wildcard": (
206 TEST_SNI_CERT_DIRECTORY + "embedded_wildcard_rsa_cert.pem",
207 TEST_SNI_CERT_DIRECTORY + "embedded_wildcard_rsa_key.pem",
208 ["www.labelstart*labelend.com"],
209 ),
210 "non_empty_label_wildcard": (
211 TEST_SNI_CERT_DIRECTORY + "non_empty_label_wildcard_rsa_cert.pem",
212 TEST_SNI_CERT_DIRECTORY + "non_empty_label_wildcard_rsa_key.pem",
213 ["WILD*.middle.end"],
214 ),
215 "trailing_wildcard": (
216 TEST_SNI_CERT_DIRECTORY + "trailing_wildcard_rsa_cert.pem",
217 TEST_SNI_CERT_DIRECTORY + "trailing_wildcard_rsa_key.pem",
218 ["the.prefix.*"],
219 ),
220 "wildcard_insect": (
221 TEST_SNI_CERT_DIRECTORY + "wildcard_insect_rsa_cert.pem",
222 TEST_SNI_CERT_DIRECTORY + "wildcard_insect_rsa_key.pem",
223 [
224 "ant.insect.hexapod",
225 "BEE.insect.hexapod",
226 "wasp.INSECT.hexapod",
227 "butterfly.insect.hexapod",
228 ],
229 ),
230 "termite": (
231 TEST_SNI_CERT_DIRECTORY + "termite_rsa_cert.pem",
232 TEST_SNI_CERT_DIRECTORY + "termite_rsa_key.pem",
233 ["termite.insect.hexapod"],
234 ),
235 "underwing": (
236 TEST_SNI_CERT_DIRECTORY + "underwing_ecdsa_cert.pem",
237 TEST_SNI_CERT_DIRECTORY + "underwing_ecdsa_key.pem",
238 ["underwing.insect.hexapod"],
239 ),
240 }
241
242
243 # Test cases for certificate selection.
244 # Test inputs: server certificates to load into s2nd, client SNI and capabilities, outputs are selected server cert
245 # and negotiated cipher.
246 MultiCertTest = collections.namedtuple(
247 "MultiCertTest",
248 "description server_certs client_sni client_ciphers expected_cert expect_matching_hostname",
249 )
250 MULTI_CERT_TEST_CASES = [
251 MultiCertTest(
252 description="Test basic SNI match for default cert.",
253 server_certs=[
254 SNI_CERTS["alligator"],
255 SNI_CERTS["beaver"],
256 SNI_CERTS["alligator_ecdsa"],
257 ],
258 client_sni="www.alligator.com",
259 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
260 expected_cert=SNI_CERTS["alligator"],
261 expect_matching_hostname=True,
262 ),
263 MultiCertTest(
264 description="Test basic SNI matches for non-default cert.",
265 server_certs=[
266 SNI_CERTS["alligator"],
267 SNI_CERTS["beaver"],
268 SNI_CERTS["alligator_ecdsa"],
269 ],
270 client_sni="www.beaver.com",
271 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
272 expected_cert=SNI_CERTS["beaver"],
273 expect_matching_hostname=True,
274 ),
275 MultiCertTest(
276 description="Test default cert is selected when there are no SNI matches.",
277 server_certs=[
278 SNI_CERTS["alligator"],
279 SNI_CERTS["beaver"],
280 SNI_CERTS["alligator_ecdsa"],
281 ],
282 client_sni="not.a.match",
283 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
284 expected_cert=SNI_CERTS["alligator"],
285 expect_matching_hostname=False,
286 ),
287 MultiCertTest(
288 description="Test default cert is selected when no SNI is sent.",
289 server_certs=[
290 SNI_CERTS["alligator"],
291 SNI_CERTS["beaver"],
292 SNI_CERTS["alligator_ecdsa"],
293 ],
294 client_sni=None,
295 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
296 expected_cert=SNI_CERTS["alligator"],
297 expect_matching_hostname=False,
298 ),
299 MultiCertTest(
300 description="Test ECDSA cert is selected with matching domain and client only supports ECDSA.",
301 server_certs=[
302 SNI_CERTS["alligator"],
303 SNI_CERTS["beaver"],
304 SNI_CERTS["alligator_ecdsa"],
305 ],
306 client_sni="www.alligator.com",
307 client_ciphers=[Ciphers.ECDHE_ECDSA_AES128_SHA],
308 expected_cert=SNI_CERTS["alligator_ecdsa"],
309 expect_matching_hostname=True,
310 ),
311 MultiCertTest(
312 description="Test ECDSA cert selected when: domain matches for both ECDSA+RSA, client supports ECDSA+RSA "
313 " ciphers, ECDSA is higher priority on server side.",
314 server_certs=[
315 SNI_CERTS["alligator"],
316 SNI_CERTS["beaver"],
317 SNI_CERTS["alligator_ecdsa"],
318 ],
319 client_sni="www.alligator.com",
320 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA, Ciphers.ECDHE_ECDSA_AES128_SHA],
321 expected_cert=SNI_CERTS["alligator_ecdsa"],
322 expect_matching_hostname=True,
323 ),
324 MultiCertTest(
325 description="Test domain match is highest priority. Domain matching ECDSA certificate should be selected"
326 " even if domain mismatched RSA certificate is available and RSA cipher is higher priority.",
327 server_certs=[SNI_CERTS["beaver"], SNI_CERTS["alligator_ecdsa"]],
328 client_sni="www.alligator.com",
329 client_ciphers=[
330 Ciphers.ECDHE_RSA_AES128_SHA256,
331 Ciphers.ECDHE_ECDSA_AES128_SHA256,
332 ],
333 expected_cert=SNI_CERTS["alligator_ecdsa"],
334 expect_matching_hostname=True,
335 ),
336 MultiCertTest(
337 description="Test certificate with single SAN entry matching is selected before mismatched multi SAN cert",
338 server_certs=[SNI_CERTS["many_animals"], SNI_CERTS["alligator"]],
339 client_sni="www.alligator.com",
340 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
341 expected_cert=SNI_CERTS["alligator"],
342 expect_matching_hostname=True,
343 ),
344 # many_animals was the first cert added
345 MultiCertTest(
346 description="Test default cert with multiple sans and no SNI sent.",
347 server_certs=[SNI_CERTS["many_animals"], SNI_CERTS["alligator"]],
348 client_sni=None,
349 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
350 expected_cert=SNI_CERTS["many_animals"],
351 expect_matching_hostname=False,
352 ),
353 MultiCertTest(
354 description="Test certificate match with CN",
355 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["narwhal_cn"]],
356 client_sni="www.narwhal.com",
357 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
358 expected_cert=SNI_CERTS["narwhal_cn"],
359 expect_matching_hostname=True,
360 ),
361 MultiCertTest(
362 description="Test SAN+CN cert can match using SAN.",
363 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["octopus_cn_platypus_san"]],
364 client_sni="www.platypus.com",
365 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
366 expected_cert=SNI_CERTS["octopus_cn_platypus_san"],
367 expect_matching_hostname=True,
368 ),
369 MultiCertTest(
370 description="Test that CN is not considered for matching if the certificate contains SANs.",
371 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["octopus_cn_platypus_san"]],
372 client_sni="www.octopus.com",
373 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
374 expected_cert=SNI_CERTS["alligator"],
375 expect_matching_hostname=False,
376 ),
377 MultiCertTest(
378 description="Test certificate with multiple CNs can match.",
379 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["quail_cn_rattlesnake_cn"]],
380 client_sni="www.rattlesnake.com",
381 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
382 expected_cert=SNI_CERTS["quail_cn_rattlesnake_cn"],
383 expect_matching_hostname=False,
384 ),
385 MultiCertTest(
386 description="Test cert with embedded wildcard is not treated as a wildcard.",
387 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["embedded_wildcard"]],
388 client_sni="www.labelstartWILDCARDlabelend.com",
389 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
390 expected_cert=SNI_CERTS["alligator"],
391 expect_matching_hostname=False,
392 ),
393 MultiCertTest(
394 description="Test non empty left label wildcard cert is not treated as a wildcard."
395 " s2n only supports wildcards with a single * as the left label",
396 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["non_empty_label_wildcard"]],
397 client_sni="WILDCARD.middle.end",
398 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
399 expected_cert=SNI_CERTS["alligator"],
400 expect_matching_hostname=False,
401 ),
402 MultiCertTest(
403 description="Test cert with trailing * is not treated as wildcard.",
404 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["trailing_wildcard"]],
405 client_sni="the.prefix.WILDCARD",
406 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
407 expected_cert=SNI_CERTS["alligator"],
408 expect_matching_hostname=False,
409 ),
410 MultiCertTest(
411 description="Certificate with exact sni match(termite.insect.hexapod) is preferred over wildcard"
412 " *.insect.hexapod",
413 server_certs=[
414 SNI_CERTS["wildcard_insect"],
415 SNI_CERTS["alligator"],
416 SNI_CERTS["termite"],
417 ],
418 client_sni="termite.insect.hexapod",
419 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
420 expected_cert=SNI_CERTS["termite"],
421 expect_matching_hostname=True,
422 ),
423 MultiCertTest(
424 description="ECDSA Certificate with exact sni match(underwing.insect.hexapod) is preferred over RSA wildcard"
425 " *.insect.hexapod when RSA ciphers are higher priority than ECDSA in server preferences.",
426 server_certs=[
427 SNI_CERTS["wildcard_insect"],
428 SNI_CERTS["alligator"],
429 SNI_CERTS["underwing"],
430 ],
431 client_sni="underwing.insect.hexapod",
432 client_ciphers=[
433 Ciphers.ECDHE_RSA_AES128_GCM_SHA256,
434 Ciphers.ECDHE_ECDSA_AES128_GCM_SHA256,
435 ],
436 expected_cert=SNI_CERTS["underwing"],
437 expect_matching_hostname=True,
438 ),
439 MultiCertTest(
440 description="Firstly loaded matching certificate should be selected among certificates with the same domain names",
441 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["second_alligator_rsa"]],
442 client_sni="www.alligator.com",
443 client_ciphers=[Ciphers.AES128_GCM_SHA256],
444 expected_cert=SNI_CERTS["alligator"],
445 expect_matching_hostname=True,
446 ),
447 MultiCertTest(
448 description="Firstly loaded matching certificate should be selected among matching+non-matching certificates",
449 server_certs=[
450 SNI_CERTS["beaver"],
451 SNI_CERTS["alligator"],
452 SNI_CERTS["second_alligator_rsa"],
453 ],
454 client_sni="www.alligator.com",
455 client_ciphers=[Ciphers.AES128_GCM_SHA256],
456 expected_cert=SNI_CERTS["alligator"],
457 expect_matching_hostname=True,
458 ),
459 ]
460 # Positive test for wildcard matches
461 MULTI_CERT_TEST_CASES.extend(
462 [
463 MultiCertTest(
464 description="Test wildcard *.insect.hexapod matches subdomain "
465 + specific_insect_domain,
466 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["wildcard_insect"]],
467 client_sni=specific_insect_domain,
468 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
469 expected_cert=SNI_CERTS["wildcard_insect"],
470 expect_matching_hostname=True,
471 )
472 for specific_insect_domain in SNI_CERTS["wildcard_insect"][2]
473 ]
474 )
475 # Positive test for basic SAN matches
476 MULTI_CERT_TEST_CASES.extend(
477 [
478 MultiCertTest(
479 description="Match SAN " + many_animal_domain + " in many_animals cert",
480 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["many_animals"]],
481 client_sni=many_animal_domain,
482 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
483 expected_cert=SNI_CERTS["many_animals"],
484 expect_matching_hostname=True,
485 )
486 for many_animal_domain in SNI_CERTS["many_animals"][2]
487 ]
488 )
489 # Positive test for mixed cased SAN matches
490 MULTI_CERT_TEST_CASES.extend(
491 [
492 MultiCertTest(
493 description="Match SAN "
494 + many_animal_domain
495 + " in many_animals_mixed_case cert",
496 server_certs=[SNI_CERTS["alligator"], SNI_CERTS["many_animals_mixed_case"]],
497 client_sni=many_animal_domain,
498 client_ciphers=[Ciphers.ECDHE_RSA_AES128_SHA],
499 expected_cert=SNI_CERTS["many_animals_mixed_case"],
500 expect_matching_hostname=True,
501 )
502 for many_animal_domain in SNI_CERTS["many_animals_mixed_case"][2]
503 ]
504 )