* Fix issues with pkcs11-tool testing of C_GenerateRandom/C_SeedRandom and OpenSC PKCS#11 implementation of those functions.

Thanks goes to Rickard Bondesson who noticed the issues.

http://www.opensc-project.org/pipermail/opensc-devel/2008-November/011436.html



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3595 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
martin 2008-11-24 22:06:27 +00:00
parent 36112bf6e0
commit 1e41d4d267
4 changed files with 15 additions and 10 deletions

View File

@ -491,6 +491,9 @@ static int iso7816_get_challenge(sc_card_t *card, u8 *rnd, size_t len)
sc_apdu_t apdu; sc_apdu_t apdu;
u8 buf[10]; u8 buf[10];
if (!rnd)
return SC_ERROR_INVALID_ARGUMENTS;
sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT,
0x84, 0x00, 0x00); 0x84, 0x00, 0x00);
apdu.le = 8; apdu.le = 8;

View File

@ -957,7 +957,7 @@ CK_RV C_SeedRandom(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK) { if (rv == CKR_OK) {
slot = session->slot; slot = session->slot;
if (slot->card->framework->seed_random == NULL) if (slot->card->framework->seed_random == NULL)
rv = CKR_FUNCTION_NOT_SUPPORTED; rv = CKR_RANDOM_SEED_NOT_SUPPORTED;
else else
rv = slot->card->framework->seed_random(slot->card, pSeed, ulSeedLen); rv = slot->card->framework->seed_random(slot->card, pSeed, ulSeedLen);
} }
@ -982,7 +982,7 @@ CK_RV C_GenerateRandom(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK) { if (rv == CKR_OK) {
slot = session->slot; slot = session->slot;
if (slot->card->framework->get_random == NULL) if (slot->card->framework->get_random == NULL)
rv = CKR_FUNCTION_NOT_SUPPORTED; rv = CKR_RANDOM_NO_RNG;
else else
rv = slot->card->framework->get_random(slot->card, RandomData, ulRandomLen); rv = slot->card->framework->get_random(slot->card, RandomData, ulRandomLen);
} }

View File

@ -1376,6 +1376,7 @@ CK_RV C_WaitForSlotEvent(CK_FLAGS flags,
{ {
CK_RV rv; CK_RV rv;
enter("C_WaitForSlotEvent"); enter("C_WaitForSlotEvent");
spy_dump_ulong_in("flags", flags);
rv = po->C_WaitForSlotEvent(flags, pSlot, pRserved); rv = po->C_WaitForSlotEvent(flags, pSlot, pRserved);
return retne(rv); return retne(rv);
} }

View File

@ -2978,12 +2978,13 @@ static int test_random(CK_SLOT_ID slot)
if (rv != CKR_OK) if (rv != CKR_OK)
p11_fatal("C_OpenSession", rv); p11_fatal("C_OpenSession", rv);
rv = p11->C_SeedRandom(session, seed1, 10); rv = p11->C_SeedRandom(session, seed1, 100);
if (rv == CKR_RANDOM_NO_RNG || rv == CKR_FUNCTION_NOT_SUPPORTED) { if (rv == CKR_RANDOM_NO_RNG) {
printf(" not implemented\n"); printf(" RNG not available\n");
return 0; return 0;
} }
if (rv == CKR_RANDOM_SEED_NOT_SUPPORTED)
if (rv == CKR_RANDOM_SEED_NOT_SUPPORTED || rv == CKR_FUNCTION_NOT_SUPPORTED)
printf(" seeding (C_SeedRandom) not supported\n"); printf(" seeding (C_SeedRandom) not supported\n");
else if (rv != CKR_OK) { else if (rv != CKR_OK) {
p11_perror("C_SeedRandom", rv); p11_perror("C_SeedRandom", rv);
@ -2998,19 +2999,19 @@ static int test_random(CK_SLOT_ID slot)
rv = p11->C_GenerateRandom(session, buf1, 100); rv = p11->C_GenerateRandom(session, buf1, 100);
if (rv != CKR_OK) { if (rv != CKR_OK) {
p11_perror("C_GenerateRandom", rv); p11_perror("C_GenerateRandom(buf1,100)", rv);
return 1; return 1;
} }
rv = p11->C_GenerateRandom(session, buf1, 0); rv = p11->C_GenerateRandom(session, buf1, 0);
if (rv != CKR_OK) { if (rv != CKR_OK) {
p11_perror("C_GenerateRandom(,,0)", rv); p11_perror("C_GenerateRandom(buf1,0)", rv);
return 1; return 1;
} }
rv = p11->C_GenerateRandom(session, NULL, 100); rv = p11->C_GenerateRandom(session, buf2, 100);
if (rv != CKR_OK) { if (rv != CKR_OK) {
p11_perror("C_GenerateRandom(,NULL,)", rv); p11_perror("C_GenerateRandom(buf2,100)", rv);
return 1; return 1;
} }