diff options
author | Werner Koch <[email protected]> | 2024-06-05 15:04:33 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2024-06-05 15:04:33 +0000 |
commit | 77afc9ee1c75a28083edf6d98888f9b472c3e39d (patch) | |
tree | f1178f2db721cc404602110cf9227deaaa037a98 /g10/keygen.c | |
parent | gpg: Do not show RENC if no key capabilities are found for a key. (diff) | |
download | gnupg-77afc9ee1c75a28083edf6d98888f9b472c3e39d.tar.gz gnupg-77afc9ee1c75a28083edf6d98888f9b472c3e39d.zip |
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
Diffstat (limited to 'g10/keygen.c')
-rw-r--r-- | g10/keygen.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/g10/keygen.c b/g10/keygen.c index f512f640d..66fe681de 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -174,6 +174,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, @@ -1210,6 +1212,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. */ |