let the ykpiv_connect() function select as well
This commit is contained in:
@@ -45,6 +45,7 @@ static const err_t errors[] = {
|
|||||||
ERR (YKPIV_MEMORY_ERROR, "Error allocating memory"),
|
ERR (YKPIV_MEMORY_ERROR, "Error allocating memory"),
|
||||||
ERR (YKPIV_PCSC_ERROR, "Error in PCSC call"),
|
ERR (YKPIV_PCSC_ERROR, "Error in PCSC call"),
|
||||||
ERR (YKPIV_SIZE_ERROR, "Wrong buffer size"),
|
ERR (YKPIV_SIZE_ERROR, "Wrong buffer size"),
|
||||||
|
ERR (YKPIV_APPLET_ERROR, "No PIV applet found"),
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+22
@@ -145,6 +145,28 @@ ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted) {
|
|||||||
return YKPIV_PCSC_ERROR;
|
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;
|
return YKPIV_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ extern "C"
|
|||||||
YKPIV_MEMORY_ERROR = -1,
|
YKPIV_MEMORY_ERROR = -1,
|
||||||
YKPIV_PCSC_ERROR = -2,
|
YKPIV_PCSC_ERROR = -2,
|
||||||
YKPIV_SIZE_ERROR = -3,
|
YKPIV_SIZE_ERROR = -3,
|
||||||
|
YKPIV_APPLET_ERROR = -4,
|
||||||
} ykpiv_rc;
|
} ykpiv_rc;
|
||||||
|
|
||||||
const char *ykpiv_strerror(ykpiv_rc err);
|
const char *ykpiv_strerror(ykpiv_rc err);
|
||||||
|
|||||||
@@ -41,11 +41,6 @@
|
|||||||
|
|
||||||
#include "cmdline.h"
|
#include "cmdline.h"
|
||||||
|
|
||||||
unsigned const char aid[] = {
|
|
||||||
0xa0, 0x00, 0x00, 0x03, 0x08
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* FASC-N containing S9999F9999F999999F0F1F0000000000300001E encoded in
|
/* FASC-N containing S9999F9999F999999F0F1F0000000000300001E encoded in
|
||||||
* 4-bit BCD with 1 bit parity. run through the tools/fasc.pl script to get
|
* 4-bit BCD with 1 bit parity. run through the tools/fasc.pl script to get
|
||||||
* bytes. */
|
* bytes. */
|
||||||
@@ -95,27 +90,6 @@ static bool sign_data(ykpiv_state*, unsigned char*, int, unsigned char, unsigned
|
|||||||
ASN1_BIT_STRING*);
|
ASN1_BIT_STRING*);
|
||||||
static int get_object_id(enum enum_slot slot);
|
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) {
|
static bool authenticate(ykpiv_state *state, unsigned const char *key) {
|
||||||
APDU apdu;
|
APDU apdu;
|
||||||
unsigned char data[0xff];
|
unsigned char data[0xff];
|
||||||
@@ -1314,11 +1288,6 @@ int main(int argc, char *argv[]) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(select_applet(state) == false) {
|
|
||||||
fprintf(stderr, "Failed to select applet.\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(authenticate(state, key) == false) {
|
if(authenticate(state, key) == false) {
|
||||||
fprintf(stderr, "Failed authentication with the applet.\n");
|
fprintf(stderr, "Failed authentication with the applet.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
Reference in New Issue
Block a user