add a verify-pin action (needed for signing request)

This commit is contained in:
Klas Lindfors
2014-02-06 10:20:37 +01:00
parent 71cb66e5bf
commit ca45b6a565
2 changed files with 42 additions and 1 deletions
+40
View File
@@ -921,6 +921,33 @@ request_out:
return ret;
}
static bool verify_pin(SCARDHANDLE *card, const char *pin, int verbose) {
APDU apdu;
unsigned char data[0xff];
unsigned long recv_len = sizeof(data);
int sw;
int len = strlen(pin);
if(len > 8) {
fprintf(stderr, "Maximum 8 digits of PIN supported.\n");
}
memset(apdu.raw, 0, sizeof(apdu.raw));
apdu.st.ins = 0x20;
apdu.st.p1 = 0x00;
apdu.st.p2 = 0x80;
apdu.st.lc = 0x08;
memcpy(apdu.st.data, pin, len);
if(len < 8) {
memset(apdu.st.data + len, 0xff, 8 - len);
}
sw = send_data(card, &apdu, apdu.st.lc + 5, data, &recv_len, verbose);
if(sw != 0x9000) {
return false;
}
return true;
}
static unsigned char get_algorithm(EVP_PKEY *key) {
int type = EVP_PKEY_type(key->type);
switch(type) {
@@ -1219,6 +1246,19 @@ int main(int argc, char *argv[]) {
}
}
break;
case action_arg_verifyMINUS_pin:
if(args_info.pin_arg) {
if(verify_pin(&card, args_info.pin_arg, verbosity)) {
printf("Successfully verified PIN.\n");
} else {
fprintf(stderr, "Failed to verify PIN.\n");
return EXIT_FAILURE;
}
} else {
fprintf(stderr, "The verify-pin action needs a pin (-P).\n");
return EXIT_FAILURE;
}
break;
case action__NULL:
default:
fprintf(stderr, "Wrong action. %d.\n", action);