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 |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 26 | import os |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 27 | import abc |
| 28 | import argparse |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 29 | import itertools |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 30 | |
| 31 | # pylint: disable=useless-super-delegation |
| 32 | |
| 33 | CERTIFICATES = { |
| 34 | 'ecdsa_secp256r1_sha256': ( |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 35 | 'data_files/ecdsa_secp256r1.crt', |
| 36 | 'data_files/ecdsa_secp256r1.key'), |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 37 | 'ecdsa_secp384r1_sha384': ( |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 38 | 'data_files/ecdsa_secp384r1.crt', |
| 39 | 'data_files/ecdsa_secp384r1.key'), |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 40 | 'ecdsa_secp521r1_sha512': ( |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 41 | 'data_files/ecdsa_secp521r1.crt', |
| 42 | 'data_files/ecdsa_secp521r1.key'), |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 43 | 'rsa_pss_rsae_sha256': ( |
| 44 | 'data_files/server2-sha256.crt', 'data_files/server2.key' |
| 45 | ) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 46 | } |
| 47 | |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 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 | |
| 79 | |
| 80 | def remove_duplicates(seq): |
| 81 | seen = set() |
| 82 | seen_add = seen.add |
| 83 | return [x for x in seq if not (x in seen or seen_add(x))] |
| 84 | |
| 85 | |
| 86 | class TLSProgram(metaclass=abc.ABCMeta): |
| 87 | """ |
| 88 | Base class for generate server/client command. |
| 89 | """ |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 90 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 91 | def __init__(self, ciphersuite, signature_algorithm, named_group): |
| 92 | self._cipher = ciphersuite |
| 93 | self._sig_alg = signature_algorithm |
| 94 | self._named_group = named_group |
| 95 | self.add_ciphersuites(ciphersuite) |
| 96 | self.add_named_groups(named_group) |
| 97 | self.add_signature_algorithms(signature_algorithm) |
| 98 | |
| 99 | @abc.abstractmethod |
| 100 | def add_ciphersuites(self, *ciphersuites): |
| 101 | pass |
| 102 | |
| 103 | @abc.abstractmethod |
| 104 | def add_signature_algorithms(self, *signature_algorithms): |
| 105 | pass |
| 106 | |
| 107 | @abc.abstractmethod |
| 108 | def add_named_groups(self, *named_groups): |
| 109 | pass |
| 110 | |
| 111 | @abc.abstractmethod |
| 112 | def pre_checks(self): |
| 113 | return [] |
| 114 | |
| 115 | @abc.abstractmethod |
| 116 | def cmd(self): |
| 117 | pass |
| 118 | |
| 119 | @abc.abstractmethod |
| 120 | def post_checks(self): |
| 121 | return [] |
| 122 | |
| 123 | |
| 124 | class OpenSSLServ(TLSProgram): |
| 125 | """ |
| 126 | Generate test commands for OpenSSL server. |
| 127 | """ |
| 128 | program = '$OPENSSL_NEXT' |
| 129 | |
| 130 | def __init__( |
| 131 | self, |
| 132 | ciphersuite, |
| 133 | signature_algorithm, |
| 134 | named_group): |
| 135 | self.ciphersuites = [] |
| 136 | self.named_groups = [] |
| 137 | self.signature_algorithms = [] |
| 138 | self.certificates = [] |
| 139 | super().__init__(ciphersuite, signature_algorithm, named_group) |
| 140 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 141 | def add_ciphersuites(self, *ciphersuites): |
| 142 | self.ciphersuites.extend(ciphersuites) |
| 143 | |
| 144 | def add_signature_algorithms(self, *signature_algorithms): |
| 145 | self.signature_algorithms.extend(signature_algorithms) |
| 146 | for sig_alg in signature_algorithms: |
| 147 | self.certificates.append(CERTIFICATES[sig_alg]) |
| 148 | |
| 149 | NAMED_GROUP = { |
| 150 | 'secp256r1': 'P-256', |
| 151 | 'secp384r1': 'P-384', |
| 152 | 'secp521r1': 'P-521', |
| 153 | 'x25519': 'X25519', |
| 154 | 'x448': 'X448', |
| 155 | } |
| 156 | |
| 157 | def add_named_groups(self, *named_groups): |
| 158 | for named_group in named_groups: |
| 159 | self.named_groups.append(self.NAMED_GROUP[named_group]) |
| 160 | |
| 161 | def cmd(self): |
| 162 | ret = ['$O_NEXT_SRV_NO_CERT'] |
| 163 | for cert, key in self.certificates: |
| 164 | ret += ['-cert {cert} -key {key}'.format(cert=cert, key=key)] |
| 165 | ret += ['-accept $SRV_PORT'] |
| 166 | ciphersuites = ','.join(self.ciphersuites) |
| 167 | signature_algorithms = ','.join(self.signature_algorithms) |
| 168 | named_groups = ','.join(self.named_groups) |
| 169 | ret += ["-ciphersuites {ciphersuites}".format(ciphersuites=ciphersuites), |
| 170 | "-sigalgs {signature_algorithms}".format( |
| 171 | signature_algorithms=signature_algorithms), |
| 172 | "-groups {named_groups}".format(named_groups=named_groups)] |
| 173 | ret += ['-msg -tls1_3 -no_middlebox -num_tickets 0 -no_resume_ephemeral -no_cache'] |
| 174 | return ' '.join(ret) |
| 175 | |
| 176 | def pre_checks(self): |
| 177 | return ["requires_openssl_tls1_3"] |
| 178 | |
| 179 | def post_checks(self): |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 180 | return ['-c "HTTP/1.0 200 ok"'] |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 181 | |
| 182 | |
| 183 | class GnuTLSServ(TLSProgram): |
| 184 | """ |
| 185 | Generate test commands for GnuTLS server. |
| 186 | """ |
| 187 | |
| 188 | def __init__(self, ciphersuite, signature_algorithm, named_group): |
| 189 | self.priority_strings = [] |
| 190 | self.certificates = [] |
| 191 | super().__init__(ciphersuite, signature_algorithm, named_group) |
| 192 | |
| 193 | CIPHER_SUITE = { |
| 194 | 'TLS_AES_256_GCM_SHA384': [ |
| 195 | 'AES-256-GCM', |
| 196 | 'SHA384', |
| 197 | 'AEAD'], |
| 198 | 'TLS_AES_128_GCM_SHA256': [ |
| 199 | 'AES-128-GCM', |
| 200 | 'SHA256', |
| 201 | 'AEAD'], |
| 202 | 'TLS_CHACHA20_POLY1305_SHA256': [ |
| 203 | 'CHACHA20-POLY1305', |
| 204 | 'SHA256', |
| 205 | 'AEAD'], |
| 206 | 'TLS_AES_128_CCM_SHA256': [ |
| 207 | 'AES-128-CCM', |
| 208 | 'SHA256', |
| 209 | 'AEAD'], |
| 210 | 'TLS_AES_128_CCM_8_SHA256': [ |
| 211 | 'AES-128-CCM-8', |
| 212 | 'SHA256', |
| 213 | 'AEAD']} |
| 214 | |
| 215 | def add_ciphersuites(self, *ciphersuites): |
Jerry Yu | d64e20d | 2021-11-26 10:50:01 +0800 | [diff] [blame] | 216 | for ciphersuite in ciphersuites: |
| 217 | self.priority_strings.extend(self.CIPHER_SUITE[ciphersuite]) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 218 | |
| 219 | SIGNATURE_ALGORITHM = { |
| 220 | 'ecdsa_secp256r1_sha256': ['SIGN-ECDSA-SECP256R1-SHA256'], |
| 221 | 'ecdsa_secp521r1_sha512': ['SIGN-ECDSA-SECP521R1-SHA512'], |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 222 | 'ecdsa_secp384r1_sha384': ['SIGN-ECDSA-SECP384R1-SHA384'], |
| 223 | 'rsa_pss_rsae_sha256': ['SIGN-RSA-PSS-RSAE-SHA256']} |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 224 | |
| 225 | def add_signature_algorithms(self, *signature_algorithms): |
| 226 | for sig_alg in signature_algorithms: |
| 227 | self.priority_strings.extend(self.SIGNATURE_ALGORITHM[sig_alg]) |
| 228 | self.certificates.append(CERTIFICATES[sig_alg]) |
| 229 | |
| 230 | NAMED_GROUP = { |
| 231 | 'secp256r1': ['GROUP-SECP256R1'], |
| 232 | 'secp384r1': ['GROUP-SECP384R1'], |
| 233 | 'secp521r1': ['GROUP-SECP521R1'], |
| 234 | 'x25519': ['GROUP-X25519'], |
| 235 | 'x448': ['GROUP-X448'], |
| 236 | } |
| 237 | |
| 238 | def add_named_groups(self, *named_groups): |
| 239 | for named_group in named_groups: |
| 240 | self.priority_strings.extend(self.NAMED_GROUP[named_group]) |
| 241 | |
| 242 | def pre_checks(self): |
| 243 | return ["requires_gnutls_tls1_3", |
| 244 | "requires_gnutls_next_no_ticket", |
| 245 | "requires_gnutls_next_disable_tls13_compat", ] |
| 246 | |
| 247 | def post_checks(self): |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 248 | return ['-c "HTTP/1.0 200 OK"'] |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 249 | |
| 250 | def cmd(self): |
| 251 | ret = [ |
| 252 | '$G_NEXT_SRV_NO_CERT', |
| 253 | '--http', |
| 254 | '--disable-client-cert', |
| 255 | '--debug=4'] |
| 256 | for cert, key in self.certificates: |
| 257 | ret += ['--x509certfile {cert} --x509keyfile {key}'.format( |
| 258 | cert=cert, key=key)] |
| 259 | priority_strings = ':+'.join(['NONE'] + |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 260 | list(sorted(self.priority_strings)) + |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 261 | ['VERS-TLS1.3']) |
| 262 | priority_strings += ':%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE' |
| 263 | ret += ['--priority={priority_strings}'.format( |
| 264 | priority_strings=priority_strings)] |
| 265 | ret = ' '.join(ret) |
| 266 | return ret |
| 267 | |
| 268 | |
| 269 | class MbedTLSCli(TLSProgram): |
| 270 | """ |
| 271 | Generate test commands for mbedTLS client. |
| 272 | """ |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 273 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 274 | def __init__(self, ciphersuite, signature_algorithm, named_group): |
| 275 | self.ciphersuites = [] |
| 276 | self.certificates = [] |
| 277 | self.signature_algorithms = [] |
| 278 | self.named_groups = [] |
| 279 | self.needed_named_groups = [] |
| 280 | super().__init__(ciphersuite, signature_algorithm, named_group) |
| 281 | |
| 282 | CIPHER_SUITE = { |
| 283 | 'TLS_AES_256_GCM_SHA384': 'TLS1-3-AES-256-GCM-SHA384', |
| 284 | 'TLS_AES_128_GCM_SHA256': 'TLS1-3-AES-128-GCM-SHA256', |
| 285 | 'TLS_CHACHA20_POLY1305_SHA256': 'TLS1-3-CHACHA20-POLY1305-SHA256', |
| 286 | 'TLS_AES_128_CCM_SHA256': 'TLS1-3-AES-128-CCM-SHA256', |
| 287 | 'TLS_AES_128_CCM_8_SHA256': 'TLS1-3-AES-128-CCM-8-SHA256'} |
| 288 | |
| 289 | def add_ciphersuites(self, *ciphersuites): |
Jerry Yu | d64e20d | 2021-11-26 10:50:01 +0800 | [diff] [blame] | 290 | for ciphersuite in ciphersuites: |
| 291 | self.ciphersuites.append(self.CIPHER_SUITE[ciphersuite]) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 292 | |
| 293 | def add_signature_algorithms(self, *signature_algorithms): |
| 294 | for sig_alg in signature_algorithms: |
| 295 | self.signature_algorithms.append(sig_alg) |
| 296 | if sig_alg == 'ecdsa_secp256r1_sha256': |
| 297 | self.needed_named_groups.append('secp256r1') |
| 298 | elif sig_alg == 'ecdsa_secp521r1_sha512': |
| 299 | self.needed_named_groups.append('secp521r1') |
| 300 | elif sig_alg == 'ecdsa_secp384r1_sha384': |
| 301 | self.needed_named_groups.append('secp384r1') |
| 302 | |
| 303 | self.certificates.append(CERTIFICATES[sig_alg]) |
| 304 | |
| 305 | def add_named_groups(self, *named_groups): |
| 306 | for named_group in named_groups: |
| 307 | self.named_groups.append(named_group) |
| 308 | |
| 309 | def pre_checks(self): |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 310 | |
| 311 | ret = ['requires_config_enabled MBEDTLS_DEBUG_C', |
| 312 | 'requires_config_enabled MBEDTLS_SSL_CLI_C', |
| 313 | 'requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL', |
| 314 | 'requires_config_disabled MBEDTLS_USE_PSA_CRYPTO'] |
| 315 | if 'rsa_pss_rsae_sha256' in self.signature_algorithms: |
| 316 | ret.append( |
| 317 | 'requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT') |
| 318 | return ret |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 319 | |
| 320 | def post_checks(self): |
| 321 | |
| 322 | check_strings = ["ECDH curve: {group}".format(group=self._named_group), |
| 323 | "server hello, chosen ciphersuite: ( {:04x} ) - {}".format( |
| 324 | CIPHER_SUITE_IANA_VALUE[self._cipher], |
| 325 | self.CIPHER_SUITE[self._cipher]), |
| 326 | "Certificate Verify: Signature algorithm ( {:04x} )".format( |
| 327 | SIG_ALG_IANA_VALUE[self._sig_alg]), |
| 328 | "Verifying peer X.509 certificate... ok", ] |
| 329 | return ['-c "{}"'.format(i) for i in check_strings] |
| 330 | |
| 331 | def cmd(self): |
| 332 | ret = ['$P_CLI'] |
| 333 | ret += [ |
| 334 | 'server_addr=127.0.0.1 server_port=$SRV_PORT', |
| 335 | 'debug_level=4 force_version=tls1_3'] |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 336 | ret += ['ca_file={CAFILE}'.format(CAFILE=CAFILE[self._sig_alg])] |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 337 | self.ciphersuites = list(set(self.ciphersuites)) |
| 338 | cipher = ','.join(self.ciphersuites) |
| 339 | if cipher: |
| 340 | ret += ["force_ciphersuite={cipher}".format(cipher=cipher)] |
| 341 | self.named_groups = remove_duplicates( |
| 342 | self.named_groups + self.needed_named_groups) |
| 343 | group = ','.join(self.named_groups) |
| 344 | if group: |
| 345 | ret += ["curves={group}".format(group=group)] |
| 346 | sig_alg = ','.join(self.signature_algorithms) |
| 347 | ret += ['sig_algs={sig_alg}'.format(sig_alg=sig_alg)] |
| 348 | ret = ' '.join(ret) |
| 349 | return ret |
| 350 | |
| 351 | |
| 352 | SERVER_CLS = {'OpenSSL': OpenSSLServ, 'GnuTLS': GnuTLSServ} |
| 353 | CLIENT_CLS = {'mbedTLS': MbedTLSCli} |
| 354 | |
| 355 | |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 356 | 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] | 357 | sig_alg=None, named_group=None, **kwargs): |
| 358 | """ |
| 359 | Generate test case with `ssl-opt.sh` format. |
| 360 | """ |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 361 | name = 'TLS 1.3 {client[0]}->{server[0]}: {cipher},{named_group},{sig_alg}'.format( |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 362 | client=client, server=server, cipher=cipher, sig_alg=sig_alg, named_group=named_group) |
| 363 | server = SERVER_CLS[server](cipher, sig_alg, named_group) |
| 364 | client = CLIENT_CLS[client](cipher, sig_alg, named_group) |
| 365 | |
| 366 | cmd = ['run_test "{}"'.format(name), '"{}"'.format( |
| 367 | server.cmd()), '"{}"'.format(client.cmd()), '0'] |
| 368 | cmd += server.post_checks() |
| 369 | cmd += client.post_checks() |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 370 | prefix = ' \\\n' + (' '*9) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 371 | cmd = prefix.join(cmd) |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 372 | return '\n'.join(server.pre_checks() + client.pre_checks() + [cmd]) |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 373 | |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 374 | |
| 375 | SSL_OUTPUT_HEADER = '''#!/bin/sh |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 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 | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 404 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 405 | def main(): |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 406 | """ |
| 407 | Main function of this program |
| 408 | """ |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 409 | parser = argparse.ArgumentParser() |
| 410 | |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 411 | parser.add_argument('-o', '--output', nargs='?', |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 412 | default=None, help='Output file path if `-a` was set') |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 413 | |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 414 | parser.add_argument('-a', '--generate-all-tls13-compat-tests', action='store_true', |
| 415 | default=False, help='Generate all available tls13 compat tests') |
| 416 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 417 | parser.add_argument('--list-ciphers', action='store_true', |
| 418 | default=False, help='List supported ciphersuites') |
| 419 | |
| 420 | parser.add_argument('--list-sig-algs', action='store_true', |
| 421 | default=False, help='List supported signature algorithms') |
| 422 | |
| 423 | parser.add_argument('--list-named-groups', action='store_true', |
| 424 | default=False, help='List supported named groups') |
| 425 | |
| 426 | parser.add_argument('--list-servers', action='store_true', |
| 427 | default=False, help='List supported TLS servers') |
| 428 | |
| 429 | parser.add_argument('--list-clients', action='store_true', |
| 430 | default=False, help='List supported TLS Clients') |
| 431 | |
| 432 | parser.add_argument('server', choices=SERVER_CLS.keys(), nargs='?', |
| 433 | default=list(SERVER_CLS.keys())[0], |
| 434 | help='Choose TLS server program for test') |
| 435 | parser.add_argument('client', choices=CLIENT_CLS.keys(), nargs='?', |
| 436 | default=list(CLIENT_CLS.keys())[0], |
| 437 | help='Choose TLS client program for test') |
| 438 | parser.add_argument('cipher', choices=CIPHER_SUITE_IANA_VALUE.keys(), nargs='?', |
| 439 | default=list(CIPHER_SUITE_IANA_VALUE.keys())[0], |
| 440 | help='Choose cipher suite for test') |
| 441 | parser.add_argument('sig_alg', choices=SIG_ALG_IANA_VALUE.keys(), nargs='?', |
| 442 | default=list(SIG_ALG_IANA_VALUE.keys())[0], |
| 443 | help='Choose cipher suite for test') |
| 444 | parser.add_argument('named_group', choices=NAMED_GROUP_IANA_VALUE.keys(), nargs='?', |
| 445 | default=list(NAMED_GROUP_IANA_VALUE.keys())[0], |
| 446 | help='Choose cipher suite for test') |
| 447 | |
| 448 | args = parser.parse_args() |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 449 | |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 450 | def get_all_test_cases(): |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 451 | for i in itertools.product(CIPHER_SUITE_IANA_VALUE.keys(), SIG_ALG_IANA_VALUE.keys(), |
| 452 | NAMED_GROUP_IANA_VALUE.keys(), SERVER_CLS.keys(), |
| 453 | CLIENT_CLS.keys()): |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 454 | yield generate_compat_test(**dict( |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 455 | zip(['cipher', 'sig_alg', 'named_group', 'server', 'client'], i))) |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 456 | |
| 457 | if args.generate_all_tls13_compat_tests: |
| 458 | if args.output: |
| 459 | with open(args.output, 'w', encoding="utf-8") as f: |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 460 | f.write(SSL_OUTPUT_HEADER.format(filename=os.path.basename(args.output))) |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 461 | f.write('\n\n'.join(get_all_test_cases())) |
Jerry Yu | dda036d | 2021-11-30 11:19:41 +0800 | [diff] [blame^] | 462 | f.write('\n') |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 463 | else: |
| 464 | print('\n'.join(get_all_test_cases())) |
Jerry Yu | c4aa152 | 2021-11-26 11:13:58 +0800 | [diff] [blame] | 465 | return 0 |
| 466 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 467 | 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] | 468 | or args.list_servers or args.list_clients: |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 469 | if args.list_ciphers: |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 470 | print(*CIPHER_SUITE_IANA_VALUE.keys()) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 471 | if args.list_sig_algs: |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 472 | print(*SIG_ALG_IANA_VALUE.keys()) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 473 | if args.list_named_groups: |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 474 | print(*NAMED_GROUP_IANA_VALUE.keys()) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 475 | if args.list_servers: |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 476 | print(*SERVER_CLS.keys()) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 477 | if args.list_clients: |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 478 | print(*CLIENT_CLS.keys()) |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 479 | return 0 |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 480 | |
Jerry Yu | 7f5e5ad | 2021-11-29 17:37:19 +0800 | [diff] [blame] | 481 | print(generate_compat_test(**vars(args))) |
Jerry Yu | cdcb683 | 2021-11-29 16:50:13 +0800 | [diff] [blame] | 482 | return 0 |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 483 | |
Jerry Yu | 29deed4 | 2021-11-25 11:09:54 +0800 | [diff] [blame] | 484 | |
Jerry Yu | 305bfc3 | 2021-11-24 16:04:47 +0800 | [diff] [blame] | 485 | if __name__ == "__main__": |
| 486 | sys.exit(main()) |