From 397675d8a6b708e2af1008e283546c2f2e39555b Mon Sep 17 00:00:00 2001 From: Denys Date: Tue, 24 Sep 2024 00:22:18 +0300 Subject: [PATCH] Fix broken tests(time-machine) --- src/tests/ffi-enc.cpp | 23 +++++++++++++++++++++++ src/tests/generatekey.cpp | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/tests/ffi-enc.cpp b/src/tests/ffi-enc.cpp index 3591cd4d52..e46379662f 100644 --- a/src/tests/ffi-enc.cpp +++ b/src/tests/ffi-enc.cpp @@ -178,6 +178,17 @@ TEST_F(rnp_tests, test_ffi_encrypt_pass) assert_rnp_failure(rnp_op_encrypt_add_password(op, "pass1", "WRONG", 0, NULL)); assert_rnp_failure(rnp_op_encrypt_add_password(op, "pass1", NULL, 0, "WRONG")); assert_rnp_success(rnp_op_encrypt_add_password(op, "pass1", NULL, 0, NULL)); + + // Allow insecure ciphers + if (blowfish_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "BLOWFISH", 0, RNP_SECURITY_REMOVE_ALL, 0, nullptr)); + } + if (cast5_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "CAST5", 0, RNP_SECURITY_REMOVE_ALL, 0, nullptr)); + } + // add password if (!sm2_enabled() && !twofish_enabled()) { assert_rnp_failure(rnp_op_encrypt_add_password(op, "pass2", "SM3", 12345, "TWOFISH")); @@ -624,6 +635,10 @@ TEST_F(rnp_tests, test_ffi_encrypt_pk) key = NULL; // set the data encryption cipher if (cast5_enabled()) { + if (cast5_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "CAST5", 0, RNP_SECURITY_REMOVE_ALL, 0, nullptr)); + } assert_rnp_success(rnp_op_encrypt_set_cipher(op, "CAST5")); } else { assert_rnp_failure(rnp_op_encrypt_set_cipher(op, "CAST5")); @@ -1184,6 +1199,10 @@ TEST_F(rnp_tests, test_ffi_encrypt_pk_key_provider) key = NULL; // set the data encryption cipher if (cast5_enabled()) { + if (cast5_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "CAST5", 0, RNP_SECURITY_REMOVE_ALL, 0, NULL)); + } assert_rnp_success(rnp_op_encrypt_set_cipher(op, "CAST5")); } else { assert_rnp_failure(rnp_op_encrypt_set_cipher(op, "CAST5")); @@ -1293,6 +1312,10 @@ TEST_F(rnp_tests, test_ffi_encrypt_and_sign) key = NULL; // set the data encryption cipher if (cast5_enabled()) { + if (cast5_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "CAST5", 0, RNP_SECURITY_REMOVE_ALL, 0, NULL)); + } assert_rnp_success(rnp_op_encrypt_set_cipher(op, "CAST5")); } else { assert_rnp_failure(rnp_op_encrypt_set_cipher(op, "CAST5")); diff --git a/src/tests/generatekey.cpp b/src/tests/generatekey.cpp index 1cc18e01cc..67879547b4 100644 --- a/src/tests/generatekey.cpp +++ b/src/tests/generatekey.cpp @@ -242,6 +242,26 @@ cipher_supported(const std::string &cipher) return true; } +static void +enable_insecure_ciphers(rnp_ffi_t ffi) +{ + // Allow insecure ciphers + if (cast5_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "CAST5", 0, RNP_SECURITY_REMOVE_ALL, 0, nullptr)); + } + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "TRIPLEDES", 0, RNP_SECURITY_REMOVE_ALL, 0, nullptr)); + if (idea_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "IDEA", 0, RNP_SECURITY_REMOVE_ALL, 0, nullptr)); + } + if (blowfish_enabled()) { + assert_rnp_success(rnp_remove_security_rule( + ffi, RNP_FEATURE_SYMM_ALG, "BLOWFISH", 0, RNP_SECURITY_REMOVE_ALL, 0, nullptr)); + } +} + TEST_F(rnp_tests, rnpkeys_generatekey_testEncryption) { const char *cipherAlg[] = { @@ -264,6 +284,7 @@ TEST_F(rnp_tests, rnpkeys_generatekey_testEncryption) for (unsigned int armored = 0; armored <= 1; ++armored) { /* Set up rnp and encrypt the dataa */ assert_true(setup_cli_rnp_common(&rnp, RNP_KEYSTORE_GPG, NULL, NULL)); + enable_insecure_ciphers(rnp.ffi); /* Load keyring */ assert_true(rnp.load_keyrings(false)); size_t seccount = 0;