1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

gpg: Add magic parameter "default" to --quick-add-adsk.

* g10/getkey.c (has_key_with_fingerprint): New.
* g10/keyedit.c (menu_addadsk): Replace code by new function.
(keyedit_quick_addadsk): Handle magic arg "default".
* g10/keygen.c (append_all_default_adsks): New.
--

GnuPG-bug-id: 6882
(cherry picked from commit 77afc9ee1c)
This commit is contained in:
Werner Koch 2024-06-05 17:04:33 +02:00
parent 222045d850
commit ce75af47eb
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
6 changed files with 88 additions and 18 deletions

View file

@ -161,6 +161,8 @@ static int mdc_available;
static int ks_modify;
static int aead_available;
static void release_parameter_list (struct para_data_s *r);
static struct para_data_s *prepare_adsk (ctrl_t ctrl, const char *name);
static gpg_error_t parse_algo_usage_expire (ctrl_t ctrl, int for_subkey,
const char *algostr, const char *usagestr,
const char *expirestr,
@ -1141,6 +1143,45 @@ keygen_prepare_new_key_adsks (void)
}
/* Append all default ADSKs to the KEYBLOCK but ignore those which are
* already on that keyblock. Returns 0 if any key has been added;
* GPG_ERR_FALSE if no key was added or any other error code. */
gpg_error_t
append_all_default_adsks (ctrl_t ctrl, kbnode_t keyblock)
{
gpg_error_t err = 0;
int any_done = 0;
strlist_t sl;
struct para_data_s *para;
byte adskfpr[MAX_FINGERPRINT_LEN];
size_t adskfprlen;
keygen_prepare_new_key_adsks ();
for (sl = opt.def_new_key_adsks; sl && !err; sl = sl->next)
{
if (!*sl->d)
continue;
para = prepare_adsk (ctrl, sl->d);
if (para)
{
fingerprint_from_pk (para->u.adsk, adskfpr, &adskfprlen);
if (!has_key_with_fingerprint (keyblock, adskfpr, adskfprlen))
{
err = append_adsk_to_key (ctrl, keyblock, para->u.adsk);
if (!err)
any_done = 1;
}
release_parameter_list (para);
}
}
if (!err && !any_done)
err = gpg_error (GPG_ERR_FALSE);
return err;
}
/* Write a direct key signature to the first key in ROOT using the key
PSK. REVKEY is describes the direct key signature and TIMESTAMP is
the timestamp to set on the signature. */