| 1 |
|
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from configuration import available_ports, ALL_TEST_CIPHERS, ALL_TEST_CURVES, PROTOCOLS |
| 6 |
from common import ProviderOptions, data_bytes, Certificates |
| 7 |
from fixtures import managed_process |
| 8 |
from constants import TEST_OCSP_DIRECTORY |
| 9 |
from providers import Provider, S2N, OpenSSL, GnuTLS |
| 10 |
from utils import invalid_test_parameters, get_parameter_name |
| 11 |
from global_flags import get_flag, S2N_PROVIDER_VERSION |
| 12 |
|
| 13 |
|
| 14 |
OCSP_CERTS = [Certificates.OCSP, Certificates.OCSP_ECDSA] |
| 15 |
|
| 16 |
|
| 17 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 18 |
@pytest.mark.parametrize("cipher", ALL_TEST_CIPHERS, ids=get_parameter_name) |
| 19 |
@pytest.mark.parametrize("provider", [S2N, OpenSSL, GnuTLS], ids=get_parameter_name) |
| 20 |
@pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name) |
| 21 |
@pytest.mark.parametrize("protocol", PROTOCOLS, ids=get_parameter_name) |
| 22 |
@pytest.mark.parametrize("certificate", OCSP_CERTS, ids=get_parameter_name) |
| 23 |
def test_s2n_client_ocsp_response( |
| 24 |
managed_process, |
| 25 |
cipher, |
| 26 |
provider, |
| 27 |
curve, |
| 28 |
protocol, |
| 29 |
certificate, |
| 30 |
): |
| 31 |
if "boringssl" in get_flag(S2N_PROVIDER_VERSION): |
| 32 |
pytest.skip("s2n-tls client with boringssl does not support ocsp") |
| 33 |
|
| 34 |
port = next(available_ports) |
| 35 |
|
| 36 |
random_bytes = data_bytes(128) |
| 37 |
client_options = ProviderOptions( |
| 38 |
mode=Provider.ClientMode, |
| 39 |
port=port, |
| 40 |
cipher=cipher, |
| 41 |
curve=curve, |
| 42 |
protocol=protocol, |
| 43 |
insecure=True, |
| 44 |
data_to_send=random_bytes, |
| 45 |
enable_client_ocsp=True, |
| 46 |
) |
| 47 |
|
| 48 |
server_options = ProviderOptions( |
| 49 |
mode=Provider.ServerMode, |
| 50 |
port=port, |
| 51 |
cipher=cipher, |
| 52 |
curve=curve, |
| 53 |
protocol=protocol, |
| 54 |
key=certificate.key, |
| 55 |
cert=certificate.cert, |
| 56 |
ocsp_response={ |
| 57 |
"RSA": TEST_OCSP_DIRECTORY + "ocsp_response.der", |
| 58 |
"EC": TEST_OCSP_DIRECTORY + "ocsp_ecdsa_response.der", |
| 59 |
}.get(certificate.algorithm), |
| 60 |
) |
| 61 |
|
| 62 |
kill_marker = None |
| 63 |
if provider == GnuTLS: |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
kill_marker = b"Alert(21) in epoch" |
| 74 |
server_options.extra_flags = ["-d", "5"] |
| 75 |
|
| 76 |
server = managed_process( |
| 77 |
provider, server_options, timeout=30, kill_marker=kill_marker |
| 78 |
) |
| 79 |
client = managed_process(S2N, client_options, timeout=30) |
| 80 |
|
| 81 |
for client_results in client.get_results(): |
| 82 |
client_results.assert_success() |
| 83 |
assert b"OCSP response received" in client_results.stdout |
| 84 |
|
| 85 |
for server_results in server.get_results(): |
| 86 |
server_results.assert_success() |
| 87 |
|
| 88 |
assert ( |
| 89 |
random_bytes[1:] in server_results.stdout |
| 90 |
or random_bytes[1:] in server_results.stderr |
| 91 |
) |
| 92 |
|
| 93 |
|
| 94 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 95 |
@pytest.mark.parametrize("cipher", ALL_TEST_CIPHERS, ids=get_parameter_name) |
| 96 |
@pytest.mark.parametrize("provider", [GnuTLS, OpenSSL], ids=get_parameter_name) |
| 97 |
@pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name) |
| 98 |
@pytest.mark.parametrize("protocol", PROTOCOLS, ids=get_parameter_name) |
| 99 |
@pytest.mark.parametrize("certificate", OCSP_CERTS, ids=get_parameter_name) |
| 100 |
def test_s2n_server_ocsp_response( |
| 101 |
managed_process, |
| 102 |
cipher, |
| 103 |
provider, |
| 104 |
curve, |
| 105 |
protocol, |
| 106 |
certificate, |
| 107 |
): |
| 108 |
port = next(available_ports) |
| 109 |
|
| 110 |
random_bytes = data_bytes(128) |
| 111 |
client_options = ProviderOptions( |
| 112 |
mode=Provider.ClientMode, |
| 113 |
port=port, |
| 114 |
cipher=cipher, |
| 115 |
curve=curve, |
| 116 |
protocol=protocol, |
| 117 |
insecure=True, |
| 118 |
data_to_send=random_bytes, |
| 119 |
enable_client_ocsp=True, |
| 120 |
) |
| 121 |
|
| 122 |
server_options = ProviderOptions( |
| 123 |
mode=Provider.ServerMode, |
| 124 |
port=port, |
| 125 |
cipher=cipher, |
| 126 |
curve=curve, |
| 127 |
protocol=protocol, |
| 128 |
insecure=True, |
| 129 |
key=certificate.key, |
| 130 |
cert=certificate.cert, |
| 131 |
ocsp_response={ |
| 132 |
"RSA": TEST_OCSP_DIRECTORY + "ocsp_response.der", |
| 133 |
"EC": TEST_OCSP_DIRECTORY + "ocsp_ecdsa_response.der", |
| 134 |
}.get(certificate.algorithm), |
| 135 |
) |
| 136 |
|
| 137 |
server = managed_process(S2N, server_options, timeout=90) |
| 138 |
client = managed_process(provider, client_options, timeout=90) |
| 139 |
|
| 140 |
for client_results in client.get_results(): |
| 141 |
client_results.assert_success() |
| 142 |
assert any( |
| 143 |
[ |
| 144 |
{ |
| 145 |
GnuTLS: b"OCSP Response Information:\n\tResponse Status: Successful", |
| 146 |
OpenSSL: b"OCSP Response Status: successful", |
| 147 |
}.get(provider) |
| 148 |
in stream |
| 149 |
for stream in client_results.output_streams() |
| 150 |
] |
| 151 |
) |
| 152 |
|
| 153 |
for server_results in server.get_results(): |
| 154 |
server_results.assert_success() |
| 155 |
|
| 156 |
assert any( |
| 157 |
[random_bytes[1:] in stream for stream in server_results.output_streams()] |
| 158 |
) |