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