Skip to content

Commit

Permalink
Fix v5 secret key decryption and add corresponding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Dec 1, 2023
1 parent 1b1f579 commit 51e6d9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librepgp/stream-key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/tests/ffi-key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 51e6d9a

Please sign in to comment.