| 1 |
|
| 2 |
|
| 3 |
import copy |
| 4 |
import pytest |
| 5 |
|
| 6 |
from configuration import available_ports, PROTOCOLS |
| 7 |
from common import ProviderOptions, Ciphers, Certificates, data_bytes |
| 8 |
from fixtures import managed_process |
| 9 |
from providers import Provider, S2N, OpenSSL, GnuTLS |
| 10 |
from utils import ( |
| 11 |
invalid_test_parameters, |
| 12 |
get_parameter_name, |
| 13 |
get_expected_s2n_version, |
| 14 |
to_bytes, |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
CIPHERS_TO_TEST = [ |
| 19 |
Ciphers.AES256_SHA, |
| 20 |
Ciphers.ECDHE_ECDSA_AES256_SHA, |
| 21 |
Ciphers.AES256_GCM_SHA384, |
| 22 |
] |
| 23 |
|
| 24 |
CERTIFICATES_TO_TEST = [Certificates.RSA_4096_SHA384, Certificates.ECDSA_384] |
| 25 |
|
| 26 |
|
| 27 |
def invalid_test_parameters_frag_len(*args, **kwargs): |
| 28 |
provider = kwargs.get("provider") |
| 29 |
frag_len = kwargs.get("frag_len") |
| 30 |
|
| 31 |
|
| 32 |
if provider == GnuTLS: |
| 33 |
if frag_len > 4096: |
| 34 |
return True |
| 35 |
|
| 36 |
return invalid_test_parameters(*args, **kwargs) |
| 37 |
|
| 38 |
|
| 39 |
@pytest.mark.uncollect_if(func=invalid_test_parameters_frag_len) |
| 40 |
@pytest.mark.parametrize("cipher", CIPHERS_TO_TEST, ids=get_parameter_name) |
| 41 |
@pytest.mark.parametrize("provider", [OpenSSL, GnuTLS], ids=get_parameter_name) |
| 42 |
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name) |
| 43 |
@pytest.mark.parametrize("protocol", PROTOCOLS, ids=get_parameter_name) |
| 44 |
@pytest.mark.parametrize("certificate", CERTIFICATES_TO_TEST, ids=get_parameter_name) |
| 45 |
@pytest.mark.parametrize( |
| 46 |
"frag_len", [512, 2048, 8192, 12345, 16384], ids=get_parameter_name |
| 47 |
) |
| 48 |
def test_s2n_server_framented_data( |
| 49 |
managed_process, |
| 50 |
cipher, |
| 51 |
provider, |
| 52 |
other_provider, |
| 53 |
protocol, |
| 54 |
certificate, |
| 55 |
frag_len, |
| 56 |
): |
| 57 |
if provider is OpenSSL and "openssl-1.0.2" in provider.get_version(): |
| 58 |
pytest.skip( |
| 59 |
"{} does not allow setting max fragmentation for packets".format(provider) |
| 60 |
) |
| 61 |
|
| 62 |
port = next(available_ports) |
| 63 |
|
| 64 |
random_bytes = data_bytes(65519) |
| 65 |
client_options = ProviderOptions( |
| 66 |
mode=Provider.ClientMode, |
| 67 |
port=port, |
| 68 |
cipher=cipher, |
| 69 |
data_to_send=random_bytes, |
| 70 |
insecure=True, |
| 71 |
record_size=frag_len, |
| 72 |
protocol=protocol, |
| 73 |
) |
| 74 |
|
| 75 |
server_options = copy.copy(client_options) |
| 76 |
server_options.extra_flags = None |
| 77 |
server_options.data_to_send = None |
| 78 |
server_options.mode = Provider.ServerMode |
| 79 |
server_options.key = certificate.key |
| 80 |
server_options.cert = certificate.cert |
| 81 |
server_options.cipher = None |
| 82 |
|
| 83 |
server = managed_process(S2N, server_options, timeout=5) |
| 84 |
client = managed_process(provider, client_options, timeout=5) |
| 85 |
|
| 86 |
for client_results in client.get_results(): |
| 87 |
client_results.assert_success() |
| 88 |
|
| 89 |
expected_version = get_expected_s2n_version(protocol, provider) |
| 90 |
|
| 91 |
for server_results in server.get_results(): |
| 92 |
server_results.assert_success() |
| 93 |
assert ( |
| 94 |
to_bytes("Actual protocol version: {}".format(expected_version)) |
| 95 |
in server_results.stdout |
| 96 |
) |
| 97 |
|
| 98 |
if provider == GnuTLS: |
| 99 |
|
| 100 |
|
| 101 |
assert random_bytes[:frag_len] in server_results.stdout |
| 102 |
else: |
| 103 |
assert random_bytes in server_results.stdout |