| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #include "internal.h" |
|---|
| 19 | #include "pkcs15.h" |
|---|
| 20 | #include "cardctl.h" |
|---|
| 21 | |
|---|
| 22 | #include <stdlib.h> |
|---|
| 23 | #include <string.h> |
|---|
| 24 | #include <stdio.h> |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #define MANU_ID "entersafe" |
|---|
| 28 | |
|---|
| 29 | static int entersafe_detect_card( sc_pkcs15_card_t *p15card) |
|---|
| 30 | { |
|---|
| 31 | sc_card_t *card = p15card->card; |
|---|
| 32 | |
|---|
| 33 | SC_FUNC_CALLED(card->ctx, 1); |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | if (strcmp(card->name, "entersafe")) |
|---|
| 37 | return SC_ERROR_WRONG_CARD; |
|---|
| 38 | |
|---|
| 39 | return SC_SUCCESS; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | static int sc_pkcs15emu_entersafe_init( sc_pkcs15_card_t *p15card) |
|---|
| 43 | { |
|---|
| 44 | int r, i; |
|---|
| 45 | char buf[256]; |
|---|
| 46 | sc_path_t path; |
|---|
| 47 | sc_file_t *file = NULL; |
|---|
| 48 | sc_card_t *card = p15card->card; |
|---|
| 49 | sc_serial_number_t serial; |
|---|
| 50 | |
|---|
| 51 | SC_FUNC_CALLED(card->ctx, 1); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial); |
|---|
| 55 | r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0); |
|---|
| 56 | if (r != SC_SUCCESS) |
|---|
| 57 | return SC_ERROR_INTERNAL; |
|---|
| 58 | if (p15card->serial_number) |
|---|
| 59 | free(p15card->serial_number); |
|---|
| 60 | p15card->serial_number = (char *) malloc(strlen(buf) + 1); |
|---|
| 61 | if (!p15card->serial_number) |
|---|
| 62 | return SC_ERROR_INTERNAL; |
|---|
| 63 | strcpy(p15card->serial_number, buf); |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | if (p15card->manufacturer_id) |
|---|
| 67 | free(p15card->manufacturer_id); |
|---|
| 68 | p15card->manufacturer_id = (char *) malloc(strlen(MANU_ID) + 1); |
|---|
| 69 | if (!p15card->manufacturer_id) |
|---|
| 70 | return SC_ERROR_INTERNAL; |
|---|
| 71 | strcpy(p15card->manufacturer_id, MANU_ID); |
|---|
| 72 | |
|---|
| 73 | return SC_SUCCESS; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *p15card, |
|---|
| 77 | sc_pkcs15emu_opt_t *opts) |
|---|
| 78 | { |
|---|
| 79 | SC_FUNC_CALLED(p15card->card->ctx, 1); |
|---|
| 80 | |
|---|
| 81 | if (opts && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK) |
|---|
| 82 | return sc_pkcs15emu_entersafe_init(p15card); |
|---|
| 83 | else { |
|---|
| 84 | int r = entersafe_detect_card(p15card); |
|---|
| 85 | if (r) |
|---|
| 86 | return SC_ERROR_WRONG_CARD; |
|---|
| 87 | return sc_pkcs15emu_entersafe_init(p15card); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|