| 1 |
|
| 2 |
|
| 3 |
import copy |
| 4 |
import pytest |
| 5 |
|
| 6 |
from configuration import available_ports, TLS13_CIPHERS |
| 7 |
from common import ProviderOptions, Protocols, random_str |
| 8 |
from fixtures import managed_process |
| 9 |
from providers import Provider, S2N, OpenSSL |
| 10 |
from utils import invalid_test_parameters, get_parameter_name |
| 11 |
|
| 12 |
SERVER_DATA = "Some random data from the server:" + random_str(10) |
| 13 |
CLIENT_DATA = "Some random data from the client:" + random_str(10) |
| 14 |
|
| 15 |
|
| 16 |
def test_nothing(): |
| 17 |
""" |
| 18 |
Sometimes the key update test parameters in combination with the s2n libcrypto |
| 19 |
results in no test cases existing. In this case, pass a nothing test to avoid |
| 20 |
marking the entire codebuild run as failed. |
| 21 |
""" |
| 22 |
assert True |
| 23 |
|
| 24 |
|
| 25 |
@pytest.mark.flaky(reruns=5) |
| 26 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 27 |
@pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name) |
| 28 |
@pytest.mark.parametrize("provider", [OpenSSL], ids=get_parameter_name) |
| 29 |
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name) |
| 30 |
@pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name) |
| 31 |
def test_s2n_server_key_update( |
| 32 |
managed_process, |
| 33 |
cipher, |
| 34 |
provider, |
| 35 |
other_provider, |
| 36 |
protocol, |
| 37 |
): |
| 38 |
host = "localhost" |
| 39 |
port = next(available_ports) |
| 40 |
|
| 41 |
update_requested = b"K" |
| 42 |
starting_marker = "Verify return code" |
| 43 |
key_update_marker = "KEYUPDATE" |
| 44 |
|
| 45 |
send_marker_list = [starting_marker, key_update_marker] |
| 46 |
|
| 47 |
client_options = ProviderOptions( |
| 48 |
mode=Provider.ClientMode, |
| 49 |
host=host, |
| 50 |
port=port, |
| 51 |
cipher=cipher, |
| 52 |
data_to_send=[update_requested, CLIENT_DATA.encode()], |
| 53 |
insecure=True, |
| 54 |
protocol=protocol, |
| 55 |
) |
| 56 |
|
| 57 |
server_options = copy.copy(client_options) |
| 58 |
|
| 59 |
server_options.mode = Provider.ServerMode |
| 60 |
server_options.key = "../pems/ecdsa_p384_pkcs1_key.pem" |
| 61 |
server_options.cert = "../pems/ecdsa_p384_pkcs1_cert.pem" |
| 62 |
server_options.data_to_send = [SERVER_DATA.encode()] |
| 63 |
|
| 64 |
server = managed_process(S2N, server_options, send_marker=CLIENT_DATA, timeout=30) |
| 65 |
client = managed_process( |
| 66 |
provider, |
| 67 |
client_options, |
| 68 |
send_marker=send_marker_list, |
| 69 |
close_marker=SERVER_DATA, |
| 70 |
timeout=30, |
| 71 |
) |
| 72 |
|
| 73 |
for results in client.get_results(): |
| 74 |
results.assert_success() |
| 75 |
assert key_update_marker in str(results.stderr) |
| 76 |
assert SERVER_DATA.encode() in results.stdout |
| 77 |
|
| 78 |
for results in server.get_results(): |
| 79 |
results.assert_success() |
| 80 |
assert CLIENT_DATA.encode() in results.stdout |
| 81 |
|
| 82 |
|
| 83 |
@pytest.mark.flaky(reruns=5) |
| 84 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 85 |
@pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name) |
| 86 |
@pytest.mark.parametrize("provider", [OpenSSL], ids=get_parameter_name) |
| 87 |
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name) |
| 88 |
@pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name) |
| 89 |
def test_s2n_client_key_update( |
| 90 |
managed_process, |
| 91 |
cipher, |
| 92 |
provider, |
| 93 |
other_provider, |
| 94 |
protocol, |
| 95 |
): |
| 96 |
host = "localhost" |
| 97 |
port = next(available_ports) |
| 98 |
|
| 99 |
update_requested = b"K\n" |
| 100 |
|
| 101 |
starting_marker = "Secure Renegotiation IS supported" |
| 102 |
key_update_marker = "TLSv1.3 write server key update" |
| 103 |
read_key_update_marker = b"TLSv1.3 read client key update" |
| 104 |
|
| 105 |
send_marker_list = [starting_marker, key_update_marker] |
| 106 |
|
| 107 |
client_options = ProviderOptions( |
| 108 |
mode=Provider.ClientMode, |
| 109 |
host=host, |
| 110 |
port=port, |
| 111 |
cipher=cipher, |
| 112 |
data_to_send=[CLIENT_DATA.encode()], |
| 113 |
insecure=True, |
| 114 |
protocol=protocol, |
| 115 |
) |
| 116 |
|
| 117 |
server_options = copy.copy(client_options) |
| 118 |
|
| 119 |
server_options.mode = Provider.ServerMode |
| 120 |
server_options.key = "../pems/ecdsa_p384_pkcs1_key.pem" |
| 121 |
server_options.cert = "../pems/ecdsa_p384_pkcs1_cert.pem" |
| 122 |
server_options.data_to_send = [update_requested, SERVER_DATA.encode()] |
| 123 |
|
| 124 |
server = managed_process( |
| 125 |
provider, |
| 126 |
server_options, |
| 127 |
send_marker=send_marker_list, |
| 128 |
close_marker=CLIENT_DATA, |
| 129 |
timeout=30, |
| 130 |
) |
| 131 |
client = managed_process( |
| 132 |
S2N, |
| 133 |
client_options, |
| 134 |
send_marker=SERVER_DATA, |
| 135 |
close_marker=SERVER_DATA, |
| 136 |
timeout=30, |
| 137 |
) |
| 138 |
|
| 139 |
for results in client.get_results(): |
| 140 |
results.assert_success() |
| 141 |
assert SERVER_DATA.encode() in results.stdout |
| 142 |
|
| 143 |
for results in server.get_results(): |
| 144 |
results.assert_success() |
| 145 |
assert read_key_update_marker in results.stderr |
| 146 |
assert CLIENT_DATA.encode() in results.stdout |