Skip to content

Commit 01c418a

Browse files
committed
Minidriver.c sign_pin and user_consent - PinCacheAlwaysPrompt
At least 5 card drivers set user_consent on a sign pin The user_consent indicates a prompt for the pin should always be done by minidriver. PKCS15 can also set user_consent and PKCS11 sets key attribute CKA_ALWAYS_AUTHENTICATE when key has user_consent, but windows need the PinCacheAlwaysPrompt flag set on the pin. pkcs15-piv.c now defines a sign pin which is used only with the 9C key. ======= On branch minidriver-PinCacheAlwaysPrompt Changes to be committed: modified: libopensc/pkcs15-piv.c modified: minidriver/minidriver.c
1 parent 6ceb50e commit 01c418a

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/libopensc/pkcs15-piv.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,20 @@ static int sc_pkcs15emu_piv_init(sc_pkcs15_card_t *p15card)
385385
SC_PKCS15_PIN_FLAG_INITIALIZED |
386386
SC_PKCS15_PIN_FLAG_LOCAL,
387387
-1, 0xFF,
388-
SC_PKCS15_CO_FLAG_PRIVATE },
389-
{ "02", "PIV PUK", "", 0x81,
388+
SC_PKCS15_CO_FLAG_PRIVATE},
389+
390+
{ "02", "PIN", "", 0x80,
391+
/* used in minidriver as the sign key and for 9C key */
392+
/* label, flag and ref will change if using global pin */
393+
SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
394+
8, 4, 8,
395+
SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
396+
SC_PKCS15_PIN_FLAG_INITIALIZED |
397+
SC_PKCS15_PIN_FLAG_LOCAL,
398+
-1, 0xFF,
399+
SC_PKCS15_CO_FLAG_PRIVATE},
400+
401+
{ "03", "PIV PUK", "", 0x81,
390402
SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
391403
8, 4, 8,
392404
SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
@@ -540,7 +552,7 @@ static int sc_pkcs15emu_piv_init(sc_pkcs15_card_t *p15card)
540552
SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
541553
/*EC*/SC_PKCS15_PRKEY_USAGE_SIGN |
542554
SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
543-
"", 0x9C, "01", SC_PKCS15_CO_FLAG_PRIVATE, 1},
555+
"", 0x9C, "02", SC_PKCS15_CO_FLAG_PRIVATE, 1}, /* use sign pin and user_consent */
544556
{ "03", "KEY MAN key",
545557
/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
546558
/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
@@ -968,7 +980,7 @@ static int sc_pkcs15emu_piv_init(sc_pkcs15_card_t *p15card)
968980
sc_format_path(pins[i].path, &pin_info.path);
969981

970982
label = pins[i].label;
971-
if (i == 0 &&
983+
if ((i == 0 || i == 1) &&
972984
sc_card_ctl(card, SC_CARDCTL_PIV_PIN_PREFERENCE,
973985
&pin_ref) == 0 &&
974986
pin_ref == 0x00) { /* must be 80 for PIV pin, or 00 for Global PIN */

src/minidriver/minidriver.c

+22-4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ typedef struct _VENDOR_SPECIFIC
233233
struct md_dh_agreement* dh_agreements;
234234
BYTE allocatedAgreements;
235235

236+
/* if any key used with the MD_ROLE_USER_SIGN has user_consent set PinCacheAlwaysPrompt */
237+
BYTE need_pin_always;
238+
236239
CRITICAL_SECTION hScard_lock;
237240
} VENDOR_SPECIFIC;
238241

@@ -1888,6 +1891,10 @@ md_set_cmapfile(PCARD_DATA pCardData, struct md_file *file)
18881891
cont->flags & CONTAINER_MAP_DEFAULT_CONTAINER ?
18891892
" (default)" : "");
18901893

1894+
/* set flag that at least one key that uses the sign key needs PinCacheAlwaysPrompt */
1895+
if (key_obj->user_consent)
1896+
vs->need_pin_always = 1;
1897+
18911898
if (pin_mode < pin_mode_n) {
18921899
pin_mode = pin_mode_n;
18931900
pin_cont_idx = ii;
@@ -6475,16 +6482,27 @@ DWORD WINAPI CardGetProperty(__in PCARD_DATA pCardData,
64756482
"returning info on normal PIN [%lu]\n",
64766483
(unsigned long)dwFlags);
64776484

6478-
if (dwFlags == ROLE_USER)
6485+
if (dwFlags == ROLE_USER) {
6486+
p->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
64796487
p->PinPurpose = PrimaryCardPin;
6480-
else if (dwFlags == MD_ROLE_USER_SIGN)
6488+
}
6489+
else if (dwFlags == MD_ROLE_USER_SIGN) {
6490+
if (vs->need_pin_always) {
6491+
p->PinCachePolicy.PinCachePolicyType = PinCacheAlwaysPrompt;
6492+
logprintf(pCardData, 7, "Setting PinCacheAlwaysPrompt\n)";
6493+
}
6494+
else
6495+
p->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
6496+
64816497
p->PinPurpose = DigitalSignaturePin;
6482-
else
6498+
}
6499+
else {
64836500
p->PinPurpose = AuthenticationPin;
6501+
p->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
6502+
}
64846503

64856504
p->PinCachePolicy.dwVersion = PIN_CACHE_POLICY_CURRENT_VERSION;
64866505
p->PinCachePolicy.dwPinCachePolicyInfo = 0;
6487-
p->PinCachePolicy.PinCachePolicyType = PinCacheNormal;
64886506
p->dwChangePermission = CREATE_PIN_SET(dwFlags);
64896507
p->dwUnblockPermission = CREATE_PIN_SET(ROLE_ADMIN);
64906508
break;

0 commit comments

Comments
 (0)