Major refactor and vendor abstraction.

This commit is contained in:
Alessio Di Mauro
2015-07-14 14:13:02 +02:00
parent 9489748380
commit dae7297050
9 changed files with 212 additions and 103 deletions
+17 -11
View File
@@ -127,6 +127,10 @@ ykpiv_rc ykpiv_disconnect(ykpiv_state *state) {
}
ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted) {
return ykpiv_connect2(state, wanted, NULL, 0);
}
ykpiv_rc ykpiv_connect2(ykpiv_state *state, const char *wanted, unsigned char **readers, unsigned long *len) {
unsigned long num_readers = 0;
unsigned long active_protocol;
char reader_buf[1024];
@@ -165,19 +169,21 @@ ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted) {
return YKPIV_PCSC_ERROR;
}
// TODO: improve here
state->n_readers = 0;
state->tot_readers_len = num_readers;
reader_ptr = reader_buf;
for (i = 0; i < num_readers; i++)
if (reader_buf[i] == '\0' && i != num_readers - 1) {
strcpy(state->readers[state->n_readers], reader_ptr); // TODO: strdup?
state->n_readers = state->n_readers + 1;
reader_ptr += i + 1;
// Save available readers (aka PKCS11 slots)
if (readers != NULL) {
*readers = malloc(sizeof(char) * num_readers);
if (*readers == NULL) {
if(state->verbose) {
fprintf (stderr, "error: malloc failed");
}
SCardReleaseContext(state->context);
return YKPIV_MEMORY_ERROR;
}
// *********
memcpy(*readers, reader_buf, num_readers);
*len = num_readers;
}
reader_ptr = reader_buf; // TODO: reader_buf is never free'd
reader_ptr = reader_buf;
if(wanted) {
while(*reader_ptr != '\0') {
if(strstr(reader_ptr, wanted)) {
+1 -3
View File
@@ -64,6 +64,7 @@ extern "C"
ykpiv_rc ykpiv_init(ykpiv_state **state, int verbose);
ykpiv_rc ykpiv_done(ykpiv_state *state);
ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted);
ykpiv_rc ykpiv_connect2(ykpiv_state *state, const char *wanted, unsigned char **readers, unsigned long *len);
ykpiv_rc ykpiv_disconnect(ykpiv_state *state);
ykpiv_rc ykpiv_transfer_data(ykpiv_state *state, const unsigned char *templ,
const unsigned char *in_data, long in_len,
@@ -85,9 +86,6 @@ extern "C"
ykpiv_rc ykpiv_save_object(ykpiv_state *state, int object_id,
unsigned char *indata, size_t len);
ykpiv_rc ykpiv_get_reader_slot_number(ykpiv_state *state, unsigned long *slots, unsigned long *total);
ykpiv_rc ykpiv_get_reader_slot(ykpiv_state *state, unsigned long slot, char *reader);
#define YKPIV_ALGO_3DES 0x03
#define YKPIV_ALGO_RSA1024 0x06
#define YKPIV_ALGO_RSA2048 0x07
+1 -2
View File
@@ -52,6 +52,5 @@ YKPIV_0.2.0
{
global:
ykpiv_decipher_data;
ykpiv_get_reader_slot_number;
ykpiv_get_reader_slot;
ykpiv_connect2;
} YKPIV_0.1.0;