Skip to content

Commit 8da62d4

Browse files
johubertjjmayclin
authored andcommitted
test(integv2): add partial support for OpenSSL 3.0 provider (#5131)
Co-authored-by: James Mayclin <[email protected]>
1 parent 977363e commit 8da62d4

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

tests/integrationv2/conftest.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import pytest
55
from global_flags import set_flag, S2N_PROVIDER_VERSION, S2N_FIPS_MODE
6-
from providers import S2N, JavaSSL
6+
from providers import S2N, JavaSSL, OpenSSL
77

88
PATH_CONFIGURATION_KEY = pytest.StashKey()
99

@@ -30,6 +30,9 @@ def available_providers():
3030
if os.path.exists("./bin/SSLSocketClient.class"):
3131
providers.add(JavaSSL)
3232

33+
if OpenSSL.get_provider() == "OpenSSL" and OpenSSL.get_version() >= "3.0":
34+
providers.add(OpenSSL)
35+
3336
return providers
3437

3538

tests/integrationv2/providers.py

+43-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
import pytest
66
import threading
77

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+
)
917
from global_flags import get_flag, S2N_PROVIDER_VERSION, S2N_FIPS_MODE
1018
from stat import S_IMODE
1119

@@ -348,12 +356,22 @@ def setup_server(self):
348356

349357

350358
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+
351369
def __init__(self, options: ProviderOptions):
352370
Provider.__init__(self, options)
353371
# We print some OpenSSL logging that includes stderr
354372
self.expect_stderr = True # lgtm [py/overwritten-inherited-attribute]
355373
# 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()
357375

358376
@classmethod
359377
def get_send_marker(cls):
@@ -408,30 +426,40 @@ def _cipher_to_cmdline(self, cipher):
408426

409427
@classmethod
410428
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
412434

413435
@classmethod
414436
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+
)
417452

418453
return True
419454

420455
@classmethod
421456
def supports_cipher(cls, cipher, with_curve=None):
422457
return True
423458

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":
433461
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."
435463
)
436464

437465
def setup_client(self):

0 commit comments

Comments
 (0)