1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-10 13:04:23 +01:00

gpg: Print a warning if the card backup key could not be written.

* g10/keygen.c (card_write_key_to_backup_file): Fix error handing by
removing the RC variable.  Add warning note.
--

GnuPG-bug-id: 2169
This commit is contained in:
Werner Koch 2025-01-08 14:04:23 +01:00
parent 72e3fddbfe
commit b9028f869d
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -6094,7 +6094,6 @@ static gpg_error_t
card_write_key_to_backup_file (PKT_public_key *sk, const char *backup_dir) card_write_key_to_backup_file (PKT_public_key *sk, const char *backup_dir)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
int rc;
char keyid_buffer[2 * 8 + 1]; char keyid_buffer[2 * 8 + 1];
char name_buffer[50]; char name_buffer[50];
char *fname; char *fname;
@ -6129,10 +6128,10 @@ card_write_key_to_backup_file (PKT_public_key *sk, const char *backup_dir)
pkt->pkttype = PKT_SECRET_KEY; pkt->pkttype = PKT_SECRET_KEY;
pkt->pkt.secret_key = sk; pkt->pkt.secret_key = sk;
rc = build_packet (fp, pkt); err = build_packet (fp, pkt);
if (rc) if (err)
{ {
log_error ("build packet failed: %s\n", gpg_strerror (rc)); log_error ("build packet failed: %s\n", gpg_strerror (err));
iobuf_cancel (fp); iobuf_cancel (fp);
} }
else else
@ -6176,6 +6175,7 @@ card_store_key_with_backup (ctrl_t ctrl, PKT_public_key *sub_psk,
void *kek = NULL; void *kek = NULL;
size_t keklen; size_t keklen;
char *ecdh_param_str = NULL; char *ecdh_param_str = NULL;
int key_is_on_card = 0;
memset (&info, 0, sizeof (info)); memset (&info, 0, sizeof (info));
@ -6210,6 +6210,7 @@ card_store_key_with_backup (ctrl_t ctrl, PKT_public_key *sub_psk,
if (err) if (err)
goto leave; goto leave;
key_is_on_card = 1;
err = agent_keywrap_key (ctrl, 1, &kek, &keklen); err = agent_keywrap_key (ctrl, 1, &kek, &keklen);
if (err) if (err)
{ {
@ -6247,6 +6248,15 @@ card_store_key_with_backup (ctrl_t ctrl, PKT_public_key *sub_psk,
} }
leave: leave:
if (err && key_is_on_card)
{
tty_printf (_(
"Warning: Although the key has been written to the card, a backup file was\n"
" not properly written to the disk. You may want to repeat the\n"
" entire operation or just create a new encryption key on the card.\n"
));
}
xfree (info.serialno); xfree (info.serialno);
xfree (ecdh_param_str); xfree (ecdh_param_str);
xfree (cache_nonce); xfree (cache_nonce);