|
5 | 5 | import pytest
|
6 | 6 | import threading
|
7 | 7 |
|
8 |
| -from common import ProviderOptions, Ciphers, Curves, Protocols, Signatures, Cert |
| 8 | +from common import ( |
| 9 | + ProviderOptions, |
| 10 | + Certificates, |
| 11 | + Ciphers, |
| 12 | + Curves, |
| 13 | + Protocols, |
| 14 | + Signatures, |
| 15 | + Cert, |
| 16 | +) |
9 | 17 | from global_flags import get_flag, S2N_PROVIDER_VERSION, S2N_FIPS_MODE
|
10 | 18 | from stat import S_IMODE
|
11 | 19 |
|
@@ -348,12 +356,22 @@ def setup_server(self):
|
348 | 356 |
|
349 | 357 |
|
350 | 358 | class OpenSSL(Provider):
|
| 359 | + result = subprocess.run( |
| 360 | + ["openssl", "version"], shell=False, capture_output=True, text=True |
| 361 | + ) |
| 362 | + # After splitting, version_str would be: ["OpenSSL", "3.0.8", "7", "Feb", "2023\n"] |
| 363 | + version_str = result.stdout.split(" ") |
| 364 | + # e.g., "OpenSSL" |
| 365 | + provider = version_str[0] |
| 366 | + # e.g., "3.0.8" |
| 367 | + version_openssl = version_str[1] |
| 368 | + |
351 | 369 | def __init__(self, options: ProviderOptions):
|
352 | 370 | Provider.__init__(self, options)
|
353 | 371 | # We print some OpenSSL logging that includes stderr
|
354 | 372 | self.expect_stderr = True # lgtm [py/overwritten-inherited-attribute]
|
355 | 373 | # Current provider needs 1.1.x https://github.com/aws/s2n-tls/issues/3963
|
356 |
| - self._is_openssl_11() |
| 374 | + self.at_least_openssl_1_1() |
357 | 375 |
|
358 | 376 | @classmethod
|
359 | 377 | def get_send_marker(cls):
|
@@ -408,30 +426,40 @@ def _cipher_to_cmdline(self, cipher):
|
408 | 426 |
|
409 | 427 | @classmethod
|
410 | 428 | def get_version(cls):
|
411 |
| - return get_flag(S2N_PROVIDER_VERSION) |
| 429 | + return cls.version_openssl |
| 430 | + |
| 431 | + @classmethod |
| 432 | + def get_provider(cls): |
| 433 | + return cls.provider |
412 | 434 |
|
413 | 435 | @classmethod
|
414 | 436 | def supports_protocol(cls, protocol):
|
415 |
| - if protocol is Protocols.SSLv3: |
416 |
| - return False |
| 437 | + if OpenSSL.get_version()[0:3] == "1.1": |
| 438 | + return protocol not in (Protocols.SSLv3,) |
| 439 | + elif OpenSSL.get_version()[0:3] == "3.0": |
| 440 | + return protocol not in (Protocols.SSLv3, Protocols.TLS10, Protocols.TLS11) |
| 441 | + else: |
| 442 | + return True |
| 443 | + |
| 444 | + @classmethod |
| 445 | + def supports_certificate(cls, cert: Cert): |
| 446 | + if OpenSSL.get_version()[0:3] >= "3.0": |
| 447 | + return cert not in ( |
| 448 | + Certificates.RSA_1024_SHA256, |
| 449 | + Certificates.RSA_1024_SHA384, |
| 450 | + Certificates.RSA_1024_SHA512, |
| 451 | + ) |
417 | 452 |
|
418 | 453 | return True
|
419 | 454 |
|
420 | 455 | @classmethod
|
421 | 456 | def supports_cipher(cls, cipher, with_curve=None):
|
422 | 457 | return True
|
423 | 458 |
|
424 |
| - def _is_openssl_11(self) -> None: |
425 |
| - result = subprocess.run( |
426 |
| - ["openssl", "version"], shell=False, capture_output=True, text=True |
427 |
| - ) |
428 |
| - version_str = result.stdout.split(" ") |
429 |
| - project = version_str[0] |
430 |
| - version = version_str[1] |
431 |
| - print(f"openssl version: {project} version: {version}") |
432 |
| - if project != "OpenSSL" or version[0:3] != "1.1": |
| 459 | + def at_least_openssl_1_1(self) -> None: |
| 460 | + if OpenSSL.get_version() < "1.1": |
433 | 461 | raise FileNotFoundError(
|
434 |
| - f"Openssl version returned {version}, expected 1.1.x." |
| 462 | + f"Openssl version returned {OpenSSL.get_version()}, expected at least 1.1.x." |
435 | 463 | )
|
436 | 464 |
|
437 | 465 | def setup_client(self):
|
|
0 commit comments