From 6614927607122849b1babb90c670434d19979898 Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Mon, 31 Jul 2023 17:25:48 +0300 Subject: [PATCH] (WIP) Fix v5 secret key decryption and add corresponding tests. --- src/librepgp/stream-key.cpp | 1 + src/tests/ffi-key.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/librepgp/stream-key.cpp b/src/librepgp/stream-key.cpp index b515925e90..f98235e07f 100644 --- a/src/librepgp/stream-key.cpp +++ b/src/librepgp/stream-key.cpp @@ -701,6 +701,7 @@ decrypt_secret_key(pgp_key_pkt_t *key, const char *password) ret = decrypt_secret_key_v3(&crypt, decdata.data(), key->sec_data, key->sec_len); break; case PGP_V4: + case PGP_V5: pgp_cipher_cfb_decrypt(&crypt, decdata.data(), key->sec_data, key->sec_len); ret = RNP_SUCCESS; break; diff --git a/src/tests/ffi-key.cpp b/src/tests/ffi-key.cpp index c681a96365..4e25c8d87a 100644 --- a/src/tests/ffi-key.cpp +++ b/src/tests/ffi-key.cpp @@ -4608,3 +4608,23 @@ TEST_F(rnp_tests, test_v5_keys_g23) rnp_ffi_destroy(ffi); } + +TEST_F(rnp_tests, test_v5_sec_keys) +{ + rnp_ffi_t ffi = NULL; + assert_rnp_success(rnp_ffi_create(&ffi, "GPG", "GPG")); + /* v5 rsa-rsa secret key */ + assert_true(import_sec_keys(ffi, "data/test_stream_key_load/v5-rsa-sec.asc")); + rnp_key_handle_t key = NULL; + assert_rnp_success(rnp_locate_key(ffi, "keyid", "b856a4197113d431", &key)); + assert_rnp_success(rnp_key_unlock(key, "password")); + assert_rnp_success(rnp_key_lock(key)); + rnp_key_handle_destroy(key); + /* v5 rsa secret subkey */ + assert_rnp_success(rnp_locate_key(ffi, "keyid", "2d400055b0345c33", &key)); + assert_rnp_success(rnp_key_unlock(key, "password")); + assert_rnp_success(rnp_key_lock(key)); + rnp_key_handle_destroy(key); + + rnp_ffi_destroy(ffi); +}