| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tls/s2n_signature_algorithms.h" |
| 17 |
|
| 18 |
#include "api/s2n.h" |
| 19 |
#include "crypto/s2n_fips.h" |
| 20 |
#include "crypto/s2n_rsa_pss.h" |
| 21 |
#include "s2n_test.h" |
| 22 |
#include "testlib/s2n_testlib.h" |
| 23 |
#include "tls/s2n_cipher_suites.h" |
| 24 |
#include "tls/s2n_config.h" |
| 25 |
#include "tls/s2n_connection.h" |
| 26 |
#include "tls/s2n_security_policies.h" |
| 27 |
#include "tls/s2n_signature_scheme.h" |
| 28 |
#include "tls/s2n_tls.h" |
| 29 |
|
| 30 |
#define LENGTH (s2n_array_len(test_signature_schemes)) |
| 31 |
#define STUFFER_SIZE (LENGTH * TLS_SIGNATURE_SCHEME_LEN + 10) |
| 32 |
|
| 33 |
#define RSA_CIPHER_SUITE &s2n_ecdhe_rsa_with_aes_128_cbc_sha |
| 34 |
#define RSA_KEX_CIPHER_SUITE &s2n_rsa_with_aes_256_gcm_sha384 |
| 35 |
#define ECDSA_CIPHER_SUITE &s2n_ecdhe_ecdsa_with_aes_128_cbc_sha |
| 36 |
#define TLS13_CIPHER_SUITE &s2n_tls13_aes_128_gcm_sha256 |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
const struct s2n_signature_scheme s2n_test_tls13_ecdsa_sha384 = { |
| 43 |
.iana_value = TLS_SIGNATURE_SCHEME_ECDSA_SHA384, |
| 44 |
.hash_alg = S2N_HASH_SHA384, |
| 45 |
.sig_alg = S2N_SIGNATURE_ECDSA, |
| 46 |
.libcrypto_nid = NID_ecdsa_with_SHA384, |
| 47 |
.signature_curve = &s2n_ecc_curve_secp384r1, |
| 48 |
|
| 49 |
.minimum_protocol_version = S2N_TLS13, |
| 50 |
}; |
| 51 |
|
| 52 |
const struct s2n_signature_scheme *const test_signature_schemes[] = { |
| 53 |
&s2n_test_tls13_ecdsa_sha384, |
| 54 |
&s2n_rsa_pkcs1_sha256, |
| 55 |
&s2n_rsa_pkcs1_sha224, |
| 56 |
&s2n_rsa_pkcs1_sha1, |
| 57 |
&s2n_ecdsa_sha1, |
| 58 |
&s2n_ecdsa_sha256, |
| 59 |
}; |
| 60 |
|
| 61 |
const struct s2n_signature_preferences test_preferences = { |
| 62 |
.count = LENGTH, |
| 63 |
.signature_schemes = test_signature_schemes, |
| 64 |
}; |
| 65 |
|
| 66 |
struct s2n_local_sig_schemes_context { |
| 67 |
struct s2n_security_policy policy; |
| 68 |
struct s2n_signature_preferences signature_prefs; |
| 69 |
}; |
| 70 |
static S2N_RESULT s2n_test_set_local_sig_schemes(struct s2n_connection *conn, |
| 71 |
struct s2n_local_sig_schemes_context *context, |
| 72 |
const struct s2n_signature_scheme **sig_schemes, size_t count) |
| 73 |
{ |
| 74 |
RESULT_ENSURE_REF(context); |
| 75 |
|
| 76 |
context->signature_prefs.signature_schemes = sig_schemes; |
| 77 |
context->signature_prefs.count = count; |
| 78 |
|
| 79 |
const struct s2n_security_policy *curr_policy = NULL; |
| 80 |
RESULT_GUARD_POSIX(s2n_connection_get_security_policy(conn, &curr_policy)); |
| 81 |
|
| 82 |
context->policy = *curr_policy; |
| 83 |
context->policy.signature_preferences = &context->signature_prefs; |
| 84 |
conn->security_policy_override = &context->policy; |
| 85 |
return S2N_RESULT_OK; |
| 86 |
} |
| 87 |
|
| 88 |
static S2N_RESULT s2n_test_set_peer_sig_schemes(struct s2n_sig_scheme_list *peer_list, |
| 89 |
const struct s2n_signature_scheme **sig_schemes, size_t count) |
| 90 |
{ |
| 91 |
for (size_t i = 0; i < count; i++) { |
| 92 |
peer_list->iana_list[i] = sig_schemes[i]->iana_value; |
| 93 |
} |
| 94 |
peer_list->len = count; |
| 95 |
return S2N_RESULT_OK; |
| 96 |
} |
| 97 |
|
| 98 |
int main(int argc, char **argv) |
| 99 |
{ |
| 100 |
BEGIN_TEST(); |
| 101 |
EXPECT_SUCCESS(s2n_disable_tls13_in_test()); |
| 102 |
|
| 103 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *rsa_cert_chain = NULL, |
| 104 |
s2n_cert_chain_and_key_ptr_free); |
| 105 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&rsa_cert_chain, |
| 106 |
S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY)); |
| 107 |
|
| 108 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *ecdsa_cert_chain = NULL, |
| 109 |
s2n_cert_chain_and_key_ptr_free); |
| 110 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&ecdsa_cert_chain, |
| 111 |
S2N_ECDSA_P384_PKCS1_CERT_CHAIN, S2N_ECDSA_P384_PKCS1_KEY)); |
| 112 |
|
| 113 |
struct s2n_cert_chain_and_key *certs[] = { ecdsa_cert_chain, rsa_cert_chain }; |
| 114 |
|
| 115 |
|
| 116 |
{ |
| 117 |
struct s2n_security_policy test_security_policy = *s2n_fetch_default_config()->security_policy; |
| 118 |
test_security_policy.signature_preferences = &test_preferences; |
| 119 |
|
| 120 |
|
| 121 |
{ |
| 122 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 123 |
s2n_connection_ptr_free); |
| 124 |
EXPECT_NOT_NULL(conn); |
| 125 |
conn->security_policy_override = &test_security_policy; |
| 126 |
conn->actual_protocol_version = S2N_TLS13; |
| 127 |
|
| 128 |
DEFER_CLEANUP(struct s2n_stuffer result = { 0 }, s2n_stuffer_free); |
| 129 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&result, 0)); |
| 130 |
EXPECT_OK(s2n_signature_algorithms_supported_list_send(conn, &result)); |
| 131 |
|
| 132 |
uint16_t size = 0; |
| 133 |
EXPECT_SUCCESS(s2n_stuffer_read_uint16(&result, &size)); |
| 134 |
EXPECT_EQUAL(size, s2n_stuffer_data_available(&result)); |
| 135 |
|
| 136 |
for (size_t i = 0; i < s2n_array_len(test_signature_schemes); i++) { |
| 137 |
uint16_t iana_value = 0; |
| 138 |
EXPECT_SUCCESS(s2n_stuffer_read_uint16(&result, &iana_value)); |
| 139 |
EXPECT_EQUAL(iana_value, test_signature_schemes[i]->iana_value); |
| 140 |
} |
| 141 |
EXPECT_EQUAL(s2n_stuffer_data_available(&result), 0); |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
{ |
| 146 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 147 |
s2n_connection_ptr_free); |
| 148 |
EXPECT_NOT_NULL(conn); |
| 149 |
conn->security_policy_override = &test_security_policy; |
| 150 |
conn->actual_protocol_version = S2N_TLS12; |
| 151 |
|
| 152 |
DEFER_CLEANUP(struct s2n_stuffer result = { 0 }, s2n_stuffer_free); |
| 153 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&result, 0)); |
| 154 |
EXPECT_OK(s2n_signature_algorithms_supported_list_send(conn, &result)); |
| 155 |
|
| 156 |
uint16_t size = 0; |
| 157 |
EXPECT_SUCCESS(s2n_stuffer_read_uint16(&result, &size)); |
| 158 |
EXPECT_EQUAL(size, s2n_stuffer_data_available(&result)); |
| 159 |
|
| 160 |
for (size_t i = 0; i < s2n_array_len(test_signature_schemes); i++) { |
| 161 |
if (test_signature_schemes[i] != &s2n_test_tls13_ecdsa_sha384) { |
| 162 |
uint16_t iana_value = 0; |
| 163 |
EXPECT_SUCCESS(s2n_stuffer_read_uint16(&result, &iana_value)); |
| 164 |
EXPECT_EQUAL(iana_value, test_signature_schemes[i]->iana_value); |
| 165 |
} |
| 166 |
} |
| 167 |
EXPECT_EQUAL(s2n_stuffer_data_available(&result), 0); |
| 168 |
}; |
| 169 |
|
| 170 |
|
| 171 |
{ |
| 172 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 173 |
s2n_connection_ptr_free); |
| 174 |
EXPECT_NOT_NULL(conn); |
| 175 |
conn->security_policy_override = &test_security_policy; |
| 176 |
conn->actual_protocol_version = S2N_TLS13; |
| 177 |
|
| 178 |
DEFER_CLEANUP(struct s2n_stuffer result = { 0 }, s2n_stuffer_free); |
| 179 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&result, 0)); |
| 180 |
EXPECT_OK(s2n_signature_algorithms_supported_list_send(conn, &result)); |
| 181 |
|
| 182 |
struct s2n_sig_scheme_list signatures = { 0 }; |
| 183 |
EXPECT_SUCCESS(s2n_recv_supported_sig_scheme_list(&result, &signatures)); |
| 184 |
EXPECT_EQUAL(s2n_stuffer_data_available(&result), 0); |
| 185 |
|
| 186 |
EXPECT_EQUAL(signatures.len, s2n_array_len(test_signature_schemes)); |
| 187 |
for (size_t i = 0; i < s2n_array_len(test_signature_schemes); i++) { |
| 188 |
EXPECT_EQUAL(signatures.iana_list[i], test_signature_schemes[i]->iana_value); |
| 189 |
} |
| 190 |
EXPECT_EQUAL(s2n_stuffer_data_available(&result), 0); |
| 191 |
}; |
| 192 |
|
| 193 |
|
| 194 |
{ |
| 195 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 196 |
s2n_connection_ptr_free); |
| 197 |
EXPECT_NOT_NULL(conn); |
| 198 |
conn->security_policy_override = &test_security_policy; |
| 199 |
conn->actual_protocol_version = S2N_TLS13; |
| 200 |
conn->quic_enabled = true; |
| 201 |
|
| 202 |
DEFER_CLEANUP(struct s2n_stuffer result = { 0 }, s2n_stuffer_free); |
| 203 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&result, 0)); |
| 204 |
EXPECT_OK(s2n_signature_algorithms_supported_list_send(conn, &result)); |
| 205 |
|
| 206 |
uint16_t size = 0; |
| 207 |
EXPECT_SUCCESS(s2n_stuffer_read_uint16(&result, &size)); |
| 208 |
EXPECT_EQUAL(size, s2n_stuffer_data_available(&result)); |
| 209 |
|
| 210 |
for (size_t i = 0; i < s2n_array_len(test_signature_schemes); i++) { |
| 211 |
if (test_signature_schemes[i]->maximum_protocol_version == 0 |
| 212 |
|| test_signature_schemes[i]->maximum_protocol_version >= S2N_TLS13) { |
| 213 |
uint16_t iana_value = 0; |
| 214 |
EXPECT_SUCCESS(s2n_stuffer_read_uint16(&result, &iana_value)); |
| 215 |
EXPECT_EQUAL(iana_value, test_signature_schemes[i]->iana_value); |
| 216 |
} |
| 217 |
} |
| 218 |
EXPECT_EQUAL(s2n_stuffer_data_available(&result), 0); |
| 219 |
}; |
| 220 |
}; |
| 221 |
|
| 222 |
|
| 223 |
{ |
| 224 |
DEFER_CLEANUP(struct s2n_config *server_config = s2n_config_new(), s2n_config_ptr_free); |
| 225 |
EXPECT_OK(s2n_config_set_tls12_security_policy(server_config)); |
| 226 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, rsa_cert_chain)); |
| 227 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, ecdsa_cert_chain)); |
| 228 |
|
| 229 |
|
| 230 |
DEFER_CLEANUP(struct s2n_config *client_ecdsa_config = s2n_config_new(), s2n_config_ptr_free); |
| 231 |
EXPECT_OK(s2n_config_set_tls12_security_policy(client_ecdsa_config)); |
| 232 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_ecdsa_config, ecdsa_cert_chain)); |
| 233 |
DEFER_CLEANUP(struct s2n_config *client_rsa_config = s2n_config_new(), s2n_config_ptr_free); |
| 234 |
EXPECT_OK(s2n_config_set_tls12_security_policy(client_rsa_config)); |
| 235 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_rsa_config, rsa_cert_chain)); |
| 236 |
|
| 237 |
|
| 238 |
const struct s2n_signature_scheme *ecdsa_default = &s2n_ecdsa_sha1; |
| 239 |
const struct s2n_signature_scheme *rsa_default = &s2n_rsa_pkcs1_sha1; |
| 240 |
|
| 241 |
|
| 242 |
{ |
| 243 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 244 |
s2n_connection_ptr_free); |
| 245 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_rsa_config)); |
| 246 |
|
| 247 |
|
| 248 |
const struct s2n_signature_scheme *test_schemes[] = { |
| 249 |
&s2n_ecdsa_sha384, |
| 250 |
&s2n_rsa_pss_rsae_sha256, |
| 251 |
&s2n_rsa_pss_pss_sha256, |
| 252 |
&s2n_rsa_pkcs1_sha256, |
| 253 |
}; |
| 254 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 255 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 256 |
test_schemes, s2n_array_len(test_schemes))); |
| 257 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 258 |
test_schemes, s2n_array_len(test_schemes))); |
| 259 |
|
| 260 |
|
| 261 |
conn->secure->cipher_suite = RSA_KEX_CIPHER_SUITE; |
| 262 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 263 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, &s2n_null_sig_scheme); |
| 264 |
|
| 265 |
|
| 266 |
conn->mode = S2N_CLIENT; |
| 267 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 268 |
EXPECT_NOT_EQUAL(conn->handshake_params.client_cert_sig_scheme, &s2n_null_sig_scheme); |
| 269 |
}; |
| 270 |
|
| 271 |
|
| 272 |
{ |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
const struct s2n_signature_scheme *test_schemes[] = { |
| 277 |
&s2n_ecdsa_sha384, |
| 278 |
&s2n_rsa_pss_rsae_sha256, |
| 279 |
&s2n_rsa_pss_pss_sha256, |
| 280 |
&s2n_rsa_pkcs1_sha256, |
| 281 |
}; |
| 282 |
|
| 283 |
|
| 284 |
{ |
| 285 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 286 |
s2n_connection_ptr_free); |
| 287 |
EXPECT_OK(s2n_connection_set_tls12_security_policy(conn)); |
| 288 |
|
| 289 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 290 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 291 |
test_schemes, s2n_array_len(test_schemes))); |
| 292 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 293 |
test_schemes, s2n_array_len(test_schemes))); |
| 294 |
|
| 295 |
|
| 296 |
{ |
| 297 |
const struct s2n_signature_scheme *expected = &s2n_ecdsa_sha1; |
| 298 |
conn->handshake_params.client_cert_pkey_type = S2N_PKEY_TYPE_ECDSA; |
| 299 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_ecdsa_config)); |
| 300 |
|
| 301 |
|
| 302 |
conn->actual_protocol_version = S2N_TLS11; |
| 303 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 304 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, expected); |
| 305 |
|
| 306 |
|
| 307 |
conn->actual_protocol_version = S2N_TLS12; |
| 308 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 309 |
EXPECT_NOT_EQUAL(conn->handshake_params.client_cert_sig_scheme, expected); |
| 310 |
}; |
| 311 |
|
| 312 |
|
| 313 |
{ |
| 314 |
const struct s2n_signature_scheme *expected = &s2n_rsa_pkcs1_md5_sha1; |
| 315 |
conn->handshake_params.client_cert_pkey_type = S2N_PKEY_TYPE_RSA; |
| 316 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_rsa_config)); |
| 317 |
|
| 318 |
|
| 319 |
conn->actual_protocol_version = S2N_TLS11; |
| 320 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 321 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, expected); |
| 322 |
|
| 323 |
|
| 324 |
conn->actual_protocol_version = S2N_TLS12; |
| 325 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 326 |
EXPECT_NOT_EQUAL(conn->handshake_params.client_cert_sig_scheme, expected); |
| 327 |
}; |
| 328 |
}; |
| 329 |
|
| 330 |
|
| 331 |
{ |
| 332 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 333 |
s2n_connection_ptr_free); |
| 334 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 335 |
|
| 336 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 337 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 338 |
test_schemes, s2n_array_len(test_schemes))); |
| 339 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 340 |
test_schemes, s2n_array_len(test_schemes))); |
| 341 |
|
| 342 |
|
| 343 |
{ |
| 344 |
const struct s2n_signature_scheme *expected = &s2n_ecdsa_sha1; |
| 345 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 346 |
|
| 347 |
|
| 348 |
conn->actual_protocol_version = S2N_TLS11; |
| 349 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 350 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, expected); |
| 351 |
|
| 352 |
|
| 353 |
conn->actual_protocol_version = S2N_TLS12; |
| 354 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 355 |
EXPECT_NOT_EQUAL(conn->handshake_params.server_cert_sig_scheme, expected); |
| 356 |
}; |
| 357 |
|
| 358 |
|
| 359 |
{ |
| 360 |
const struct s2n_signature_scheme *expected = &s2n_rsa_pkcs1_md5_sha1; |
| 361 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 362 |
|
| 363 |
|
| 364 |
conn->actual_protocol_version = S2N_TLS11; |
| 365 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 366 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, expected); |
| 367 |
|
| 368 |
|
| 369 |
conn->actual_protocol_version = S2N_TLS12; |
| 370 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 371 |
EXPECT_NOT_EQUAL(conn->handshake_params.server_cert_sig_scheme, expected); |
| 372 |
}; |
| 373 |
}; |
| 374 |
}; |
| 375 |
|
| 376 |
|
| 377 |
{ |
| 378 |
const struct s2n_signature_scheme *expected = &s2n_ecdsa_sha256; |
| 379 |
|
| 380 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 381 |
s2n_connection_ptr_free); |
| 382 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_ecdsa_config)); |
| 383 |
|
| 384 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 385 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, &expected, 1)); |
| 386 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 387 |
&expected, 1)); |
| 388 |
|
| 389 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 390 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, expected); |
| 391 |
}; |
| 392 |
|
| 393 |
|
| 394 |
{ |
| 395 |
const struct s2n_signature_scheme *expected = &s2n_ecdsa_sha256; |
| 396 |
|
| 397 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 398 |
s2n_connection_ptr_free); |
| 399 |
conn->actual_protocol_version = S2N_TLS12; |
| 400 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 401 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 402 |
|
| 403 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 404 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, &expected, 1)); |
| 405 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 406 |
&expected, 1)); |
| 407 |
|
| 408 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 409 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, expected); |
| 410 |
}; |
| 411 |
|
| 412 |
|
| 413 |
{ |
| 414 |
const struct s2n_signature_scheme *order[] = { |
| 415 |
&s2n_ecdsa_sha256, |
| 416 |
&s2n_ecdsa_sha384, |
| 417 |
&s2n_ecdsa_sha1, |
| 418 |
}; |
| 419 |
const struct s2n_signature_scheme *reversed_order[] = { |
| 420 |
&s2n_ecdsa_sha1, |
| 421 |
&s2n_ecdsa_sha384, |
| 422 |
&s2n_ecdsa_sha256, |
| 423 |
}; |
| 424 |
|
| 425 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 426 |
s2n_connection_ptr_free); |
| 427 |
conn->actual_protocol_version = S2N_TLS12; |
| 428 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 429 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 430 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 431 |
|
| 432 |
|
| 433 |
{ |
| 434 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 435 |
order, s2n_array_len(order))); |
| 436 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 437 |
reversed_order, s2n_array_len(reversed_order))); |
| 438 |
|
| 439 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 440 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, order[0]); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
{ |
| 445 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 446 |
reversed_order, s2n_array_len(reversed_order))); |
| 447 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 448 |
order, s2n_array_len(order))); |
| 449 |
|
| 450 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 451 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, reversed_order[0]); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
{ |
| 458 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 459 |
order, s2n_array_len(order))); |
| 460 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 461 |
order, s2n_array_len(order))); |
| 462 |
|
| 463 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 464 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, order[0]); |
| 465 |
} |
| 466 |
}; |
| 467 |
|
| 468 |
|
| 469 |
{ |
| 470 |
|
| 471 |
{ |
| 472 |
|
| 473 |
const struct s2n_signature_scheme *invalid = &s2n_ecdsa_sha224; |
| 474 |
|
| 475 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 476 |
s2n_connection_ptr_free); |
| 477 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 478 |
|
| 479 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 480 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 481 |
&invalid, 1)); |
| 482 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 483 |
&invalid, 1)); |
| 484 |
|
| 485 |
|
| 486 |
conn->actual_protocol_version = S2N_TLS13; |
| 487 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 488 |
EXPECT_ERROR_WITH_ERRNO( |
| 489 |
s2n_signature_algorithm_select(conn), |
| 490 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 491 |
|
| 492 |
|
| 493 |
conn->actual_protocol_version = S2N_TLS12; |
| 494 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 495 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 496 |
}; |
| 497 |
|
| 498 |
|
| 499 |
{ |
| 500 |
const struct s2n_signature_scheme *invalid = &s2n_test_tls13_ecdsa_sha384; |
| 501 |
|
| 502 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 503 |
s2n_connection_ptr_free); |
| 504 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 505 |
|
| 506 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 507 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 508 |
&invalid, 1)); |
| 509 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 510 |
&invalid, 1)); |
| 511 |
|
| 512 |
|
| 513 |
conn->actual_protocol_version = S2N_TLS12; |
| 514 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 515 |
EXPECT_ERROR_WITH_ERRNO( |
| 516 |
s2n_signature_algorithm_select(conn), |
| 517 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 518 |
|
| 519 |
|
| 520 |
conn->actual_protocol_version = S2N_TLS13; |
| 521 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 522 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 523 |
}; |
| 524 |
|
| 525 |
|
| 526 |
{ |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
struct s2n_signature_scheme sha1_tls13_scheme = s2n_ecdsa_sha384; |
| 531 |
sha1_tls13_scheme.hash_alg = s2n_ecdsa_sha1.hash_alg; |
| 532 |
const struct s2n_signature_scheme *invalid = &sha1_tls13_scheme; |
| 533 |
|
| 534 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 535 |
s2n_connection_ptr_free); |
| 536 |
conn->actual_protocol_version = S2N_TLS13; |
| 537 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 538 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 539 |
|
| 540 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 541 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 542 |
&invalid, 1)); |
| 543 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 544 |
&invalid, 1)); |
| 545 |
|
| 546 |
|
| 547 |
EXPECT_ERROR_WITH_ERRNO( |
| 548 |
s2n_signature_algorithm_select(conn), |
| 549 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 550 |
|
| 551 |
|
| 552 |
sha1_tls13_scheme.hash_alg = s2n_ecdsa_sha384.hash_alg; |
| 553 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 554 |
}; |
| 555 |
|
| 556 |
|
| 557 |
{ |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
struct s2n_signature_scheme pkcs1_tls13_scheme = s2n_rsa_pss_rsae_sha256; |
| 562 |
pkcs1_tls13_scheme.sig_alg = s2n_rsa_pkcs1_sha256.sig_alg; |
| 563 |
const struct s2n_signature_scheme *invalid = &pkcs1_tls13_scheme; |
| 564 |
|
| 565 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 566 |
s2n_connection_ptr_free); |
| 567 |
conn->actual_protocol_version = S2N_TLS13; |
| 568 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 569 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 570 |
|
| 571 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 572 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 573 |
&invalid, 1)); |
| 574 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 575 |
&invalid, 1)); |
| 576 |
|
| 577 |
|
| 578 |
EXPECT_ERROR_WITH_ERRNO( |
| 579 |
s2n_signature_algorithm_select(conn), |
| 580 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 581 |
|
| 582 |
|
| 583 |
if (s2n_is_rsa_pss_signing_supported()) { |
| 584 |
pkcs1_tls13_scheme.sig_alg = s2n_rsa_pss_rsae_sha256.sig_alg; |
| 585 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 586 |
} |
| 587 |
}; |
| 588 |
|
| 589 |
|
| 590 |
{ |
| 591 |
const struct s2n_signature_scheme *scheme = &s2n_rsa_pkcs1_sha256; |
| 592 |
|
| 593 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 594 |
s2n_connection_ptr_free); |
| 595 |
EXPECT_OK(s2n_connection_set_tls12_security_policy(conn)); |
| 596 |
conn->actual_protocol_version = S2N_TLS12; |
| 597 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 598 |
|
| 599 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 600 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 601 |
&scheme, 1)); |
| 602 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 603 |
&scheme, 1)); |
| 604 |
|
| 605 |
|
| 606 |
EXPECT_ERROR_WITH_ERRNO( |
| 607 |
s2n_signature_algorithm_select(conn), |
| 608 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 609 |
|
| 610 |
|
| 611 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_ecdsa_config)); |
| 612 |
EXPECT_ERROR_WITH_ERRNO( |
| 613 |
s2n_signature_algorithm_select(conn), |
| 614 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 615 |
|
| 616 |
|
| 617 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_rsa_config)); |
| 618 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 619 |
}; |
| 620 |
|
| 621 |
|
| 622 |
{ |
| 623 |
const struct s2n_signature_scheme *scheme = &s2n_ecdsa_sha384; |
| 624 |
|
| 625 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 626 |
s2n_connection_ptr_free); |
| 627 |
EXPECT_OK(s2n_connection_set_tls12_security_policy(conn)); |
| 628 |
conn->actual_protocol_version = S2N_TLS12; |
| 629 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 630 |
|
| 631 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 632 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 633 |
&scheme, 1)); |
| 634 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 635 |
&scheme, 1)); |
| 636 |
|
| 637 |
|
| 638 |
EXPECT_ERROR_WITH_ERRNO( |
| 639 |
s2n_signature_algorithm_select(conn), |
| 640 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 641 |
|
| 642 |
|
| 643 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_rsa_config)); |
| 644 |
EXPECT_ERROR_WITH_ERRNO( |
| 645 |
s2n_signature_algorithm_select(conn), |
| 646 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 647 |
|
| 648 |
|
| 649 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_ecdsa_config)); |
| 650 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 651 |
}; |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
{ |
| 660 |
const struct s2n_signature_scheme *ecdsa384 = &s2n_ecdsa_sha384; |
| 661 |
const struct s2n_signature_scheme *ecdsa256 = &s2n_ecdsa_sha256; |
| 662 |
|
| 663 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 664 |
s2n_connection_ptr_free); |
| 665 |
EXPECT_OK(s2n_connection_set_tls12_security_policy(conn)); |
| 666 |
conn->actual_protocol_version = S2N_TLS13; |
| 667 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 668 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 669 |
|
| 670 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 671 |
|
| 672 |
|
| 673 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 674 |
&ecdsa256, 1)); |
| 675 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 676 |
&ecdsa256, 1)); |
| 677 |
EXPECT_ERROR_WITH_ERRNO( |
| 678 |
s2n_signature_algorithm_select(conn), |
| 679 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 680 |
|
| 681 |
|
| 682 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 683 |
&ecdsa384, 1)); |
| 684 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 685 |
&ecdsa384, 1)); |
| 686 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 687 |
}; |
| 688 |
}; |
| 689 |
|
| 690 |
|
| 691 |
{ |
| 692 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 693 |
s2n_connection_ptr_free); |
| 694 |
conn->actual_protocol_version = S2N_TLS13; |
| 695 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 696 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_ecdsa_config)); |
| 697 |
|
| 698 |
const struct s2n_signature_scheme *expected = &s2n_ecdsa_sha384; |
| 699 |
const struct s2n_signature_scheme *schemes[] = { |
| 700 |
|
| 701 |
&s2n_rsa_pss_rsae_sha256, |
| 702 |
&s2n_rsa_pss_pss_sha256, |
| 703 |
&s2n_rsa_pkcs1_sha256, |
| 704 |
|
| 705 |
&s2n_ecdsa_sha224, |
| 706 |
|
| 707 |
&s2n_ecdsa_sha256, |
| 708 |
expected |
| 709 |
}; |
| 710 |
|
| 711 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 712 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 713 |
schemes, s2n_array_len(schemes))); |
| 714 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 715 |
schemes, s2n_array_len(schemes))); |
| 716 |
|
| 717 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 718 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, expected); |
| 719 |
}; |
| 720 |
|
| 721 |
|
| 722 |
{ |
| 723 |
const struct s2n_signature_scheme *expected = &s2n_rsa_pkcs1_sha256; |
| 724 |
const struct s2n_signature_scheme *peer_schemes[] = { |
| 725 |
expected |
| 726 |
}; |
| 727 |
const struct s2n_signature_scheme *local_schemes[] = { |
| 728 |
&s2n_rsa_pss_rsae_sha256, |
| 729 |
&s2n_rsa_pss_pss_sha256, |
| 730 |
&s2n_ecdsa_sha384, |
| 731 |
expected, |
| 732 |
}; |
| 733 |
|
| 734 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 735 |
s2n_connection_ptr_free); |
| 736 |
conn->actual_protocol_version = S2N_TLS12; |
| 737 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 738 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 739 |
|
| 740 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 741 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 742 |
local_schemes, s2n_array_len(local_schemes))); |
| 743 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 744 |
peer_schemes, s2n_array_len(peer_schemes))); |
| 745 |
|
| 746 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 747 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, expected); |
| 748 |
}; |
| 749 |
|
| 750 |
|
| 751 |
{ |
| 752 |
const struct s2n_signature_scheme *ecdsa_not_default = &s2n_ecdsa_sha384; |
| 753 |
const struct s2n_signature_scheme *rsa_not_default = &s2n_rsa_pkcs1_sha256; |
| 754 |
|
| 755 |
|
| 756 |
{ |
| 757 |
|
| 758 |
const struct s2n_signature_scheme *schemes_with_defaults[] = { |
| 759 |
ecdsa_not_default, |
| 760 |
rsa_not_default, |
| 761 |
rsa_default, |
| 762 |
ecdsa_default |
| 763 |
}; |
| 764 |
|
| 765 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 766 |
s2n_connection_ptr_free); |
| 767 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 768 |
|
| 769 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 770 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 771 |
schemes_with_defaults, s2n_array_len(schemes_with_defaults))); |
| 772 |
|
| 773 |
|
| 774 |
conn->actual_protocol_version = S2N_TLS12; |
| 775 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 776 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 777 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, ecdsa_default); |
| 778 |
|
| 779 |
|
| 780 |
conn->actual_protocol_version = S2N_TLS12; |
| 781 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 782 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 783 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, rsa_default); |
| 784 |
|
| 785 |
|
| 786 |
conn->actual_protocol_version = S2N_TLS13; |
| 787 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 788 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 789 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, ecdsa_not_default); |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
{ |
| 794 |
const struct s2n_signature_scheme *schemes_without_defaults[] = { |
| 795 |
ecdsa_not_default, |
| 796 |
rsa_not_default, |
| 797 |
|
| 798 |
|
| 799 |
&s2n_ecdsa_sha512, |
| 800 |
&s2n_ecdsa_sha256, |
| 801 |
&s2n_rsa_pss_rsae_sha384, |
| 802 |
}; |
| 803 |
|
| 804 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 805 |
s2n_connection_ptr_free); |
| 806 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 807 |
|
| 808 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 809 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 810 |
schemes_without_defaults, s2n_array_len(schemes_without_defaults))); |
| 811 |
|
| 812 |
|
| 813 |
conn->actual_protocol_version = S2N_TLS12; |
| 814 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 815 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 816 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, ecdsa_not_default); |
| 817 |
|
| 818 |
|
| 819 |
conn->actual_protocol_version = S2N_TLS12; |
| 820 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 821 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 822 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, rsa_not_default); |
| 823 |
|
| 824 |
|
| 825 |
conn->actual_protocol_version = S2N_TLS13; |
| 826 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 827 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 828 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, ecdsa_not_default); |
| 829 |
}; |
| 830 |
|
| 831 |
|
| 832 |
{ |
| 833 |
const struct s2n_signature_scheme *expected = &s2n_ecdsa_sha384; |
| 834 |
const struct s2n_signature_scheme *schemes[] = { |
| 835 |
|
| 836 |
&s2n_rsa_pss_rsae_sha256, |
| 837 |
&s2n_rsa_pss_pss_sha256, |
| 838 |
&s2n_rsa_pkcs1_sha256, |
| 839 |
|
| 840 |
&s2n_ecdsa_sha224, |
| 841 |
|
| 842 |
&s2n_ecdsa_sha256, |
| 843 |
expected |
| 844 |
}; |
| 845 |
|
| 846 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 847 |
s2n_connection_ptr_free); |
| 848 |
conn->actual_protocol_version = S2N_TLS13; |
| 849 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 850 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_ecdsa_config)); |
| 851 |
|
| 852 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 853 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 854 |
schemes, s2n_array_len(schemes))); |
| 855 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 856 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, expected); |
| 857 |
}; |
| 858 |
}; |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
{ |
| 866 |
const struct s2n_signature_scheme *ecdsa_not_default = &s2n_ecdsa_sha384; |
| 867 |
const struct s2n_signature_scheme *rsa_not_default = &s2n_rsa_pss_rsae_sha256; |
| 868 |
|
| 869 |
|
| 870 |
{ |
| 871 |
|
| 872 |
const struct s2n_signature_scheme *invalid_scheme = &s2n_rsa_pss_pss_sha256; |
| 873 |
|
| 874 |
|
| 875 |
const struct s2n_signature_scheme *local_schemes[] = { |
| 876 |
invalid_scheme, |
| 877 |
ecdsa_not_default, |
| 878 |
rsa_not_default, |
| 879 |
rsa_default, |
| 880 |
ecdsa_default |
| 881 |
}; |
| 882 |
const struct s2n_signature_scheme *peer_schemes[] = { |
| 883 |
invalid_scheme |
| 884 |
}; |
| 885 |
|
| 886 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 887 |
s2n_connection_ptr_free); |
| 888 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 889 |
|
| 890 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 891 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 892 |
local_schemes, s2n_array_len(local_schemes))); |
| 893 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 894 |
peer_schemes, s2n_array_len(peer_schemes))); |
| 895 |
|
| 896 |
|
| 897 |
conn->actual_protocol_version = S2N_TLS12; |
| 898 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 899 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 900 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, ecdsa_default); |
| 901 |
|
| 902 |
|
| 903 |
conn->actual_protocol_version = S2N_TLS12; |
| 904 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 905 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 906 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, rsa_default); |
| 907 |
}; |
| 908 |
|
| 909 |
|
| 910 |
{ |
| 911 |
|
| 912 |
const struct s2n_signature_scheme *local_schemes[] = { |
| 913 |
&s2n_ecdsa_sha224, |
| 914 |
rsa_default, |
| 915 |
ecdsa_default, |
| 916 |
ecdsa_not_default |
| 917 |
}; |
| 918 |
const struct s2n_signature_scheme *peer_schemes[] = { |
| 919 |
&s2n_ecdsa_sha224, |
| 920 |
|
| 921 |
rsa_default, |
| 922 |
ecdsa_default |
| 923 |
}; |
| 924 |
|
| 925 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 926 |
s2n_connection_ptr_free); |
| 927 |
conn->actual_protocol_version = S2N_TLS13; |
| 928 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 929 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, server_config)); |
| 930 |
|
| 931 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 932 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 933 |
local_schemes, s2n_array_len(local_schemes))); |
| 934 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 935 |
peer_schemes, s2n_array_len(peer_schemes))); |
| 936 |
|
| 937 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 938 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, ecdsa_not_default); |
| 939 |
}; |
| 940 |
}; |
| 941 |
}; |
| 942 |
|
| 943 |
|
| 944 |
{ |
| 945 |
struct s2n_security_policy test_security_policy = *s2n_fetch_default_config()->security_policy; |
| 946 |
test_security_policy.signature_preferences = &test_preferences; |
| 947 |
|
| 948 |
|
| 949 |
{ |
| 950 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 951 |
s2n_connection_ptr_free); |
| 952 |
conn->security_policy_override = &test_security_policy; |
| 953 |
conn->actual_protocol_version = S2N_TLS12; |
| 954 |
|
| 955 |
DEFER_CLEANUP(struct s2n_stuffer input = { 0 }, s2n_stuffer_free); |
| 956 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0)); |
| 957 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, s2n_rsa_pkcs1_sha256.iana_value)); |
| 958 |
|
| 959 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &input)); |
| 960 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, &s2n_rsa_pkcs1_sha256); |
| 961 |
}; |
| 962 |
|
| 963 |
|
| 964 |
{ |
| 965 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 966 |
s2n_connection_ptr_free); |
| 967 |
conn->security_policy_override = &test_security_policy; |
| 968 |
conn->actual_protocol_version = S2N_TLS12; |
| 969 |
|
| 970 |
DEFER_CLEANUP(struct s2n_stuffer input = { 0 }, s2n_stuffer_free); |
| 971 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0)); |
| 972 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, s2n_rsa_pkcs1_sha256.iana_value)); |
| 973 |
|
| 974 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &input)); |
| 975 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, &s2n_rsa_pkcs1_sha256); |
| 976 |
}; |
| 977 |
|
| 978 |
|
| 979 |
{ |
| 980 |
struct s2n_stuffer empty = { 0 }; |
| 981 |
|
| 982 |
|
| 983 |
{ |
| 984 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 985 |
s2n_connection_ptr_free); |
| 986 |
conn->security_policy_override = &test_security_policy; |
| 987 |
conn->actual_protocol_version = S2N_TLS12; |
| 988 |
|
| 989 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 990 |
EXPECT_ERROR_WITH_ERRNO(s2n_signature_algorithm_recv(conn, &empty), |
| 991 |
S2N_ERR_BAD_MESSAGE); |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
{ |
| 996 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 997 |
s2n_connection_ptr_free); |
| 998 |
conn->security_policy_override = &test_security_policy; |
| 999 |
conn->actual_protocol_version = S2N_TLS11; |
| 1000 |
|
| 1001 |
conn->secure->cipher_suite = RSA_CIPHER_SUITE; |
| 1002 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &empty)); |
| 1003 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, &s2n_rsa_pkcs1_md5_sha1); |
| 1004 |
|
| 1005 |
conn->secure->cipher_suite = ECDSA_CIPHER_SUITE; |
| 1006 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &empty)); |
| 1007 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, &s2n_ecdsa_sha1); |
| 1008 |
}; |
| 1009 |
|
| 1010 |
|
| 1011 |
{ |
| 1012 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 1013 |
s2n_connection_ptr_free); |
| 1014 |
conn->security_policy_override = &test_security_policy; |
| 1015 |
conn->actual_protocol_version = S2N_TLS11; |
| 1016 |
|
| 1017 |
conn->handshake_params.client_cert_pkey_type = S2N_PKEY_TYPE_RSA; |
| 1018 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &empty)); |
| 1019 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, &s2n_rsa_pkcs1_md5_sha1); |
| 1020 |
|
| 1021 |
conn->handshake_params.client_cert_pkey_type = S2N_PKEY_TYPE_ECDSA; |
| 1022 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &empty)); |
| 1023 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, &s2n_ecdsa_sha1); |
| 1024 |
}; |
| 1025 |
}; |
| 1026 |
|
| 1027 |
|
| 1028 |
{ |
| 1029 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 1030 |
s2n_connection_ptr_free); |
| 1031 |
|
| 1032 |
DEFER_CLEANUP(struct s2n_stuffer input = { 0 }, s2n_stuffer_free); |
| 1033 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0)); |
| 1034 |
|
| 1035 |
const struct s2n_signature_scheme *const test_schemes[] = { |
| 1036 |
&s2n_rsa_pkcs1_sha256, |
| 1037 |
&s2n_ecdsa_sha256, |
| 1038 |
|
| 1039 |
&s2n_rsa_pkcs1_md5_sha1, |
| 1040 |
&s2n_ecdsa_sha1, |
| 1041 |
}; |
| 1042 |
const struct s2n_signature_scheme *const supported_schemes[] = { |
| 1043 |
&s2n_ecdsa_sha384, |
| 1044 |
}; |
| 1045 |
|
| 1046 |
struct s2n_security_policy test_policy = test_security_policy; |
| 1047 |
struct s2n_signature_preferences test_prefs = { |
| 1048 |
.signature_schemes = supported_schemes, |
| 1049 |
.count = s2n_array_len(supported_schemes), |
| 1050 |
}; |
| 1051 |
test_policy.signature_preferences = &test_prefs; |
| 1052 |
|
| 1053 |
struct s2n_security_policy control_policy = test_security_policy; |
| 1054 |
struct s2n_signature_preferences control_prefs = { |
| 1055 |
.signature_schemes = test_schemes, |
| 1056 |
.count = s2n_array_len(test_schemes), |
| 1057 |
}; |
| 1058 |
control_policy.signature_preferences = &control_prefs; |
| 1059 |
|
| 1060 |
|
| 1061 |
conn->security_policy_override = &test_policy; |
| 1062 |
for (size_t i = 0; i < s2n_array_len(test_schemes); i++) { |
| 1063 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, test_schemes[i]->iana_value)); |
| 1064 |
EXPECT_ERROR_WITH_ERRNO(s2n_signature_algorithm_recv(conn, &input), |
| 1065 |
S2N_ERR_INVALID_SIGNATURE_SCHEME); |
| 1066 |
} |
| 1067 |
|
| 1068 |
|
| 1069 |
conn->security_policy_override = &control_policy; |
| 1070 |
for (size_t i = 0; i < s2n_array_len(test_schemes); i++) { |
| 1071 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, test_schemes[i]->iana_value)); |
| 1072 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &input)); |
| 1073 |
} |
| 1074 |
}; |
| 1075 |
|
| 1076 |
|
| 1077 |
{ |
| 1078 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 1079 |
s2n_connection_ptr_free); |
| 1080 |
conn->security_policy_override = &test_security_policy; |
| 1081 |
|
| 1082 |
DEFER_CLEANUP(struct s2n_stuffer input = { 0 }, s2n_stuffer_free); |
| 1083 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0)); |
| 1084 |
|
| 1085 |
conn->actual_protocol_version = S2N_TLS12; |
| 1086 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, s2n_rsa_pkcs1_sha224.iana_value)); |
| 1087 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &input)); |
| 1088 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, &s2n_rsa_pkcs1_sha224); |
| 1089 |
|
| 1090 |
conn->actual_protocol_version = S2N_TLS13; |
| 1091 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, s2n_rsa_pkcs1_sha224.iana_value)); |
| 1092 |
EXPECT_ERROR_WITH_ERRNO(s2n_signature_algorithm_recv(conn, &input), |
| 1093 |
S2N_ERR_INVALID_SIGNATURE_SCHEME); |
| 1094 |
}; |
| 1095 |
}; |
| 1096 |
|
| 1097 |
|
| 1098 |
const uint16_t max_sig_schemes = TLS_SIGNATURE_SCHEME_LIST_MAX_LEN; |
| 1099 |
for (uint16_t count = max_sig_schemes - 1; count <= max_sig_schemes + 1; count++) { |
| 1100 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 1101 |
s2n_connection_ptr_free); |
| 1102 |
EXPECT_NOT_NULL(conn); |
| 1103 |
|
| 1104 |
DEFER_CLEANUP(struct s2n_stuffer input = { 0 }, s2n_stuffer_free); |
| 1105 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0)); |
| 1106 |
|
| 1107 |
uint16_t sig_scheme_list_size = count * TLS_SIGNATURE_SCHEME_LEN; |
| 1108 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, sig_scheme_list_size)); |
| 1109 |
for (size_t i = 0; i < count; i++) { |
| 1110 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, s2n_rsa_pkcs1_sha256.iana_value)); |
| 1111 |
} |
| 1112 |
|
| 1113 |
int ret = s2n_recv_supported_sig_scheme_list(&input, &conn->handshake_params.peer_sig_scheme_list); |
| 1114 |
if (count <= max_sig_schemes) { |
| 1115 |
EXPECT_SUCCESS(ret); |
| 1116 |
} else { |
| 1117 |
EXPECT_FAILURE_WITH_ERRNO(ret, S2N_ERR_TOO_MANY_SIGNATURE_SCHEMES); |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
for (size_t i = S2N_TLS10; i < S2N_TLS13; i++) { |
| 1123 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 1124 |
s2n_connection_ptr_free); |
| 1125 |
EXPECT_NOT_NULL(conn); |
| 1126 |
conn->actual_protocol_version = i; |
| 1127 |
|
| 1128 |
DEFER_CLEANUP(struct s2n_stuffer result = { 0 }, s2n_stuffer_free); |
| 1129 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&result, 0)); |
| 1130 |
EXPECT_OK(s2n_signature_algorithms_supported_list_send(conn, &result)); |
| 1131 |
|
| 1132 |
struct s2n_sig_scheme_list signatures = { 0 }; |
| 1133 |
EXPECT_SUCCESS(s2n_recv_supported_sig_scheme_list(&result, &signatures)); |
| 1134 |
EXPECT_EQUAL(s2n_stuffer_data_available(&result), 0); |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
uint16_t iana = 0, other_iana = 0; |
| 1139 |
for (size_t a = 0; a < signatures.len; a++) { |
| 1140 |
iana = signatures.iana_list[a]; |
| 1141 |
for (int b = 0; b < signatures.len; b++) { |
| 1142 |
if (a == b) { |
| 1143 |
continue; |
| 1144 |
} |
| 1145 |
other_iana = signatures.iana_list[b]; |
| 1146 |
EXPECT_NOT_EQUAL(iana, other_iana); |
| 1147 |
} |
| 1148 |
} |
| 1149 |
}; |
| 1150 |
|
| 1151 |
|
| 1152 |
{ |
| 1153 |
const struct s2n_signature_scheme *const pss_test_signature_schemes[] = { |
| 1154 |
&s2n_rsa_pss_rsae_sha256, |
| 1155 |
&s2n_rsa_pss_pss_sha256, |
| 1156 |
}; |
| 1157 |
|
| 1158 |
const struct s2n_signature_preferences pss_test_preferences = { |
| 1159 |
.count = 2, |
| 1160 |
.signature_schemes = pss_test_signature_schemes, |
| 1161 |
}; |
| 1162 |
|
| 1163 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free); |
| 1164 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, rsa_cert_chain)); |
| 1165 |
|
| 1166 |
struct s2n_security_policy test_security_policy = *s2n_fetch_default_config()->security_policy; |
| 1167 |
test_security_policy.signature_preferences = &pss_test_preferences, |
| 1168 |
config->security_policy = &test_security_policy; |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
{ |
| 1173 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 1174 |
s2n_connection_ptr_free); |
| 1175 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 1176 |
conn->actual_protocol_version = S2N_TLS13; |
| 1177 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, config)); |
| 1178 |
|
| 1179 |
DEFER_CLEANUP(struct s2n_stuffer result = { 0 }, s2n_stuffer_free); |
| 1180 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&result, 0)); |
| 1181 |
EXPECT_OK(s2n_signature_algorithms_supported_list_send(conn, &result)); |
| 1182 |
|
| 1183 |
uint16_t size = 0; |
| 1184 |
EXPECT_SUCCESS(s2n_stuffer_read_uint16(&result, &size)); |
| 1185 |
EXPECT_EQUAL(size, s2n_stuffer_data_available(&result)); |
| 1186 |
if (s2n_is_rsa_pss_certs_supported()) { |
| 1187 |
EXPECT_EQUAL(size, 2 * sizeof(uint16_t)); |
| 1188 |
} else if (s2n_is_rsa_pss_signing_supported()) { |
| 1189 |
EXPECT_EQUAL(size, 1 * sizeof(uint16_t)); |
| 1190 |
} else { |
| 1191 |
EXPECT_EQUAL(size, 0); |
| 1192 |
} |
| 1193 |
}; |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
{ |
| 1198 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 1199 |
s2n_connection_ptr_free); |
| 1200 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 1201 |
conn->actual_protocol_version = S2N_TLS13; |
| 1202 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, config)); |
| 1203 |
|
| 1204 |
DEFER_CLEANUP(struct s2n_stuffer input = { 0 }, s2n_stuffer_free); |
| 1205 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0)); |
| 1206 |
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&input, s2n_rsa_pss_rsae_sha256.iana_value)); |
| 1207 |
|
| 1208 |
if (s2n_is_rsa_pss_signing_supported()) { |
| 1209 |
EXPECT_OK(s2n_signature_algorithm_recv(conn, &input)); |
| 1210 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, &s2n_rsa_pss_rsae_sha256); |
| 1211 |
} else { |
| 1212 |
EXPECT_ERROR_WITH_ERRNO(s2n_signature_algorithm_recv(conn, &input), |
| 1213 |
S2N_ERR_INVALID_SIGNATURE_SCHEME); |
| 1214 |
} |
| 1215 |
}; |
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
{ |
| 1220 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), |
| 1221 |
s2n_connection_ptr_free); |
| 1222 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 1223 |
conn->actual_protocol_version = S2N_TLS13; |
| 1224 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, config)); |
| 1225 |
|
| 1226 |
const struct s2n_signature_scheme *schemes[] = { &s2n_rsa_pss_rsae_sha256 }; |
| 1227 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 1228 |
schemes, s2n_array_len(schemes))); |
| 1229 |
|
| 1230 |
if (s2n_is_rsa_pss_signing_supported()) { |
| 1231 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 1232 |
EXPECT_EQUAL(conn->handshake_params.client_cert_sig_scheme, |
| 1233 |
&s2n_rsa_pss_rsae_sha256); |
| 1234 |
} else { |
| 1235 |
EXPECT_ERROR_WITH_ERRNO( |
| 1236 |
s2n_signature_algorithm_select(conn), |
| 1237 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 1238 |
} |
| 1239 |
}; |
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
{ |
| 1245 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), |
| 1246 |
s2n_connection_ptr_free); |
| 1247 |
EXPECT_OK(s2n_connection_set_tls12_security_policy(conn)); |
| 1248 |
conn->secure->cipher_suite = TLS13_CIPHER_SUITE; |
| 1249 |
conn->actual_protocol_version = S2N_TLS13; |
| 1250 |
|
| 1251 |
|
| 1252 |
const struct s2n_signature_scheme *peer_schemes[] = { &s2n_rsa_pkcs1_sha224 }; |
| 1253 |
EXPECT_OK(s2n_test_set_peer_sig_schemes(&conn->handshake_params.peer_sig_scheme_list, |
| 1254 |
peer_schemes, s2n_array_len(peer_schemes))); |
| 1255 |
|
| 1256 |
|
| 1257 |
const struct s2n_signature_scheme *local_schemes[] = { |
| 1258 |
&s2n_rsa_pkcs1_sha224, |
| 1259 |
&s2n_rsa_pss_rsae_sha256, |
| 1260 |
&s2n_rsa_pss_rsae_sha384, |
| 1261 |
}; |
| 1262 |
struct s2n_local_sig_schemes_context local_context = { 0 }; |
| 1263 |
EXPECT_OK(s2n_test_set_local_sig_schemes(conn, &local_context, |
| 1264 |
local_schemes, s2n_array_len(local_schemes))); |
| 1265 |
|
| 1266 |
|
| 1267 |
EXPECT_ERROR_WITH_ERRNO( |
| 1268 |
s2n_signature_algorithm_select(conn), |
| 1269 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 1270 |
|
| 1271 |
|
| 1272 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, config)); |
| 1273 |
|
| 1274 |
|
| 1275 |
if (s2n_is_rsa_pss_signing_supported()) { |
| 1276 |
EXPECT_OK(s2n_signature_algorithm_select(conn)); |
| 1277 |
EXPECT_EQUAL(conn->handshake_params.server_cert_sig_scheme, |
| 1278 |
&s2n_rsa_pss_rsae_sha256); |
| 1279 |
} else { |
| 1280 |
EXPECT_ERROR_WITH_ERRNO( |
| 1281 |
s2n_signature_algorithm_select(conn), |
| 1282 |
S2N_ERR_NO_VALID_SIGNATURE_SCHEME); |
| 1283 |
} |
| 1284 |
}; |
| 1285 |
}; |
| 1286 |
|
| 1287 |
|
| 1288 |
{ |
| 1289 |
const struct s2n_signature_scheme *const default_schemes[] = { |
| 1290 |
&s2n_rsa_pkcs1_sha1, |
| 1291 |
&s2n_ecdsa_sha1 |
| 1292 |
}; |
| 1293 |
|
| 1294 |
const struct s2n_signature_scheme *const sha256_schemes[] = { |
| 1295 |
&s2n_rsa_pkcs1_sha256, |
| 1296 |
&s2n_ecdsa_sha256 |
| 1297 |
}; |
| 1298 |
|
| 1299 |
const struct s2n_signature_scheme *const sha384_schemes[] = { |
| 1300 |
&s2n_rsa_pkcs1_sha384, |
| 1301 |
&s2n_ecdsa_sha384 |
| 1302 |
}; |
| 1303 |
|
| 1304 |
const struct s2n_signature_preferences defaults_preferences = { |
| 1305 |
.count = s2n_array_len(default_schemes), |
| 1306 |
.signature_schemes = default_schemes, |
| 1307 |
}; |
| 1308 |
|
| 1309 |
const struct s2n_signature_preferences sha256_preferences = { |
| 1310 |
.count = s2n_array_len(sha256_schemes), |
| 1311 |
.signature_schemes = sha256_schemes, |
| 1312 |
}; |
| 1313 |
for (size_t i = 0; i < sha256_preferences.count; i++) { |
| 1314 |
for (size_t j = 0; j < defaults_preferences.count; j++) { |
| 1315 |
EXPECT_NOT_EQUAL(sha256_preferences.signature_schemes[i]->iana_value, |
| 1316 |
defaults_preferences.signature_schemes[j]->iana_value); |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
const struct s2n_signature_preferences sha384_preferences = { |
| 1321 |
.count = s2n_array_len(sha384_schemes), |
| 1322 |
.signature_schemes = sha384_schemes, |
| 1323 |
}; |
| 1324 |
for (size_t i = 0; i < sha384_preferences.count; i++) { |
| 1325 |
for (size_t j = 0; j < defaults_preferences.count; j++) { |
| 1326 |
EXPECT_NOT_EQUAL(sha384_preferences.signature_schemes[i]->iana_value, |
| 1327 |
defaults_preferences.signature_schemes[j]->iana_value); |
| 1328 |
} |
| 1329 |
} |
| 1330 |
|
| 1331 |
|
| 1332 |
struct s2n_security_policy defaults_policy = security_policy_20190214; |
| 1333 |
defaults_policy.signature_preferences = &defaults_preferences; |
| 1334 |
struct s2n_security_policy sha256_policy = security_policy_20190214; |
| 1335 |
sha256_policy.signature_preferences = &sha256_preferences; |
| 1336 |
struct s2n_security_policy sha384_policy = security_policy_20190214; |
| 1337 |
sha384_policy.signature_preferences = &sha384_preferences; |
| 1338 |
|
| 1339 |
|
| 1340 |
for (size_t cert_i = 0; cert_i < s2n_array_len(certs); cert_i++) { |
| 1341 |
|
| 1342 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free); |
| 1343 |
EXPECT_NOT_NULL(config); |
| 1344 |
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config)); |
| 1345 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, certs[cert_i])); |
| 1346 |
|
| 1347 |
|
| 1348 |
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), |
| 1349 |
s2n_connection_ptr_free); |
| 1350 |
DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), |
| 1351 |
s2n_connection_ptr_free); |
| 1352 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config)); |
| 1353 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config)); |
| 1354 |
|
| 1355 |
|
| 1356 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair, s2n_io_pair_close); |
| 1357 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 1358 |
EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair)); |
| 1359 |
|
| 1360 |
|
| 1361 |
client_conn->security_policy_override = &sha256_policy; |
| 1362 |
server_conn->security_policy_override = &sha256_policy; |
| 1363 |
|
| 1364 |
EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn)); |
| 1365 |
EXPECT_EQUAL(client_conn->actual_protocol_version, S2N_TLS12); |
| 1366 |
EXPECT_EQUAL(server_conn->actual_protocol_version, S2N_TLS12); |
| 1367 |
}; |
| 1368 |
|
| 1369 |
|
| 1370 |
for (size_t cert_i = 0; cert_i < s2n_array_len(certs); cert_i++) { |
| 1371 |
|
| 1372 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free); |
| 1373 |
EXPECT_NOT_NULL(config); |
| 1374 |
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config)); |
| 1375 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, certs[cert_i])); |
| 1376 |
|
| 1377 |
|
| 1378 |
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), |
| 1379 |
s2n_connection_ptr_free); |
| 1380 |
DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), |
| 1381 |
s2n_connection_ptr_free); |
| 1382 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config)); |
| 1383 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config)); |
| 1384 |
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING)); |
| 1385 |
EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING)); |
| 1386 |
|
| 1387 |
|
| 1388 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair, s2n_io_pair_close); |
| 1389 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 1390 |
EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair)); |
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
client_conn->security_policy_override = &sha256_policy; |
| 1396 |
server_conn->security_policy_override = &sha384_policy; |
| 1397 |
|
| 1398 |
EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate_test_server_and_client(server_conn, client_conn), |
| 1399 |
S2N_ERR_INVALID_SIGNATURE_SCHEME); |
| 1400 |
EXPECT_EQUAL(client_conn->actual_protocol_version, S2N_TLS12); |
| 1401 |
EXPECT_EQUAL(server_conn->actual_protocol_version, S2N_TLS12); |
| 1402 |
}; |
| 1403 |
|
| 1404 |
|
| 1405 |
for (size_t cert_i = 0; cert_i < s2n_array_len(certs); cert_i++) { |
| 1406 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free); |
| 1407 |
EXPECT_NOT_NULL(config); |
| 1408 |
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config)); |
| 1409 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, certs[cert_i])); |
| 1410 |
|
| 1411 |
|
| 1412 |
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), |
| 1413 |
s2n_connection_ptr_free); |
| 1414 |
DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), |
| 1415 |
s2n_connection_ptr_free); |
| 1416 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config)); |
| 1417 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config)); |
| 1418 |
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING)); |
| 1419 |
EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING)); |
| 1420 |
|
| 1421 |
|
| 1422 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair, s2n_io_pair_close); |
| 1423 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 1424 |
EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair)); |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
client_conn->security_policy_override = &sha256_policy; |
| 1430 |
server_conn->security_policy_override = &defaults_policy; |
| 1431 |
|
| 1432 |
EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate_test_server_and_client(server_conn, client_conn), |
| 1433 |
S2N_ERR_INVALID_SIGNATURE_SCHEME); |
| 1434 |
EXPECT_EQUAL(client_conn->actual_protocol_version, S2N_TLS12); |
| 1435 |
EXPECT_EQUAL(server_conn->actual_protocol_version, S2N_TLS12); |
| 1436 |
}; |
| 1437 |
}; |
| 1438 |
|
| 1439 |
EXPECT_SUCCESS(s2n_reset_tls13_in_test()); |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
if (s2n_is_tls13_fully_supported()) { |
| 1450 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free); |
| 1451 |
EXPECT_NOT_NULL(config); |
| 1452 |
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config)); |
| 1453 |
|
| 1454 |
|
| 1455 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *ecdsa_p521_chain = NULL, |
| 1456 |
s2n_cert_chain_and_key_ptr_free); |
| 1457 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&ecdsa_p521_chain, |
| 1458 |
S2N_ECDSA_P512_CERT_CHAIN, S2N_ECDSA_P512_KEY)); |
| 1459 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, ecdsa_p521_chain)); |
| 1460 |
|
| 1461 |
|
| 1462 |
struct s2n_cipher_suite *cipher_suite_tls13 = &s2n_tls13_aes_128_gcm_sha256; |
| 1463 |
struct s2n_cipher_suite *cipher_suite_tls12 = &s2n_ecdhe_ecdsa_with_aes_128_gcm_sha256; |
| 1464 |
struct s2n_cipher_preferences cipher_prefs = { |
| 1465 |
.count = 1, |
| 1466 |
.suites = NULL |
| 1467 |
}; |
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
const struct s2n_signature_scheme *sig_schemes[] = { |
| 1473 |
&s2n_ecdsa_sha224, |
| 1474 |
&s2n_ecdsa_sha256, |
| 1475 |
&s2n_ecdsa_sha512 |
| 1476 |
}; |
| 1477 |
struct s2n_signature_preferences sig_prefs = { |
| 1478 |
.count = s2n_array_len(sig_schemes), |
| 1479 |
.signature_schemes = sig_schemes |
| 1480 |
}; |
| 1481 |
|
| 1482 |
const struct s2n_ecc_named_curve *curves[] = { |
| 1483 |
&s2n_ecc_curve_secp384r1, |
| 1484 |
&s2n_ecc_curve_secp521r1 |
| 1485 |
}; |
| 1486 |
struct s2n_ecc_preferences ecc_prefs = { |
| 1487 |
.count = s2n_array_len(curves), |
| 1488 |
.ecc_curves = curves |
| 1489 |
}; |
| 1490 |
struct s2n_security_policy policy = security_policy_20230317; |
| 1491 |
policy.cipher_preferences = &cipher_prefs; |
| 1492 |
policy.signature_preferences = &sig_prefs; |
| 1493 |
policy.ecc_preferences = &ecc_prefs; |
| 1494 |
config->security_policy = &policy; |
| 1495 |
|
| 1496 |
for (uint8_t version = S2N_TLS12; version <= S2N_TLS13; version++) { |
| 1497 |
if (version >= S2N_TLS13) { |
| 1498 |
cipher_prefs.suites = &cipher_suite_tls13; |
| 1499 |
} else { |
| 1500 |
cipher_prefs.suites = &cipher_suite_tls12; |
| 1501 |
} |
| 1502 |
|
| 1503 |
DEFER_CLEANUP(struct s2n_connection *client = s2n_connection_new(S2N_CLIENT), |
| 1504 |
s2n_connection_ptr_free); |
| 1505 |
EXPECT_SUCCESS(s2n_connection_set_config(client, config)); |
| 1506 |
|
| 1507 |
DEFER_CLEANUP(struct s2n_connection *server = s2n_connection_new(S2N_SERVER), |
| 1508 |
s2n_connection_ptr_free); |
| 1509 |
EXPECT_SUCCESS(s2n_connection_set_config(server, config)); |
| 1510 |
|
| 1511 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair, s2n_io_pair_close); |
| 1512 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 1513 |
EXPECT_SUCCESS(s2n_connections_set_io_pair(client, server, &io_pair)); |
| 1514 |
|
| 1515 |
EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server, client)); |
| 1516 |
EXPECT_EQUAL(client->actual_protocol_version, version); |
| 1517 |
EXPECT_EQUAL(server->actual_protocol_version, version); |
| 1518 |
|
| 1519 |
if (version >= S2N_TLS13) { |
| 1520 |
|
| 1521 |
EXPECT_EQUAL(server->handshake_params.server_cert_sig_scheme, &s2n_ecdsa_sha512); |
| 1522 |
} else { |
| 1523 |
|
| 1524 |
EXPECT_NOT_EQUAL(server->handshake_params.server_cert_sig_scheme, &s2n_ecdsa_sha512); |
| 1525 |
EXPECT_EQUAL(server->handshake_params.server_cert_sig_scheme, &s2n_ecdsa_sha224); |
| 1526 |
} |
| 1527 |
|
| 1528 |
|
| 1529 |
EXPECT_NOT_EQUAL(server->secure->cipher_suite->prf_alg, S2N_HMAC_SHA512); |
| 1530 |
EXPECT_EQUAL(server->secure->cipher_suite->prf_alg, S2N_HMAC_SHA256); |
| 1531 |
|
| 1532 |
|
| 1533 |
EXPECT_NOT_EQUAL(server->kex_params.server_ecc_evp_params.negotiated_curve, |
| 1534 |
&s2n_ecc_curve_secp521r1); |
| 1535 |
EXPECT_EQUAL(server->kex_params.server_ecc_evp_params.negotiated_curve, |
| 1536 |
&s2n_ecc_curve_secp384r1); |
| 1537 |
} |
| 1538 |
} |
| 1539 |
|
| 1540 |
|
| 1541 |
{ |
| 1542 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free); |
| 1543 |
EXPECT_NOT_NULL(config); |
| 1544 |
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config)); |
| 1545 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, rsa_cert_chain)); |
| 1546 |
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "test_all_rsa_kex")); |
| 1547 |
EXPECT_SUCCESS(s2n_config_set_client_auth_type(config, S2N_CERT_AUTH_REQUIRED)); |
| 1548 |
|
| 1549 |
DEFER_CLEANUP(struct s2n_connection *client = s2n_connection_new(S2N_CLIENT), |
| 1550 |
s2n_connection_ptr_free); |
| 1551 |
EXPECT_SUCCESS(s2n_connection_set_config(client, config)); |
| 1552 |
|
| 1553 |
DEFER_CLEANUP(struct s2n_connection *server = s2n_connection_new(S2N_SERVER), |
| 1554 |
s2n_connection_ptr_free); |
| 1555 |
EXPECT_SUCCESS(s2n_connection_set_config(server, config)); |
| 1556 |
|
| 1557 |
DEFER_CLEANUP(struct s2n_test_io_stuffer_pair io_pair, s2n_io_stuffer_pair_free); |
| 1558 |
EXPECT_OK(s2n_io_stuffer_pair_init(&io_pair)); |
| 1559 |
EXPECT_OK(s2n_connections_set_io_stuffer_pair(client, server, &io_pair)); |
| 1560 |
EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server, client)); |
| 1561 |
|
| 1562 |
|
| 1563 |
EXPECT_EQUAL(server->secure->cipher_suite->key_exchange_alg, &s2n_rsa); |
| 1564 |
|
| 1565 |
|
| 1566 |
EXPECT_EQUAL(server->handshake_params.server_cert_sig_scheme, &s2n_null_sig_scheme); |
| 1567 |
EXPECT_EQUAL(client->handshake_params.server_cert_sig_scheme, &s2n_null_sig_scheme); |
| 1568 |
|
| 1569 |
|
| 1570 |
EXPECT_EQUAL(server->handshake_params.client_cert_sig_scheme, &s2n_rsa_pkcs1_sha256); |
| 1571 |
EXPECT_EQUAL(client->handshake_params.client_cert_sig_scheme, &s2n_rsa_pkcs1_sha256); |
| 1572 |
}; |
| 1573 |
|
| 1574 |
END_TEST(); |
| 1575 |
|
| 1576 |
return 0; |
| 1577 |
} |