root/trunk/src/libopensc/pkcs15-esinit.c

Revision 3556, 2.5 KB (checked in by aj, 4 months ago)

Add new entersafe driver for ePass 3000 tokens.

Line 
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15 */
16/* Initially written by Weitao Sun (weitao@ftsafe.com) 2008*/
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
29static 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        /* check if we have the correct card OS */
36        if (strcmp(card->name, "entersafe"))
37                return SC_ERROR_WRONG_CARD;
38
39    return SC_SUCCESS;
40}
41
42static 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        /* get serial number */
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        /* the manufacturer ID, in this case Giesecke & Devrient GmbH */
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
76int 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}
Note: See TracBrowser for help on using the browser.