add ykpiv_get_version() function

This commit is contained in:
Klas Lindfors
2014-06-17 15:26:48 +02:00
parent 880c8a0061
commit a97010d5e3
4 changed files with 31 additions and 12 deletions
+22
View File
@@ -535,3 +535,25 @@ ykpiv_rc ykpiv_sign_data(ykpiv_state *state,
memcpy(sign_out, dataptr, len);
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;
}
}
+4
View File
@@ -31,6 +31,8 @@
#define YKPIV_H
#include <stdint.h>
#include <stddef.h>
#include <ykpiv-version.h>
#ifdef __cplusplus
@@ -72,6 +74,7 @@ extern "C"
ykpiv_rc ykpiv_sign_data(ykpiv_state *state, const unsigned char *sign_in,
int in_len,unsigned char *sign_out, int *out_len,
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_RSA1024 0x06
@@ -88,6 +91,7 @@ extern "C"
/* Yubico vendor specific instructions */
#define YKPIV_INS_SET_MGMKEY 0xff
#define YKPIV_INS_GET_VERSION 0xfd
#ifdef __cplusplus
}
+1
View File
@@ -40,6 +40,7 @@ global:
ykpiv_set_mgmkey;
ykpiv_parse_key;
ykpiv_sign_data;
ykpiv_get_version;
local:
*;
+4 -12
View File
@@ -93,19 +93,11 @@ static FILE *open_file(const char*, int);
static int get_object_id(enum enum_slot slot);
static void print_version(ykpiv_state *state) {
APDU apdu;
unsigned char data[0xff];
unsigned long recv_len = sizeof(data);
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]);
char version[7];
if(ykpiv_get_version(state, version, sizeof(version)) == YKPIV_OK) {
printf("Applet version %s found.\n", version);
} else {
printf("Applet version not found. Status code: %x\n", sw);
printf("Failed to retreive apple version.\n");
}
}