Skip to content

Commit

Permalink
Add check to s2n_signature_scheme_valid_to_accept (#3728)
Browse files Browse the repository at this point in the history

Co-authored-by: Harrison Kaiser <[email protected]>
  • Loading branch information
harrisonkaiser and uwaces authored Jan 5, 2023
1 parent 2663f20 commit 41cfe12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/unit/s2n_tls13_cert_verify_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ int run_tests(const struct s2n_tls13_cert_verify_test *test_case, s2n_mode verif

struct s2n_connection *verifying_conn = NULL, *sending_conn = NULL;
EXPECT_NOT_NULL(verifying_conn = s2n_connection_new(verifier_mode));
verifying_conn->actual_protocol_version = S2N_TLS13;
EXPECT_NOT_NULL(sending_conn = s2n_connection_new(verifier_mode == S2N_CLIENT ? S2N_SERVER : S2N_CLIENT));

EXPECT_SUCCESS(s2n_stuffer_alloc(&certificate_in, S2N_MAX_TEST_PEM_SIZE));
Expand Down Expand Up @@ -154,6 +155,7 @@ int run_tests(const struct s2n_tls13_cert_verify_test *test_case, s2n_mode verif

struct s2n_connection *verifying_conn = NULL;
EXPECT_NOT_NULL(verifying_conn = s2n_connection_new(verifier_mode));
verifying_conn->actual_protocol_version = S2N_TLS13;
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, cert_chain));
EXPECT_SUCCESS(s2n_connection_set_config(verifying_conn, config));
verifying_conn->handshake_params.our_chain_and_key = cert_chain;
Expand Down Expand Up @@ -222,6 +224,7 @@ int run_tests(const struct s2n_tls13_cert_verify_test *test_case, s2n_mode verif

struct s2n_connection *verifying_conn = NULL;
EXPECT_NOT_NULL(verifying_conn = s2n_connection_new(verifier_mode));
verifying_conn->actual_protocol_version = S2N_TLS13;
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, cert_chain));
EXPECT_SUCCESS(s2n_connection_set_config(verifying_conn, config));
verifying_conn->handshake_params.our_chain_and_key = cert_chain;
Expand Down
11 changes: 11 additions & 0 deletions tls/s2n_signature_algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

static int s2n_signature_scheme_valid_to_offer(struct s2n_connection *conn, const struct s2n_signature_scheme *scheme)
{
POSIX_ENSURE_REF(conn);

/* We don't know what protocol version we will eventually negotiate, but we know that it won't be any higher. */
POSIX_ENSURE_GTE(conn->actual_protocol_version, scheme->minimum_protocol_version);

Expand All @@ -50,13 +52,22 @@ static int s2n_signature_scheme_valid_to_offer(struct s2n_connection *conn, cons
static int s2n_signature_scheme_valid_to_accept(struct s2n_connection *conn, const struct s2n_signature_scheme *scheme)
{
POSIX_ENSURE_REF(scheme);
POSIX_ENSURE_REF(conn);

POSIX_GUARD(s2n_signature_scheme_valid_to_offer(conn, scheme));

if (scheme->maximum_protocol_version != S2N_UNKNOWN_PROTOCOL_VERSION) {
POSIX_ENSURE_LTE(conn->actual_protocol_version, scheme->maximum_protocol_version);
}

POSIX_ENSURE_NE(conn->actual_protocol_version, S2N_UNKNOWN_PROTOCOL_VERSION);
if (conn->actual_protocol_version >= S2N_TLS13) {
POSIX_ENSURE_NE(scheme->hash_alg, S2N_HASH_SHA1);
POSIX_ENSURE_NE(scheme->sig_alg, S2N_SIGNATURE_RSA);
} else {
POSIX_ENSURE_NE(scheme->sig_alg, S2N_SIGNATURE_RSA_PSS_PSS);
}

return 0;
}

Expand Down

0 comments on commit 41cfe12

Please sign in to comment.