2008-08-20 05:41:20 +00:00
|
|
|
/*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
/* Initially written by Weitao Sun (weitao@ftsafe.com) 2008*/
|
|
|
|
|
2015-04-22 21:55:33 +00:00
|
|
|
#if HAVE_CONFIG_H
|
2010-03-04 08:14:36 +00:00
|
|
|
#include "config.h"
|
2015-04-22 21:55:33 +00:00
|
|
|
#endif
|
2008-08-20 05:41:20 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-03-04 08:14:36 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "pkcs15.h"
|
|
|
|
#include "cardctl.h"
|
2008-08-20 05:41:20 +00:00
|
|
|
|
|
|
|
#define MANU_ID "entersafe"
|
|
|
|
|
|
|
|
static int entersafe_detect_card( sc_pkcs15_card_t *p15card)
|
|
|
|
{
|
|
|
|
sc_card_t *card = p15card->card;
|
|
|
|
|
2010-03-15 12:17:13 +00:00
|
|
|
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
2008-08-20 05:41:20 +00:00
|
|
|
|
|
|
|
/* check if we have the correct card OS */
|
|
|
|
if (strcmp(card->name, "entersafe"))
|
|
|
|
return SC_ERROR_WRONG_CARD;
|
|
|
|
|
|
|
|
return SC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sc_pkcs15emu_entersafe_init( sc_pkcs15_card_t *p15card)
|
|
|
|
{
|
2009-10-06 07:36:51 +00:00
|
|
|
int r;
|
2008-08-20 05:41:20 +00:00
|
|
|
char buf[256];
|
|
|
|
sc_card_t *card = p15card->card;
|
|
|
|
sc_serial_number_t serial;
|
|
|
|
|
2010-03-15 12:17:13 +00:00
|
|
|
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
2008-08-20 05:41:20 +00:00
|
|
|
|
|
|
|
/* get serial number */
|
|
|
|
r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
|
2017-10-31 09:12:12 +00:00
|
|
|
if (r != SC_SUCCESS)
|
|
|
|
return SC_ERROR_INTERNAL;
|
2008-08-20 05:41:20 +00:00
|
|
|
r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
|
|
|
|
if (r != SC_SUCCESS)
|
|
|
|
return SC_ERROR_INTERNAL;
|
2020-06-10 10:35:19 +00:00
|
|
|
free(p15card->tokeninfo->serial_number);
|
2019-05-28 15:46:44 +00:00
|
|
|
p15card->tokeninfo->serial_number = strdup(buf);
|
2010-10-05 15:44:58 +00:00
|
|
|
if (!p15card->tokeninfo->serial_number)
|
2008-08-20 05:41:20 +00:00
|
|
|
return SC_ERROR_INTERNAL;
|
|
|
|
|
|
|
|
/* the manufacturer ID, in this case Giesecke & Devrient GmbH */
|
2020-06-10 10:35:19 +00:00
|
|
|
free(p15card->tokeninfo->manufacturer_id);
|
2019-05-28 15:46:44 +00:00
|
|
|
p15card->tokeninfo->manufacturer_id = strdup(MANU_ID);
|
2010-10-05 15:44:58 +00:00
|
|
|
if (!p15card->tokeninfo->manufacturer_id)
|
2008-08-20 05:41:20 +00:00
|
|
|
return SC_ERROR_INTERNAL;
|
|
|
|
|
|
|
|
return SC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *p15card,
|
2019-03-26 14:14:25 +00:00
|
|
|
struct sc_aid *aid)
|
2008-08-20 05:41:20 +00:00
|
|
|
{
|
2010-03-15 12:17:13 +00:00
|
|
|
SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
|
2008-08-20 05:41:20 +00:00
|
|
|
|
2019-03-26 14:14:25 +00:00
|
|
|
if (entersafe_detect_card(p15card))
|
|
|
|
return SC_ERROR_WRONG_CARD;
|
|
|
|
return sc_pkcs15emu_entersafe_init(p15card);
|
2008-08-20 05:41:20 +00:00
|
|
|
}
|