| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #ifndef P15CARD_HELPER_H |
|---|
| 22 | #define P15CARD_HELPER_H |
|---|
| 23 | |
|---|
| 24 | #include <opensc/pkcs15.h> |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #define USAGE_NONREP SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | \ |
|---|
| 28 | SC_PKCS15_PRKEY_USAGE_SIGN |
|---|
| 29 | #define USAGE_DS SC_PKCS15_PRKEY_USAGE_SIGN |
|---|
| 30 | #define USAGE_CRYPTO SC_PKCS15_PRKEY_USAGE_ENCRYPT | \ |
|---|
| 31 | SC_PKCS15_PRKEY_USAGE_DECRYPT | \ |
|---|
| 32 | SC_PKCS15_PRKEY_USAGE_WRAP | \ |
|---|
| 33 | SC_PKCS15_PRKEY_USAGE_UNWRAP |
|---|
| 34 | #define USAGE_KE SC_PKCS15_PRKEY_USAGE_ENCRYPT | \ |
|---|
| 35 | SC_PKCS15_PRKEY_USAGE_DECRYPT | \ |
|---|
| 36 | SC_PKCS15_PRKEY_USAGE_WRAP | \ |
|---|
| 37 | SC_PKCS15_PRKEY_USAGE_UNWRAP |
|---|
| 38 | #define USAGE_AUT SC_PKCS15_PRKEY_USAGE_ENCRYPT | \ |
|---|
| 39 | SC_PKCS15_PRKEY_USAGE_DECRYPT | \ |
|---|
| 40 | SC_PKCS15_PRKEY_USAGE_WRAP | \ |
|---|
| 41 | SC_PKCS15_PRKEY_USAGE_UNWRAP | \ |
|---|
| 42 | SC_PKCS15_PRKEY_USAGE_SIGN |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | typedef struct objdata_st { |
|---|
| 46 | const char *id; |
|---|
| 47 | const char *label; |
|---|
| 48 | const char *aoid; |
|---|
| 49 | int authority; |
|---|
| 50 | const char *path; |
|---|
| 51 | int obj_flags; |
|---|
| 52 | } objdata; |
|---|
| 53 | |
|---|
| 54 | typedef struct cdata_st { |
|---|
| 55 | const char *id; |
|---|
| 56 | const char *label; |
|---|
| 57 | int authority; |
|---|
| 58 | const char *path; |
|---|
| 59 | int obj_flags; |
|---|
| 60 | } cdata; |
|---|
| 61 | |
|---|
| 62 | typedef struct pdata_st { |
|---|
| 63 | const char *id; |
|---|
| 64 | const char *label; |
|---|
| 65 | const char *path; |
|---|
| 66 | int ref; |
|---|
| 67 | int type; |
|---|
| 68 | unsigned int maxlen; |
|---|
| 69 | unsigned int minlen; |
|---|
| 70 | unsigned int storedlen; |
|---|
| 71 | int flags; |
|---|
| 72 | int tries_left; |
|---|
| 73 | const char pad_char; |
|---|
| 74 | int obj_flags; |
|---|
| 75 | } pindata; |
|---|
| 76 | |
|---|
| 77 | typedef struct pubdata_st { |
|---|
| 78 | const char *id; |
|---|
| 79 | const char *label; |
|---|
| 80 | unsigned int modulus_len; |
|---|
| 81 | int usage; |
|---|
| 82 | const char *path; |
|---|
| 83 | int ref; |
|---|
| 84 | const char *auth_id; |
|---|
| 85 | int obj_flags; |
|---|
| 86 | } pubdata; |
|---|
| 87 | |
|---|
| 88 | typedef struct prdata_st { |
|---|
| 89 | const char *id; |
|---|
| 90 | const char *label; |
|---|
| 91 | unsigned int modulus_len; |
|---|
| 92 | int usage; |
|---|
| 93 | const char *path; |
|---|
| 94 | int ref; |
|---|
| 95 | const char *auth_id; |
|---|
| 96 | int obj_flags; |
|---|
| 97 | } prdata; |
|---|
| 98 | |
|---|
| 99 | typedef struct keyinfo_st { |
|---|
| 100 | int fileid; |
|---|
| 101 | sc_pkcs15_id_t id; |
|---|
| 102 | unsigned int modulus_len; |
|---|
| 103 | u8 modulus[1024/8]; |
|---|
| 104 | } keyinfo; |
|---|
| 105 | |
|---|
| 106 | typedef struct p15data_items p15data_items; |
|---|
| 107 | |
|---|
| 108 | typedef int (*cert_load_function)(sc_card_t *card, u8** data, size_t* length, int* shouldFree); |
|---|
| 109 | #define CERT_LOAD_FUNCTION(x) int x(sc_card_t *card, u8** data, size_t*length, int *shouldFree) |
|---|
| 110 | typedef int (*cert_handle_function)(sc_pkcs15_card_t *p15card, p15data_items* items, const cdata* cert, u8* data, size_t length); |
|---|
| 111 | #define CERT_HANDLE_FUNCTION(x) int x(sc_pkcs15_card_t *p15card, p15data_items* items, const cdata* cert, u8* data, size_t length) |
|---|
| 112 | |
|---|
| 113 | struct p15data_items { |
|---|
| 114 | const objdata* objects; |
|---|
| 115 | const cdata* certs; |
|---|
| 116 | const pindata* pins; |
|---|
| 117 | const pubdata* public_keys; |
|---|
| 118 | const prdata* private_keys; |
|---|
| 119 | |
|---|
| 120 | cert_load_function cert_load; |
|---|
| 121 | cert_handle_function cert_handle; |
|---|
| 122 | int cert_continue; |
|---|
| 123 | int forced_private; |
|---|
| 124 | int forced_public; |
|---|
| 125 | }; |
|---|
| 126 | |
|---|
| 127 | CERT_HANDLE_FUNCTION(default_cert_handle); |
|---|
| 128 | |
|---|
| 129 | int sc_pkcs15emu_initialize_objects(sc_pkcs15_card_t *p15card, p15data_items* items); |
|---|
| 130 | int sc_pkcs15emu_initialize_certificates(sc_pkcs15_card_t *p15card, p15data_items* items); |
|---|
| 131 | int sc_pkcs15emu_initialize_pins(sc_pkcs15_card_t *p15card, p15data_items *items); |
|---|
| 132 | int sc_pkcs15emu_initialize_private_keys(sc_pkcs15_card_t *p15card, p15data_items *items); |
|---|
| 133 | int sc_pkcs15emu_initialize_public_keys(sc_pkcs15_card_t *p15card, p15data_items *items); |
|---|
| 134 | int sc_pkcs15emu_initialize_all(sc_pkcs15_card_t *p15card, p15data_items *items); |
|---|
| 135 | |
|---|
| 136 | #endif |
|---|