Change all our uses of CRYPTO_THREAD_run_once to use RUN_ONCE instead
[openssl.git] / test / ssl_test_ctx.c
index 4d038d2c23b2c7dd37ab717e29c79d809ab5aa41..090e1a330e736dd8e812c1099bf38ef54a2ce273 100644 (file)
@@ -83,7 +83,8 @@ static const test_enum ssl_alerts[] = {
     {"UnknownCA", SSL_AD_UNKNOWN_CA},
     {"HandshakeFailure", SSL_AD_HANDSHAKE_FAILURE},
     {"UnrecognizedName", SSL_AD_UNRECOGNIZED_NAME},
-    {"BadCertificate", SSL_AD_BAD_CERTIFICATE}
+    {"BadCertificate", SSL_AD_BAD_CERTIFICATE},
+    {"NoApplicationProtocol", SSL_AD_NO_APPLICATION_PROTOCOL},
 };
 
 __owur static int parse_alert(int *alert, const char *value)
@@ -281,6 +282,28 @@ const char *ssl_test_method_name(ssl_test_method_t method)
     return enum_name(ssl_test_methods, OSSL_NELEM(ssl_test_methods), method);
 }
 
+#define IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(field)                     \
+    static int parse_##field(SSL_TEST_CTX *test_ctx, const char *value) \
+    {                                                                   \
+        OPENSSL_free(test_ctx->field);                                  \
+        test_ctx->field = OPENSSL_strdup(value);                        \
+        OPENSSL_assert(test_ctx->field != NULL);                        \
+        return 1;                                                       \
+    }
+
+/************************************/
+/* NPN and ALPN options             */
+/************************************/
+
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(client_npn_protocols)
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(server_npn_protocols)
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(server2_npn_protocols)
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(expected_npn_protocol)
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(client_alpn_protocols)
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(server_alpn_protocols)
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(server2_alpn_protocols)
+IMPLEMENT_SSL_TEST_CTX_STRING_OPTION(expected_alpn_protocol)
+
 /*************************************************************/
 /* Known test options and their corresponding parse methods. */
 /*************************************************************/
@@ -301,9 +324,16 @@ static const ssl_test_ctx_option ssl_test_ctx_options[] = {
     { "ServerNameCallback", &parse_servername_callback },
     { "SessionTicketExpected", &parse_session_ticket },
     { "Method", &parse_test_method },
+    { "ClientNPNProtocols", &parse_client_npn_protocols },
+    { "ServerNPNProtocols", &parse_server_npn_protocols },
+    { "Server2NPNProtocols", &parse_server2_npn_protocols },
+    { "ExpectedNPNProtocol", &parse_expected_npn_protocol },
+    { "ClientALPNProtocols", &parse_client_alpn_protocols },
+    { "ServerALPNProtocols", &parse_server_alpn_protocols },
+    { "Server2ALPNProtocols", &parse_server2_alpn_protocols },
+    { "ExpectedALPNProtocol", &parse_expected_alpn_protocol },
 };
 
-
 /*
  * Since these methods are used to create tests, we use OPENSSL_assert liberally
  * for malloc failures and other internal errors.
@@ -318,6 +348,15 @@ SSL_TEST_CTX *SSL_TEST_CTX_new()
 
 void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx)
 {
+
+    OPENSSL_free(ctx->client_npn_protocols);
+    OPENSSL_free(ctx->server_npn_protocols);
+    OPENSSL_free(ctx->server2_npn_protocols);
+    OPENSSL_free(ctx->client_alpn_protocols);
+    OPENSSL_free(ctx->server_alpn_protocols);
+    OPENSSL_free(ctx->server2_alpn_protocols);
+    OPENSSL_free(ctx->expected_npn_protocol);
+    OPENSSL_free(ctx->expected_alpn_protocol);
     OPENSSL_free(ctx);
 }