PROV: Refactor the RSA DER support
[openssl.git] / test / cmp_vfy_test.c
index 41ddad86ba8a4abc629bcf8bb447bb87c7f29d5b..c74dd2faeca4be5a5141f902e236b4a20a7d2ccd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
  * Copyright Nokia 2007-2019
  * Copyright Siemens AG 2015-2019
  *
@@ -11,6 +11,7 @@
 
 #include "cmp_testlib.h"
 #include "../crypto/crmf/crmf_local.h" /* for manipulating POPO signature */
+DEFINE_STACK_OF(OSSL_CRMF_MSG)
 
 static const char *server_f;
 static const char *client_f;
@@ -44,12 +45,6 @@ static void tear_down(CMP_VFY_TEST_FIXTURE *fixture)
     OPENSSL_free(fixture);
 }
 
-static int print_to_bio_out(const char *func, const char *file, int line,
-                            OSSL_CMP_severity level, const char *msg)
-{
-    return OSSL_CMP_print_to_bio(bio_out, func, file, line, level, msg);
-}
-
 static time_t test_time_valid = 0, test_time_after_expiration = 0;
 
 static CMP_VFY_TEST_FIXTURE *set_up(const char *const test_case_name)
@@ -69,7 +64,7 @@ static CMP_VFY_TEST_FIXTURE *set_up(const char *const test_case_name)
         return NULL;
     }
     X509_VERIFY_PARAM_set_time(X509_STORE_get0_param(ts), test_time_valid);
-    X509_STORE_set_verify_cb(ts, OSSL_CMP_print_cert_verify_cb);
+    X509_STORE_set_verify_cb(ts, X509_STORE_CTX_print_verify_cb);
     return fixture;
 }
 
@@ -115,6 +110,7 @@ static int test_verify_popo(void)
     return result;
 }
 
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 static int test_verify_popo_bad(void)
 {
     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
@@ -122,6 +118,7 @@ static int test_verify_popo_bad(void)
     EXECUTE_TEST(execute_verify_popo_test, tear_down);
     return result;
 }
+#endif
 
 static int execute_validate_msg_test(CMP_VFY_TEST_FIXTURE *fixture)
 {
@@ -313,7 +310,7 @@ static int test_validate_msg_signature_sender_cert_absent(void)
 }
 
 
-static int test_validate_with_sender(X509_NAME *name, int expected)
+static int test_validate_with_sender(const X509_NAME *name, int expected)
 {
     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
     fixture->expected = expected;
@@ -437,8 +434,7 @@ static void setup_check_received(CMP_VFY_TEST_FIXTURE **fixture, int expected,
                                                       nonce_data, nonce_len))) {
         tear_down((*fixture));
         (*fixture) = NULL;
-    }
-    else if (trid_data != NULL) {
+    } else if (trid_data != NULL) {
         ASN1_OCTET_STRING *trid = ASN1_OCTET_STRING_new();
         if (trid == NULL
             || !ASN1_OCTET_STRING_set(trid, trid_data,
@@ -451,6 +447,7 @@ static void setup_check_received(CMP_VFY_TEST_FIXTURE **fixture, int expected,
     }
 }
 
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 static int test_MSG_check_received_no_protection_no_cb(void)
 {
     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
@@ -466,6 +463,7 @@ static int test_MSG_check_received_no_protection_restrictive_cb(void)
     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
     return result;
 }
+#endif
 
 static int test_MSG_check_received_no_protection_permissive_cb(void)
 {
@@ -491,6 +489,7 @@ static int test_MSG_check_received_check_transaction_id(void)
     return result;
 }
 
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 static int test_MSG_check_received_check_transaction_id_bad(void)
 {
     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
@@ -498,6 +497,7 @@ static int test_MSG_check_received_check_transaction_id_bad(void)
     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
     return result;
 }
+#endif
 
 static int test_MSG_check_received_check_recipient_nonce(void)
 {
@@ -514,6 +514,7 @@ static int test_MSG_check_received_check_recipient_nonce(void)
     return result;
 }
 
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 static int test_MSG_check_received_check_recipient_nonce_bad(void)
 {
     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
@@ -521,6 +522,7 @@ static int test_MSG_check_received_check_recipient_nonce_bad(void)
     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
     return result;
 }
+#endif
 
 void cleanup_tests(void)
 {
@@ -549,6 +551,11 @@ int setup_tests(void)
     ts.tm_year += 10;              /* February 18th 2028 */
     test_time_after_expiration = mktime(&ts);
 
+    if (!test_skip_common_options()) {
+        TEST_error("Error parsing test options\n");
+        return 0;
+    }
+
     RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
     if (!TEST_ptr(server_f = test_get_argument(0))
             || !TEST_ptr(client_f = test_get_argument(1))
@@ -598,7 +605,9 @@ int setup_tests(void)
 
     /* Message validation tests */
     ADD_TEST(test_verify_popo);
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
     ADD_TEST(test_verify_popo_bad);
+#endif
     ADD_TEST(test_validate_msg_signature_trusted_ok);
     ADD_TEST(test_validate_msg_signature_trusted_expired);
     ADD_TEST(test_validate_msg_signature_srvcert_wrong);
@@ -619,13 +628,19 @@ int setup_tests(void)
     ADD_TEST(test_validate_cert_path_expired);
     ADD_TEST(test_validate_cert_path_wrong_anchor);
 
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
     ADD_TEST(test_MSG_check_received_no_protection_no_cb);
     ADD_TEST(test_MSG_check_received_no_protection_restrictive_cb);
+#endif
     ADD_TEST(test_MSG_check_received_no_protection_permissive_cb);
     ADD_TEST(test_MSG_check_received_check_transaction_id);
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
     ADD_TEST(test_MSG_check_received_check_transaction_id_bad);
+#endif
     ADD_TEST(test_MSG_check_received_check_recipient_nonce);
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
     ADD_TEST(test_MSG_check_received_check_recipient_nonce_bad);
+#endif
 
     return 1;