implement generate

This commit is contained in:
Klas Lindfors
2014-02-03 16:02:59 +01:00
parent ecffbe953c
commit 6478ebc37d
2 changed files with 33 additions and 1 deletions
+2 -1
View File
@@ -27,4 +27,5 @@
option "verbose" v "Print more information" flag off option "verbose" v "Print more information" flag off
option "reader" r "Only use a matching reader" string optional option "reader" r "Only use a matching reader" string optional
option "key" k "Authentication key to use" string optional default="010203040506070801020304050607080102030405060708" option "key" k "Authentication key to use" string optional default="010203040506070801020304050607080102030405060708"
option "action" a "Action to take" values="version" enum option "action" a "Action to take" values="version","generate" enum
option "slot" s "What key slot to operate on" values="9a","9b","9c","9d","9e" enum optional
+31
View File
@@ -231,6 +231,30 @@ static void print_version(SCARDHANDLE *card, int verbose) {
} }
} }
static bool generate_key(SCARDHANDLE *card, const char *slot, int verbose) {
APDU apdu;
unsigned char data[0xff];
unsigned long recv_len = sizeof(data);
int sw;
int key = 0;
sscanf(slot, "%hhx", &key);
printf("slot: %x\n", key);
memset(apdu.raw, 0, sizeof(apdu));
apdu.st.ins = 0x47;
apdu.st.p2 = key;
apdu.st.lc = 5;
apdu.st.data[0] = 0xac;
apdu.st.data[1] = 3;
apdu.st.data[2] = 0x80;
apdu.st.data[3] = 1;
apdu.st.data[4] = 0x07; /* rsa 2048 TODO: implement more */
sw = send_data(card, apdu, 10, data, &recv_len, verbose);
return true;
}
int send_data(SCARDHANDLE *card, APDU apdu, unsigned int send_len, unsigned char *data, unsigned long *recv_len, int verbose) { int send_data(SCARDHANDLE *card, APDU apdu, unsigned int send_len, unsigned char *data, unsigned long *recv_len, int verbose) {
long rc; long rc;
int sw; int sw;
@@ -320,6 +344,13 @@ int main(int argc, char *argv[]) {
if(args_info.action_arg == action_arg_version) { if(args_info.action_arg == action_arg_version) {
print_version(&card, args_info.verbose_flag); print_version(&card, args_info.verbose_flag);
} else if(args_info.action_arg == action_arg_generate) {
if(args_info.slot_arg != slot__NULL) {
generate_key(&card, args_info.slot_orig, args_info.verbose_flag);
} else {
fprintf(stderr, "The generate command needs a slot (-s) to operate on.\n");
return EXIT_FAILURE;
}
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;