From 0d3948ed427b8971ac4814665d9be791475aa212 Mon Sep 17 00:00:00 2001 From: okir Date: Fri, 16 May 2003 16:33:42 +0000 Subject: [PATCH] - in test_signature: check CKA_SIGN before doing any signature tests git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1141 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/tools/pkcs11-tool.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c index 25e84ac9..512926c7 100644 --- a/src/tools/pkcs11-tool.c +++ b/src/tools/pkcs11-tool.c @@ -749,7 +749,8 @@ find_object(CK_SESSION_HANDLE sess, CK_OBJECT_CLASS cls, if (rv != CKR_OK) p11_fatal("C_FindObjects", rv); -done: +done: if (count == 0) + *ret = CK_INVALID_HANDLE; p11->C_FindObjectsFinal(sess); return count; @@ -1347,17 +1348,25 @@ test_signature(CK_SLOT_ID slot, CK_SESSION_HANDLE session) if (firstMechType == NO_MECHANISM) { printf("Signatures: not implemented\n"); return errors; - } else if (!find_object(sess, CKO_PRIVATE_KEY, &privKeyObject, - NULL, 0, 0)) { - printf("Signatures: no private key found in this slot\n"); - return errors; - } else { - printf("Signatures (currently only RSA signatures)"); + } + + printf("Signatures (currently only RSA signatures)"); + for (j = 0; find_object(sess, CKO_PRIVATE_KEY, &privKeyObject, NULL, 0, j); j++) { + printf(" testing key %ld ", j); if ((label = getLABEL(sess, privKeyObject, NULL)) != NULL) { - printf(", key = %s", label); + printf("(%s) ", label); free(label); } - printf(" :\n"); + if (!getSIGN(sess, privKeyObject)) { + printf(" -- can't be used for signature, skipping\n"); + continue; + } + printf("\n"); + break; + } + if (privKeyObject == CK_INVALID_HANDLE) { + printf("Signatures: no private key found in this slot\n"); + return 0; } data[0] = 0;