Skip to content

Commit c69a7f6

Browse files
Use more abstractions for protocol version formatting
Signed-off-by: Gilles Peskine <[email protected]>
1 parent 6749a8d commit c69a7f6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

scripts/generate_tls_handshake_tests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ def write_tls_handshake_defragmentation_test(
6464
tc.requirements.append('skip_next_test')
6565

6666
if version is not None:
67-
their_args += ' -tls1_' + str(version.value)
67+
their_args += ' ' + version.openssl_option()
6868
# Emit a version requirement, because we're forcing the version via
6969
# OpenSSL, not via Mbed TLS, and the automatic depdendencies in
7070
# ssl-opt.sh only handle forcing the version via Mbed TLS.
71-
tc.requirements.append('requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_' +
72-
str(version.value))
71+
tc.requirements.append(version.requires_command())
7372
if side == Side.SERVER and version == Version.TLS12 and \
7473
length is not None and \
7574
length <= TLS12_CLIENT_HELLO_ASSUMED_MAX_LENGTH:

scripts/mbedtls_framework/tls_test_case.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,22 @@ class Side(enum.Enum):
8080
SERVER = 1
8181

8282
class Version(enum.Enum):
83+
"""TLS protocol version.
84+
85+
This class doesn't know about DTLS yet.
86+
"""
87+
8388
TLS12 = 2
8489
TLS13 = 3
90+
91+
def force_version(self) -> str:
92+
"""Argument to pass to ssl_client2 or ssl_server2 to force this version."""
93+
return f'force_version=tls1{self.value}'
94+
95+
def openssl_option(self) -> str:
96+
"""Option to pass to openssl s_client or openssl s_server to select this version."""
97+
return f'-tls1_{self.value}'
98+
99+
def requires_command(self) -> str:
100+
"""Command to require this protocol version in an ssl-opt.sh test case."""
101+
return 'requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_' + str(self.value)

0 commit comments

Comments
 (0)