|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +import copy |
| 4 | + |
| 5 | +from configuration import available_ports |
| 6 | +from common import Certificates, Ciphers, Protocols, ProviderOptions, data_bytes |
| 7 | +from fixtures import managed_process # lgtm [py/unused-import] |
| 8 | +from providers import Provider, S2N, JavaSSL |
| 9 | +from utils import ( |
| 10 | + to_bytes, |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +def test_s2n_server_sslv2_client_hello(managed_process): |
| 15 | + # TLS 1.3: not supported by SSLv2 ClientHellos |
| 16 | + # TLS 1.2: supported |
| 17 | + # TLS 1.0 - TLS 1.1: not supported by Java |
| 18 | + TEST_PROTOCOL = Protocols.TLS12 |
| 19 | + |
| 20 | + port = next(available_ports) |
| 21 | + |
| 22 | + # s2nd can receive large amounts of data because all the data is |
| 23 | + # echo'd to stdout unmodified. This lets us compare received to |
| 24 | + # expected easily. |
| 25 | + # We purposefully send a non block aligned number to make sure |
| 26 | + # nothing blocks waiting for more data. |
| 27 | + random_bytes = data_bytes(65519) |
| 28 | + |
| 29 | + certificate = Certificates.RSA_2048_SHA256 |
| 30 | + |
| 31 | + client_options = ProviderOptions( |
| 32 | + mode=Provider.ClientMode, |
| 33 | + port=port, |
| 34 | + # The cipher must use RSA key exchange. ECDHE is not supported with |
| 35 | + # SSLv2 formatted client hellos. |
| 36 | + cipher=Ciphers.AES256_SHA256, |
| 37 | + cert=certificate.cert, |
| 38 | + data_to_send=random_bytes, |
| 39 | + insecure=True, |
| 40 | + protocol=TEST_PROTOCOL, |
| 41 | + extra_flags=["SSLv2Hello"], |
| 42 | + ) |
| 43 | + |
| 44 | + server_options = copy.copy(client_options) |
| 45 | + server_options.mode = Provider.ServerMode |
| 46 | + server_options.data_to_send = None |
| 47 | + server_options.key = certificate.key |
| 48 | + server_options.cert = certificate.cert |
| 49 | + server_options.extra_flags = None |
| 50 | + |
| 51 | + # Passing the type of client and server as a parameter will |
| 52 | + # allow us to use a fixture to enumerate all possibilities. |
| 53 | + server = managed_process(S2N, server_options, timeout=5) |
| 54 | + client = managed_process(JavaSSL, client_options, timeout=5) |
| 55 | + |
| 56 | + # The client will be one of all supported providers. We |
| 57 | + # just want to make sure there was no exception and that |
| 58 | + # the client exited cleanly. |
| 59 | + for client_results in client.get_results(): |
| 60 | + client_results.assert_success() |
| 61 | + |
| 62 | + # The server is always S2N in this test, so we can examine |
| 63 | + # the stdout reliably. |
| 64 | + for server_results in server.get_results(): |
| 65 | + server_results.assert_success() |
| 66 | + assert ( |
| 67 | + to_bytes(f"Client hello version: {Protocols.SSLv2.value}") |
| 68 | + in server_results.stdout |
| 69 | + ) |
| 70 | + assert ( |
| 71 | + to_bytes(f"Actual protocol version: {TEST_PROTOCOL.value}") |
| 72 | + in server_results.stdout |
| 73 | + ) |
| 74 | + assert random_bytes in server_results.stdout |
0 commit comments