[PATCH GnuPG 2/2] scd:piv: Allow key import on all cards
David Seifert
soap at gentoo.org
Thu Nov 12 10:22:06 CET 2026
* scd/app-piv.c (do_writekey): Do not restrict to YubiKeys.
--
Key import uses the Yubico import command (INS 0xFE), which is not
part of the PIV specification. Other vendors implement it too, for
example Token2, so do not check for a YubiKey before sending it. A
card without the command rejects it, and since the previous commit
the slot then keeps its existing key and public key. On such cards
the error changes from "Not supported" to the error for the status
word returned by the card.
Tested on a TOKEN2 PIN+ R3.3 card in a Cherry ST-2xxx reader (T=0),
slot 9E, and on a Nitrokey 3, slot 95, which holds a P-256 key
generated on the card:
Card Import Result
---------- --------------------- ----------------------------
TOKEN2 RSA-2048, RSA-4096 imported; RSA-4096 key signs
TOKEN2 Ed25519 (scdaemon) rejected; key kept
Nitrokey 3 RSA-2048 (card, 6A81) "Not supported"; key kept
"Key kept" means READKEY still returns the keygrip of the slot's key.
The Nitrokey 3 does not implement the import command.
Signed-off-by: David Seifert <soap at gentoo.org>
---
scd/app-piv.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/scd/app-piv.c b/scd/app-piv.c
index f26203e67..3961cd860 100644
--- a/scd/app-piv.c
+++ b/scd/app-piv.c
@@ -3120,11 +3120,12 @@ writekey_ecc (app_t app, data_object_t dobj, int keyref,
}
-/* Write a key to a slot. This command requires proprietary
- * extensions of the PIV specification and is thus only implemented for
- * supported card types. The input is a canonical encoded
- * S-expression with the secret key in KEYDATA and its length (for
- * assertion) in KEYDATALEN. KEYREFSTR needs to be the usual 2
+/* Write a key to a slot. This command uses the import command of
+ * Yubico, which is not part of the PIV specification. It is sent to
+ * all cards because other vendors, for example Token2, implement it
+ * too; cards without it reject the command. The input is a canonical
+ * encoded S-expression with the secret key in KEYDATA and its length
+ * (for assertion) in KEYDATALEN. KEYREFSTR needs to be the usual 2
* hexdigit slot number prefixed with "PIV."
*
* Supported FLAGS are:
@@ -3145,12 +3146,6 @@ do_writekey (app_t app, ctrl_t ctrl,
(void)ctrl;
- if (!app->app_local->flags.yubikey)
- {
- err = gpg_error (GPG_ERR_NOT_SUPPORTED);
- goto leave;
- }
-
/* Check keyref and test whether a key already exists. */
dobj = find_dobj_by_keyref (app, keyrefstr);
if ((keyref = keyref_from_dobj (dobj)) == -1)
--
2.56.0
More information about the Gnupg-devel
mailing list