Skip to content

Commit 7996cbb

Browse files
committed
pkcs15-openpgp.c Authentication key for decrypt requires MSE
pkcs11-tool --test calls "test_decrypt" and test any RSA key that supports decryption. OpenPGP can do this for the Authentication key, but requires the optional MANAGE SECURITY ENVIRONMENT (MSE) command. Do not set decrypt or wrap usage bits unless MSE is supported for the card. Found using YubiKey NFC and Nitro start that do not support MSE. On branch X25519-improvements-2 Changes to be committed: modified: libopensc/pkcs15-openpgp.c
1 parent 0779a3c commit 7996cbb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/libopensc/card-openpgp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ pgp_update_new_algo_attr(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_
25002500
pgp_blob_t *algo_blob = NULL;
25012501
const unsigned int tag = 0x00C0 | key_info->key_id;
25022502
u8 *data;
2503-
int data_len;
2503+
size_t data_len;
25042504
int r = SC_SUCCESS;
25052505
unsigned int i;
25062506

src/libopensc/pkcs15-openpgp.c

+9
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
182182
{
183183
sc_card_t *card = p15card->card;
184184
sc_context_t *ctx = card->ctx;
185+
struct pgp_priv_data *priv = DRVDATA(card);
185186
char string[256];
186187
u8 c4data[10];
187188
u8 c5data[100];
@@ -402,6 +403,10 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
402403

403404
case SC_OPENPGP_KEYALGO_RSA:
404405
if (cxdata_len >= 3) {
406+
/* with Authentication key, can only decrypt if can change MSE */
407+
if (i == 2 && !(priv->ext_caps & EXT_CAP_MSE)) {
408+
prkey_info.usage &= ~PGP_ENC_PRKEY_USAGE;
409+
}
405410
prkey_info.modulus_length = bebytes2ushort(cxdata + 1);
406411
r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
407412
break;
@@ -526,6 +531,10 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
526531
break;
527532
case SC_OPENPGP_KEYALGO_RSA:
528533
if (cxdata_len >= 3) {
534+
/* with Authentication pubkey, can only encrypt if can change MSE */
535+
if (i == 2 && !(priv->ext_caps & EXT_CAP_MSE)) {
536+
pubkey_info.usage &= ~PGP_ENC_PUBKEY_USAGE;
537+
}
529538
pubkey_info.modulus_length = bebytes2ushort(cxdata + 1);
530539
r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
531540
break;

0 commit comments

Comments
 (0)