Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: update default cert chain for unit tests #4582

Merged
merged 19 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/pems/ocsp/OCSP-TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ openssl ocsp -CAfile ca_cert.pem \
-cert server_cert.pem -respout ocsp_response_no_next_update.der
```

### Generating ocsp_response_revoked.der
```
# Run responder
openssl ocsp -port 8889 -text -CA ca_cert.pem \
-index certs_revoked.txt \
-rkey ocsp_key.pem \
-rsigner ocsp_cert.pem \
-nrequest 1 -ndays $(( 365 * 100 ))

# Run requester
openssl ocsp -CAfile ca_cert.pem \
-url http://127.0.0.1:8889 \
-issuer ca_cert.pem \
-cert server_cert.pem \
-respout ocsp_response_revoked.der
```

### Index Files
The index files in the previous commands are in the CA Database format, and are the source of truth for certificates being verified or rejected.

Expand Down
Binary file modified tests/pems/ocsp/ocsp_response_revoked.der
Binary file not shown.
10 changes: 6 additions & 4 deletions tests/testlib/s2n_testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ S2N_RESULT s2n_connection_set_test_master_secret(struct s2n_connection *conn, co
/* These paths assume that the unit tests are run from inside the unit/ directory.
* Absolute paths will be needed if test directories go to deeper levels.
*/
#define S2N_RSA_2048_PKCS8_CERT_CHAIN "../pems/rsa_2048_pkcs8_cert.pem"
#define S2N_RSA_2048_PKCS1_CERT_CHAIN "../pems/rsa_2048_pkcs1_cert.pem"
#define S2N_RSA_2048_PKCS8_CERT_CHAIN "../pems/rsa_2048_pkcs8_cert.pem"
#define S2N_RSA_2048_PKCS1_CERT_CHAIN "../pems/rsa_2048_pkcs1_cert.pem"
#define S2N_RSA_2048_PKCS1_SHA256_CERT_CHAIN "../pems/permutations/rsae_pkcs_2048_sha256/server-chain.pem"
#define S2N_RSA_2048_PKCS1_SHA256_CERT_KEY "../pems/permutations/rsae_pkcs_2048_sha256/server-key.pem"

#define S2N_RSA_2048_PKCS1_LEAF_CERT "../pems/rsa_2048_pkcs1_leaf.pem"
#define S2N_ECDSA_P256_PKCS1_CERT_CHAIN "../pems/ecdsa_p256_pkcs1_cert.pem"
Expand Down Expand Up @@ -194,8 +196,8 @@ S2N_RESULT s2n_connection_set_test_master_secret(struct s2n_connection *conn, co

#define S2N_TEST_TRUST_STORE "../pems/trust-store/ca-bundle.crt"

#define S2N_DEFAULT_TEST_CERT_CHAIN S2N_RSA_2048_PKCS1_CERT_CHAIN
goatgoose marked this conversation as resolved.
Show resolved Hide resolved
#define S2N_DEFAULT_TEST_PRIVATE_KEY S2N_RSA_2048_PKCS1_KEY
#define S2N_DEFAULT_TEST_CERT_CHAIN S2N_RSA_2048_PKCS1_SHA256_CERT_CHAIN
#define S2N_DEFAULT_TEST_PRIVATE_KEY S2N_RSA_2048_PKCS1_SHA256_CERT_KEY

#define S2N_DEFAULT_ECDSA_TEST_CERT_CHAIN S2N_ECDSA_P384_PKCS1_CERT_CHAIN
#define S2N_DEFAULT_ECDSA_TEST_PRIVATE_KEY S2N_ECDSA_P384_PKCS1_KEY
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_cert_validation_callback_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int main(int argc, char *argv[])
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
EXPECT_NOT_NULL(conn);
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
EXPECT_SUCCESS(s2n_set_server_name(conn, "s2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(conn, "localhost"));
jouho marked this conversation as resolved.
Show resolved Hide resolved

DEFER_CLEANUP(struct s2n_stuffer cert_chain_stuffer = { 0 }, s2n_stuffer_free);
EXPECT_OK(s2n_test_cert_chain_data_from_pem(conn, S2N_DEFAULT_TEST_CERT_CHAIN, &cert_chain_stuffer));
Expand Down Expand Up @@ -313,7 +313,7 @@ int main(int argc, char *argv[])
EXPECT_NOT_NULL(client_conn);
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config));
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "s2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));

DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
Expand Down Expand Up @@ -359,7 +359,7 @@ int main(int argc, char *argv[])
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
EXPECT_NOT_NULL(client_conn);
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "s2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));

DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s2n_config_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ int main(int argc, char **argv)
s2n_connection_ptr_free);
EXPECT_NOT_NULL(client_conn);
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "s2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));

struct s2n_test_io_pair io_pair = { 0 };
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/s2n_crl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ int main(int argc, char *argv[])
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
EXPECT_NOT_NULL(client_conn);
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "S2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING));

DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
Expand Down Expand Up @@ -822,7 +822,7 @@ int main(int argc, char *argv[])
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
EXPECT_NOT_NULL(client_conn);
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "S2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING));

DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s2n_mem_usage_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#elif defined(__OpenBSD__)
#define MEM_PER_CONNECTION 61
#else
#define MEM_PER_CONNECTION 49
#define MEM_PER_CONNECTION 50
goatgoose marked this conversation as resolved.
Show resolved Hide resolved
#endif

/* This is the maximum memory per connection including 4KB of slack */
Expand Down
21 changes: 5 additions & 16 deletions tests/unit/s2n_x509_validator_test.c
goatgoose marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ static int mock_time(void *data, uint64_t *timestamp)

static int fetch_expired_after_ocsp_timestamp(void *data, uint64_t *timestamp)
{
/* 2200-11-27 */
*timestamp = 7283958536000000000;
/* 2250-01-01 */
*timestamp = 8835984000000000000;
return 0;
}

Expand Down Expand Up @@ -212,7 +212,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand All @@ -238,7 +237,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

EXPECT_SUCCESS(s2n_x509_validator_set_max_chain_depth(&validator, 2));
Expand Down Expand Up @@ -287,7 +285,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand Down Expand Up @@ -325,7 +322,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand Down Expand Up @@ -406,7 +402,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand Down Expand Up @@ -444,7 +439,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

EXPECT_SUCCESS(s2n_x509_validator_set_max_chain_depth(&validator, 2));
Expand Down Expand Up @@ -489,7 +483,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

s2n_clock_time_nanoseconds old_clock = connection->config->wall_clock;
Expand Down Expand Up @@ -546,7 +539,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

s2n_clock_time_nanoseconds old_clock = connection->config->wall_clock;
Expand Down Expand Up @@ -585,11 +577,12 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

/* alter a random byte in the certificate to make it invalid */
chain_data[500] = (uint8_t) (chain_data[500] << 2);
size_t corrupt_index = 200;
EXPECT_TRUE(chain_len > corrupt_index);
chain_data[corrupt_index] = (uint8_t) (chain_data[corrupt_index] << 2);
struct s2n_pkey public_key_out;
EXPECT_SUCCESS(s2n_pkey_zero_init(&public_key_out));
s2n_pkey_type pkey_type = S2N_PKEY_TYPE_UNKNOWN;
Expand Down Expand Up @@ -629,7 +622,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand Down Expand Up @@ -677,7 +669,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand Down Expand Up @@ -717,7 +708,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand Down Expand Up @@ -765,7 +755,6 @@ int main(int argc, char **argv)
uint8_t *chain_data = s2n_stuffer_raw_read(&cert_chain_stuffer, chain_len);
EXPECT_NOT_NULL(chain_data);

/* The default cert chain includes a SHA1 signature, so the security policy must allow SHA1 cert signatures. */
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(connection, "default"));

struct s2n_pkey public_key_out;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/s2n_x509_validator_time_verification_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ int main(int argc, char *argv[])
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
EXPECT_NOT_NULL(client_conn);
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "s2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));

DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
Expand Down Expand Up @@ -256,7 +256,7 @@ int main(int argc, char *argv[])
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
EXPECT_NOT_NULL(conn);
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
EXPECT_SUCCESS(s2n_set_server_name(conn, "s2nTestServer"));
EXPECT_SUCCESS(s2n_set_server_name(conn, "localhost"));

DEFER_CLEANUP(struct s2n_stuffer cert_chain_stuffer = { 0 }, s2n_stuffer_free);
EXPECT_OK(s2n_test_cert_chain_data_from_pem(conn, S2N_DEFAULT_TEST_CERT_CHAIN, &cert_chain_stuffer));
Expand Down
Loading