Use multiple certs per s2n_config in s2n_self_talk_test.c
To get some basic coverage in unit tests for multicert. A majority of
test coverage is in integration tests.
@@ -108,7 +108,6 @@ int main(int argc, char **argv)
char *cert_chain_pem;
char *private_key_pem;
char *dhparams_pem;
- struct s2n_cert_chain_and_key *chain_and_key;
BEGIN_TEST();
EXPECT_NOT_NULL(cert_chain_pem = malloc(S2N_MAX_TEST_PEM_SIZE));
@@ -117,8 +116,9 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(setenv("S2N_ENABLE_CLIENT_MODE", "1", 0));
- for (int cert = 0; cert < SUPPORTED_CERTIFICATE_FORMATS; cert++) {
for (int is_dh_key_exchange = 0; is_dh_key_exchange <= 1; is_dh_key_exchange++) {
+ struct s2n_cert_chain_and_key *chain_and_keys[SUPPORTED_CERTIFICATE_FORMATS];
+
/* Create a pipe */
EXPECT_SUCCESS(pipe(server_to_client));
EXPECT_SUCCESS(pipe(client_to_server));
@@ -144,12 +144,14 @@ int main(int argc, char **argv)
conn->actual_protocol_version = S2N_TLS12;
EXPECT_NOT_NULL(config = s2n_config_new());
-
+ for (int cert = 0; cert < SUPPORTED_CERTIFICATE_FORMATS; cert++) {
EXPECT_SUCCESS(s2n_read_test_pem(certificate_paths[cert], cert_chain_pem, S2N_MAX_TEST_PEM_SIZE));
EXPECT_SUCCESS(s2n_read_test_pem(private_key_paths[cert], private_key_pem, S2N_MAX_TEST_PEM_SIZE));
- EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
- EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain_pem, private_key_pem));
- EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
+ EXPECT_NOT_NULL(chain_and_keys[cert] = s2n_cert_chain_and_key_new());
+ EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_keys[cert], cert_chain_pem, private_key_pem));
+ EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_keys[cert]));
+ }
+
if (is_dh_key_exchange) {
EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_DHPARAMS, dhparams_pem, S2N_MAX_TEST_PEM_SIZE));
EXPECT_SUCCESS(s2n_config_add_dhparams(config, dhparams_pem));
@@ -189,14 +191,15 @@ int main(int argc, char **argv)
} while(shutdown_rc != 0);
EXPECT_SUCCESS(s2n_connection_free(conn));
- EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
+ for (int cert = 0; cert < SUPPORTED_CERTIFICATE_FORMATS; cert++) {
+ EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_keys[cert]));
+ }
EXPECT_SUCCESS(s2n_config_free(config));
/* Clean up */
EXPECT_EQUAL(waitpid(-1, &status, 0), pid);
EXPECT_EQUAL(status, 0);
}
- }
free(cert_chain_pem);
free(private_key_pem);
