Debian Codegraph @

crt/s2n/tests/integrationv2/common.py

raw symbols SCIP
1 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 # SPDX-License-Identifier: Apache-2.0
3 import os
4 import re
5 import subprocess
6 import threading
7 import itertools
8 import random
9 import string
10 import pytest
11
12 from constants import TEST_CERT_DIRECTORY
13 from global_flags import get_flag, S2N_PROVIDER_VERSION
14
15
16 def data_bytes(n_bytes):
17 """
18 Generate bytes to send over the TLS connection.
19 These bytes purposefully fall outside of the ascii range
20 to prevent triggering "connected commands" present in
21 some SSL clients.
22 """
23 byte_array = [0] * n_bytes
24 allowed = [i for i in range(128, 255)]
25
26 j = 0
27 for i in range(n_bytes):
28 byte_array[i] = allowed[j]
29 j += 1
30 if j > 126:
31 j = 0
32
33 return bytes(byte_array)
34
35
36 def random_str(n):
37 return "".join(
38 random.choice(string.ascii_uppercase + string.digits) for _ in range(n)
39 )
40
41
42 def pq_enabled():
43 """
44 Returns true or false to indicate whether PQ crypto is enabled in s2n
45 """
46 return "awslc" in get_flag(S2N_PROVIDER_VERSION)
47
48
49 class AvailablePorts(object):
50 """
51 This iterator will atomically return the next number.
52 This is useful when running multiple tests in parallel
53 that all need unique port numbers.
54 """
55
56 def __init__(self, low=8000, high=30000):
57 worker_count = 1
58 # If pytest is being run in parallel, worker processes will have
59 # the WORKER_COUNT variable set.
60 parallel_workers = os.getenv("PYTEST_XDIST_WORKER_COUNT")
61 if parallel_workers is not None:
62 worker_count = int(parallel_workers)
63 chunk_size = int((high - low) / worker_count)
64
65 # If xdist is being used, parse the workerid from the envvar. This can
66 # be used to allocate unique ports to each worker.
67 worker = os.getenv("PYTEST_XDIST_WORKER")
68 worker_id = 0
69 if worker is not None:
70 worker_id = re.findall(r"gw(\d+)", worker)
71 if len(worker_id) != 0:
72 worker_id = int(worker_id[0])
73
74 # This is a naive way to allocate ports, but it allows us to cut
75 # the run time in half without workers colliding.
76 worker_offset = worker_id * chunk_size
77 base_range = range(low + worker_offset, high)
78 wrap_range = range(low, low + worker_offset)
79 self.ports = iter(itertools.chain(base_range, wrap_range))
80
81 self.lock = threading.Lock()
82
83 def __iter__(self):
84 return self
85
86 def __next__(self):
87 with self.lock:
88 return next(self.ports)
89
90
91 class TimeoutException(subprocess.SubprocessError):
92 """
93 TimeoutException wraps the subprocess class giving more control
94 over the formatting of output.
95 """
96
97 def __init__(self, timeout_exception):
98 self.exception = timeout_exception
99
100 def __str__(self):
101 cmd = " ".join(self.exception.cmd)
102 return "{} {}".format(self.exception, cmd)
103
104
105 class Cert(object):
106 def __init__(self, name, prefix, location=TEST_CERT_DIRECTORY):
107 self.name = name
108 self.cert = location + prefix + "_cert.pem"
109 self.key = location + prefix + "_key.pem"
110 self.algorithm = "ANY"
111 self.curve = None
112
113 if "ECDSA" in name:
114 self.algorithm = "EC"
115 self.curve = name[-3:]
116 elif "RSA" in name:
117 self.algorithm = "RSA"
118 if "PSS" in name:
119 self.algorithm = "RSAPSS"
120
121 def compatible_with_cipher(self, cipher):
122 if self.algorithm == cipher.algorithm:
123 return True
124 # TLS1.3 cipher suites do not specify auth method, so allow any auth method
125 if cipher.algorithm == "ANY":
126 return True
127 if self.algorithm == "RSAPSS":
128 # RSA-PSS certs can only be used by ciphers with RSA auth
129 if cipher.algorithm != "RSA":
130 return False
131 # RSA-PSS certs do not support RSA key exchange, only RSA auth
132 # "DHE" here is intended to capture both "DHE" and "ECDHE"
133 if "DHE" in cipher.name:
134 return True
135 return False
136
137 def compatible_with_curve(self, curve):
138 if self.algorithm != "EC":
139 return True
140 return curve.name[-3:] == self.curve
141
142 def compatible_with_sigalg(self, sigalg):
143 if self.algorithm != sigalg.algorithm:
144 return False
145 sig_alg_has_curve = (
146 sigalg.algorithm == "EC" and sigalg.min_protocol == Protocols.TLS13
147 )
148 if sig_alg_has_curve and self.curve not in sigalg.name:
149 return False
150 return True
151
152 def __str__(self):
153 return self.name
154
155
156 class Certificates(object):
157 """
158 When referencing certificates, use these values.
159 """
160
161 RSA_1024_SHA256 = Cert("RSA_1024_SHA256", "rsa_1024_sha256_client")
162 RSA_1024_SHA384 = Cert("RSA_1024_SHA384", "rsa_1024_sha384_client")
163 RSA_1024_SHA512 = Cert("RSA_1024_SHA512", "rsa_1024_sha512_client")
164 RSA_2048_SHA256 = Cert("RSA_2048_SHA256", "rsa_2048_sha256_client")
165 RSA_2048_SHA384 = Cert("RSA_2048_SHA384", "rsa_2048_sha384_client")
166 RSA_2048_SHA512 = Cert("RSA_2048_SHA512", "rsa_2048_sha512_client")
167 RSA_3072_SHA256 = Cert("RSA_3072_SHA256", "rsa_3072_sha256_client")
168 RSA_3072_SHA384 = Cert("RSA_3072_SHA384", "rsa_3072_sha384_client")
169 RSA_3072_SHA512 = Cert("RSA_3072_SHA512", "rsa_3072_sha512_client")
170 RSA_4096_SHA256 = Cert("RSA_4096_SHA256", "rsa_4096_sha256_client")
171 RSA_4096_SHA384 = Cert("RSA_4096_SHA384", "rsa_4096_sha384_client")
172 RSA_4096_SHA512 = Cert("RSA_4096_SHA512", "rsa_4096_sha512_client")
173
174 ECDSA_256 = Cert("ECDSA_256", "localhost_ecdsa_p256")
175 ECDSA_384 = Cert("ECDSA_384", "ecdsa_p384_pkcs1")
176 ECDSA_521 = Cert("ECDSA_521", "ecdsa_p521")
177
178 RSA_2048_SHA256_WILDCARD = Cert(
179 "RSA_2048_SHA256_WILDCARD", "rsa_2048_sha256_wildcard"
180 )
181 RSA_PSS_2048_SHA256 = Cert("RSA_PSS_2048_SHA256", "localhost_rsa_pss_2048_sha256")
182
183 RSA_2048_PKCS1 = Cert("RSA_2048_PKCS1", "rsa_2048_pkcs1")
184
185 OCSP = Cert("OCSP_RSA", "ocsp/server")
186 OCSP_ECDSA = Cert("OCSP_ECDSA_256", "ocsp/server_ecdsa")
187
188
189 class Protocol(object):
190 def __init__(self, name, value):
191 self.name = name
192 self.value = value
193
194 def __gt__(self, other):
195 return self.value > other.value
196
197 def __ge__(self, other):
198 return self.value >= other.value
199
200 def __lt__(self, other):
201 return self.value < other.value
202
203 def __le__(self, other):
204 return self.value <= other.value
205
206 def __eq__(self, other):
207 return other and self.value == other.value
208
209 def __str__(self):
210 return self.name
211
212
213 class Protocols(object):
214 """
215 When referencing protocols, use these protocol values.
216 The first argument is the human readable name. The second
217 argument is the S2N value. It is used for comparing
218 protocols. Since this is hardcoded in S2N, it is not
219 expected to change.
220 """
221
222 TLS13 = Protocol("TLS1.3", 34)
223 TLS12 = Protocol("TLS1.2", 33)
224 TLS11 = Protocol("TLS1.1", 32)
225 TLS10 = Protocol("TLS1.0", 31)
226 SSLv3 = Protocol("SSLv3", 30)
227 SSLv2 = Protocol("SSLv2", 20)
228
229
230 class Cipher(object):
231 def __init__(
232 self,
233 name,
234 min_version,
235 openssl1_1_1,
236 fips,
237 parameters=None,
238 iana_standard_name=None,
239 s2n=False,
240 pq=False,
241 ):
242 self.name = name
243 self.min_version = min_version
244 self.openssl1_1_1 = openssl1_1_1
245 self.fips = fips
246 self.parameters = parameters
247 self.iana_standard_name = iana_standard_name
248 self.s2n = s2n
249 self.pq = pq
250
251 if self.min_version >= Protocols.TLS13:
252 self.algorithm = "ANY"
253 elif iana_standard_name is None:
254 self.algorithm = "ANY"
255 elif "ECDSA" in iana_standard_name:
256 self.algorithm = "EC"
257 elif "RSA" in iana_standard_name:
258 self.algorithm = "RSA"
259 else:
260 pytest.fail("Unknown signature algorithm on cipher")
261
262 def __eq__(self, other):
263 return self.name == other
264
265 def __hash__(self):
266 return hash(self.name)
267
268 def __str__(self):
269 return self.name
270
271
272 class Ciphers(object):
273 """
274 When referencing ciphers, use these class values.
275 """
276
277 DHE_RSA_DES_CBC3_SHA = Cipher(
278 "DHE-RSA-DES-CBC3-SHA",
279 Protocols.SSLv3,
280 False,
281 False,
282 iana_standard_name="SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
283 )
284 DHE_RSA_AES128_SHA = Cipher(
285 "DHE-RSA-AES128-SHA",
286 Protocols.SSLv3,
287 True,
288 False,
289 TEST_CERT_DIRECTORY + "dhparams_2048.pem",
290 iana_standard_name="TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
291 )
292 DHE_RSA_AES256_SHA = Cipher(
293 "DHE-RSA-AES256-SHA",
294 Protocols.SSLv3,
295 True,
296 False,
297 TEST_CERT_DIRECTORY + "dhparams_2048.pem",
298 iana_standard_name="TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
299 )
300 DHE_RSA_AES128_SHA256 = Cipher(
301 "DHE-RSA-AES128-SHA256",
302 Protocols.TLS12,
303 True,
304 True,
305 TEST_CERT_DIRECTORY + "dhparams_2048.pem",
306 iana_standard_name="TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
307 )
308 DHE_RSA_AES256_SHA256 = Cipher(
309 "DHE-RSA-AES256-SHA256",
310 Protocols.TLS12,
311 True,
312 True,
313 TEST_CERT_DIRECTORY + "dhparams_2048.pem",
314 iana_standard_name="TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
315 )
316 DHE_RSA_AES128_GCM_SHA256 = Cipher(
317 "DHE-RSA-AES128-GCM-SHA256",
318 Protocols.TLS12,
319 True,
320 True,
321 TEST_CERT_DIRECTORY + "dhparams_2048.pem",
322 iana_standard_name="TLS_DHE_RSA_WITH_AES_128_GCM_SHA256",
323 )
324 DHE_RSA_AES256_GCM_SHA384 = Cipher(
325 "DHE-RSA-AES256-GCM-SHA384",
326 Protocols.TLS12,
327 True,
328 True,
329 TEST_CERT_DIRECTORY + "dhparams_2048.pem",
330 iana_standard_name="TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
331 )
332 DHE_RSA_CHACHA20_POLY1305 = Cipher(
333 "DHE-RSA-CHACHA20-POLY1305",
334 Protocols.TLS12,
335 True,
336 False,
337 TEST_CERT_DIRECTORY + "dhparams_2048.pem",
338 iana_standard_name="TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
339 )
340
341 AES128_SHA = Cipher(
342 "AES128-SHA",
343 Protocols.SSLv3,
344 True,
345 True,
346 iana_standard_name="TLS_RSA_WITH_AES_128_CBC_SHA",
347 )
348 AES256_SHA = Cipher(
349 "AES256-SHA",
350 Protocols.SSLv3,
351 True,
352 True,
353 iana_standard_name="TLS_RSA_WITH_AES_256_CBC_SHA",
354 )
355 AES128_SHA256 = Cipher(
356 "AES128-SHA256",
357 Protocols.TLS12,
358 True,
359 True,
360 iana_standard_name="TLS_RSA_WITH_AES_128_CBC_SHA256",
361 )
362 AES256_SHA256 = Cipher(
363 "AES256-SHA256",
364 Protocols.TLS12,
365 True,
366 True,
367 iana_standard_name="TLS_RSA_WITH_AES_256_CBC_SHA256",
368 )
369 AES128_GCM_SHA256 = Cipher(
370 "TLS_AES_128_GCM_SHA256",
371 Protocols.TLS13,
372 True,
373 True,
374 iana_standard_name="TLS_AES_128_GCM_SHA256",
375 )
376 AES256_GCM_SHA384 = Cipher(
377 "TLS_AES_256_GCM_SHA384",
378 Protocols.TLS13,
379 True,
380 True,
381 iana_standard_name="TLS_AES_256_GCM_SHA384",
382 )
383
384 ECDHE_ECDSA_AES128_SHA = Cipher(
385 "ECDHE-ECDSA-AES128-SHA",
386 Protocols.SSLv3,
387 True,
388 False,
389 iana_standard_name="TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
390 )
391 ECDHE_ECDSA_AES256_SHA = Cipher(
392 "ECDHE-ECDSA-AES256-SHA",
393 Protocols.SSLv3,
394 True,
395 False,
396 iana_standard_name="TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
397 )
398 ECDHE_ECDSA_AES128_SHA256 = Cipher(
399 "ECDHE-ECDSA-AES128-SHA256",
400 Protocols.TLS12,
401 True,
402 True,
403 iana_standard_name="TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
404 )
405 ECDHE_ECDSA_AES256_SHA384 = Cipher(
406 "ECDHE-ECDSA-AES256-SHA384",
407 Protocols.TLS12,
408 True,
409 True,
410 iana_standard_name="TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
411 )
412 ECDHE_ECDSA_AES128_GCM_SHA256 = Cipher(
413 "ECDHE-ECDSA-AES128-GCM-SHA256",
414 Protocols.TLS12,
415 True,
416 True,
417 iana_standard_name="TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
418 )
419 ECDHE_ECDSA_AES256_GCM_SHA384 = Cipher(
420 "ECDHE-ECDSA-AES256-GCM-SHA384",
421 Protocols.TLS12,
422 True,
423 True,
424 iana_standard_name="TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
425 )
426 ECDHE_ECDSA_CHACHA20_POLY1305 = Cipher(
427 "ECDHE-ECDSA-CHACHA20-POLY1305",
428 Protocols.TLS12,
429 True,
430 False,
431 iana_standard_name="TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
432 )
433
434 ECDHE_RSA_DES_CBC3_SHA = Cipher(
435 "ECDHE-RSA-DES-CBC3-SHA",
436 Protocols.SSLv3,
437 False,
438 False,
439 iana_standard_name="TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
440 )
441 ECDHE_RSA_AES128_SHA = Cipher(
442 "ECDHE-RSA-AES128-SHA",
443 Protocols.SSLv3,
444 True,
445 False,
446 iana_standard_name="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
447 )
448 ECDHE_RSA_AES256_SHA = Cipher(
449 "ECDHE-RSA-AES256-SHA",
450 Protocols.SSLv3,
451 True,
452 False,
453 iana_standard_name="TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
454 )
455 ECDHE_RSA_RC4_SHA = Cipher(
456 "ECDHE-RSA-RC4-SHA",
457 Protocols.SSLv3,
458 False,
459 False,
460 iana_standard_name="TLS_ECDHE_RSA_WITH_RC4_128_SHA",
461 )
462 ECDHE_RSA_AES128_SHA256 = Cipher(
463 "ECDHE-RSA-AES128-SHA256",
464 Protocols.TLS12,
465 True,
466 True,
467 iana_standard_name="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
468 )
469 ECDHE_RSA_AES256_SHA384 = Cipher(
470 "ECDHE-RSA-AES256-SHA384",
471 Protocols.TLS12,
472 True,
473 True,
474 iana_standard_name="TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
475 )
476 ECDHE_RSA_AES128_GCM_SHA256 = Cipher(
477 "ECDHE-RSA-AES128-GCM-SHA256",
478 Protocols.TLS12,
479 True,
480 True,
481 iana_standard_name="TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
482 )
483 ECDHE_RSA_AES256_GCM_SHA384 = Cipher(
484 "ECDHE-RSA-AES256-GCM-SHA384",
485 Protocols.TLS12,
486 True,
487 True,
488 iana_standard_name="TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
489 )
490 ECDHE_RSA_CHACHA20_POLY1305 = Cipher(
491 "ECDHE-RSA-CHACHA20-POLY1305",
492 Protocols.TLS12,
493 True,
494 False,
495 iana_standard_name="TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
496 )
497 CHACHA20_POLY1305_SHA256 = Cipher(
498 "TLS_CHACHA20_POLY1305_SHA256",
499 Protocols.TLS13,
500 True,
501 False,
502 iana_standard_name="TLS_CHACHA20_POLY1305_SHA256",
503 )
504
505 KMS_TLS_1_0_2018_10 = Cipher(
506 "KMS-TLS-1-0-2018-10", Protocols.TLS10, False, False, s2n=True
507 )
508 PQ_TLS_1_0_2023_01 = Cipher(
509 "PQ-TLS-1-0-2023-01-24", Protocols.TLS10, False, False, s2n=True, pq=True
510 )
511 PQ_TLS_1_3_2023_06_01 = Cipher(
512 "PQ-TLS-1-3-2023-06-01", Protocols.TLS12, False, False, s2n=True, pq=True
513 )
514
515 SECURITY_POLICY_DEFAULT = Cipher(
516 "default", Protocols.TLS12, False, False, s2n=True, pq=False
517 )
518 SECURITY_POLICY_DEFAULT_TLS13 = Cipher(
519 "default_tls13", Protocols.TLS12, False, False, s2n=True, pq=False
520 )
521 """
522 There is no "default_tls12" policy like there is a "default_tls13".
523 We could use "default", but we will someday add TLS1.3 support to "default".
524 Instead, pin to the latest version of "default" known to not include TLS1.3.
525 See https://github.com/aws/s2n-tls/blob/main/docs/usage-guide/topics/ch06-security-policies.md#default-policy-history
526 """
527 SECURITY_POLICY_DEFAULT_TLS12 = Cipher(
528 "20240501", Protocols.TLS12, False, False, s2n=True, pq=False
529 )
530
531 SECURITY_POLICY_20210816 = Cipher(
532 "20210816", Protocols.TLS12, False, False, s2n=True, pq=False
533 )
534
535 @staticmethod
536 def from_iana(iana_name):
537 ciphers = [
538 cipher
539 for attr in vars(Ciphers)
540 if not callable(cipher := getattr(Ciphers, attr))
541 and not attr.startswith("_")
542 and cipher.iana_standard_name
543 ]
544 return {cipher.iana_standard_name: cipher for cipher in ciphers}.get(iana_name)
545
546
547 class Curve(object):
548 def __init__(self, name, min_protocol=Protocols.SSLv3):
549 self.name = name
550 self.min_protocol = min_protocol
551
552 def __str__(self):
553 return self.name
554
555
556 class Curves(object):
557 """
558 When referencing curves, use these class values.
559 Don't hardcode curve names.
560 """
561
562 X25519 = Curve("X25519", Protocols.TLS13)
563 P256 = Curve("P-256")
564 # Our only SSLv3 provider doesn't support extensions
565 # so there is no way to negotiate a curve other than the
566 # default P-256 in SSLv3.
567 P384 = Curve("P-384", Protocols.TLS10)
568 P521 = Curve("P-521", Protocols.TLS10)
569
570 @staticmethod
571 def from_name(name):
572 curves = [
573 curve
574 for attr in vars(Curves)
575 if not callable(curve := getattr(Curves, attr))
576 and not attr.startswith("_")
577 and curve.name
578 ]
579 return {curve.name: curve for curve in curves}.get(name)
580
581
582 class Signature(object):
583 def __init__(
584 self,
585 name,
586 min_protocol=Protocols.SSLv3,
587 max_protocol=Protocols.TLS13,
588 sig_type=None,
589 sig_digest=None,
590 ):
591 self.min_protocol = min_protocol
592 self.max_protocol = max_protocol
593
594 if "RSA" in name.upper():
595 self.algorithm = "RSA"
596 if "PSS_PSS" in name.upper():
597 self.algorithm = "RSAPSS"
598 if "EC" in name.upper() or "ED" in name.upper():
599 self.algorithm = "EC"
600
601 if not (sig_type or sig_digest) and "+" in name:
602 sig_type, sig_digest = name.split("+")
603
604 self.name = name
605
606 self.sig_type = sig_type
607 self.sig_digest = sig_digest
608
609 def __str__(self):
610 return self.name
611
612
613 class Signatures(object):
614 NONE = Signature("None+None", max_protocol=Protocols.TLS13)
615 RSA_SHA1 = Signature("RSA+SHA1", max_protocol=Protocols.TLS12)
616 RSA_SHA224 = Signature("RSA+SHA224", max_protocol=Protocols.TLS12)
617 RSA_SHA256 = Signature("RSA+SHA256", max_protocol=Protocols.TLS12)
618 RSA_SHA384 = Signature("RSA+SHA384", max_protocol=Protocols.TLS12)
619 RSA_SHA512 = Signature("RSA+SHA512", max_protocol=Protocols.TLS12)
620 RSA_MD5_SHA1 = Signature("RSA+MD5_SHA1", max_protocol=Protocols.TLS11)
621 ECDSA_SHA224 = Signature("ECDSA+SHA224", max_protocol=Protocols.TLS12)
622 ECDSA_SHA256 = Signature("ECDSA+SHA256", max_protocol=Protocols.TLS12)
623 ECDSA_SHA384 = Signature("ECDSA+SHA384", max_protocol=Protocols.TLS12)
624 ECDSA_SHA512 = Signature("ECDSA+SHA512", max_protocol=Protocols.TLS12)
625 ECDSA_SHA1 = Signature("ECDSA+SHA1", max_protocol=Protocols.TLS12)
626
627 RSA_PSS_RSAE_SHA256 = Signature(
628 "RSA-PSS+SHA256", sig_type="RSA-PSS-RSAE", sig_digest="SHA256"
629 )
630
631 RSA_PSS_PSS_SHA256 = Signature(
632 "rsa_pss_pss_sha256",
633 min_protocol=Protocols.TLS12,
634 sig_type="RSA-PSS-PSS",
635 sig_digest="SHA256",
636 )
637
638 ECDSA_SECP256r1_SHA256 = Signature(
639 "ecdsa_secp256r1_sha256",
640 min_protocol=Protocols.TLS13,
641 sig_type="ECDSA",
642 sig_digest="SHA256",
643 )
644 ECDSA_SECP384r1_SHA384 = Signature(
645 "ecdsa_secp384r1_sha384",
646 min_protocol=Protocols.TLS13,
647 sig_type="ECDSA",
648 sig_digest="SHA384",
649 )
650 ECDSA_SECP521r1_SHA512 = Signature(
651 "ecdsa_secp521r1_sha512",
652 min_protocol=Protocols.TLS13,
653 sig_type="ECDSA",
654 sig_digest="SHA512",
655 )
656
657
658 class Results(object):
659 """
660 An instance of this object will be returned to the test by a managed_process'
661 get_results() method.
662 """
663
664 # Byte array containing the standard output of the process
665 stdout = None
666
667 # Byte array containing the standard error of the process
668 stderr = None
669
670 # Exit code of the process
671 exit_code = None
672
673 # Any exception thrown while running the process
674 exception = None
675
676 def __init__(
677 self,
678 stdout,
679 stderr,
680 exit_code,
681 exception,
682 expect_stderr=False,
683 expect_nonzero_exit=False,
684 ):
685 self.stdout = stdout
686 self.stderr = stderr
687 self.exit_code = exit_code
688 self.exception = exception
689 self.expect_stderr = expect_stderr
690 self.expect_nonzero_exit = expect_nonzero_exit
691
692 def __str__(self):
693 return "Stdout: {}\nStderr: {}\nExit code: {}\nException: {}".format(
694 self.stdout, self.stderr, self.exit_code, self.exception
695 )
696
697 def assert_success(self):
698 assert self.exception is None, self.exception
699 if not self.expect_nonzero_exit:
700 assert self.exit_code == 0, f"exit code: {self.exit_code}"
701 if not self.expect_stderr:
702 assert not self.stderr, self.stderr
703
704 def output_streams(self):
705 return {self.stdout, self.stderr}
706
707
708 class ProviderOptions(object):
709 def __init__(
710 self,
711 mode=None,
712 host=None,
713 port=None,
714 cipher=None,
715 curve=None,
716 key=None,
717 cert=None,
718 use_session_ticket=False,
719 insecure=False,
720 data_to_send=None,
721 use_client_auth=False,
722 extra_flags=None,
723 trust_store=None,
724 reconnects_before_exit=None,
725 reconnect=None,
726 verify_hostname=None,
727 server_name=None,
728 protocol=None,
729 use_mainline_version=None,
730 env_overrides=dict(),
731 enable_client_ocsp=False,
732 ocsp_response=None,
733 signature_algorithm=None,
734 record_size=None,
735 verbose=None,
736 echo=True,
737 ):
738 # Client or server
739 self.mode = mode
740
741 # Hostname
742 self.host = host
743 if not self.host:
744 self.host = "localhost"
745
746 # Port (string because this will be converted to a command line
747 self.port = str(port)
748
749 # Cipher suite
750 self.cipher = cipher
751
752 # Named curve
753 self.curve = curve
754
755 # Path to a key PEM
756 self.key = key
757
758 # Path to a certificate PEM
759 self.cert = cert
760
761 self.trust_store = trust_store
762
763 # Boolean whether to use a resumption ticket
764 self.use_session_ticket = use_session_ticket
765
766 # Boolean whether to disable x509 verification
767 self.insecure = insecure
768
769 # Which protocol to use with this provider
770 self.protocol = protocol
771
772 # This data will be sent to the peer
773 self.data_to_send = data_to_send
774
775 # Parameters to configure client authentication
776 self.use_client_auth = use_client_auth
777
778 # Reconnects on the server side (includes first connection)
779 self.reconnects_before_exit = reconnects_before_exit
780
781 # Tell the client to reconnect
782 self.reconnect = reconnect
783
784 # Tell the client to verify that the hostname returned by the server
785 # matches this argument
786 self.verify_hostname = verify_hostname
787
788 # Tell the client to send this server name to the server
789 self.server_name = server_name
790
791 # Extra flags to pass to the provider
792 self.extra_flags = extra_flags
793
794 # Boolean whether the provider is an older version of s2n
795 self.use_mainline_version = use_mainline_version
796
797 # Extra environment parameters
798 self.env_overrides = env_overrides
799
800 # Enable OCSP on the client
801 self.enable_client_ocsp = enable_client_ocsp
802
803 # Path to OCSP response on the server
804 self.ocsp_response = ocsp_response
805
806 self.signature_algorithm = signature_algorithm
807
808 self.record_size = record_size
809
810 # How verbose should the provider be when printing to stdout?
811 # Default to more information, leave the option for less.
812 # Useful if you find that debugging information is printed between
813 # application data you expect the provider to print on stdout.
814 self.verbose = verbose
815
816 # Should the provider echo any data sent / received?
817 # If not, the connection will be closed after one handshake.
818 self.echo = echo