Date: Thu, 13 Jun 2002 08:45:09 -0700 (PDT) From: Dag-Erling Smorgrav <des@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 12826 for review Message-ID: <200206131545.g5DFj9E22711@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=12826 Change 12826 by des@des.at.des.thinksec.com on 2002/06/13 08:44:41 Show (most) token characteristics as well as slot characteristics. Sponsored by: DARPA, NAI Labs Affected files ... ... //depot/projects/cryptoki/bin/slots/slots.c#2 edit Differences ... ==== //depot/projects/cryptoki/bin/slots/slots.c#2 (text+ko) ==== @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $P4: //depot/projects/cryptoki/bin/slots/slots.c#1 $ + * $P4: //depot/projects/cryptoki/bin/slots/slots.c#2 $ */ #include <ctype.h> @@ -45,48 +45,135 @@ static int a_flag; /* show all slots */ static int v_flag; /* verbose */ +#define TERMINATE(str) \ + terminate(str, sizeof str) +#define PRINT_FLAG(flags, flag) \ + do { if ((flags) & flag) printf(" %s", #flag); } while (0) + +static void +terminate(char *str, size_t len) +{ + int n; + + for (n = len - 1; n >= 0; --n) + if (isspace(str[n])) + str[n] = '\0'; + else + break; +} + static void +show_token(CK_SLOT_ID ulSlotID) +{ + CK_TOKEN_INFO TokenInfo; + CK_RV rv; + + rv = C_GetTokenInfo(ulSlotID, &TokenInfo); + switch (rv) { + case CKR_OK: + break; + case CKR_FUNCTION_NOT_SUPPORTED: /* XXX */ + case CKR_TOKEN_NOT_PRESENT: + printf(" (no token)"); + return; + case CKR_TOKEN_NOT_RECOGNIZED: + printf(" (unrecognized token)"); + return; + default: + errx(1, "C_GetTokenInfo(%lu): 0x%x", ulSlotID, rv); + } + TERMINATE(TokenInfo.label); + TERMINATE(TokenInfo.manufacturerID); + TERMINATE(TokenInfo.model); + TERMINATE(TokenInfo.serialNumber); + if (v_flag) { + printf(" token label: %.*s\n", + (int)(sizeof TokenInfo.label), + TokenInfo.label); + printf(" token manufacturer: %.*s\n", + (int)(sizeof TokenInfo.manufacturerID), + TokenInfo.manufacturerID); + printf(" token model: %.*s\n", + (int)(sizeof TokenInfo.model), + TokenInfo.model); + printf(" token hardware version: %d.%d\n", + TokenInfo.hardwareVersion.major, + TokenInfo.hardwareVersion.minor); + printf(" token firmware version: %d.%d\n", + TokenInfo.firmwareVersion.major, + TokenInfo.firmwareVersion.minor); + printf(" token serial number: %.*s\n", + (int)(sizeof TokenInfo.serialNumber), + TokenInfo.serialNumber); + printf(" token flags:"); + PRINT_FLAG(TokenInfo.flags, CKF_RNG); + PRINT_FLAG(TokenInfo.flags, CKF_WRITE_PROTECTED); + PRINT_FLAG(TokenInfo.flags, CKF_LOGIN_REQUIRED); + PRINT_FLAG(TokenInfo.flags, CKF_USER_PIN_INITIALIZED); + PRINT_FLAG(TokenInfo.flags, CKF_RESTORE_KEY_NOT_NEEDED); + PRINT_FLAG(TokenInfo.flags, CKF_CLOCK_ON_TOKEN); + PRINT_FLAG(TokenInfo.flags, CKF_PROTECTED_AUTHENTICATION_PATH); + PRINT_FLAG(TokenInfo.flags, CKF_DUAL_CRYPTO_OPERATIONS); + PRINT_FLAG(TokenInfo.flags, CKF_TOKEN_INITIALIZED); + PRINT_FLAG(TokenInfo.flags, CKF_SECONDARY_AUTHENTICATION); + PRINT_FLAG(TokenInfo.flags, CKF_USER_PIN_COUNT_LOW); + PRINT_FLAG(TokenInfo.flags, CKF_USER_PIN_FINAL_TRY); + PRINT_FLAG(TokenInfo.flags, CKF_USER_PIN_LOCKED); + PRINT_FLAG(TokenInfo.flags, CKF_USER_PIN_TO_BE_CHANGED); + PRINT_FLAG(TokenInfo.flags, CKF_SO_PIN_COUNT_LOW); + PRINT_FLAG(TokenInfo.flags, CKF_SO_PIN_FINAL_TRY); + PRINT_FLAG(TokenInfo.flags, CKF_SO_PIN_LOCKED); + PRINT_FLAG(TokenInfo.flags, CKF_SO_PIN_TO_BE_CHANGED); + printf("\n"); + if (TokenInfo.flags & CKF_CLOCK_ON_TOKEN) + printf(" token wall time: %.*s UTC", + (int)(sizeof TokenInfo.utcTime), + TokenInfo.utcTime); + } else { + printf(" \"%.*s\"", + (int)(sizeof TokenInfo.label), + TokenInfo.label); + } +} + +static void show_slot(CK_SLOT_ID ulSlotID) { CK_SLOT_INFO SlotInfo; CK_RV rv; - int n; rv = C_GetSlotInfo(ulSlotID, &SlotInfo); if (rv != CKR_OK) errx(1, "C_GetSlotInfo(%lu): 0x%x", ulSlotID, rv); - for (n = (sizeof SlotInfo.slotDescription) - 1; n >= 0; --n) - if (isspace(SlotInfo.slotDescription[n])) - SlotInfo.slotDescription[n] = '\0'; - else - break; - for (n = (sizeof SlotInfo.manufacturerID) - 1; n >= 0; --n) - if (isspace(SlotInfo.manufacturerID[n])) - SlotInfo.manufacturerID[n] = '\0'; - else - break; - printf("Slot %lu:\n", ulSlotID); - printf(" decription: %s\n", SlotInfo.slotDescription); - printf(" manufacturer: %s\n", SlotInfo.manufacturerID); + TERMINATE(SlotInfo.slotDescription); + TERMINATE(SlotInfo.manufacturerID); if (v_flag) { - printf(" flags:"); - if (SlotInfo.flags & CKF_TOKEN_PRESENT) - printf(" CKF_TOKEN_PRESENT"); - if (SlotInfo.flags & CKF_REMOVABLE_DEVICE) - printf(" CKF_REMOVABLE_DEVICE"); - if (SlotInfo.flags & CKF_HW_SLOT) - printf(" CKF_HW_SLOT"); - printf("\n"); - printf(" hardware version: %d.%d\n", + printf("Slot %lu:\n", ulSlotID); + printf(" decription: %.*s\n", + (int)(sizeof SlotInfo.slotDescription), + SlotInfo.slotDescription); + printf(" manufacturer: %.*s\n", + (int)(sizeof SlotInfo.manufacturerID), + SlotInfo.manufacturerID); + printf(" hardware version: %d.%d\n", SlotInfo.hardwareVersion.major, SlotInfo.hardwareVersion.major); - printf(" firmware version: %d.%d\n", + printf(" firmware version: %d.%d\n", SlotInfo.firmwareVersion.major, SlotInfo.firmwareVersion.major); + printf(" flags:"); + PRINT_FLAG(SlotInfo.flags, CKF_TOKEN_PRESENT); + PRINT_FLAG(SlotInfo.flags, CKF_REMOVABLE_DEVICE); + PRINT_FLAG(SlotInfo.flags, CKF_HW_SLOT); + printf("\n"); + } else { + printf("%.*s (%.*s):", + (int)(sizeof SlotInfo.slotDescription), + SlotInfo.slotDescription, + (int)(sizeof SlotInfo.manufacturerID), + SlotInfo.manufacturerID); } - if (SlotInfo.flags & CKF_TOKEN_PRESENT) { - /* print token information */ - } + show_token(ulSlotID); printf("\n"); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206131545.g5DFj9E22711>