More GetTokenInfo.

This commit is contained in:
Alessio Di Mauro
2015-07-06 16:42:36 +02:00
parent f95c6f2f2d
commit 9f6dfed7cd
6 changed files with 88 additions and 21 deletions
+2
View File
@@ -228,6 +228,8 @@ typedef struct CK_TOKEN_INFO {
* and sign) */ * and sign) */
#define CKF_DUAL_CRYPTO_OPERATIONS 0x00000200 #define CKF_DUAL_CRYPTO_OPERATIONS 0x00000200
#define CKF_TOKEN_INITIALIZED 0x00000400
typedef CK_TOKEN_INFO CK_PTR CK_TOKEN_INFO_PTR; typedef CK_TOKEN_INFO CK_PTR CK_TOKEN_INFO_PTR;
+11 -2
View File
@@ -1,10 +1,11 @@
#include "vendors.h" #include "vendors.h"
#include "yubico.h" #include "yubico.h"
#include <string.h>
vendor_id_t get_vendor_id(char *vendor_name) { vendor_id_t get_vendor_id(char *vendor_name) {
vendor_id_t vid; vendor_id_t vid;
if (strncmp(vendor_name, "Yubico", 6) == 0) if (strstr(vendor_name, "Yubico") != NULL)
return YUBICO; return YUBICO;
return UNKNOWN; return UNKNOWN;
@@ -16,10 +17,18 @@ vendor_t get_vendor(vendor_id_t vid) {
switch (vid) { switch (vid) {
case YUBICO: case YUBICO:
v.get_version = YUBICO_get_version; v.get_version = YUBICO_get_version;
v.get_label = YUBICO_get_label;
v.get_manufacturer = YUBICO_get_manufacturer;
v.get_model = YUBICO_get_model;
v.get_flags = YUBICO_get_flags;
break; break;
case UNKNOWN: case UNKNOWN:
v.get_version = NULL; v.get_version = NULL; // TODO: make up dummy functions?
v.get_label = NULL;
v.get_manufacturer = NULL;
v.get_model = NULL;
v.get_flags = NULL;
} }
+9 -1
View File
@@ -8,10 +8,18 @@ typedef enum {
YUBICO = 0x01 YUBICO = 0x01
} vendor_id_t; } vendor_id_t;
typedef CK_VERSION (*get_version_f)(char *, int); typedef CK_VERSION (*get_version_f)(CK_UTF8CHAR_PTR, CK_ULONG);
typedef CK_UTF8CHAR_PTR (*get_label_f)(void);
typedef CK_UTF8CHAR_PTR (*get_manufacturer_f)(void);
typedef CK_UTF8CHAR_PTR (*get_model_f)(void);
typedef CK_FLAGS (*get_flags_f)(void);
typedef struct { typedef struct {
get_version_f get_version; get_version_f get_version;
get_label_f get_label;
get_manufacturer_f get_manufacturer;
get_model_f get_model;
get_flags_f get_flags;
} vendor_t; } vendor_t;
vendor_id_t get_vendor_id(char *vendor_name); vendor_id_t get_vendor_id(char *vendor_name);
+33 -13
View File
@@ -4,8 +4,6 @@
#include <string.h> #include <string.h>
#include "vendors.h" #include "vendors.h"
// TODO: do a bit of backend magic or should be handled by libykpiv?
#define D(x) do { \ #define D(x) do { \
printf ("debug: %s:%d (%s): ", __FILE__, __LINE__, __FUNCTION__); \ printf ("debug: %s:%d (%s): ", __FILE__, __LINE__, __FUNCTION__); \
printf x; \ printf x; \
@@ -15,6 +13,9 @@
#define YKCS11_DBG 1 // General debug, must be either 1 or 0 #define YKCS11_DBG 1 // General debug, must be either 1 or 0
#define YKCS11_DINOUT 1 // Function in/out debug, must be either 1 or 0 #define YKCS11_DINOUT 1 // Function in/out debug, must be either 1 or 0
#define PIV_MIN_PIN_LEN 6
#define PIV_MAX_PIN_LEN 8
#if YKCS11_DBG #if YKCS11_DBG
#define DBG(x) D(x); #define DBG(x) D(x);
#else #else
@@ -165,26 +166,42 @@ CK_DEFINE_FUNCTION(CK_RV, C_GetTokenInfo)(
{ {
DIN; DIN;
CK_VERSION ver = {0, 0}; CK_VERSION ver = {0, 0};
vendor_t yubico; vendor_id_t vid;
char buf[64]; vendor_t vendor;
CK_BYTE buf[64];
CK_UTF8CHAR_PTR p;
CK_BYTE len;
ykpiv_get_version(piv_state, buf, 64); if (piv_state == NULL)
yubico = get_vendor(get_vendor_id("Yubico")); return CKR_CRYPTOKI_NOT_INITIALIZED;
ver = yubico.get_version(buf, strlen(buf));
ykpiv_get_reader_slot(piv_state, slotID, buf);
vid = get_vendor_id(buf);
if (vid == UNKNOWN)
return CKR_TOKEN_NOT_RECOGNIZED;
vendor = get_vendor(vid);
memset(pInfo->label, ' ', sizeof(pInfo->label)); memset(pInfo->label, ' ', sizeof(pInfo->label));
strncpy(pInfo->label, "LABEL", 5); p = vendor.get_label();
len = strlen(p);
strncpy(pInfo->label, p, len);
memset(pInfo->manufacturerID, ' ', sizeof(pInfo->manufacturerID)); memset(pInfo->manufacturerID, ' ', sizeof(pInfo->manufacturerID));
strncpy(pInfo->manufacturerID, "MANUFACTURER_ID", 15); p = vendor.get_manufacturer();
len = strlen(p);
strncpy(pInfo->manufacturerID, p, len);
memset(pInfo->model, ' ', sizeof(pInfo->model)); memset(pInfo->model, ' ', sizeof(pInfo->model));
strncpy(pInfo->model, "MODEL", 5); p = vendor.get_model();
len = strlen(p);
strncpy(pInfo->model, p, len);
memset(pInfo->serialNumber, ' ', sizeof(pInfo->serialNumber)); memset(pInfo->serialNumber, ' ', sizeof(pInfo->serialNumber));
strncpy(pInfo->serialNumber, "12345", 5); strncpy(pInfo->serialNumber, "12345", 5);
pInfo->flags = 0x00000400; // bit flags indicating capabilities and status of the device as defined below pInfo->flags = vendor.get_flags(); // bit flags indicating capabilities and status of the device as defined below
pInfo->ulMaxSessionCount = CK_UNAVAILABLE_INFORMATION; // TODO: should this be 1? pInfo->ulMaxSessionCount = CK_UNAVAILABLE_INFORMATION; // TODO: should this be 1?
@@ -194,9 +211,9 @@ CK_DEFINE_FUNCTION(CK_RV, C_GetTokenInfo)(
pInfo->ulRwSessionCount = CK_UNAVAILABLE_INFORMATION; // number of read/write sessions that this application currently has open with the token pInfo->ulRwSessionCount = CK_UNAVAILABLE_INFORMATION; // number of read/write sessions that this application currently has open with the token
pInfo->ulMaxPinLen = 127; // maximum length in bytes of the PIN pInfo->ulMaxPinLen = PIV_MIN_PIN_LEN; // maximum length in bytes of the PIN
pInfo->ulMinPinLen = 3; // minimum length in bytes of the PIN pInfo->ulMinPinLen = PIV_MAX_PIN_LEN; // minimum length in bytes of the PIN
pInfo->ulTotalPublicMemory = CK_UNAVAILABLE_INFORMATION; pInfo->ulTotalPublicMemory = CK_UNAVAILABLE_INFORMATION;
@@ -206,6 +223,9 @@ CK_DEFINE_FUNCTION(CK_RV, C_GetTokenInfo)(
pInfo->ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION; pInfo->ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION;
ykpiv_get_version(piv_state, buf, sizeof(buf));
ver = vendor.get_version(buf, strlen(buf));
pInfo->hardwareVersion = ver; // version number of hardware pInfo->hardwareVersion = ver; // version number of hardware
pInfo->firmwareVersion = ver; // version number of firmware pInfo->firmwareVersion = ver; // version number of firmware
+25 -1
View File
@@ -1,7 +1,7 @@
#include "yubico.h" #include "yubico.h"
#include "pkcs11.h" #include "pkcs11.h"
CK_VERSION YUBICO_get_version(char *version, int len) { CK_VERSION YUBICO_get_version(CK_UTF8CHAR_PTR version, CK_ULONG len) {
CK_VERSION v = {0, 0}; CK_VERSION v = {0, 0};
int i = 0; int i = 0;
@@ -27,3 +27,27 @@ CK_VERSION YUBICO_get_version(char *version, int len) {
return v; return v;
} }
CK_UTF8CHAR_PTR YUBICO_get_label(void) {
return "YubiKey";
}
CK_UTF8CHAR_PTR YUBICO_get_manufacturer(void) {
return "Yubico";
}
CK_UTF8CHAR_PTR YUBICO_get_model(void) {
return "PRO";
}
CK_FLAGS YUBICO_get_flags(void) {
return CKF_RNG | CKF_LOGIN_REQUIRED | CKF_USER_PIN_INITIALIZED | CKF_TOKEN_INITIALIZED;
}
+5 -1
View File
@@ -3,6 +3,10 @@
#include "pkcs11.h" #include "pkcs11.h"
CK_VERSION YUBICO_get_version(char *version, int len); CK_VERSION YUBICO_get_version(CK_UTF8CHAR_PTR version, CK_ULONG len);
CK_UTF8CHAR_PTR YUBICO_get_label(void);
CK_UTF8CHAR_PTR YUBICO_get_manufacturer(void);
CK_UTF8CHAR_PTR YUBICO_get_model(void);
CK_FLAGS YUBICO_get_flags(void);
#endif #endif