summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2022-11-22 08:43:03 +0100
committerDr. David von Oheimb <dev@ddvo.net>2022-12-08 08:25:49 +0100
commitf6fdbe63c7c51bd7c2c37567781d166e475ab5b1 (patch)
treedc9dfd7e4137c28f1ae8ae4d2e861b590eb509cf /test
parentc919280f793dc468814587c0f103425def872dcc (diff)
OSSL_CMP_validate_msg(): make sure to reject protection type mismatch
Do not accept password-based if expected signature-based and no secret is available and do not accept signature-based if expected password-based and no trust anchors available. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> (Merged from https://github.com/openssl/openssl/pull/19729) (cherry picked from commit fc93335760686ad7cf3633d457caf18b0ac83ea2)
Diffstat (limited to 'test')
-rw-r--r--test/cmp_vfy_test.c74
1 files changed, 47 insertions, 27 deletions
diff --git a/test/cmp_vfy_test.c b/test/cmp_vfy_test.c
index 5aa6a008cc..23117760d1 100644
--- a/test/cmp_vfy_test.c
+++ b/test/cmp_vfy_test.c
@@ -83,6 +83,12 @@ static X509 *insta_cert = NULL, *instaca_cert = NULL;
static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH];
static OSSL_CMP_MSG *ir_unprotected, *ir_rmprotection;
+/* secret value used for IP_waitingStatus_PBM.der */
+static const unsigned char sec_1[] = {
+ '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3',
+ 'Q', '-', 'u', 'd', 'N', 'R'
+};
+
static int flip_bit(ASN1_BIT_STRING *bitstr)
{
int bit_num = 7;
@@ -142,19 +148,14 @@ static int execute_validate_cert_path_test(CMP_VFY_TEST_FIXTURE *fixture)
return res;
}
-static int test_validate_msg_mac_alg_protection(void)
+static int test_validate_msg_mac_alg_protection(int miss, int wrong)
{
- /* secret value belonging to cmp-test/CMP_IP_waitingStatus_PBM.der */
- const unsigned char sec_1[] = {
- '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3',
- 'Q', '-', 'u', 'd', 'N', 'R'
- };
-
SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
- fixture->expected = 1;
- if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_1,
- sizeof(sec_1)))
+ fixture->expected = !miss && !wrong;
+ if (!TEST_true(miss ? OSSL_CMP_CTX_set0_trusted(fixture->cmp_ctx, NULL)
+ : OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_1,
+ wrong ? 4 : sizeof(sec_1)))
|| !TEST_ptr(fixture->msg = load_pkimsg(ip_waiting_f, libctx))) {
tear_down(fixture);
fixture = NULL;
@@ -163,6 +164,21 @@ static int test_validate_msg_mac_alg_protection(void)
return result;
}
+static int test_validate_msg_mac_alg_protection_ok(void)
+{
+ return test_validate_msg_mac_alg_protection(0, 0);
+}
+
+static int test_validate_msg_mac_alg_protection_missing(void)
+{
+ return test_validate_msg_mac_alg_protection(1, 0);
+}
+
+static int test_validate_msg_mac_alg_protection_wrong(void)
+{
+ return test_validate_msg_mac_alg_protection(0, 1);
+}
+
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
static int test_validate_msg_mac_alg_protection_bad(void)
{
@@ -231,12 +247,17 @@ static int test_validate_msg_signature_trusted_expired(void)
}
#endif
-static int test_validate_msg_signature_srvcert_wrong(void)
+static int test_validate_msg_signature_srvcert(int bad_sig, int miss, int wrong)
{
SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
- fixture->expected = 0;
+ fixture->cert = srvcert;
+ fixture->expected = !bad_sig && !wrong && !miss;
if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx))
- || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx, clcert))) {
+ || !TEST_true(miss ? OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
+ sec_1, sizeof(sec_1))
+ : OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx,
+ wrong? clcert : srvcert))
+ || (bad_sig && !flip_bit(fixture->msg->protection))) {
tear_down(fixture);
fixture = NULL;
}
@@ -244,30 +265,26 @@ static int test_validate_msg_signature_srvcert_wrong(void)
return result;
}
-static int test_validate_msg_signature_srvcert(int bad_sig)
+static int test_validate_msg_signature_srvcert_missing(void)
{
- SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
- fixture->expected = !bad_sig;
- if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx))
- || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx, srvcert))
- || (bad_sig && !flip_bit(fixture->msg->protection))) {
- tear_down(fixture);
- fixture = NULL;
- }
- EXECUTE_TEST(execute_validate_msg_test, tear_down);
- return result;
+ return test_validate_msg_signature_srvcert(0, 1, 0);
+}
+
+static int test_validate_msg_signature_srvcert_wrong(void)
+{
+ return test_validate_msg_signature_srvcert(0, 0, 1);
}
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
static int test_validate_msg_signature_bad(void)
{
- return test_validate_msg_signature_srvcert(1);
+ return test_validate_msg_signature_srvcert(1, 0, 0);
}
#endif
static int test_validate_msg_signature_sender_cert_srvcert(void)
{
- return test_validate_msg_signature_srvcert(0);
+ return test_validate_msg_signature_srvcert(0, 0, 0);
}
static int test_validate_msg_signature_sender_cert_untrusted(void)
@@ -634,6 +651,7 @@ int setup_tests(void)
ADD_TEST(test_validate_msg_signature_trusted_ok);
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
ADD_TEST(test_validate_msg_signature_trusted_expired);
+ ADD_TEST(test_validate_msg_signature_srvcert_missing);
#endif
ADD_TEST(test_validate_msg_signature_srvcert_wrong);
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
@@ -651,8 +669,10 @@ int setup_tests(void)
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
ADD_TEST(test_validate_msg_unprotected_request);
#endif
- ADD_TEST(test_validate_msg_mac_alg_protection);
+ ADD_TEST(test_validate_msg_mac_alg_protection_ok);
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ ADD_TEST(test_validate_msg_mac_alg_protection_missing);
+ ADD_TEST(test_validate_msg_mac_alg_protection_wrong);
ADD_TEST(test_validate_msg_mac_alg_protection_bad);
#endif