diff options
author | Werner Koch <wk@gnupg.org> | 2020-02-10 00:33:51 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2020-02-10 00:33:51 +0100 |
commit | fb6ff7ead7dff33541b595f3e8d5342f9c7a6d6c (patch) | |
tree | 69a2c883362dd902ac853259dd5debfb21d8c74b /scd/app-openpgp.c | |
parent | common: Extend the new get_keyalgo_string function (diff) | |
download | gnupg2-fb6ff7ead7dff33541b595f3e8d5342f9c7a6d6c.tar.xz gnupg2-fb6ff7ead7dff33541b595f3e8d5342f9c7a6d6c.zip |
scd:openpgp: Let the genkey function also accept a full keyref.
* scd/app-openpgp.c (send_key_attr): Use log_assert.
(do_genkey): Allow prefix.
--
It is more uniform to always use full keyref (e.g. "OPENPGP.1")
instead of just the key number.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to '')
-rw-r--r-- | scd/app-openpgp.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index 293c53cb5..07fbf7474 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -955,8 +955,12 @@ send_key_attr (ctrl_t ctrl, app_t app, const char *keyword, int keyno) { char buffer[200]; - assert (keyno >=0 && keyno < DIM(app->app_local->keyattr)); + log_assert (keyno >=0 && keyno < DIM(app->app_local->keyattr)); + /* Note that the code in gpg-card supports prefixing the key number + * with "OPENPGP." but older code does not yet support this. There + * is also a discrepancy with the algorithm numbers: We should use + * the gcrypt numbers but the current code assumes OpenPGP numbers. */ if (app->app_local->keyattr[keyno].key_type == KEY_TYPE_RSA) snprintf (buffer, sizeof buffer, "%d 1 rsa%u %u %d", keyno+1, @@ -4311,7 +4315,7 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, const char *keytype, const unsigned char *keydata; size_t buflen, keydatalen; u32 created_at; - int keyno = atoi (keynostr) - 1; + int keyno; int force = (flags & 1); time_t start_at; int exmode = 0; @@ -4319,7 +4323,12 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, const char *keytype, (void)keytype; /* Ignored for OpenPGP cards. */ - if (keyno < 0 || keyno > 2) + /* Strip the OpenPGP prefix which is for historical reasons optional. */ + if (!ascii_strncasecmp (keynostr, "OPENPGP.", 8)) + keynostr += 8; + + keyno = atoi (keynostr) - 1; + if (!digitp (keynostr) || keyno < 0 || keyno > 2) return gpg_error (GPG_ERR_INV_ID); /* We flush the cache to increase the traffic before a key |