fixed PIN info reading

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@16 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
jey 2001-10-21 19:42:32 +00:00
parent 08fba4d225
commit 9ea1e4be9e
4 changed files with 25 additions and 22 deletions

View File

@ -153,9 +153,9 @@ CK_RV C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
pInfo->ulSessionCount = 0;
pInfo->ulMaxRwSessionCount = 1;
pInfo->ulRwSessionCount = 0;
if (slot[slotID].p15card->pins[0].magic == SC_PKCS15_PIN_MAGIC) {
pInfo->ulMaxPinLen = slot[slotID].p15card->pins[0].stored_length;
pInfo->ulMinPinLen = slot[slotID].p15card->pins[0].min_length;
if (slot[slotID].p15card->pin_info[0].magic == SC_PKCS15_PIN_MAGIC) {
pInfo->ulMaxPinLen = slot[slotID].p15card->pin_info[0].stored_length;
pInfo->ulMinPinLen = slot[slotID].p15card->pin_info[0].min_length;
} else {
/* choose reasonable defaults */
pInfo->ulMaxPinLen = 8;

View File

@ -137,7 +137,7 @@ CK_RV C_Login(CK_SESSION_HANDLE hSession, /* the session's handle */
return CKR_USER_ALREADY_LOGGED_IN;
LOG("Master PIN code verification starts.\n");
rc = sc_pkcs15_verify_pin(card, &card->pins[0], pPin, ulPinLen);
rc = sc_pkcs15_verify_pin(card, &card->pin_info[0], pPin, ulPinLen);
switch (rc) {
case 0:
LOG("Master PIN code verified succesfully.\n");
@ -210,7 +210,7 @@ CK_RV C_SetPIN(CK_SESSION_HANDLE hSession,
card = slot[ses->slot].p15card;
LOG("Master PIN code update starts.\n");
rc = sc_pkcs15_change_pin(card, &card->pins[0], pOldPin, ulOldLen, pNewPin, ulNewLen);
rc = sc_pkcs15_change_pin(card, &card->pin_info[0], pOldPin, ulOldLen, pNewPin, ulNewLen);
switch (rc) {
case 0:
LOG("Master PIN code CHANGED succesfully.\n");

View File

@ -80,8 +80,8 @@ int slot_connect(int id)
sc_disconnect_card(card);
return CKR_TOKEN_NOT_RECOGNIZED;
}
while (sc_pkcs15_read_pin_info(slot[id].p15card, ++c, &pin) == 0);
c = sc_pkcs15_enum_pins(slot[id].p15card);
// FIXME: c < 0 ==> error
LOG("Found total of %d PIN codes.\n", c);
slot[id].flags = SLOT_CONNECTED;

View File

@ -12,7 +12,6 @@ int main(int argc, char **argv) {
struct sc_context *ctx = NULL;
struct sc_card *card = NULL;
struct sc_pkcs15_card *p15_card = NULL;
struct sc_pkcs15_pin_info pin;
char buf[16], buf2[16];
u8 *certbuf;
@ -62,6 +61,7 @@ int main(int argc, char **argv) {
return 0;
#endif
#if 0
i = sc_pkcs15_enum_certificates(p15_card);
if (i < 0) {
fprintf(stderr, "Certificate enumeration failed with %s\n", sc_strerror(i));
@ -77,37 +77,40 @@ int main(int argc, char **argv) {
return 1;
}
printf("Certificate size is %d bytes\n", c);
sc_asn1_print_tags(certbuf, c);
free(certbuf);
}
return 0;
#endif
printf("Searching for PIN codes...\n");
c = 0;
while (sc_pkcs15_read_pin_info(p15_card, ++c, &pin) == 0) {
sc_pkcs15_print_pin_info(&pin);
}
c--;
if (c == 0) {
printf("No PIN codes found!\n");
i = sc_pkcs15_enum_pins(p15_card);
if (i < 0) {
fprintf(stderr, "Error enumerating PIN codes: %s\n", sc_strerror(i));
return 1;
}
i = sc_sec_ask_pin_code(&p15_card->pins[0], buf, sizeof(buf), "Please enter PIN code");
if (i == 0)
fprintf(stderr, "No PIN codes found!\n");
for (c = 0; c < i; c++) {
sc_pkcs15_print_pin_info(&p15_card->pin_info[c]);
}
i = sc_sec_ask_pin_code(&p15_card->pin_info[0], buf, sizeof(buf), "Please enter PIN code");
if (i) {
fprintf(stderr, "\nFailed to ask PIN code from user\n");
return 1;
}
i = sc_sec_ask_pin_code(&p15_card->pins[0], buf2, sizeof(buf2), "Please enter _new_ PIN code");
#if 0
i = sc_sec_ask_pin_code(&p15_card->pin_info[0], buf2, sizeof(buf2), "Please enter _new_ PIN code");
if (i) {
fprintf(stderr, "\nFailed to ask PIN code from user\n");
return 1;
}
i = sc_pkcs15_change_pin(p15_card, &p15_card->pins[0], buf, strlen(buf), buf2, strlen(buf2));
// i = sc_pkcs15_verify_pin(p15_card, &p15_card->pins[0], buf, strlen(buf));
i = sc_pkcs15_change_pin(p15_card, &p15_card->pin_info[0], buf, strlen(buf), buf2, strlen(buf2));
#endif
i = sc_pkcs15_verify_pin(p15_card, &p15_card->pin_info[0], buf, strlen(buf));
if (i) {
if (i == SC_ERROR_PIN_CODE_INCORRECT)
fprintf(stderr, "Incorrect PIN code (%d tries left)\n", p15_card->pins[0].tries_left);
fprintf(stderr, "Incorrect PIN code (%d tries left)\n", p15_card->pin_info[0].tries_left);
else
fprintf(stderr, "PIN verifying failed: %s\n", sc_strerror(i));
return 1;