From 51e6d9a57d8491640f952fe47383a756a3231a18 Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Mon, 31 Jul 2023 17:25:48 +0300 Subject: [PATCH] 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 6fb61d0e5a..1eab0e1214 100644 --- a/src/librepgp/stream-key.cpp +++ b/src/librepgp/stream-key.cpp @@ -792,6 +792,7 @@ decrypt_secret_key(pgp_key_pkt_t *key, const char *password) FALLTHROUGH_STATEMENT; #endif 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 bf2bfcacff..0a644e2979 100644 --- a/src/tests/ffi-key.cpp +++ b/src/tests/ffi-key.cpp @@ -4701,3 +4701,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); +}