let the ykpiv_connect() function select as well

This commit is contained in:
Klas Lindfors
2014-06-17 09:20:32 +02:00
parent 9eb5c7fda1
commit 6dcb6798e6
4 changed files with 24 additions and 31 deletions
+1
View File
@@ -45,6 +45,7 @@ static const err_t errors[] = {
ERR (YKPIV_MEMORY_ERROR, "Error allocating memory"),
ERR (YKPIV_PCSC_ERROR, "Error in PCSC call"),
ERR (YKPIV_SIZE_ERROR, "Wrong buffer size"),
ERR (YKPIV_APPLET_ERROR, "No PIV applet found"),
};
/**
+22
View File
@@ -145,6 +145,28 @@ ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted) {
return YKPIV_PCSC_ERROR;
}
{
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 = 0xa4;
apdu.st.p1 = 0x04;
apdu.st.lc = sizeof(aid);
memcpy(apdu.st.data, aid, sizeof(aid));
if((res = ykpiv_send_data(state, apdu.raw, data, &recv_len, &sw) != YKPIV_OK)) {
return res;
} else if(sw == 0x9000) {
return YKPIV_OK;
}
return YKPIV_APPLET_ERROR;
}
return YKPIV_OK;
}
+1
View File
@@ -44,6 +44,7 @@ extern "C"
YKPIV_MEMORY_ERROR = -1,
YKPIV_PCSC_ERROR = -2,
YKPIV_SIZE_ERROR = -3,
YKPIV_APPLET_ERROR = -4,
} ykpiv_rc;
const char *ykpiv_strerror(ykpiv_rc err);
-31
View File
@@ -41,11 +41,6 @@
#include "cmdline.h"
unsigned const char aid[] = {
0xa0, 0x00, 0x00, 0x03, 0x08
};
/* FASC-N containing S9999F9999F999999F0F1F0000000000300001E encoded in
* 4-bit BCD with 1 bit parity. run through the tools/fasc.pl script to get
* bytes. */
@@ -95,27 +90,6 @@ static bool sign_data(ykpiv_state*, unsigned char*, int, unsigned char, unsigned
ASN1_BIT_STRING*);
static int get_object_id(enum enum_slot slot);
static bool select_applet(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 = 0xa4;
apdu.st.p1 = 0x04;
apdu.st.lc = sizeof(aid);
memcpy(apdu.st.data, aid, sizeof(aid));
if(ykpiv_send_data(state, apdu.raw, data, &recv_len, &sw) != YKPIV_OK) {
return false;
} else if(sw == 0x9000) {
return true;
}
return false;
}
static bool authenticate(ykpiv_state *state, unsigned const char *key) {
APDU apdu;
unsigned char data[0xff];
@@ -1314,11 +1288,6 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
if(select_applet(state) == false) {
fprintf(stderr, "Failed to select applet.\n");
return EXIT_FAILURE;
}
if(authenticate(state, key) == false) {
fprintf(stderr, "Failed authentication with the applet.\n");
return EXIT_FAILURE;