Skip to content

Commit

Permalink
Blacklist PKCS11 changes
Browse files Browse the repository at this point in the history
 Changes to be committed:
	modified:   pkcs11/misc.c
	modified:   pkcs11/slot.c
  • Loading branch information
dengert committed Apr 17, 2024
1 parent ba93194 commit 58256f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pkcs11/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ static CK_RV sc_to_cryptoki_error_common(int rc)
return CKR_DEVICE_ERROR;
case SC_ERROR_WRONG_PADDING:
return CKR_ENCRYPTED_DATA_INVALID;
case SC_ERROR_CARD_BLACKLISTED:
return CKR_TOKEN_NOT_RECOGNIZED;
}
return CKR_GENERAL_ERROR;
}
Expand Down
10 changes: 10 additions & 0 deletions src/pkcs11/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ CK_RV card_detect(sc_reader_t *reader)
return CKR_TOKEN_NOT_PRESENT;
}

if (rc & SC_READER_CARD_BLACKLISTED) {
sc_log(context, "%s: token (blacklisted) not recognized", reader->name);
/* TODO ? but do not remove so slot shows card is still present */
/* TODO need to see what pkcs11 apps do with CKR_TOKEN_NOT_RECOGNIZED */
/* or do we make slot with unknown card */
return CKR_TOKEN_NOT_RECOGNIZED;
}

/* If the card was changed, disconnect the current one */
if (rc & SC_READER_CARD_CHANGED) {
sc_log(context, "%s: Card changed", reader->name);
Expand Down Expand Up @@ -479,10 +487,12 @@ CK_RV slot_get_token(CK_SLOT_ID id, struct sc_pkcs11_slot ** slot)
return CKR_TOKEN_NOT_PRESENT;
sc_log(context, "Slot(id=0x%lX): get token: now detect card", id);
rv = card_detect((*slot)->reader);
/* TODO test SC_READER_CARD_NOT_RECOGNIZED return CKR_TOKEN_NOT_RECOGNIZED */
if (rv != CKR_OK)
return rv;
}


if (!((*slot)->slot_info.flags & CKF_TOKEN_PRESENT)) {
sc_log(context, "card detected, but slot not presenting token");
return CKR_TOKEN_NOT_PRESENT;
Expand Down

0 comments on commit 58256f2

Please sign in to comment.