Hello,
I would like to commit a change to pkcs11-spy, that changes the output
related to enquiries on attribute values (C_GetAttributeValue). The
reason for that change is that PKCS#11 defines a precise algorithm for
these enquiries. That algorithm depends for example on pointer
(NULL_PTR) and size of input-buffer.
The new output is more detailed and less verbose. And it makes tracing
of applications a little bit more easy. See attached file sample.txt.
The patch uses the following format string with variable sized hex-dump
of pointers: sprintf(buf, "0x%0*lx / %ld", 2 * ptr_sz, ptr, buf_len);
It works well on Linux (32 and 64 bit). But does this kind of format
string would work on other platforms too? Other objections about that
patch?
Regards
Andre
=======
Before:
=======
47: C_GetAttributeValue
[in] hSession = 0x8a75080
[in] hObject = 0x8a74718
[in] pTemplate[1]:
CKA_NETSCAPE_EMAIL(Netsc) requested with 0 buffer
[out] pTemplate[1]:
CKA_NETSCAPE_EMAIL(Netsc) has size -1
Returned: 18 CKR_ATTRIBUTE_TYPE_INVALID
127: C_GetAttributeValue
[in] hSession = 0x8a75080
[in] hObject = 0x8a74718
[in] pTemplate[2]:
CKA_ID requested with 0 buffer
CKA_CLASS requested with 0 buffer
[out] pTemplate[2]:
CKA_ID has size 12
CKA_CLASS has size 4
Returned: 0 CKR_OK
128: C_GetAttributeValue
[in] hSession = 0x8a75080
[in] hObject = 0x8a74718
[in] pTemplate[2]:
CKA_ID requested with 12 buffer
CKA_CLASS requested with 4 buffer
[out] pTemplate[2]:
CKA_ID [size : 0xC (12)]
344D656A ABBF1222 EC50B3A3
CKA_CLASS CKO_CERTIFICATE
Returned: 0 CKR_OK
======
After:
======
47: C_GetAttributeValue
[in] hSession = 0x8a73210
[in] hObject = 0x8a71fd0
[in] pTemplate[1]:
CKA_NETSCAPE_EMAIL(Netsc) 0x00000000 / 0
[out] pTemplate[1]:
CKA_NETSCAPE_EMAIL(Netsc) 0x00000000 / -1
Returned: 18 CKR_ATTRIBUTE_TYPE_INVALID
127: C_GetAttributeValue
[in] hSession = 0x8a73210
[in] hObject = 0x8a71fd0
[in] pTemplate[2]:
CKA_ID 0x00000000 / 0
CKA_CLASS 0x00000000 / 0
[out] pTemplate[2]:
CKA_ID 0x00000000 / 12
CKA_CLASS 0x00000000 / 4
Returned: 0 CKR_OK
128: C_GetAttributeValue
[in] hSession = 0x8a73210
[in] hObject = 0x8a71fd0
[in] pTemplate[2]:
CKA_ID 0x08cf8ea8 / 12
CKA_CLASS 0x08cf8ec0 / 4
[out] pTemplate[2]:
CKA_ID 0x08cf8ea8 / 12
344D656A ABBF1222 EC50B3A3
CKA_CLASS CKO_CERTIFICATE
Returned: 0 CKR_OK
Index: src/pkcs11/pkcs11-display.c
===================================================================
--- src/pkcs11/pkcs11-display.c (revision 4877)
+++ src/pkcs11/pkcs11-display.c (working copy)
@@ -84,6 +84,14 @@
#define CKA_CERT_MD5_HASH (CKA_TRUST + 101)
+static char *buf_spec(CK_VOID_PTR value, CK_ULONG size)
+{
+ static const size_t ptr_sz = sizeof(CK_VOID_PTR);
+ static char buf[64];
+ sprintf(buf, "0x%0*lx / %ld", 2 * ptr_sz, value, (CK_LONG) size);
+ return buf;
+}
+
void print_enum(FILE *f, CK_LONG type, CK_VOID_PTR value, CK_ULONG size, CK_VOID_PTR arg)
{
enum_spec *spec = (enum_spec*)arg;
@@ -109,7 +117,7 @@
{
CK_ULONG i;
if(size != (CK_LONG)(-1) && value != NULL) {
- fprintf(f, "[size : 0x%lX (%ld)]\n ", size, size);
+ fprintf(f, "%s\n ", buf_spec(value, size));
for(i = 0; i < size; i++) {
if (i != 0) {
if ((i % 32) == 0)
@@ -153,7 +161,7 @@
CK_ULONG i, j;
CK_BYTE c;
if(size != (CK_LONG)(-1)) {
- fprintf(f, "[size : 0x%lX (%ld)]\n ", size, size);
+ fprintf(f, "%s\n ", buf_spec(value, size));
for(i = 0; i < size; i += j) {
for(j = 0; ((i + j < size) && (j < 32)); j++) {
if (((j % 4) == 0) && (j != 0)) fprintf(f, " ");
@@ -862,20 +870,20 @@
if(ck_attribute_specs[k].type == pTemplate[j].type) {
found = 1;
fprintf(f, " %s ", ck_attribute_specs[k].name);
- if(pTemplate[j].pValue) {
+ if(pTemplate[j].pValue && ((CK_LONG) pTemplate[j].ulValueLen) > 0) {
ck_attribute_specs[k].display
(f, pTemplate[j].type, pTemplate[j].pValue,
pTemplate[j].ulValueLen,
ck_attribute_specs[k].arg);
} else {
- fprintf(f, "has size %ld\n", pTemplate[j].ulValueLen);
+ fprintf(f, "%s\n", buf_spec(pTemplate[j].pValue, pTemplate[j].ulValueLen));
}
k = ck_attribute_num;
}
}
if (!found) {
fprintf(f, " CKA_? (0x%08lx) ", pTemplate[j].type);
- fprintf(f, "has size %ld\n", pTemplate[j].ulValueLen);
+ fprintf(f, "%s\n", buf_spec(pTemplate[j].pValue, pTemplate[j].ulValueLen));
}
}
}
@@ -891,13 +899,13 @@
if(ck_attribute_specs[k].type == pTemplate[j].type) {
found = 1;
fprintf(f, " %s ", ck_attribute_specs[k].name);
- fprintf(f, "requested with %ld buffer\n", pTemplate[j].ulValueLen);
+ fprintf(f, "%s\n", buf_spec(pTemplate[j].pValue, pTemplate[j].ulValueLen));
k = ck_attribute_num;
}
}
if (!found) {
fprintf(f, " CKA_? (0x%08lx) ", pTemplate[j].type);
- fprintf(f, "requested with %ld buffer\n", pTemplate[j].ulValueLen);
+ fprintf(f, "%s\n", buf_spec(pTemplate[j].pValue, pTemplate[j].ulValueLen));
}
}
}
_______________________________________________
opensc-devel mailing list
[email protected]
http://www.opensc-project.org/mailman/listinfo/opensc-devel