Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # generate_tls13_compat_tests.py |
| 4 | # |
| 5 | # Copyright The Mbed TLS Contributors |
| 6 | # SPDX-License-Identifier: Apache-2.0 |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | # not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | |
| 20 | """ |
| 21 | Generate TLSv1.3 Compat test cases |
| 22 | |
| 23 | """ |
| 24 | |
| 25 | import sys |
| 26 | import abc |
| 27 | import argparse |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 28 | import itertools |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 29 | |
| 30 | # pylint: disable=useless-super-delegation |
| 31 | |
| 32 | CERTIFICATES = { |
| 33 | 'ecdsa_secp256r1_sha256': ( |
| 34 | 'data_files/ecdsa_secp256r1_sha256.crt', |
| 35 | 'data_files/ecdsa_secp256r1_sha256.key'), |
| 36 | 'ecdsa_secp384r1_sha384': ( |
| 37 | 'data_files/ecdsa_secp384r1_sha384.crt', |
| 38 | 'data_files/ecdsa_secp384r1_sha384.key'), |
| 39 | 'ecdsa_secp521r1_sha512': ( |
| 40 | 'data_files/ecdsa_secp521r1_sha512.crt', |
| 41 | 'data_files/ecdsa_secp521r1_sha512.key'), |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 42 | 'rsa_pss_rsae_sha256': ( |
| 43 | 'data_files/server2-sha256.crt', 'data_files/server2.key' |
| 44 | ) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 45 | } |
| 46 | |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 47 | |
| 48 | |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 49 | CAFILE = { |
| 50 | 'ecdsa_secp256r1_sha256': 'data_files/test-ca2.crt', |
| 51 | 'ecdsa_secp384r1_sha384': 'data_files/test-ca2.crt', |
| 52 | 'ecdsa_secp521r1_sha512': 'data_files/test-ca2.crt', |
| 53 | 'rsa_pss_rsae_sha256': 'data_files/test-ca_cat12.crt' |
| 54 | } |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 55 | |
| 56 | CIPHER_SUITE_IANA_VALUE = { |
| 57 | "TLS_AES_128_GCM_SHA256": 0x1301, |
| 58 | "TLS_AES_256_GCM_SHA384": 0x1302, |
| 59 | "TLS_CHACHA20_POLY1305_SHA256": 0x1303, |
| 60 | "TLS_AES_128_CCM_SHA256": 0x1304, |
| 61 | "TLS_AES_128_CCM_8_SHA256": 0x1305 |
| 62 | } |
| 63 | |
| 64 | SIG_ALG_IANA_VALUE = { |
| 65 | "ecdsa_secp256r1_sha256": 0x0403, |
| 66 | "ecdsa_secp384r1_sha384": 0x0503, |
| 67 | "ecdsa_secp521r1_sha512": 0x0603, |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 68 | 'rsa_pss_rsae_sha256': 0x0804, |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | NAMED_GROUP_IANA_VALUE = { |
| 72 | 'secp256r1': 0x17, |
| 73 | 'secp384r1': 0x18, |
| 74 | 'secp521r1': 0x19, |
| 75 | 'x25519': 0x1d, |
| 76 | 'x448': 0x1e, |
| 77 | } |
| 78 | |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 79 | OUTPUT_FILE=sys.stdout |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 80 | |
| 81 | def remove_duplicates(seq): |
| 82 | seen = set() |
| 83 | seen_add = seen.add |
| 84 | return [x for x in seq if not (x in seen or seen_add(x))] |
| 85 | |
| 86 | |
| 87 | class TLSProgram(metaclass=abc.ABCMeta): |
| 88 | """ |
| 89 | Base class for generate server/client command. |
| 90 | """ |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 91 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 92 | def __init__(self, ciphersuite, signature_algorithm, named_group): |
| 93 | self._cipher = ciphersuite |
| 94 | self._sig_alg = signature_algorithm |
| 95 | self._named_group = named_group |
| 96 | self.add_ciphersuites(ciphersuite) |
| 97 | self.add_named_groups(named_group) |
| 98 | self.add_signature_algorithms(signature_algorithm) |
| 99 | |
| 100 | @abc.abstractmethod |
| 101 | def add_ciphersuites(self, *ciphersuites): |
| 102 | pass |
| 103 | |
| 104 | @abc.abstractmethod |
| 105 | def add_signature_algorithms(self, *signature_algorithms): |
| 106 | pass |
| 107 | |
| 108 | @abc.abstractmethod |
| 109 | def add_named_groups(self, *named_groups): |
| 110 | pass |
| 111 | |
| 112 | @abc.abstractmethod |
| 113 | def pre_checks(self): |
| 114 | return [] |
| 115 | |
| 116 | @abc.abstractmethod |
| 117 | def cmd(self): |
| 118 | pass |
| 119 | |
| 120 | @abc.abstractmethod |
| 121 | def post_checks(self): |
| 122 | return [] |
| 123 | |
| 124 | |
| 125 | class OpenSSLServ(TLSProgram): |
| 126 | """ |
| 127 | Generate test commands for OpenSSL server. |
| 128 | """ |
| 129 | program = '$OPENSSL_NEXT' |
| 130 | |
| 131 | def __init__( |
| 132 | self, |
| 133 | ciphersuite, |
| 134 | signature_algorithm, |
| 135 | named_group): |
| 136 | self.ciphersuites = [] |
| 137 | self.named_groups = [] |
| 138 | self.signature_algorithms = [] |
| 139 | self.certificates = [] |
| 140 | super().__init__(ciphersuite, signature_algorithm, named_group) |
| 141 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 142 | def add_ciphersuites(self, *ciphersuites): |
| 143 | self.ciphersuites.extend(ciphersuites) |
| 144 | |
| 145 | def add_signature_algorithms(self, *signature_algorithms): |
| 146 | self.signature_algorithms.extend(signature_algorithms) |
| 147 | for sig_alg in signature_algorithms: |
| 148 | self.certificates.append(CERTIFICATES[sig_alg]) |
| 149 | |
| 150 | NAMED_GROUP = { |
| 151 | 'secp256r1': 'P-256', |
| 152 | 'secp384r1': 'P-384', |
| 153 | 'secp521r1': 'P-521', |
| 154 | 'x25519': 'X25519', |
| 155 | 'x448': 'X448', |
| 156 | } |
| 157 | |
| 158 | def add_named_groups(self, *named_groups): |
| 159 | for named_group in named_groups: |
| 160 | self.named_groups.append(self.NAMED_GROUP[named_group]) |
| 161 | |
| 162 | def cmd(self): |
| 163 | ret = ['$O_NEXT_SRV_NO_CERT'] |
| 164 | for cert, key in self.certificates: |
| 165 | ret += ['-cert {cert} -key {key}'.format(cert=cert, key=key)] |
| 166 | ret += ['-accept $SRV_PORT'] |
| 167 | ciphersuites = ','.join(self.ciphersuites) |
| 168 | signature_algorithms = ','.join(self.signature_algorithms) |
| 169 | named_groups = ','.join(self.named_groups) |
| 170 | ret += ["-ciphersuites {ciphersuites}".format(ciphersuites=ciphersuites), |
| 171 | "-sigalgs {signature_algorithms}".format( |
| 172 | signature_algorithms=signature_algorithms), |
| 173 | "-groups {named_groups}".format(named_groups=named_groups)] |
| 174 | ret += ['-msg -tls1_3 -no_middlebox -num_tickets 0 -no_resume_ephemeral -no_cache'] |
| 175 | return ' '.join(ret) |
| 176 | |
| 177 | def pre_checks(self): |
| 178 | return ["requires_openssl_tls1_3"] |
| 179 | |
| 180 | def post_checks(self): |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 181 | return ['-c "HTTP/1.0 200 ok"'] |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 182 | |
| 183 | |
| 184 | class GnuTLSServ(TLSProgram): |
| 185 | """ |
| 186 | Generate test commands for GnuTLS server. |
| 187 | """ |
| 188 | |
| 189 | def __init__(self, ciphersuite, signature_algorithm, named_group): |
| 190 | self.priority_strings = [] |
| 191 | self.certificates = [] |
| 192 | super().__init__(ciphersuite, signature_algorithm, named_group) |
| 193 | |
| 194 | CIPHER_SUITE = { |
| 195 | 'TLS_AES_256_GCM_SHA384': [ |
| 196 | 'AES-256-GCM', |
| 197 | 'SHA384', |
| 198 | 'AEAD'], |
| 199 | 'TLS_AES_128_GCM_SHA256': [ |
| 200 | 'AES-128-GCM', |
| 201 | 'SHA256', |
| 202 | 'AEAD'], |
| 203 | 'TLS_CHACHA20_POLY1305_SHA256': [ |
| 204 | 'CHACHA20-POLY1305', |
| 205 | 'SHA256', |
| 206 | 'AEAD'], |
| 207 | 'TLS_AES_128_CCM_SHA256': [ |
| 208 | 'AES-128-CCM', |
| 209 | 'SHA256', |
| 210 | 'AEAD'], |
| 211 | 'TLS_AES_128_CCM_8_SHA256': [ |
| 212 | 'AES-128-CCM-8', |
| 213 | 'SHA256', |
| 214 | 'AEAD']} |
| 215 | |
| 216 | def add_ciphersuites(self, *ciphersuites): |
Jerry Yu | d64e20d | 2021-11-26 10:50:01 +0800 | [diff] [blame] | 217 | for ciphersuite in ciphersuites: |
| 218 | self.priority_strings.extend(self.CIPHER_SUITE[ciphersuite]) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 219 | |
| 220 | SIGNATURE_ALGORITHM = { |
| 221 | 'ecdsa_secp256r1_sha256': ['SIGN-ECDSA-SECP256R1-SHA256'], |
| 222 | 'ecdsa_secp521r1_sha512': ['SIGN-ECDSA-SECP521R1-SHA512'], |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 223 | 'ecdsa_secp384r1_sha384': ['SIGN-ECDSA-SECP384R1-SHA384'], |
| 224 | 'rsa_pss_rsae_sha256': ['SIGN-RSA-PSS-RSAE-SHA256']} |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 225 | |
| 226 | def add_signature_algorithms(self, *signature_algorithms): |
| 227 | for sig_alg in signature_algorithms: |
| 228 | self.priority_strings.extend(self.SIGNATURE_ALGORITHM[sig_alg]) |
| 229 | self.certificates.append(CERTIFICATES[sig_alg]) |
| 230 | |
| 231 | NAMED_GROUP = { |
| 232 | 'secp256r1': ['GROUP-SECP256R1'], |
| 233 | 'secp384r1': ['GROUP-SECP384R1'], |
| 234 | 'secp521r1': ['GROUP-SECP521R1'], |
| 235 | 'x25519': ['GROUP-X25519'], |
| 236 | 'x448': ['GROUP-X448'], |
| 237 | } |
| 238 | |
| 239 | def add_named_groups(self, *named_groups): |
| 240 | for named_group in named_groups: |
| 241 | self.priority_strings.extend(self.NAMED_GROUP[named_group]) |
| 242 | |
| 243 | def pre_checks(self): |
| 244 | return ["requires_gnutls_tls1_3", |
| 245 | "requires_gnutls_next_no_ticket", |
| 246 | "requires_gnutls_next_disable_tls13_compat", ] |
| 247 | |
| 248 | def post_checks(self): |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 249 | return ['-c "HTTP/1.0 200 OK"'] |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 250 | |
| 251 | def cmd(self): |
| 252 | ret = [ |
| 253 | '$G_NEXT_SRV_NO_CERT', |
| 254 | '--http', |
| 255 | '--disable-client-cert', |
| 256 | '--debug=4'] |
| 257 | for cert, key in self.certificates: |
| 258 | ret += ['--x509certfile {cert} --x509keyfile {key}'.format( |
| 259 | cert=cert, key=key)] |
| 260 | priority_strings = ':+'.join(['NONE'] + |
| 261 | list(set(self.priority_strings)) + |
| 262 | ['VERS-TLS1.3']) |
| 263 | priority_strings += ':%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE' |
| 264 | ret += ['--priority={priority_strings}'.format( |
| 265 | priority_strings=priority_strings)] |
| 266 | ret = ' '.join(ret) |
| 267 | return ret |
| 268 | |
| 269 | |
| 270 | class MbedTLSCli(TLSProgram): |
| 271 | """ |
| 272 | Generate test commands for mbedTLS client. |
| 273 | """ |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 274 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 275 | def __init__(self, ciphersuite, signature_algorithm, named_group): |
| 276 | self.ciphersuites = [] |
| 277 | self.certificates = [] |
| 278 | self.signature_algorithms = [] |
| 279 | self.named_groups = [] |
| 280 | self.needed_named_groups = [] |
| 281 | super().__init__(ciphersuite, signature_algorithm, named_group) |
| 282 | |
| 283 | CIPHER_SUITE = { |
| 284 | 'TLS_AES_256_GCM_SHA384': 'TLS1-3-AES-256-GCM-SHA384', |
| 285 | 'TLS_AES_128_GCM_SHA256': 'TLS1-3-AES-128-GCM-SHA256', |
| 286 | 'TLS_CHACHA20_POLY1305_SHA256': 'TLS1-3-CHACHA20-POLY1305-SHA256', |
| 287 | 'TLS_AES_128_CCM_SHA256': 'TLS1-3-AES-128-CCM-SHA256', |
| 288 | 'TLS_AES_128_CCM_8_SHA256': 'TLS1-3-AES-128-CCM-8-SHA256'} |
| 289 | |
| 290 | def add_ciphersuites(self, *ciphersuites): |
Jerry Yu | d64e20d | 2021-11-26 10:50:01 +0800 | [diff] [blame] | 291 | for ciphersuite in ciphersuites: |
| 292 | self.ciphersuites.append(self.CIPHER_SUITE[ciphersuite]) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 293 | |
| 294 | def add_signature_algorithms(self, *signature_algorithms): |
| 295 | for sig_alg in signature_algorithms: |
| 296 | self.signature_algorithms.append(sig_alg) |
| 297 | if sig_alg == 'ecdsa_secp256r1_sha256': |
| 298 | self.needed_named_groups.append('secp256r1') |
| 299 | elif sig_alg == 'ecdsa_secp521r1_sha512': |
| 300 | self.needed_named_groups.append('secp521r1') |
| 301 | elif sig_alg == 'ecdsa_secp384r1_sha384': |
| 302 | self.needed_named_groups.append('secp384r1') |
| 303 | |
| 304 | self.certificates.append(CERTIFICATES[sig_alg]) |
| 305 | |
| 306 | def add_named_groups(self, *named_groups): |
| 307 | for named_group in named_groups: |
| 308 | self.named_groups.append(named_group) |
| 309 | |
| 310 | def pre_checks(self): |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 311 | |
| 312 | ret = ['requires_config_enabled MBEDTLS_DEBUG_C', |
| 313 | 'requires_config_enabled MBEDTLS_SSL_CLI_C', |
| 314 | 'requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL', |
| 315 | 'requires_config_disabled MBEDTLS_USE_PSA_CRYPTO'] |
| 316 | if 'rsa_pss_rsae_sha256' in self.signature_algorithms: |
| 317 | ret.append( |
| 318 | 'requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT') |
| 319 | return ret |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 320 | |
| 321 | def post_checks(self): |
| 322 | |
| 323 | check_strings = ["ECDH curve: {group}".format(group=self._named_group), |
| 324 | "server hello, chosen ciphersuite: ( {:04x} ) - {}".format( |
| 325 | CIPHER_SUITE_IANA_VALUE[self._cipher], |
| 326 | self.CIPHER_SUITE[self._cipher]), |
| 327 | "Certificate Verify: Signature algorithm ( {:04x} )".format( |
| 328 | SIG_ALG_IANA_VALUE[self._sig_alg]), |
| 329 | "Verifying peer X.509 certificate... ok", ] |
| 330 | return ['-c "{}"'.format(i) for i in check_strings] |
| 331 | |
| 332 | def cmd(self): |
| 333 | ret = ['$P_CLI'] |
| 334 | ret += [ |
| 335 | 'server_addr=127.0.0.1 server_port=$SRV_PORT', |
| 336 | 'debug_level=4 force_version=tls1_3'] |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 337 | ret += ['ca_file={CAFILE}'.format(CAFILE=CAFILE[self._sig_alg])] |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 338 | self.ciphersuites = list(set(self.ciphersuites)) |
| 339 | cipher = ','.join(self.ciphersuites) |
| 340 | if cipher: |
| 341 | ret += ["force_ciphersuite={cipher}".format(cipher=cipher)] |
| 342 | self.named_groups = remove_duplicates( |
| 343 | self.named_groups + self.needed_named_groups) |
| 344 | group = ','.join(self.named_groups) |
| 345 | if group: |
| 346 | ret += ["curves={group}".format(group=group)] |
| 347 | sig_alg = ','.join(self.signature_algorithms) |
| 348 | ret += ['sig_algs={sig_alg}'.format(sig_alg=sig_alg)] |
| 349 | ret = ' '.join(ret) |
| 350 | return ret |
| 351 | |
| 352 | |
| 353 | SERVER_CLS = {'OpenSSL': OpenSSLServ, 'GnuTLS': GnuTLSServ} |
| 354 | CLIENT_CLS = {'mbedTLS': MbedTLSCli} |
| 355 | |
| 356 | |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 357 | def generate_compat_test(server=None, client=None, cipher=None, # pylint: disable=unused-argument |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 358 | sig_alg=None, named_group=None, **kwargs): |
| 359 | """ |
| 360 | Generate test case with `ssl-opt.sh` format. |
| 361 | """ |
| 362 | name = 'TLS1.3 {client[0]}->{server[0]}: {cipher},{named_group},{sig_alg}'.format( |
| 363 | client=client, server=server, cipher=cipher, sig_alg=sig_alg, named_group=named_group) |
| 364 | server = SERVER_CLS[server](cipher, sig_alg, named_group) |
| 365 | client = CLIENT_CLS[client](cipher, sig_alg, named_group) |
| 366 | |
| 367 | cmd = ['run_test "{}"'.format(name), '"{}"'.format( |
| 368 | server.cmd()), '"{}"'.format(client.cmd()), '0'] |
| 369 | cmd += server.post_checks() |
| 370 | cmd += client.post_checks() |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 371 | prefix = ' \\\n' + (' '*9) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 372 | cmd = prefix.join(cmd) |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 373 | return '\n'.join(server.pre_checks() + client.pre_checks() + [cmd]) |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 374 | |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 375 | SSL_OUTPUT_HEADER='''#!/bin/sh |
| 376 | |
| 377 | # {filename} |
| 378 | # |
| 379 | # Copyright The Mbed TLS Contributors |
| 380 | # SPDX-License-Identifier: Apache-2.0 |
| 381 | # |
| 382 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 383 | # not use this file except in compliance with the License. |
| 384 | # You may obtain a copy of the License at |
| 385 | # |
| 386 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 387 | # |
| 388 | # Unless required by applicable law or agreed to in writing, software |
| 389 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 390 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 391 | # See the License for the specific language governing permissions and |
| 392 | # limitations under the License. |
| 393 | # |
| 394 | # Purpose |
| 395 | # |
| 396 | # List TLS1.3 compat test cases. They are generated by |
| 397 | # `generate_tls13_compat_tests.py -a`. |
| 398 | # |
| 399 | # PLEASE DO NOT EDIT THIS FILE. IF NEEDED, PLEASE MODIFY `generate_tls13_compat_tests.py` |
| 400 | # AND REGENERATE THIS FILE. |
| 401 | # |
| 402 | ''' |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 403 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 404 | def main(): |
| 405 | parser = argparse.ArgumentParser() |
| 406 | |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 407 | parser.add_argument('-o', '--output', nargs='?', |
| 408 | default=None, help='Output file path') |
| 409 | |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 410 | parser.add_argument('-a', '--generate-all-tls13-compat-tests', action='store_true', |
| 411 | default=False, help='Generate all available tls13 compat tests') |
| 412 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 413 | parser.add_argument('--list-ciphers', action='store_true', |
| 414 | default=False, help='List supported ciphersuites') |
| 415 | |
| 416 | parser.add_argument('--list-sig-algs', action='store_true', |
| 417 | default=False, help='List supported signature algorithms') |
| 418 | |
| 419 | parser.add_argument('--list-named-groups', action='store_true', |
| 420 | default=False, help='List supported named groups') |
| 421 | |
| 422 | parser.add_argument('--list-servers', action='store_true', |
| 423 | default=False, help='List supported TLS servers') |
| 424 | |
| 425 | parser.add_argument('--list-clients', action='store_true', |
| 426 | default=False, help='List supported TLS Clients') |
| 427 | |
| 428 | parser.add_argument('server', choices=SERVER_CLS.keys(), nargs='?', |
| 429 | default=list(SERVER_CLS.keys())[0], |
| 430 | help='Choose TLS server program for test') |
| 431 | parser.add_argument('client', choices=CLIENT_CLS.keys(), nargs='?', |
| 432 | default=list(CLIENT_CLS.keys())[0], |
| 433 | help='Choose TLS client program for test') |
| 434 | parser.add_argument('cipher', choices=CIPHER_SUITE_IANA_VALUE.keys(), nargs='?', |
| 435 | default=list(CIPHER_SUITE_IANA_VALUE.keys())[0], |
| 436 | help='Choose cipher suite for test') |
| 437 | parser.add_argument('sig_alg', choices=SIG_ALG_IANA_VALUE.keys(), nargs='?', |
| 438 | default=list(SIG_ALG_IANA_VALUE.keys())[0], |
| 439 | help='Choose cipher suite for test') |
| 440 | parser.add_argument('named_group', choices=NAMED_GROUP_IANA_VALUE.keys(), nargs='?', |
| 441 | default=list(NAMED_GROUP_IANA_VALUE.keys())[0], |
| 442 | help='Choose cipher suite for test') |
| 443 | |
| 444 | args = parser.parse_args() |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 445 | if args.output: |
| 446 | OUTPUT_FILE=open(args.output,'w') |
| 447 | OUTPUT_FILE.write(SSL_OUTPUT_HEADER.format(filename=args.output)) |
| 448 | |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 449 | if args.generate_all_tls13_compat_tests: |
| 450 | for i in itertools.product(CIPHER_SUITE_IANA_VALUE.keys(), SIG_ALG_IANA_VALUE.keys(), |
| 451 | NAMED_GROUP_IANA_VALUE.keys(), SERVER_CLS.keys(), |
| 452 | CLIENT_CLS.keys()): |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 453 | test_case = generate_compat_test( **dict( |
| 454 | zip(['cipher', 'sig_alg', 'named_group', 'server', 'client'], i))) |
| 455 | print(test_case,file=OUTPUT_FILE) |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 456 | return 0 |
| 457 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 458 | if args.list_ciphers or args.list_sig_algs or args.list_named_groups \ |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 459 | or args.list_servers or args.list_clients: |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 460 | if args.list_ciphers: |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 461 | print(*CIPHER_SUITE_IANA_VALUE.keys(),file=OUTPUT_FILE) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 462 | if args.list_sig_algs: |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 463 | print(*SIG_ALG_IANA_VALUE.keys(),file=OUTPUT_FILE) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 464 | if args.list_named_groups: |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 465 | print(*NAMED_GROUP_IANA_VALUE.keys(),file=OUTPUT_FILE) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 466 | if args.list_servers: |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 467 | print(*SERVER_CLS.keys(),file=OUTPUT_FILE) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 468 | if args.list_clients: |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 469 | print(*CLIENT_CLS.keys(),file=OUTPUT_FILE) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 470 | return 0 |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 471 | |
| 472 | print(generate_compat_test(**vars(args)),file=OUTPUT_FILE) |
| 473 | return 0 |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 474 | |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 475 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 476 | if __name__ == "__main__": |
| 477 | sys.exit(main()) |