add ykpiv_get_version() function
This commit is contained in:
+22
@@ -535,3 +535,25 @@ ykpiv_rc ykpiv_sign_data(ykpiv_state *state,
|
|||||||
memcpy(sign_out, dataptr, len);
|
memcpy(sign_out, dataptr, len);
|
||||||
return YKPIV_OK;
|
return YKPIV_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ykpiv_rc ykpiv_get_version(ykpiv_state *state, char *version, size_t len) {
|
||||||
|
APDU apdu;
|
||||||
|
unsigned char data[0xff];
|
||||||
|
unsigned long recv_len = sizeof(data);
|
||||||
|
int sw;
|
||||||
|
ykpiv_rc res;
|
||||||
|
|
||||||
|
memset(apdu.raw, 0, sizeof(apdu));
|
||||||
|
apdu.st.ins = YKPIV_INS_GET_VERSION;
|
||||||
|
if((res = ykpiv_send_data(state, apdu.raw, data, &recv_len, &sw)) != YKPIV_OK) {
|
||||||
|
return res;
|
||||||
|
} else if(sw == 0x9000) {
|
||||||
|
int result = snprintf(version, len, "%d.%d.%d", data[0], data[1], data[2]);
|
||||||
|
if(result < 0) {
|
||||||
|
return YKPIV_SIZE_ERROR;
|
||||||
|
}
|
||||||
|
return YKPIV_OK;
|
||||||
|
} else {
|
||||||
|
return YKPIV_GENERIC_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#define YKPIV_H
|
#define YKPIV_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <ykpiv-version.h>
|
#include <ykpiv-version.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -72,6 +74,7 @@ extern "C"
|
|||||||
ykpiv_rc ykpiv_sign_data(ykpiv_state *state, const unsigned char *sign_in,
|
ykpiv_rc ykpiv_sign_data(ykpiv_state *state, const unsigned char *sign_in,
|
||||||
int in_len,unsigned char *sign_out, int *out_len,
|
int in_len,unsigned char *sign_out, int *out_len,
|
||||||
unsigned char algorithm, unsigned char key);
|
unsigned char algorithm, unsigned char key);
|
||||||
|
ykpiv_rc ykpiv_get_version(ykpiv_state *state, char *version, size_t len);
|
||||||
|
|
||||||
#define YKPIV_ALGO_3DES 0x03
|
#define YKPIV_ALGO_3DES 0x03
|
||||||
#define YKPIV_ALGO_RSA1024 0x06
|
#define YKPIV_ALGO_RSA1024 0x06
|
||||||
@@ -88,6 +91,7 @@ extern "C"
|
|||||||
|
|
||||||
/* Yubico vendor specific instructions */
|
/* Yubico vendor specific instructions */
|
||||||
#define YKPIV_INS_SET_MGMKEY 0xff
|
#define YKPIV_INS_SET_MGMKEY 0xff
|
||||||
|
#define YKPIV_INS_GET_VERSION 0xfd
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ global:
|
|||||||
ykpiv_set_mgmkey;
|
ykpiv_set_mgmkey;
|
||||||
ykpiv_parse_key;
|
ykpiv_parse_key;
|
||||||
ykpiv_sign_data;
|
ykpiv_sign_data;
|
||||||
|
ykpiv_get_version;
|
||||||
|
|
||||||
local:
|
local:
|
||||||
*;
|
*;
|
||||||
|
|||||||
+4
-12
@@ -93,19 +93,11 @@ static FILE *open_file(const char*, int);
|
|||||||
static int get_object_id(enum enum_slot slot);
|
static int get_object_id(enum enum_slot slot);
|
||||||
|
|
||||||
static void print_version(ykpiv_state *state) {
|
static void print_version(ykpiv_state *state) {
|
||||||
APDU apdu;
|
char version[7];
|
||||||
unsigned char data[0xff];
|
if(ykpiv_get_version(state, version, sizeof(version)) == YKPIV_OK) {
|
||||||
unsigned long recv_len = sizeof(data);
|
printf("Applet version %s found.\n", version);
|
||||||
int sw;
|
|
||||||
|
|
||||||
memset(apdu.raw, 0, sizeof(apdu));
|
|
||||||
apdu.st.ins = 0xfd;
|
|
||||||
if(ykpiv_send_data(state, apdu.raw, data, &recv_len, &sw) != YKPIV_OK) {
|
|
||||||
printf("Failed to retreive apple version.\n");
|
|
||||||
} else if(sw == 0x9000) {
|
|
||||||
printf("Applet version %d.%d.%d found.\n", data[0], data[1], data[2]);
|
|
||||||
} else {
|
} else {
|
||||||
printf("Applet version not found. Status code: %x\n", sw);
|
printf("Failed to retreive apple version.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user