summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-09-28 11:27:13 +0200
committerStef Walter <stefw@collabora.co.uk>2011-09-28 11:27:13 +0200
commit639aa9e38692ba5001987bb496e10cca14880807 (patch)
tree297f4bc88744ccf42f0d868be6e0090948c49056 /tools
parent67b52ed7d7f298f64be5ead41deeeebab1238d47 (diff)
Print more information in 'p11-kit -l'
Diffstat (limited to 'tools')
-rw-r--r--tools/p11-kit.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/tools/p11-kit.c b/tools/p11-kit.c
index 3d50955..44062d0 100644
--- a/tools/p11-kit.c
+++ b/tools/p11-kit.c
@@ -35,6 +35,7 @@
#include "config.h"
#include <assert.h>
+#include <ctype.h>
#include <err.h>
#include <string.h>
#include <stdio.h>
@@ -55,6 +56,46 @@ usage (void)
exit (2);
}
+static const char HEXC_LOWER[] = "0123456789abcdef";
+
+static char *
+hex_encode (const unsigned char *data,
+ size_t n_data)
+{
+ char *result;
+ size_t i;
+ size_t o;
+
+ result = malloc (n_data * 3 + 1);
+ if (result == NULL)
+ return NULL;
+
+ for (i = 0, o = 0; i < n_data; i++) {
+ if (i > 0)
+ result[o++] = ':';
+ result[o++] = HEXC_LOWER[data[i] >> 4 & 0xf];
+ result[o++] = HEXC_LOWER[data[i] & 0xf];
+ }
+
+ result[o] = 0;
+ return result;
+}
+
+static int
+is_ascii_string (const unsigned char *data,
+ size_t n_data)
+{
+ size_t i;
+
+ for (i = 0; i < n_data; i++) {
+ if (!isascii (data[i]) &&
+ (data[i] < 0x20 && !isspace (data[i])))
+ return 0;
+ }
+
+ return 1;
+}
+
static void
print_token_info (CK_FUNCTION_LIST_PTR module, CK_SLOT_ID slot_id)
{
@@ -71,6 +112,53 @@ print_token_info (CK_FUNCTION_LIST_PTR module, CK_SLOT_ID slot_id)
value = p11_kit_space_strdup (info.label, sizeof (info.label));
printf (" token: %s\n", value);
free (value);
+
+ value = p11_kit_space_strdup (info.manufacturerID, sizeof (info.manufacturerID));
+ printf (" manufacturer: %s\n", value);
+ free (value);
+
+ value = p11_kit_space_strdup (info.model, sizeof (info.model));
+ printf (" model: %s\n", value);
+ free (value);
+
+ if (is_ascii_string (info.serialNumber, sizeof (info.serialNumber)))
+ value = p11_kit_space_strdup (info.serialNumber, sizeof (info.serialNumber));
+ else
+ value = hex_encode (info.serialNumber, sizeof (info.serialNumber));
+ printf (" serial-number: %s\n", value);
+ free (value);
+
+ if (info.hardwareVersion.major || info.hardwareVersion.minor)
+ printf (" hardware-version: %d.%d\n",
+ info.hardwareVersion.major,
+ info.hardwareVersion.minor);
+
+ if (info.firmwareVersion.major || info.firmwareVersion.minor)
+ printf (" firmware-version: %d.%d\n",
+ info.firmwareVersion.major,
+ info.firmwareVersion.minor);
+
+ printf (" flags:\n");
+ #define X(x, y) if (info.flags & (x)) printf (" %s\n", (y))
+ X(CKF_RNG, "rng");
+ X(CKF_WRITE_PROTECTED, "write-protected");
+ X(CKF_LOGIN_REQUIRED, "login-required");
+ X(CKF_USER_PIN_INITIALIZED, "user-pin-initialized");
+ X(CKF_RESTORE_KEY_NOT_NEEDED, "restore-key-not-needed");
+ X(CKF_CLOCK_ON_TOKEN, "clock-on-tokne");
+ X(CKF_PROTECTED_AUTHENTICATION_PATH, "protected-authentication-path");
+ X(CKF_DUAL_CRYPTO_OPERATIONS, "dual-crypto-operations");
+ X(CKF_TOKEN_INITIALIZED, "token-initialized");
+ X(CKF_SECONDARY_AUTHENTICATION, "secondary-authentication");
+ X(CKF_USER_PIN_COUNT_LOW, "user-pin-count-low");
+ X(CKF_USER_PIN_FINAL_TRY, "user-pin-final-try");
+ X(CKF_USER_PIN_LOCKED, "user-pin-locked");
+ X(CKF_USER_PIN_TO_BE_CHANGED, "user-pin-to-be-changed");
+ X(CKF_SO_PIN_COUNT_LOW, "so-pin-count-low");
+ X(CKF_SO_PIN_FINAL_TRY, "so-pin-final-try");
+ X(CKF_SO_PIN_LOCKED, "so-pin-locked");
+ X(CKF_SO_PIN_TO_BE_CHANGED, "so-pin-to-be-changed");
+ #undef X
}
static void
@@ -98,6 +186,10 @@ print_module_info (CK_FUNCTION_LIST_PTR module)
printf (" library-manufacturer: %s\n", value);
free (value);
+ printf (" library-version: %d.%d\n",
+ info.libraryVersion.major,
+ info.libraryVersion.minor);
+
count = sizeof (slot_list) / sizeof (slot_list[0]);
rv = (module->C_GetSlotList) (CK_TRUE, slot_list, &count);
if (rv != CKR_OK) {