/src/opensc/src/libopensc/card-muscle.c
Line | Count | Source |
1 | | /* |
2 | | * card-muscle.c: Support for MuscleCard Applet from musclecard.com |
3 | | * |
4 | | * Copyright (C) 2006, Identity Alliance, Thomas Harning <support@identityalliance.com> |
5 | | * |
6 | | * This library is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU Lesser General Public |
8 | | * License as published by the Free Software Foundation; either |
9 | | * version 2.1 of the License, or (at your option) any later version. |
10 | | * |
11 | | * This library is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | | * Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public |
17 | | * License along with this library; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #ifdef HAVE_CONFIG_H |
22 | | #include "config.h" |
23 | | #endif |
24 | | |
25 | | #include <stdlib.h> |
26 | | #include <string.h> |
27 | | |
28 | | #include "internal.h" |
29 | | #include "cardctl.h" |
30 | | #include "muscle.h" |
31 | | #include "muscle-filesystem.h" |
32 | | #include "types.h" |
33 | | #include "opensc.h" |
34 | | |
35 | | static struct sc_card_operations muscle_ops; |
36 | | static const struct sc_card_operations *iso_ops = NULL; |
37 | | |
38 | | static struct sc_card_driver muscle_drv = { |
39 | | "MuscleApplet", |
40 | | "muscle", |
41 | | &muscle_ops, |
42 | | NULL, 0, NULL |
43 | | }; |
44 | | |
45 | | static const struct sc_atr_table muscle_atrs[] = { |
46 | | /* Tyfone JCOP 242R2 cards */ |
47 | | { "3b:6d:00:00:ff:54:79:66:6f:6e:65:20:32:34:32:52:32", NULL, NULL, SC_CARD_TYPE_MUSCLE_JCOP242R2_NO_EXT_APDU, 0, NULL }, |
48 | | /* Aladdin eToken PRO USB 72K Java */ |
49 | | { "3b:d5:18:00:81:31:3a:7d:80:73:c8:21:10:30", NULL, NULL, SC_CARD_TYPE_MUSCLE_ETOKEN_72K, 0, NULL }, |
50 | | /* JCOP31 v2.4.1 contact interface */ |
51 | | { "3b:f8:13:00:00:81:31:fe:45:4a:43:4f:50:76:32:34:31:b7", NULL, NULL, SC_CARD_TYPE_MUSCLE_JCOP241, 0, NULL }, |
52 | | /* JCOP31 v2.4.1 RF interface */ |
53 | | { "3b:88:80:01:4a:43:4f:50:76:32:34:31:5e", NULL, NULL, SC_CARD_TYPE_MUSCLE_JCOP241, 0, NULL }, |
54 | | { NULL, NULL, NULL, 0, 0, NULL } |
55 | | }; |
56 | | |
57 | 8.02k | #define MUSCLE_DATA(card) ( (muscle_private_t*)card->drv_data ) |
58 | 154k | #define MUSCLE_FS(card) ( ((muscle_private_t*)card->drv_data)->fs ) |
59 | | typedef struct muscle_private { |
60 | | sc_security_env_t env; |
61 | | unsigned short verifiedPins; |
62 | | mscfs_t *fs; |
63 | | int rsa_key_ref; |
64 | | |
65 | | } muscle_private_t; |
66 | | |
67 | | static int muscle_finish(sc_card_t *card) |
68 | 4.00k | { |
69 | 4.00k | muscle_private_t *priv = MUSCLE_DATA(card); |
70 | 4.00k | if (priv) { |
71 | 4.00k | mscfs_free(priv->fs); |
72 | 4.00k | free(priv); |
73 | 4.00k | card->drv_data = NULL; |
74 | 4.00k | } |
75 | 4.00k | return 0; |
76 | 4.00k | } |
77 | | |
78 | | |
79 | | static u8 muscleAppletId[] = { 0xA0, 0x00,0x00,0x00, 0x01, 0x01 }; |
80 | | |
81 | | static int muscle_match_card(sc_card_t *card) |
82 | 9.88k | { |
83 | 9.88k | sc_apdu_t apdu; |
84 | 9.88k | u8 response[64]; |
85 | 9.88k | int r; |
86 | | |
87 | 9.88k | if (msc_select_applet(card, muscleAppletId, sizeof muscleAppletId) == 1) { |
88 | | /* Muscle applet is present, check the protocol version to be sure */ |
89 | 4.00k | sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x3C, 0x00, 0x00); |
90 | 4.00k | apdu.cla = 0xB0; |
91 | 4.00k | apdu.le = 64; |
92 | 4.00k | apdu.resplen = 64; |
93 | 4.00k | apdu.resp = response; |
94 | 4.00k | r = sc_transmit_apdu(card, &apdu); |
95 | 4.00k | if (r == SC_SUCCESS && apdu.resplen > 1 && response[0] == 0x01) { |
96 | 11 | card->type = SC_CARD_TYPE_MUSCLE_V1; |
97 | 3.99k | } else { |
98 | 3.99k | card->type = SC_CARD_TYPE_MUSCLE_GENERIC; |
99 | 3.99k | } |
100 | 4.00k | return 1; |
101 | 4.00k | } |
102 | 5.87k | return 0; |
103 | 9.88k | } |
104 | | |
105 | | /* Since Musclecard has a different ACL system then PKCS15 |
106 | | * objects need to have their READ/UPDATE/DELETE permissions mapped for files |
107 | | * and directory ACLS need to be set |
108 | | * For keys.. they have different ACLS, but are accessed in different locations, so it shouldn't be an issue here |
109 | | */ |
110 | | static unsigned short muscle_parse_singleAcl(const sc_acl_entry_t* acl) |
111 | 324 | { |
112 | 324 | unsigned short acl_entry = 0; |
113 | 643 | while(acl) { |
114 | 325 | int key = acl->key_ref; |
115 | 325 | int method = acl->method; |
116 | 325 | switch(method) { |
117 | 6 | case SC_AC_NEVER: |
118 | 6 | return 0xFFFF; |
119 | | /* Ignore... other items overwrite these */ |
120 | 256 | case SC_AC_NONE: |
121 | 256 | case SC_AC_UNKNOWN: |
122 | 256 | break; |
123 | 9 | case SC_AC_CHV: |
124 | | /* Ignore shift with more bits that acl_entry has */ |
125 | 9 | if ((size_t) key < sizeof(acl_entry) * 8) |
126 | 8 | acl_entry |= (1u << key); /* Assuming key 0 == SO */ |
127 | 9 | break; |
128 | 4 | case SC_AC_AUT: |
129 | 8 | case SC_AC_TERM: |
130 | 13 | case SC_AC_PRO: |
131 | 54 | default: |
132 | | /* Ignored */ |
133 | 54 | break; |
134 | 325 | } |
135 | 319 | acl = acl->next; |
136 | 319 | } |
137 | 318 | return acl_entry; |
138 | 324 | } |
139 | | |
140 | | static void muscle_parse_acls(const sc_file_t* file, unsigned short* read_perm, unsigned short* write_perm, unsigned short* delete_perm) |
141 | 108 | { |
142 | 108 | if (read_perm == NULL || write_perm == NULL || delete_perm == NULL) |
143 | 0 | return; |
144 | 108 | *read_perm = muscle_parse_singleAcl(sc_file_get_acl_entry(file, SC_AC_OP_READ)); |
145 | 108 | *write_perm = muscle_parse_singleAcl(sc_file_get_acl_entry(file, SC_AC_OP_UPDATE)); |
146 | 108 | *delete_perm = muscle_parse_singleAcl(sc_file_get_acl_entry(file, SC_AC_OP_DELETE)); |
147 | 108 | } |
148 | | |
149 | | static int muscle_create_directory(sc_card_t *card, sc_file_t *file) |
150 | 113 | { |
151 | 113 | mscfs_t *fs = MUSCLE_FS(card); |
152 | 113 | msc_id objectId; |
153 | 113 | u8* oid = objectId.id; |
154 | 113 | unsigned id = file->id; |
155 | 113 | unsigned short read_perm = 0, write_perm = 0, delete_perm = 0; |
156 | 113 | size_t objectSize; |
157 | 113 | int r; |
158 | 113 | if(id == 0) /* No null name files */ |
159 | 7 | return SC_ERROR_INVALID_ARGUMENTS; |
160 | | |
161 | | /* No nesting directories */ |
162 | 106 | if(fs->currentPath[0] != 0x3F || fs->currentPath[1] != 0x00) |
163 | 1 | return SC_ERROR_NOT_SUPPORTED; |
164 | 105 | oid[0] = ((id & 0xFF00) >> 8) & 0xFF; |
165 | 105 | oid[1] = id & 0xFF; |
166 | 105 | oid[2] = oid[3] = 0; |
167 | | |
168 | 105 | objectSize = file->size; |
169 | | |
170 | 105 | muscle_parse_acls(file, &read_perm, &write_perm, &delete_perm); |
171 | 105 | r = msc_create_object(card, objectId, objectSize, read_perm, write_perm, delete_perm); |
172 | 105 | mscfs_clear_cache(fs); |
173 | 105 | if(r >= 0) return 0; |
174 | 5 | return r; |
175 | 105 | } |
176 | | |
177 | | |
178 | | static int muscle_create_file(sc_card_t *card, sc_file_t *file) |
179 | 118 | { |
180 | 118 | mscfs_t *fs = MUSCLE_FS(card); |
181 | 118 | size_t objectSize = file->size; |
182 | 118 | unsigned short read_perm = 0, write_perm = 0, delete_perm = 0; |
183 | 118 | msc_id objectId; |
184 | 118 | int r; |
185 | 118 | if(file->type == SC_FILE_TYPE_DF) |
186 | 113 | return muscle_create_directory(card, file); |
187 | 5 | if(file->type != SC_FILE_TYPE_WORKING_EF) |
188 | 1 | return SC_ERROR_NOT_SUPPORTED; |
189 | 4 | if(file->id == 0) /* No null name files */ |
190 | 1 | return SC_ERROR_INVALID_ARGUMENTS; |
191 | | |
192 | 3 | muscle_parse_acls(file, &read_perm, &write_perm, &delete_perm); |
193 | | |
194 | 3 | mscfs_lookup_local(fs, file->id, &objectId); |
195 | 3 | r = msc_create_object(card, objectId, objectSize, read_perm, write_perm, delete_perm); |
196 | 3 | mscfs_clear_cache(fs); |
197 | 3 | if(r >= 0) return 0; |
198 | 1 | return r; |
199 | 3 | } |
200 | | |
201 | | static int muscle_read_binary(sc_card_t *card, unsigned int idx, u8* buf, size_t count, unsigned long *flags) |
202 | 403 | { |
203 | 403 | mscfs_t *fs = MUSCLE_FS(card); |
204 | 403 | int r; |
205 | 403 | msc_id objectId; |
206 | 403 | u8* oid = objectId.id; |
207 | 403 | mscfs_file_t *file; |
208 | | |
209 | 403 | r = mscfs_check_selection(fs, -1); |
210 | 403 | if(r < 0) LOG_FUNC_RETURN(card->ctx, r); |
211 | 403 | file = &fs->cache.array[fs->currentFileIndex]; |
212 | 403 | objectId = file->objectId; |
213 | | /* memcpy(objectId.id, file->objectId.id, 4); */ |
214 | 403 | if(!file->ef) { |
215 | 34 | oid[0] = oid[2]; |
216 | 34 | oid[1] = oid[3]; |
217 | 34 | oid[2] = oid[3] = 0; |
218 | 34 | } |
219 | 403 | r = msc_read_object(card, objectId, idx, buf, count); |
220 | 403 | LOG_FUNC_RETURN(card->ctx, r); |
221 | 403 | } |
222 | | |
223 | | static int muscle_update_binary(sc_card_t *card, unsigned int idx, const u8* buf, size_t count, unsigned long flags) |
224 | 5.44k | { |
225 | 5.44k | mscfs_t *fs = MUSCLE_FS(card); |
226 | 5.44k | int r; |
227 | 5.44k | mscfs_file_t *file; |
228 | 5.44k | msc_id objectId; |
229 | 5.44k | u8* oid = objectId.id; |
230 | | |
231 | 5.44k | r = mscfs_check_selection(fs, -1); |
232 | 5.44k | if(r < 0) LOG_FUNC_RETURN(card->ctx, r); |
233 | 5.43k | file = &fs->cache.array[fs->currentFileIndex]; |
234 | | |
235 | 5.43k | objectId = file->objectId; |
236 | | /* memcpy(objectId.id, file->objectId.id, 4); */ |
237 | 5.43k | if(!file->ef) { |
238 | 5.43k | oid[0] = oid[2]; |
239 | 5.43k | oid[1] = oid[3]; |
240 | 5.43k | oid[2] = oid[3] = 0; |
241 | 5.43k | } |
242 | 5.43k | if(file->size < idx + count) { |
243 | 0 | size_t newFileSize = idx + count; |
244 | 0 | u8* buffer = malloc(newFileSize); |
245 | 0 | if(buffer == NULL) LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY); |
246 | | |
247 | 0 | r = msc_read_object(card, objectId, 0, buffer, file->size); |
248 | | /* TODO: RETRIEVE ACLS */ |
249 | 0 | if(r < 0) goto update_bin_free_buffer; |
250 | 0 | r = msc_delete_object(card, objectId, 0); |
251 | 0 | if(r < 0) goto update_bin_free_buffer; |
252 | 0 | r = msc_create_object(card, objectId, newFileSize, 0,0,0); |
253 | 0 | if(r < 0) goto update_bin_free_buffer; |
254 | 0 | memcpy(buffer + idx, buf, count); |
255 | 0 | r = msc_update_object(card, objectId, 0, buffer, newFileSize); |
256 | 0 | if(r < 0) goto update_bin_free_buffer; |
257 | 0 | file->size = newFileSize; |
258 | 0 | update_bin_free_buffer: |
259 | 0 | free(buffer); |
260 | 0 | LOG_FUNC_RETURN(card->ctx, r); |
261 | 5.43k | } else { |
262 | 5.43k | r = msc_update_object(card, objectId, idx, buf, count); |
263 | 5.43k | } |
264 | | /* mscfs_clear_cache(fs); */ |
265 | 5.43k | return r; |
266 | 5.43k | } |
267 | | |
268 | | /* TODO: Evaluate correctness */ |
269 | | static int muscle_delete_mscfs_file(sc_card_t *card, mscfs_file_t *file_data) |
270 | 137k | { |
271 | 137k | mscfs_t *fs = MUSCLE_FS(card); |
272 | 137k | msc_id id = file_data->objectId; |
273 | 137k | u8* oid = id.id; |
274 | 137k | int r; |
275 | 137k | file_data->deleteFile = 1; |
276 | | |
277 | 137k | if(!file_data->ef) { |
278 | 131k | int x; |
279 | 131k | mscfs_file_t *childFile; |
280 | | /* Delete children */ |
281 | 131k | r = mscfs_check_cache(fs); |
282 | 131k | if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r); |
283 | | |
284 | 131k | sc_log(card->ctx, |
285 | 131k | "DELETING Children of: %02X%02X%02X%02X\n", |
286 | 131k | oid[0],oid[1],oid[2],oid[3]); |
287 | 684M | for(x = 0; x < fs->cache.size; x++) { |
288 | 684M | msc_id objectId; |
289 | 684M | childFile = &fs->cache.array[x]; |
290 | 684M | objectId = childFile->objectId; |
291 | | |
292 | 684M | if(0 == memcmp(oid + 2, objectId.id, 2) && !childFile->deleteFile) { |
293 | 136k | sc_log(card->ctx, |
294 | 136k | "DELETING: %02X%02X%02X%02X\n", |
295 | 136k | objectId.id[0],objectId.id[1], |
296 | 136k | objectId.id[2],objectId.id[3]); |
297 | 136k | r = muscle_delete_mscfs_file(card, childFile); |
298 | 136k | if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r); |
299 | | |
300 | 136k | } |
301 | 684M | } |
302 | 131k | oid[0] = oid[2]; |
303 | 131k | oid[1] = oid[3]; |
304 | 131k | oid[2] = oid[3] = 0; |
305 | | /* ??? objectId = objectId >> 16; */ |
306 | 131k | } |
307 | 136k | r = msc_delete_object(card, id, 1); |
308 | | /* Check if its the root... this file generally is virtual |
309 | | * So don't return an error if it fails */ |
310 | 136k | if((0 == memcmp(oid, "\x3F\x00\x00\x00", 4)) |
311 | 8.27k | || (0 == memcmp(oid, "\x3F\x00\x3F\x00", 4))) |
312 | 128k | return 0; |
313 | | |
314 | 8.10k | if(r < 0) { |
315 | 8 | printf("ID: %02X%02X%02X%02X\n", |
316 | 8 | oid[0],oid[1],oid[2],oid[3]); |
317 | 8 | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r); |
318 | 8 | } |
319 | 8.10k | return 0; |
320 | 8.10k | } |
321 | | |
322 | | static int muscle_delete_file(sc_card_t *card, const sc_path_t *path_in) |
323 | 246 | { |
324 | 246 | mscfs_t *fs = MUSCLE_FS(card); |
325 | 246 | mscfs_file_t *file_data = NULL; |
326 | 246 | int r = 0; |
327 | 246 | int x; |
328 | | |
329 | 246 | if (!path_in) |
330 | 0 | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS); |
331 | | |
332 | 246 | r = mscfs_loadFileInfo(fs, path_in->value, path_in->len, &file_data, NULL); |
333 | 246 | if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r); |
334 | 149k | for (x = 0; x < fs->cache.size; x++) { |
335 | 149k | mscfs_file_t *file = &fs->cache.array[x]; |
336 | 149k | file->deleteFile = 0; |
337 | 149k | } |
338 | 187 | r = muscle_delete_mscfs_file(card, file_data); |
339 | 187 | mscfs_clear_cache(fs); |
340 | 187 | if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r); |
341 | 179 | return 0; |
342 | 187 | } |
343 | | |
344 | | static void muscle_load_single_acl(sc_file_t* file, int operation, unsigned short acl) |
345 | 11.6k | { |
346 | 11.6k | int key; |
347 | | /* Everybody by default.... */ |
348 | 11.6k | sc_file_add_acl_entry(file, operation, SC_AC_NONE, 0); |
349 | 11.6k | if(acl == 0xFFFF) { |
350 | 1.07k | sc_file_add_acl_entry(file, operation, SC_AC_NEVER, 0); |
351 | 1.07k | return; |
352 | 1.07k | } |
353 | 179k | for(key = 0; key < 16; key++) { |
354 | 169k | if(acl >> key & 1) { |
355 | 37.5k | sc_file_add_acl_entry(file, operation, SC_AC_CHV, key); |
356 | 37.5k | } |
357 | 169k | } |
358 | 10.5k | } |
359 | | static void muscle_load_file_acls(sc_file_t* file, mscfs_file_t *file_data) |
360 | 1.90k | { |
361 | 1.90k | muscle_load_single_acl(file, SC_AC_OP_READ, file_data->read); |
362 | 1.90k | muscle_load_single_acl(file, SC_AC_OP_WRITE, file_data->write); |
363 | 1.90k | muscle_load_single_acl(file, SC_AC_OP_UPDATE, file_data->write); |
364 | 1.90k | muscle_load_single_acl(file, SC_AC_OP_DELETE, file_data->delete); |
365 | 1.90k | } |
366 | | static void muscle_load_dir_acls(sc_file_t* file, mscfs_file_t *file_data) |
367 | 801 | { |
368 | 801 | muscle_load_single_acl(file, SC_AC_OP_SELECT, 0); |
369 | 801 | muscle_load_single_acl(file, SC_AC_OP_LIST_FILES, 0); |
370 | 801 | muscle_load_single_acl(file, SC_AC_OP_LOCK, 0xFFFF); |
371 | 801 | muscle_load_single_acl(file, SC_AC_OP_DELETE, file_data->delete); |
372 | 801 | muscle_load_single_acl(file, SC_AC_OP_CREATE, file_data->write); |
373 | 801 | } |
374 | | |
375 | | /* Required type = -1 for don't care, 1 for EF, 0 for DF */ |
376 | | static int select_item(sc_card_t *card, const sc_path_t *path_in, sc_file_t ** file_out, int requiredType) |
377 | 10.9k | { |
378 | 10.9k | mscfs_t *fs = MUSCLE_FS(card); |
379 | 10.9k | mscfs_file_t *file_data = NULL; |
380 | 10.9k | size_t pathlen = path_in->len; |
381 | 10.9k | int r = 0; |
382 | 10.9k | int objectIndex; |
383 | 10.9k | u8* oid; |
384 | | |
385 | 10.9k | r = mscfs_check_cache(fs); |
386 | 10.9k | if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r); |
387 | 5.48k | r = mscfs_loadFileInfo(fs, path_in->value, path_in->len, &file_data, &objectIndex); |
388 | 5.48k | if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r); |
389 | | |
390 | | /* Check if its the right type */ |
391 | 3.69k | if(requiredType >= 0 && requiredType != file_data->ef) { |
392 | 51 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS); |
393 | 51 | } |
394 | 3.64k | oid = file_data->objectId.id; |
395 | | /* Is it a file or directory */ |
396 | 3.64k | if(file_data->ef) { |
397 | 1.91k | fs->currentPath[0] = oid[0]; |
398 | 1.91k | fs->currentPath[1] = oid[1]; |
399 | 1.91k | fs->currentFile[0] = oid[2]; |
400 | 1.91k | fs->currentFile[1] = oid[3]; |
401 | 1.91k | } else { |
402 | 1.73k | if(pathlen < 2) { |
403 | 10 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS); |
404 | 10 | } |
405 | 1.72k | fs->currentPath[0] = oid[pathlen - 2]; |
406 | 1.72k | fs->currentPath[1] = oid[pathlen - 1]; |
407 | 1.72k | fs->currentFile[0] = 0; |
408 | 1.72k | fs->currentFile[1] = 0; |
409 | 1.72k | } |
410 | | |
411 | 3.63k | fs->currentFileIndex = objectIndex; |
412 | 3.63k | if(file_out) { |
413 | 2.70k | sc_file_t *file; |
414 | 2.70k | file = sc_file_new(); |
415 | 2.70k | if (!file) |
416 | 0 | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_OUT_OF_MEMORY); |
417 | 2.70k | file->path = *path_in; |
418 | 2.70k | file->size = file_data->size; |
419 | 2.70k | file->id = (oid[2] << 8) | oid[3]; |
420 | 2.70k | if(!file_data->ef) { |
421 | 801 | file->type = SC_FILE_TYPE_DF; |
422 | 1.90k | } else { |
423 | 1.90k | file->type = SC_FILE_TYPE_WORKING_EF; |
424 | 1.90k | file->ef_structure = SC_FILE_EF_TRANSPARENT; |
425 | 1.90k | } |
426 | | |
427 | | /* Setup ACLS */ |
428 | 2.70k | if(file_data->ef) { |
429 | 1.90k | muscle_load_file_acls(file, file_data); |
430 | 1.90k | } else { |
431 | 801 | muscle_load_dir_acls(file, file_data); |
432 | | /* Setup directory acls... */ |
433 | 801 | } |
434 | | |
435 | 2.70k | file->magic = SC_FILE_MAGIC; |
436 | 2.70k | *file_out = file; |
437 | 2.70k | } |
438 | 3.63k | return 0; |
439 | 3.63k | } |
440 | | |
441 | | static int muscle_select_file(sc_card_t *card, const sc_path_t *path_in, |
442 | | sc_file_t **file_out) |
443 | 10.9k | { |
444 | 10.9k | int r; |
445 | | |
446 | 10.9k | if (card == NULL || path_in == NULL) |
447 | 0 | return SC_ERROR_INTERNAL; |
448 | | |
449 | 10.9k | switch (path_in->type) { |
450 | 466 | case SC_PATH_TYPE_FILE_ID: |
451 | 466 | r = select_item(card, path_in, file_out, 1); |
452 | 466 | break; |
453 | 1.12k | case SC_PATH_TYPE_DF_NAME: |
454 | 1.12k | r = select_item(card, path_in, file_out, 0); |
455 | 1.12k | break; |
456 | 9.39k | case SC_PATH_TYPE_PATH: |
457 | 9.39k | r = select_item(card, path_in, file_out, -1); |
458 | 9.39k | break; |
459 | 0 | default: |
460 | 0 | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS); |
461 | 10.9k | } |
462 | 10.9k | if(r > 0) r = 0; |
463 | 10.9k | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r); |
464 | 10.9k | } |
465 | | |
466 | | static int _listFile(mscfs_file_t *file, int reset, void *udata) |
467 | 182k | { |
468 | 182k | int next = reset ? 0x00 : 0x01; |
469 | 182k | return msc_list_objects( (sc_card_t*)udata, next, file); |
470 | 182k | } |
471 | | |
472 | | static int muscle_init(sc_card_t *card) |
473 | 4.00k | { |
474 | 4.00k | muscle_private_t *priv; |
475 | 4.00k | int r; |
476 | | |
477 | 4.00k | card->name = "MuscleApplet"; |
478 | 4.00k | card->drv_data = malloc(sizeof(muscle_private_t)); |
479 | 4.00k | if(!card->drv_data) { |
480 | 0 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY); |
481 | 0 | } |
482 | 4.00k | memset(card->drv_data, 0, sizeof(muscle_private_t)); |
483 | 4.00k | priv = MUSCLE_DATA(card); |
484 | 4.00k | priv->verifiedPins = 0; |
485 | 4.00k | priv->fs = mscfs_new(); |
486 | 4.00k | if(!priv->fs) { |
487 | 0 | free(card->drv_data); |
488 | 0 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY); |
489 | 0 | } |
490 | 4.00k | priv->fs->udata = card; |
491 | 4.00k | priv->fs->listFile = _listFile; |
492 | | |
493 | 4.00k | card->cla = 0xB0; |
494 | | |
495 | 4.00k | card->flags |= SC_CARD_FLAG_RNG; |
496 | 4.00k | card->caps |= SC_CARD_CAP_RNG; |
497 | | |
498 | | /* Card type detection */ |
499 | 4.00k | r = _sc_match_atr(card, muscle_atrs, &card->type); |
500 | 4.00k | if (r < 0) { |
501 | 3.99k | sc_log(card->ctx, "Failed to match the ATRs"); |
502 | 3.99k | } |
503 | 4.00k | if(card->type == SC_CARD_TYPE_MUSCLE_ETOKEN_72K) { |
504 | 0 | card->caps |= SC_CARD_CAP_APDU_EXT; |
505 | 0 | } |
506 | 4.00k | if(card->type == SC_CARD_TYPE_MUSCLE_JCOP241) { |
507 | 9 | card->caps |= SC_CARD_CAP_APDU_EXT; |
508 | 9 | } |
509 | 4.00k | if (!(card->caps & SC_CARD_CAP_APDU_EXT)) { |
510 | 3.99k | card->max_recv_size = 255; |
511 | 3.99k | card->max_send_size = 255; |
512 | 3.99k | } |
513 | 4.00k | if(card->type == SC_CARD_TYPE_MUSCLE_JCOP242R2_NO_EXT_APDU) { |
514 | | /* Tyfone JCOP v242R2 card that doesn't support extended APDUs */ |
515 | 0 | } |
516 | | |
517 | | |
518 | | /* FIXME: Card type detection */ |
519 | 4.00k | if (1) { |
520 | 4.00k | unsigned long flags; |
521 | | |
522 | 4.00k | flags = SC_ALGORITHM_RSA_RAW; |
523 | 4.00k | flags |= SC_ALGORITHM_RSA_HASH_NONE; |
524 | 4.00k | flags |= SC_ALGORITHM_ONBOARD_KEY_GEN; |
525 | | |
526 | 4.00k | _sc_card_add_rsa_alg(card, 1024, flags, 0); |
527 | 4.00k | _sc_card_add_rsa_alg(card, 2048, flags, 0); |
528 | 4.00k | } |
529 | 4.00k | return SC_SUCCESS; |
530 | 4.00k | } |
531 | | |
532 | | static int muscle_list_files(sc_card_t *card, u8 *buf, size_t bufLen) |
533 | 0 | { |
534 | 0 | muscle_private_t* priv = MUSCLE_DATA(card); |
535 | 0 | mscfs_t *fs = priv->fs; |
536 | 0 | int x, r; |
537 | 0 | int count = 0; |
538 | |
|
539 | 0 | r = mscfs_check_cache(priv->fs); |
540 | 0 | if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r); |
541 | | |
542 | 0 | for(x = 0; x < fs->cache.size; x++) { |
543 | 0 | u8* oid = fs->cache.array[x].objectId.id; |
544 | 0 | if (bufLen < 2) |
545 | 0 | break; |
546 | 0 | sc_log(card->ctx, |
547 | 0 | "FILE: %02X%02X%02X%02X\n", |
548 | 0 | oid[0],oid[1],oid[2],oid[3]); |
549 | 0 | if(0 == memcmp(fs->currentPath, oid, 2)) { |
550 | 0 | buf[0] = oid[2]; |
551 | 0 | buf[1] = oid[3]; |
552 | 0 | if(buf[0] == 0x00 && buf[1] == 0x00) continue; /* No directories/null names outside of root */ |
553 | 0 | buf += 2; |
554 | 0 | count += 2; |
555 | 0 | bufLen -= 2; |
556 | 0 | } |
557 | 0 | } |
558 | 0 | return count; |
559 | 0 | } |
560 | | |
561 | | static int muscle_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *cmd) |
562 | 13 | { |
563 | 13 | muscle_private_t* priv = MUSCLE_DATA(card); |
564 | 13 | const int bufferLength = MSC_MAX_PIN_COMMAND_LENGTH; |
565 | 13 | u8 buffer[MSC_MAX_PIN_COMMAND_LENGTH]; |
566 | | |
567 | 13 | if (!priv || !cmd) |
568 | 0 | return SC_ERROR_INVALID_ARGUMENTS; |
569 | | |
570 | 13 | switch(cmd->cmd) { |
571 | 1 | case SC_PIN_CMD_VERIFY: |
572 | 1 | switch(cmd->pin_type) { |
573 | 0 | case SC_AC_CHV: { |
574 | 0 | sc_apdu_t apdu; |
575 | 0 | int r; |
576 | 0 | r = msc_verify_pin_apdu(card, &apdu, buffer, bufferLength, cmd->pin_reference, cmd->pin1.data, cmd->pin1.len); |
577 | 0 | if (r < 0) |
578 | 0 | return r; |
579 | 0 | cmd->apdu = &apdu; |
580 | 0 | cmd->pin1.offset = 5; |
581 | 0 | r = iso_ops->pin_cmd(card, cmd); |
582 | 0 | if (r >= 0 && cmd->pin_reference < 16) |
583 | 0 | priv->verifiedPins |= (1 << cmd->pin_reference); |
584 | 0 | return r; |
585 | 0 | } |
586 | 0 | case SC_AC_TERM: |
587 | 0 | case SC_AC_PRO: |
588 | 0 | case SC_AC_AUT: |
589 | 0 | case SC_AC_NONE: |
590 | 1 | default: |
591 | 1 | sc_log(card->ctx, "Unsupported authentication method\n"); |
592 | 1 | return SC_ERROR_NOT_SUPPORTED; |
593 | 1 | } |
594 | 0 | case SC_PIN_CMD_CHANGE: |
595 | 0 | switch(cmd->pin_type) { |
596 | 0 | case SC_AC_CHV: { |
597 | 0 | sc_apdu_t apdu; |
598 | 0 | int r; |
599 | 0 | r = msc_change_pin_apdu(card, &apdu, buffer, bufferLength, cmd->pin_reference, cmd->pin1.data, cmd->pin1.len, cmd->pin2.data, cmd->pin2.len); |
600 | 0 | if (r < 0) |
601 | 0 | return r; |
602 | 0 | cmd->apdu = &apdu; |
603 | 0 | return iso_ops->pin_cmd(card, cmd); |
604 | 0 | } |
605 | 0 | case SC_AC_TERM: |
606 | 0 | case SC_AC_PRO: |
607 | 0 | case SC_AC_AUT: |
608 | 0 | case SC_AC_NONE: |
609 | 0 | default: |
610 | 0 | sc_log(card->ctx, "Unsupported authentication method\n"); |
611 | 0 | return SC_ERROR_NOT_SUPPORTED; |
612 | 0 | } |
613 | 0 | case SC_PIN_CMD_UNBLOCK: |
614 | 0 | switch(cmd->pin_type) { |
615 | 0 | case SC_AC_CHV: { |
616 | 0 | sc_apdu_t apdu; |
617 | 0 | int r; |
618 | 0 | r = msc_unblock_pin_apdu(card, &apdu, buffer, bufferLength, cmd->pin_reference, cmd->pin1.data, cmd->pin1.len); |
619 | 0 | if (r < 0) |
620 | 0 | return r; |
621 | 0 | cmd->apdu = &apdu; |
622 | 0 | return iso_ops->pin_cmd(card, cmd); |
623 | 0 | } |
624 | 0 | case SC_AC_TERM: |
625 | 0 | case SC_AC_PRO: |
626 | 0 | case SC_AC_AUT: |
627 | 0 | case SC_AC_NONE: |
628 | 0 | default: |
629 | 0 | sc_log(card->ctx, "Unsupported authentication method\n"); |
630 | 0 | return SC_ERROR_NOT_SUPPORTED; |
631 | 0 | } |
632 | 12 | default: |
633 | 12 | sc_log(card->ctx, "Unsupported command\n"); |
634 | 12 | return SC_ERROR_NOT_SUPPORTED; |
635 | | |
636 | 13 | } |
637 | | |
638 | 13 | } |
639 | | |
640 | | static int muscle_card_extract_key(sc_card_t *card, sc_cardctl_muscle_key_info_t *info) |
641 | 42 | { |
642 | | /* CURRENTLY DONT SUPPORT EXTRACTING PRIVATE KEYS... */ |
643 | 42 | switch(info->keyType) { |
644 | 42 | case 1: /* RSA */ |
645 | 42 | return msc_extract_rsa_public_key(card, |
646 | 42 | info->keyLocation, |
647 | 42 | &info->modLength, |
648 | 42 | &info->modValue, |
649 | 42 | &info->expLength, |
650 | 42 | &info->expValue); |
651 | 0 | default: |
652 | 0 | return SC_ERROR_NOT_SUPPORTED; |
653 | 42 | } |
654 | 42 | } |
655 | | |
656 | | static int muscle_card_import_key(sc_card_t *card, sc_cardctl_muscle_key_info_t *info) |
657 | 0 | { |
658 | | /* CURRENTLY DONT SUPPORT EXTRACTING PRIVATE KEYS... */ |
659 | 0 | switch(info->keyType) { |
660 | 0 | case 0x02: /* RSA_PRIVATE */ |
661 | 0 | case 0x03: /* RSA_PRIVATE_CRT */ |
662 | 0 | return msc_import_key(card, |
663 | 0 | info->keyLocation, |
664 | 0 | info); |
665 | 0 | default: |
666 | 0 | return SC_ERROR_NOT_SUPPORTED; |
667 | 0 | } |
668 | 0 | } |
669 | | |
670 | | static int muscle_card_generate_key(sc_card_t *card, sc_cardctl_muscle_gen_key_info_t *info) |
671 | 192 | { |
672 | 192 | return msc_generate_keypair(card, |
673 | 192 | info->privateKeyLocation, |
674 | 192 | info->publicKeyLocation, |
675 | 192 | info->keyType, |
676 | 192 | info->keySize, |
677 | 192 | 0); |
678 | 192 | } |
679 | | |
680 | | static int muscle_card_verified_pins(sc_card_t *card, sc_cardctl_muscle_verified_pins_info_t *info) |
681 | 0 | { |
682 | 0 | muscle_private_t* priv = MUSCLE_DATA(card); |
683 | 0 | info->verifiedPins = priv->verifiedPins; |
684 | 0 | return 0; |
685 | 0 | } |
686 | | static int muscle_card_ctl(sc_card_t *card, unsigned long request, void *data) |
687 | 4.36k | { |
688 | 4.36k | switch(request) { |
689 | 192 | case SC_CARDCTL_MUSCLE_GENERATE_KEY: |
690 | 192 | return muscle_card_generate_key(card, (sc_cardctl_muscle_gen_key_info_t*) data); |
691 | 42 | case SC_CARDCTL_MUSCLE_EXTRACT_KEY: |
692 | 42 | return muscle_card_extract_key(card, (sc_cardctl_muscle_key_info_t*) data); |
693 | 0 | case SC_CARDCTL_MUSCLE_IMPORT_KEY: |
694 | 0 | return muscle_card_import_key(card, (sc_cardctl_muscle_key_info_t*) data); |
695 | 0 | case SC_CARDCTL_MUSCLE_VERIFIED_PINS: |
696 | 0 | return muscle_card_verified_pins(card, (sc_cardctl_muscle_verified_pins_info_t*) data); |
697 | 4.13k | default: |
698 | 4.13k | return SC_ERROR_NOT_SUPPORTED; /* Unsupported.. whatever it is */ |
699 | 4.36k | } |
700 | 4.36k | } |
701 | | |
702 | | static int muscle_set_security_env(sc_card_t *card, |
703 | | const sc_security_env_t *env, |
704 | | int se_num) |
705 | 0 | { |
706 | 0 | muscle_private_t* priv = MUSCLE_DATA(card); |
707 | |
|
708 | 0 | if (!priv || !env) |
709 | 0 | return SC_ERROR_INVALID_ARGUMENTS; |
710 | | |
711 | 0 | if (env->operation != SC_SEC_OPERATION_SIGN && |
712 | 0 | env->operation != SC_SEC_OPERATION_DECIPHER) { |
713 | 0 | sc_log(card->ctx, "Invalid crypto operation supplied.\n"); |
714 | 0 | return SC_ERROR_NOT_SUPPORTED; |
715 | 0 | } |
716 | 0 | if (env->algorithm != SC_ALGORITHM_RSA) { |
717 | 0 | sc_log(card->ctx, "Invalid crypto algorithm supplied.\n"); |
718 | 0 | return SC_ERROR_NOT_SUPPORTED; |
719 | 0 | } |
720 | | /* ADJUST FOR PKCS1 padding support for decryption only */ |
721 | 0 | if ((env->algorithm_flags & SC_ALGORITHM_RSA_PADS) || |
722 | 0 | (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES)) { |
723 | 0 | sc_log(card->ctx, "Card supports only raw RSA.\n"); |
724 | 0 | return SC_ERROR_NOT_SUPPORTED; |
725 | 0 | } |
726 | 0 | if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) { |
727 | 0 | if (env->key_ref_len != 1 || |
728 | 0 | (env->key_ref[0] > 0x0F)) { |
729 | 0 | sc_log(card->ctx, "Invalid key reference supplied.\n"); |
730 | 0 | return SC_ERROR_NOT_SUPPORTED; |
731 | 0 | } |
732 | 0 | priv->rsa_key_ref = env->key_ref[0]; |
733 | 0 | } |
734 | 0 | if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) { |
735 | 0 | sc_log(card->ctx, "Algorithm reference not supported.\n"); |
736 | 0 | return SC_ERROR_NOT_SUPPORTED; |
737 | 0 | } |
738 | | /* if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) |
739 | | if (memcmp(env->file_ref.value, "\x00\x12", 2) != 0) { |
740 | | sc_log(card->ctx, "File reference is not 0012.\n"); |
741 | | return SC_ERROR_NOT_SUPPORTED; |
742 | | } */ |
743 | 0 | priv->env = *env; |
744 | 0 | return 0; |
745 | 0 | } |
746 | | |
747 | | static int muscle_restore_security_env(sc_card_t *card, int se_num) |
748 | 0 | { |
749 | 0 | muscle_private_t* priv = MUSCLE_DATA(card); |
750 | 0 | memset(&priv->env, 0, sizeof(priv->env)); |
751 | 0 | return 0; |
752 | 0 | } |
753 | | |
754 | | |
755 | | static int muscle_decipher(sc_card_t * card, |
756 | | const u8 * crgram, size_t crgram_len, u8 * out, |
757 | | size_t out_len) |
758 | 0 | { |
759 | 0 | muscle_private_t* priv = MUSCLE_DATA(card); |
760 | |
|
761 | 0 | u8 key_id; |
762 | 0 | int r; |
763 | |
|
764 | 0 | if (!priv || !crgram || !out) |
765 | 0 | return SC_ERROR_INVALID_ARGUMENTS; |
766 | | |
767 | | /* sanity check */ |
768 | 0 | if (priv->env.operation != SC_SEC_OPERATION_DECIPHER) |
769 | 0 | return SC_ERROR_INVALID_ARGUMENTS; |
770 | | |
771 | 0 | key_id = priv->rsa_key_ref * 2; /* Private key */ |
772 | |
|
773 | 0 | if (out_len < crgram_len) { |
774 | 0 | sc_log(card->ctx, "Output buffer too small"); |
775 | 0 | return SC_ERROR_BUFFER_TOO_SMALL; |
776 | 0 | } |
777 | | |
778 | 0 | r = msc_compute_crypt(card, |
779 | 0 | key_id, |
780 | 0 | 0x00, /* RSA NO PADDING */ |
781 | 0 | 0x04, /* decrypt */ |
782 | 0 | crgram, |
783 | 0 | out, |
784 | 0 | crgram_len, |
785 | 0 | out_len); |
786 | 0 | LOG_TEST_RET(card->ctx, r, "Card signature failed"); |
787 | 0 | return r; |
788 | 0 | } |
789 | | |
790 | | static int muscle_compute_signature(sc_card_t *card, const u8 *data, |
791 | | size_t data_len, u8 * out, size_t outlen) |
792 | 0 | { |
793 | 0 | muscle_private_t* priv = MUSCLE_DATA(card); |
794 | 0 | u8 key_id; |
795 | 0 | int r; |
796 | |
|
797 | 0 | if (!priv || !data || !out) |
798 | 0 | return SC_ERROR_INVALID_ARGUMENTS; |
799 | | |
800 | 0 | key_id = priv->rsa_key_ref * 2; /* Private key */ |
801 | |
|
802 | 0 | if (outlen < data_len) { |
803 | 0 | sc_log(card->ctx, "Output buffer too small"); |
804 | 0 | return SC_ERROR_BUFFER_TOO_SMALL; |
805 | 0 | } |
806 | | |
807 | 0 | r = msc_compute_crypt(card, |
808 | 0 | key_id, |
809 | 0 | 0x00, /* RSA NO PADDING */ |
810 | 0 | 0x04, /* -- decrypt raw... will do what we need since signing isn't yet supported */ |
811 | 0 | data, |
812 | 0 | out, |
813 | 0 | data_len, |
814 | 0 | outlen); |
815 | 0 | LOG_TEST_RET(card->ctx, r, "Card signature failed"); |
816 | 0 | return r; |
817 | 0 | } |
818 | | |
819 | | static int muscle_get_challenge(sc_card_t *card, u8 *rnd, size_t len) |
820 | 0 | { |
821 | 0 | if (len == 0) |
822 | 0 | return SC_SUCCESS; |
823 | 0 | else { |
824 | 0 | LOG_TEST_RET(card->ctx, |
825 | 0 | msc_get_challenge(card, len, 0, NULL, rnd), |
826 | 0 | "GET CHALLENGE cmd failed"); |
827 | 0 | return (int) len; |
828 | 0 | } |
829 | 0 | } |
830 | | |
831 | 182k | static int muscle_check_sw(sc_card_t * card, unsigned int sw1, unsigned int sw2) { |
832 | 182k | if(sw1 == 0x9C) { |
833 | 150 | switch(sw2) { |
834 | 14 | case 0x01: /* SW_NO_MEMORY_LEFT */ |
835 | 14 | return SC_ERROR_NOT_ENOUGH_MEMORY; |
836 | 13 | case 0x02: /* SW_AUTH_FAILED */ |
837 | 13 | return SC_ERROR_PIN_CODE_INCORRECT; |
838 | 12 | case 0x03: /* SW_OPERATION_NOT_ALLOWED */ |
839 | 12 | return SC_ERROR_NOT_ALLOWED; |
840 | 10 | case 0x05: /* SW_UNSUPPORTED_FEATURE */ |
841 | 10 | return SC_ERROR_NO_CARD_SUPPORT; |
842 | 10 | case 0x06: /* SW_UNAUTHORIZED */ |
843 | 10 | return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED; |
844 | 15 | case 0x07: /* SW_OBJECT_NOT_FOUND */ |
845 | 15 | return SC_ERROR_FILE_NOT_FOUND; |
846 | 3 | case 0x08: /* SW_OBJECT_EXISTS */ |
847 | 3 | return SC_ERROR_FILE_ALREADY_EXISTS; |
848 | 11 | case 0x09: /* SW_INCORRECT_ALG */ |
849 | 11 | return SC_ERROR_INCORRECT_PARAMETERS; |
850 | 12 | case 0x0B: /* SW_SIGNATURE_INVALID */ |
851 | 12 | return SC_ERROR_CARD_CMD_FAILED; |
852 | 4 | case 0x0C: /* SW_IDENTITY_BLOCKED */ |
853 | 4 | return SC_ERROR_AUTH_METHOD_BLOCKED; |
854 | 2 | case 0x0F: /* SW_INVALID_PARAMETER */ |
855 | 14 | case 0x10: /* SW_INCORRECT_P1 */ |
856 | 26 | case 0x11: /* SW_INCORRECT_P2 */ |
857 | 26 | return SC_ERROR_INCORRECT_PARAMETERS; |
858 | 150 | } |
859 | 150 | } |
860 | 182k | return iso_ops->check_sw(card, sw1, sw2); |
861 | 182k | } |
862 | | |
863 | | static int muscle_card_reader_lock_obtained(sc_card_t *card, int was_reset) |
864 | 286k | { |
865 | 286k | int r = SC_SUCCESS; |
866 | | |
867 | 286k | SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); |
868 | | |
869 | 286k | if (was_reset > 0) { |
870 | 0 | if (msc_select_applet(card, muscleAppletId, sizeof muscleAppletId) != 1) { |
871 | 0 | r = SC_ERROR_INVALID_CARD; |
872 | 0 | } |
873 | 0 | } |
874 | | |
875 | 286k | LOG_FUNC_RETURN(card->ctx, r); |
876 | 286k | } |
877 | | |
878 | | static int muscle_logout(sc_card_t *card) |
879 | 0 | { |
880 | 0 | int r = SC_ERROR_NOT_SUPPORTED; |
881 | |
|
882 | 0 | SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); |
883 | |
|
884 | 0 | if (msc_select_applet(card, muscleAppletId, sizeof muscleAppletId) == 1) { |
885 | 0 | r = SC_SUCCESS; |
886 | 0 | } |
887 | |
|
888 | 0 | LOG_FUNC_RETURN(card->ctx, r); |
889 | 0 | } |
890 | | |
891 | | |
892 | | static struct sc_card_driver * sc_get_driver(void) |
893 | 17.5k | { |
894 | 17.5k | struct sc_card_driver *iso_drv = sc_get_iso7816_driver(); |
895 | 17.5k | if (iso_ops == NULL) |
896 | 1 | iso_ops = iso_drv->ops; |
897 | | |
898 | 17.5k | muscle_ops = *iso_drv->ops; |
899 | 17.5k | muscle_ops.check_sw = muscle_check_sw; |
900 | 17.5k | muscle_ops.pin_cmd = muscle_pin_cmd; |
901 | 17.5k | muscle_ops.match_card = muscle_match_card; |
902 | 17.5k | muscle_ops.init = muscle_init; |
903 | 17.5k | muscle_ops.finish = muscle_finish; |
904 | | |
905 | 17.5k | muscle_ops.get_challenge = muscle_get_challenge; |
906 | | |
907 | 17.5k | muscle_ops.set_security_env = muscle_set_security_env; |
908 | 17.5k | muscle_ops.restore_security_env = muscle_restore_security_env; |
909 | 17.5k | muscle_ops.compute_signature = muscle_compute_signature; |
910 | 17.5k | muscle_ops.decipher = muscle_decipher; |
911 | 17.5k | muscle_ops.card_ctl = muscle_card_ctl; |
912 | 17.5k | muscle_ops.read_binary = muscle_read_binary; |
913 | 17.5k | muscle_ops.update_binary = muscle_update_binary; |
914 | 17.5k | muscle_ops.create_file = muscle_create_file; |
915 | 17.5k | muscle_ops.select_file = muscle_select_file; |
916 | 17.5k | muscle_ops.delete_file = muscle_delete_file; |
917 | 17.5k | muscle_ops.list_files = muscle_list_files; |
918 | 17.5k | muscle_ops.card_reader_lock_obtained = muscle_card_reader_lock_obtained; |
919 | 17.5k | muscle_ops.logout = muscle_logout; |
920 | | |
921 | 17.5k | return &muscle_drv; |
922 | 17.5k | } |
923 | | |
924 | | struct sc_card_driver * sc_get_muscle_driver(void) |
925 | 17.5k | { |
926 | 17.5k | return sc_get_driver(); |
927 | 17.5k | } |