| 1 |
|
| 2 |
|
| 3 |
import pytest |
| 4 |
import copy |
| 5 |
import os |
| 6 |
|
| 7 |
from configuration import ( |
| 8 |
available_ports, |
| 9 |
ALL_TEST_CIPHERS, |
| 10 |
ALL_TEST_CURVES, |
| 11 |
MINIMAL_TEST_CERTS, |
| 12 |
S2N_TEST_POLICIES, |
| 13 |
) |
| 14 |
from common import ProviderOptions, Protocols, data_bytes |
| 15 |
from fixtures import managed_process |
| 16 |
from providers import Provider, S2N, OpenSSL |
| 17 |
from utils import invalid_test_parameters, get_parameter_name, to_bytes |
| 18 |
|
| 19 |
S2N_RESUMPTION_MARKER = to_bytes("Resumed session") |
| 20 |
CLOSE_MARKER_BYTES = data_bytes(10) |
| 21 |
|
| 22 |
TICKET_FILE = "ticket" |
| 23 |
RESUMPTION_PROTOCOLS = [Protocols.TLS12, Protocols.TLS13] |
| 24 |
|
| 25 |
|
| 26 |
""" |
| 27 |
An old S2N server can resume a session with a new S2N server's session ticket. |
| 28 |
Tests that S2N tickets are backwards-compatible. |
| 29 |
""" |
| 30 |
|
| 31 |
|
| 32 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 33 |
@pytest.mark.parametrize("cipher", ALL_TEST_CIPHERS, ids=get_parameter_name) |
| 34 |
@pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name) |
| 35 |
@pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name) |
| 36 |
@pytest.mark.parametrize("protocol", RESUMPTION_PROTOCOLS, ids=get_parameter_name) |
| 37 |
@pytest.mark.parametrize("provider", [OpenSSL], ids=get_parameter_name) |
| 38 |
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name) |
| 39 |
def test_s2n_old_server_new_ticket( |
| 40 |
managed_process, |
| 41 |
tmp_path, |
| 42 |
cipher, |
| 43 |
curve, |
| 44 |
certificate, |
| 45 |
protocol, |
| 46 |
provider, |
| 47 |
other_provider, |
| 48 |
): |
| 49 |
ticket_file = str(tmp_path / TICKET_FILE) |
| 50 |
assert not os.path.exists(ticket_file) |
| 51 |
|
| 52 |
options = ProviderOptions( |
| 53 |
port=next(available_ports), |
| 54 |
cipher=cipher, |
| 55 |
curve=curve, |
| 56 |
protocol=protocol, |
| 57 |
insecure=True, |
| 58 |
use_session_ticket=True, |
| 59 |
) |
| 60 |
|
| 61 |
client_options = copy.copy(options) |
| 62 |
client_options.mode = Provider.ClientMode |
| 63 |
client_options.extra_flags = ["-sess_out", ticket_file] |
| 64 |
|
| 65 |
server_options = copy.copy(options) |
| 66 |
server_options.mode = Provider.ServerMode |
| 67 |
server_options.key = certificate.key |
| 68 |
server_options.cert = certificate.cert |
| 69 |
server_options.data_to_send = CLOSE_MARKER_BYTES |
| 70 |
|
| 71 |
s2n_server = managed_process(S2N, server_options, send_marker=S2N.get_send_marker()) |
| 72 |
client = managed_process( |
| 73 |
provider, client_options, close_marker=str(CLOSE_MARKER_BYTES) |
| 74 |
) |
| 75 |
|
| 76 |
for results in client.get_results(): |
| 77 |
results.assert_success() |
| 78 |
|
| 79 |
for results in s2n_server.get_results(): |
| 80 |
results.assert_success() |
| 81 |
|
| 82 |
assert os.path.exists(ticket_file) |
| 83 |
client_options.extra_flags = ["-sess_in", ticket_file] |
| 84 |
server_options.use_mainline_version = True |
| 85 |
|
| 86 |
s2n_server = managed_process(S2N, server_options, send_marker=S2N.get_send_marker()) |
| 87 |
client = managed_process( |
| 88 |
provider, client_options, close_marker=str(CLOSE_MARKER_BYTES) |
| 89 |
) |
| 90 |
|
| 91 |
for results in client.get_results(): |
| 92 |
results.assert_success() |
| 93 |
|
| 94 |
for results in s2n_server.get_results(): |
| 95 |
results.assert_success() |
| 96 |
assert S2N_RESUMPTION_MARKER in results.stdout |
| 97 |
|
| 98 |
|
| 99 |
""" |
| 100 |
A new S2N server can resume a session with an old S2N server's session ticket. |
| 101 |
Tests that S2N tickets are forwards-compatible. |
| 102 |
""" |
| 103 |
|
| 104 |
|
| 105 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 106 |
@pytest.mark.parametrize("cipher", ALL_TEST_CIPHERS, ids=get_parameter_name) |
| 107 |
@pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name) |
| 108 |
@pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name) |
| 109 |
@pytest.mark.parametrize("protocol", RESUMPTION_PROTOCOLS, ids=get_parameter_name) |
| 110 |
@pytest.mark.parametrize("provider", [OpenSSL], ids=get_parameter_name) |
| 111 |
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name) |
| 112 |
def test_s2n_new_server_old_ticket( |
| 113 |
managed_process, |
| 114 |
tmp_path, |
| 115 |
cipher, |
| 116 |
curve, |
| 117 |
certificate, |
| 118 |
protocol, |
| 119 |
provider, |
| 120 |
other_provider, |
| 121 |
): |
| 122 |
ticket_file = str(tmp_path / TICKET_FILE) |
| 123 |
assert not os.path.exists(ticket_file) |
| 124 |
|
| 125 |
options = ProviderOptions( |
| 126 |
port=next(available_ports), |
| 127 |
cipher=cipher, |
| 128 |
curve=curve, |
| 129 |
protocol=protocol, |
| 130 |
insecure=True, |
| 131 |
use_session_ticket=True, |
| 132 |
) |
| 133 |
|
| 134 |
client_options = copy.copy(options) |
| 135 |
client_options.mode = Provider.ClientMode |
| 136 |
client_options.extra_flags = ["-sess_out", ticket_file] |
| 137 |
|
| 138 |
server_options = copy.copy(options) |
| 139 |
server_options.mode = Provider.ServerMode |
| 140 |
server_options.use_mainline_version = True |
| 141 |
server_options.key = certificate.key |
| 142 |
server_options.cert = certificate.cert |
| 143 |
server_options.data_to_send = CLOSE_MARKER_BYTES |
| 144 |
|
| 145 |
s2n_server = managed_process(S2N, server_options, send_marker=S2N.get_send_marker()) |
| 146 |
client = managed_process( |
| 147 |
provider, client_options, close_marker=str(CLOSE_MARKER_BYTES) |
| 148 |
) |
| 149 |
|
| 150 |
for results in client.get_results(): |
| 151 |
results.assert_success() |
| 152 |
|
| 153 |
for results in s2n_server.get_results(): |
| 154 |
results.assert_success() |
| 155 |
|
| 156 |
assert os.path.exists(ticket_file) |
| 157 |
client_options.extra_flags = ["-sess_in", ticket_file] |
| 158 |
server_options.use_mainline_version = False |
| 159 |
|
| 160 |
s2n_server = managed_process(S2N, server_options, send_marker=S2N.get_send_marker()) |
| 161 |
client = managed_process( |
| 162 |
provider, client_options, close_marker=str(CLOSE_MARKER_BYTES) |
| 163 |
) |
| 164 |
|
| 165 |
for results in client.get_results(): |
| 166 |
results.assert_success() |
| 167 |
|
| 168 |
for results in s2n_server.get_results(): |
| 169 |
results.assert_success() |
| 170 |
assert S2N_RESUMPTION_MARKER in results.stdout |
| 171 |
|
| 172 |
|
| 173 |
""" |
| 174 |
An old S2N client can resume a session with an new S2N client's session ticket. |
| 175 |
Tests that S2N tickets are backwards-compatible. In our client tests we use an S2N |
| 176 |
server because the Openssl server uses a different ticket key for each session. |
| 177 |
""" |
| 178 |
|
| 179 |
|
| 180 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 181 |
@pytest.mark.parametrize("cipher", S2N_TEST_POLICIES, ids=get_parameter_name) |
| 182 |
@pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name) |
| 183 |
@pytest.mark.parametrize("provider", [S2N], ids=get_parameter_name) |
| 184 |
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name) |
| 185 |
def test_s2n_old_client_new_ticket( |
| 186 |
managed_process, |
| 187 |
tmp_path, |
| 188 |
cipher, |
| 189 |
certificate, |
| 190 |
provider, |
| 191 |
other_provider, |
| 192 |
): |
| 193 |
ticket_file = str(tmp_path / TICKET_FILE) |
| 194 |
assert not os.path.exists(ticket_file) |
| 195 |
|
| 196 |
options = ProviderOptions( |
| 197 |
port=next(available_ports), |
| 198 |
cipher=cipher, |
| 199 |
insecure=True, |
| 200 |
use_session_ticket=True, |
| 201 |
) |
| 202 |
|
| 203 |
client_options = copy.copy(options) |
| 204 |
client_options.mode = Provider.ClientMode |
| 205 |
client_options.extra_flags = ["--ticket-out", ticket_file] |
| 206 |
|
| 207 |
server_options = copy.copy(options) |
| 208 |
server_options.mode = Provider.ServerMode |
| 209 |
server_options.key = certificate.key |
| 210 |
server_options.cert = certificate.cert |
| 211 |
|
| 212 |
server = managed_process(provider, server_options) |
| 213 |
s2n_client = managed_process(S2N, client_options) |
| 214 |
|
| 215 |
for results in s2n_client.get_results(): |
| 216 |
results.assert_success() |
| 217 |
|
| 218 |
for results in server.get_results(): |
| 219 |
results.assert_success() |
| 220 |
|
| 221 |
assert os.path.exists(ticket_file) |
| 222 |
client_options.extra_flags = ["--ticket-in", ticket_file] |
| 223 |
client_options.use_mainline_version = True |
| 224 |
|
| 225 |
server = managed_process(provider, server_options) |
| 226 |
s2n_client = managed_process(other_provider, client_options) |
| 227 |
|
| 228 |
for results in s2n_client.get_results(): |
| 229 |
results.assert_success() |
| 230 |
assert S2N_RESUMPTION_MARKER in results.stdout |
| 231 |
|
| 232 |
for results in server.get_results(): |
| 233 |
results.assert_success() |
| 234 |
assert S2N_RESUMPTION_MARKER in results.stdout |
| 235 |
|
| 236 |
|
| 237 |
""" |
| 238 |
A new S2N client can resume a session with an old S2N client's session ticket. |
| 239 |
Tests that S2N tickets are forwards-compatible. |
| 240 |
""" |
| 241 |
|
| 242 |
|
| 243 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 244 |
@pytest.mark.parametrize("cipher", S2N_TEST_POLICIES, ids=get_parameter_name) |
| 245 |
@pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name) |
| 246 |
@pytest.mark.parametrize("provider", [S2N], ids=get_parameter_name) |
| 247 |
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name) |
| 248 |
def test_s2n_new_client_old_ticket( |
| 249 |
managed_process, |
| 250 |
tmp_path, |
| 251 |
cipher, |
| 252 |
certificate, |
| 253 |
provider, |
| 254 |
other_provider, |
| 255 |
): |
| 256 |
ticket_file = str(tmp_path / TICKET_FILE) |
| 257 |
assert not os.path.exists(ticket_file) |
| 258 |
|
| 259 |
options = ProviderOptions( |
| 260 |
port=next(available_ports), |
| 261 |
cipher=cipher, |
| 262 |
insecure=True, |
| 263 |
use_session_ticket=True, |
| 264 |
) |
| 265 |
|
| 266 |
client_options = copy.copy(options) |
| 267 |
client_options.mode = Provider.ClientMode |
| 268 |
client_options.extra_flags = ["--ticket-out", ticket_file] |
| 269 |
client_options.use_mainline_version = True |
| 270 |
|
| 271 |
server_options = copy.copy(options) |
| 272 |
server_options.mode = Provider.ServerMode |
| 273 |
server_options.key = certificate.key |
| 274 |
server_options.cert = certificate.cert |
| 275 |
|
| 276 |
server = managed_process(provider, server_options) |
| 277 |
s2n_client = managed_process(S2N, client_options) |
| 278 |
|
| 279 |
for results in s2n_client.get_results(): |
| 280 |
results.assert_success() |
| 281 |
|
| 282 |
for results in server.get_results(): |
| 283 |
results.assert_success() |
| 284 |
|
| 285 |
assert os.path.exists(ticket_file) |
| 286 |
client_options.extra_flags = ["--ticket-in", ticket_file] |
| 287 |
client_options.use_mainline_version = False |
| 288 |
|
| 289 |
server = managed_process(provider, server_options) |
| 290 |
s2n_client = managed_process(S2N, client_options) |
| 291 |
|
| 292 |
for results in s2n_client.get_results(): |
| 293 |
results.assert_success() |
| 294 |
assert S2N_RESUMPTION_MARKER in results.stdout |
| 295 |
|
| 296 |
for results in server.get_results(): |
| 297 |
results.assert_success() |
| 298 |
assert S2N_RESUMPTION_MARKER in results.stdout |