[pkg-opensc-commit] [opensc] 09/50: pkcs15: 'aid' argument for emulator init
Eric Dorland
eric at moszumanska.debian.org
Sat May 28 03:35:46 UTC 2016
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository opensc.
commit 9ac41205945f2a47e5b7e16c14a16ddcf4159e0e
Author: Viktor Tarasov <viktor.tarasov at gmail.com>
Date: Tue Apr 5 19:44:37 2016 +0200
pkcs15: 'aid' argument for emulator init
Allows to PKCS#15 emulator to bind more then one application
---
src/libopensc/Makefile.am | 4 +-
src/libopensc/Makefile.mak | 2 +-
src/libopensc/pkcs15-actalis.c | 5 +-
src/libopensc/pkcs15-atrust-acos.c | 3 +-
src/libopensc/pkcs15-dnie.c | 1 +
src/libopensc/pkcs15-esinit.c | 3 +-
src/libopensc/pkcs15-esteid.c | 3 +-
src/libopensc/pkcs15-gemsafeGPK.c | 4 +-
src/libopensc/pkcs15-gemsafeV1.c | 3 +-
src/libopensc/pkcs15-gids.c | 2 +
src/libopensc/pkcs15-iasecc.c | 78 +++++++
src/libopensc/pkcs15-infocamere.c | 3 +-
src/libopensc/pkcs15-itacns.c | 7 +-
src/libopensc/pkcs15-oberthur.c | 454 ++++++++++++++++++-------------------
src/libopensc/pkcs15-openpgp.c | 4 +-
src/libopensc/pkcs15-piv.c | 6 +-
src/libopensc/pkcs15-postecert.c | 3 +-
src/libopensc/pkcs15-pteid.c | 4 +-
src/libopensc/pkcs15-sc-hsm.c | 1 +
src/libopensc/pkcs15-starcert.c | 3 +-
src/libopensc/pkcs15-syn.c | 110 +++------
src/libopensc/pkcs15-syn.h | 63 +++++
src/libopensc/pkcs15-tccardos.c | 2 +
src/libopensc/pkcs15-tcos.c | 2 +
src/libopensc/pkcs15-westcos.c | 3 +-
src/libopensc/pkcs15.c | 19 +-
src/libopensc/pkcs15.h | 2 +-
27 files changed, 452 insertions(+), 342 deletions(-)
diff --git a/src/libopensc/Makefile.am b/src/libopensc/Makefile.am
index 48c2626..9d0ad08 100644
--- a/src/libopensc/Makefile.am
+++ b/src/libopensc/Makefile.am
@@ -6,7 +6,7 @@ EXTRA_DIST = Makefile.mak
lib_LTLIBRARIES = libopensc.la
noinst_HEADERS = cards.h ctbcs.h internal.h esteid.h muscle.h muscle-filesystem.h \
- internal-winscard.h p15card-helper.h \
+ internal-winscard.h p15card-helper.h pkcs15-syn.h \
opensc.h pkcs15.h \
cardctl.h asn1.h log.h \
errors.h types.h compression.h itacns.h iso7816.h \
@@ -48,7 +48,7 @@ libopensc_la_SOURCES = \
pkcs15-actalis.c pkcs15-atrust-acos.c pkcs15-tccardos.c pkcs15-piv.c \
pkcs15-esinit.c pkcs15-westcos.c pkcs15-pteid.c pkcs15-oberthur.c \
pkcs15-itacns.c pkcs15-gemsafeV1.c pkcs15-sc-hsm.c \
- pkcs15-dnie.c pkcs15-gids.c \
+ pkcs15-dnie.c pkcs15-gids.c pkcs15-iasecc.c \
compression.c p15card-helper.c sm.c \
aux-data.c \
libopensc.exports
diff --git a/src/libopensc/Makefile.mak b/src/libopensc/Makefile.mak
index 845ca39..a3ad40e 100644
--- a/src/libopensc/Makefile.mak
+++ b/src/libopensc/Makefile.mak
@@ -31,7 +31,7 @@ OBJECTS = \
pkcs15-actalis.obj pkcs15-atrust-acos.obj pkcs15-tccardos.obj pkcs15-piv.obj \
pkcs15-esinit.obj pkcs15-westcos.obj pkcs15-pteid.obj pkcs15-oberthur.obj \
pkcs15-itacns.obj pkcs15-gemsafeV1.obj pkcs15-sc-hsm.obj \
- pkcs15-dnie.obj pkcs15-gids.obj \
+ pkcs15-dnie.obj pkcs15-gids.obj pkcs15-iasecc.obj \
compression.obj p15card-helper.obj sm.obj \
aux-data.obj \
$(TOPDIR)\win32\versioninfo.res
diff --git a/src/libopensc/pkcs15-actalis.c b/src/libopensc/pkcs15-actalis.c
index 9391418..bbe53a0 100644
--- a/src/libopensc/pkcs15-actalis.c
+++ b/src/libopensc/pkcs15-actalis.c
@@ -37,7 +37,7 @@
#include "libopensc/pkcs15.h"
#include "libopensc/log.h"
-int sc_pkcs15emu_actalis_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_actalis_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static int (*set_security_env) (sc_card_t *, const sc_security_env_t *, int);
@@ -306,7 +306,8 @@ static int actalis_detect_card(sc_pkcs15_card_t * p15card)
}
int sc_pkcs15emu_actalis_init_ex(sc_pkcs15_card_t * p15card,
- sc_pkcs15emu_opt_t * opts)
+ struct sc_aid *aid,
+ sc_pkcs15emu_opt_t * opts)
{
if (opts && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)
return sc_pkcs15emu_actalis_init(p15card);
diff --git a/src/libopensc/pkcs15-atrust-acos.c b/src/libopensc/pkcs15-atrust-acos.c
index 69bdb50..f3b44b8 100644
--- a/src/libopensc/pkcs15-atrust-acos.c
+++ b/src/libopensc/pkcs15-atrust-acos.c
@@ -34,7 +34,7 @@
#define MANU_ID "A-Trust"
#define CARD_LABEL "a.sign Premium a"
-int sc_pkcs15emu_atrust_acos_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_atrust_acos_init_ex(sc_pkcs15_card_t *, struct sc_aid *aid, sc_pkcs15emu_opt_t *);
typedef struct cdata_st {
const char *label;
@@ -265,6 +265,7 @@ static int sc_pkcs15emu_atrust_acos_init(sc_pkcs15_card_t *p15card)
}
int sc_pkcs15emu_atrust_acos_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
diff --git a/src/libopensc/pkcs15-dnie.c b/src/libopensc/pkcs15-dnie.c
index d521f99..edccdf8 100644
--- a/src/libopensc/pkcs15-dnie.c
+++ b/src/libopensc/pkcs15-dnie.c
@@ -261,6 +261,7 @@ static int sc_pkcs15emu_dnie_init(sc_pkcs15_card_t * p15card)
/* public functions for in-built module */
/****************************************/
int sc_pkcs15emu_dnie_init_ex(sc_pkcs15_card_t * p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t * opts)
{
int r=SC_SUCCESS;
diff --git a/src/libopensc/pkcs15-esinit.c b/src/libopensc/pkcs15-esinit.c
index cabdb47..e474946 100644
--- a/src/libopensc/pkcs15-esinit.c
+++ b/src/libopensc/pkcs15-esinit.c
@@ -29,7 +29,7 @@
#define MANU_ID "entersafe"
-int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static int entersafe_detect_card( sc_pkcs15_card_t *p15card)
{
@@ -77,6 +77,7 @@ static int sc_pkcs15emu_entersafe_init( sc_pkcs15_card_t *p15card)
}
int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
diff --git a/src/libopensc/pkcs15-esteid.c b/src/libopensc/pkcs15-esteid.c
index 3b4062f..7bbba7e 100644
--- a/src/libopensc/pkcs15-esteid.c
+++ b/src/libopensc/pkcs15-esteid.c
@@ -39,7 +39,7 @@
#include "pkcs15.h"
#include "esteid.h"
-int sc_pkcs15emu_esteid_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_esteid_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static void
set_string (char **strp, const char *value)
@@ -269,6 +269,7 @@ static int esteid_detect_card(sc_pkcs15_card_t *p15card)
}
int sc_pkcs15emu_esteid_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
diff --git a/src/libopensc/pkcs15-gemsafeGPK.c b/src/libopensc/pkcs15-gemsafeGPK.c
index 006c488..abf92df 100644
--- a/src/libopensc/pkcs15-gemsafeGPK.c
+++ b/src/libopensc/pkcs15-gemsafeGPK.c
@@ -35,7 +35,7 @@
#define MANU_ID "GemSAFE on GPK16000"
-int sc_pkcs15emu_gemsafeGPK_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_gemsafeGPK_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static int (*pin_cmd_save)(struct sc_card *, struct sc_pin_cmd_data *,
int *tries_left);
@@ -506,7 +506,7 @@ static int sc_pkcs15emu_gemsafeGPK_init(sc_pkcs15_card_t *p15card)
return SC_SUCCESS;
}
-int sc_pkcs15emu_gemsafeGPK_init_ex(sc_pkcs15_card_t *p15card,
+int sc_pkcs15emu_gemsafeGPK_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
sc_card_t *card = p15card->card;
diff --git a/src/libopensc/pkcs15-gemsafeV1.c b/src/libopensc/pkcs15-gemsafeV1.c
index 43858f1..ac7dab7 100644
--- a/src/libopensc/pkcs15-gemsafeV1.c
+++ b/src/libopensc/pkcs15-gemsafeV1.c
@@ -40,7 +40,7 @@
#define GEMSAFE_READ_QUANTUM 248
#define GEMSAFE_MAX_OBJLEN 28672
-int sc_pkcs15emu_gemsafeV1_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_gemsafeV1_init_ex(sc_pkcs15_card_t *, struct sc_aid *,sc_pkcs15emu_opt_t *);
static int
sc_pkcs15emu_add_cert(sc_pkcs15_card_t *p15card,
@@ -434,6 +434,7 @@ static int sc_pkcs15emu_gemsafeV1_init( sc_pkcs15_card_t *p15card)
}
int sc_pkcs15emu_gemsafeV1_init_ex( sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
if (opts && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)
diff --git a/src/libopensc/pkcs15-gids.c b/src/libopensc/pkcs15-gids.c
index ef6fea2..f0eed06 100644
--- a/src/libopensc/pkcs15-gids.c
+++ b/src/libopensc/pkcs15-gids.c
@@ -221,6 +221,7 @@ static int sc_pkcs15emu_gids_init (sc_pkcs15_card_t * p15card)
}
int sc_pkcs15emu_gids_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
if (opts && (opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)) {
@@ -236,6 +237,7 @@ int sc_pkcs15emu_gids_init_ex(sc_pkcs15_card_t *p15card,
#else
int sc_pkcs15emu_gids_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
return SC_ERROR_WRONG_CARD;
diff --git a/src/libopensc/pkcs15-iasecc.c b/src/libopensc/pkcs15-iasecc.c
new file mode 100644
index 0000000..8e8cd3c
--- /dev/null
+++ b/src/libopensc/pkcs15-iasecc.c
@@ -0,0 +1,78 @@
+/*
+ * PKCS15 emulation layer for IAS/ECC card.
+ *
+ * Copyright (C) 2016, Viktor Tarasov <viktor.tarasov at gmail.com>
+ * Copyright (C) 2004, Bud P. Bruegger <bud at comune.grosseto.it>
+ * Copyright (C) 2004, Antonino Iacono <ant_iacono at tin.it>
+ * Copyright (C) 2003, Olaf Kirch <okir at suse.de>
+ *
+ * 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
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#ifdef ENABLE_OPENSSL
+#include <openssl/x509v3.h>
+#endif
+
+#include "internal.h"
+#include "pkcs15.h"
+
+int sc_pkcs15emu_iasecc_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+
+
+static int
+sc_pkcs15emu_iasecc_init (struct sc_pkcs15_card *p15card, struct sc_aid *aid)
+{
+ struct sc_context *ctx = p15card->card->ctx;
+ int rv;
+
+ LOG_FUNC_CALLED(ctx);
+
+ rv = sc_pkcs15_bind_internal(p15card, aid);
+
+ LOG_FUNC_RETURN(ctx, rv);
+}
+
+
+static int
+iasecc_detect_card(sc_pkcs15_card_t *p15card)
+{
+ if (p15card->card->type < SC_CARD_TYPE_IASECC_BASE)
+ return SC_ERROR_WRONG_CARD;
+
+ if (p15card->card->type > SC_CARD_TYPE_IASECC_BASE + 10)
+ return SC_ERROR_WRONG_CARD;
+
+ return SC_SUCCESS;
+}
+
+
+int
+sc_pkcs15emu_iasecc_init_ex(struct sc_pkcs15_card *p15card, struct sc_aid *aid, struct sc_pkcs15emu_opt *opts)
+{
+ if (opts && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)
+ return sc_pkcs15emu_iasecc_init(p15card, aid);
+
+ if (iasecc_detect_card(p15card))
+ return SC_ERROR_WRONG_CARD;
+
+ return sc_pkcs15emu_iasecc_init(p15card, aid);
+}
diff --git a/src/libopensc/pkcs15-infocamere.c b/src/libopensc/pkcs15-infocamere.c
index c89fc65..6326b98 100644
--- a/src/libopensc/pkcs15-infocamere.c
+++ b/src/libopensc/pkcs15-infocamere.c
@@ -36,7 +36,7 @@
#include "pkcs15.h"
#include "log.h"
-int sc_pkcs15emu_infocamere_init_ex(sc_pkcs15_card_t *,
+int sc_pkcs15emu_infocamere_init_ex(sc_pkcs15_card_t *, struct sc_aid *aid,
sc_pkcs15emu_opt_t *);
static int (*set_security_env) (sc_card_t *, const sc_security_env_t *,
@@ -822,6 +822,7 @@ static int infocamere_detect_card(sc_pkcs15_card_t * p15card)
}
int sc_pkcs15emu_infocamere_init_ex(sc_pkcs15_card_t * p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t * opts)
{
diff --git a/src/libopensc/pkcs15-itacns.c b/src/libopensc/pkcs15-itacns.c
index 02107cd..cdb1086 100644
--- a/src/libopensc/pkcs15-itacns.c
+++ b/src/libopensc/pkcs15-itacns.c
@@ -44,8 +44,7 @@
#include <openssl/x509v3.h>
#endif
-int sc_pkcs15emu_itacns_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_itacns_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static const char path_serial[] = "10001003";
@@ -847,8 +846,8 @@ static int itacns_init(sc_pkcs15_card_t *p15card)
return r;
}
-int sc_pkcs15emu_itacns_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts)
+int sc_pkcs15emu_itacns_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid,
+ sc_pkcs15emu_opt_t *opts)
{
sc_card_t *card = p15card->card;
SC_FUNC_CALLED(card->ctx, 1);
diff --git a/src/libopensc/pkcs15-oberthur.c b/src/libopensc/pkcs15-oberthur.c
index db84993..49df9f4 100644
--- a/src/libopensc/pkcs15-oberthur.c
+++ b/src/libopensc/pkcs15-oberthur.c
@@ -25,7 +25,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -65,7 +65,7 @@
#define PIN_DOMAIN_LABEL "SCM"
const unsigned char PinDomainID[3] = {0x53, 0x43, 0x4D};
-
+
#define AWP_PIN_DF "3F005011"
#define AWP_TOKEN_INFO "3F0050111000"
#define AWP_PUK_FILE "3F0050112000"
@@ -91,7 +91,7 @@ static int sc_pkcs15emu_oberthur_add_pubkey(struct sc_pkcs15_card *, unsigned, u
static int sc_pkcs15emu_oberthur_add_cert(struct sc_pkcs15_card *, unsigned);
static int sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *, unsigned, unsigned, int);
-int sc_pkcs15emu_oberthur_init_ex(struct sc_pkcs15_card *, struct sc_pkcs15emu_opt *);
+int sc_pkcs15emu_oberthur_init_ex(struct sc_pkcs15_card *, struct sc_aid *, struct sc_pkcs15emu_opt *);
static int sc_oberthur_parse_tokeninfo (struct sc_pkcs15_card *, unsigned char *, size_t, int);
static int sc_oberthur_parse_containers (struct sc_pkcs15_card *, unsigned char *, size_t, int);
@@ -162,7 +162,7 @@ sc_oberthur_decode_usage(unsigned flags)
}
-static int
+static int
sc_oberthur_get_friends (unsigned int id, struct crypto_container *ccont)
{
struct container *cont;
@@ -173,14 +173,14 @@ sc_oberthur_get_friends (unsigned int id, struct crypto_container *ccont)
memcpy(ccont, &cont->exchange, sizeof(struct crypto_container));
break;
}
-
+
if (cont->sign.id_pub == id || cont->sign.id_prv == id || cont->sign.id_cert == id) {
if (ccont)
memcpy(ccont, &cont->sign, sizeof(struct crypto_container));
break;
}
}
-
+
return cont ? 0 : SC_ERROR_TEMPLATE_NOT_FOUND;
}
@@ -191,7 +191,7 @@ sc_oberthur_get_certificate_authority(struct sc_pkcs15_der *der, int *out_author
#ifdef ENABLE_OPENSSL
X509 *x;
BUF_MEM buf_mem;
- BIO *bio = NULL;
+ BIO *bio = NULL;
BASIC_CONSTRAINTS *bs = NULL;
if (!der)
@@ -204,20 +204,20 @@ sc_oberthur_get_certificate_authority(struct sc_pkcs15_der *der, int *out_author
memcpy(buf_mem.data, der->value, der->len);
buf_mem.max = buf_mem.length = der->len;
- bio = BIO_new(BIO_s_mem());
+ bio = BIO_new(BIO_s_mem());
if(!bio)
return SC_ERROR_OUT_OF_MEMORY;
-
+
BIO_set_mem_buf(bio, &buf_mem, BIO_NOCLOSE);
x = d2i_X509_bio(bio, 0);
BIO_free(bio);
if (!x)
return SC_ERROR_INVALID_DATA;
-
+
bs = (BASIC_CONSTRAINTS *)X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL);
if (out_authority)
*out_authority = (bs && bs->ca);
-
+
X509_free(x);
return SC_SUCCESS;
@@ -227,8 +227,8 @@ sc_oberthur_get_certificate_authority(struct sc_pkcs15_der *der, int *out_author
}
-static int
-sc_oberthur_read_file(struct sc_pkcs15_card *p15card, const char *in_path,
+static int
+sc_oberthur_read_file(struct sc_pkcs15_card *p15card, const char *in_path,
unsigned char **out, size_t *out_len,
int verify_pin)
{
@@ -239,27 +239,27 @@ sc_oberthur_read_file(struct sc_pkcs15_card *p15card, const char *in_path,
size_t sz;
int rv;
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
+ LOG_FUNC_CALLED(ctx);
if (!in_path || !out || !out_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Cannot read oberthur file");
-
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "read file '%s'; verify_pin:%i", in_path, verify_pin);
-
+ LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Cannot read oberthur file");
+
+ sc_log(ctx, "read file '%s'; verify_pin:%i", in_path, verify_pin);
+
*out = NULL;
*out_len = 0;
-
+
sc_format_path(in_path, &path);
rv = sc_select_file(card, &path, &file);
- SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot select oberthur file to read");
+ LOG_TEST_RET(ctx, rv, "Cannot select oberthur file to read");
if (file->ef_structure == SC_FILE_EF_TRANSPARENT)
sz = file->size;
else
sz = (file->record_length + 2) * file->record_count;
-
+
*out = calloc(sz, 1);
if (*out == NULL)
- SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "Cannot read oberthur file");
+ LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot read oberthur file");
if (file->ef_structure == SC_FILE_EF_TRANSPARENT) {
rv = sc_read_binary(card, 0, *out, sz, 0);
@@ -268,7 +268,7 @@ sc_oberthur_read_file(struct sc_pkcs15_card *p15card, const char *in_path,
int rec;
int offs = 0;
int rec_len = file->record_length;
-
+
for (rec = 1; ; rec++) {
rv = sc_read_record(card, rec, *out + offs + 2, rec_len, SC_RECORD_BY_REC_NR);
if (rv == SC_ERROR_RECORD_NOT_FOUND) {
@@ -279,29 +279,29 @@ sc_oberthur_read_file(struct sc_pkcs15_card *p15card, const char *in_path,
break;
}
- rec_len = rv;
-
+ rec_len = rv;
+
*(*out + offs) = 'R';
*(*out + offs + 1) = rv;
-
+
offs += rv + 2;
}
sz = offs;
}
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "read oberthur file result %i", rv);
+ sc_log(ctx, "read oberthur file result %i", rv);
if (verify_pin && rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
struct sc_pkcs15_object *objs[0x10], *pin_obj = NULL;
const struct sc_acl_entry *acl = sc_file_get_acl_entry(file, SC_AC_OP_READ);
int ii;
rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 0x10);
- SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot read oberthur file: get AUTH objects error");
+ LOG_TEST_RET(ctx, rv, "Cannot read oberthur file: get AUTH objects error");
for (ii=0; ii<rv; ii++) {
struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *) objs[ii]->data;
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "compare PIN/ACL refs:%i/%i, method:%i/%i",
+ sc_log(ctx, "compare PIN/ACL refs:%i/%i, method:%i/%i",
auth_info->attrs.pin.reference, acl->key_ref, auth_info->auth_method, acl->method);
if (auth_info->attrs.pin.reference == (int)acl->key_ref && auth_info->auth_method == (unsigned)acl->method) {
pin_obj = objs[ii];
@@ -318,7 +318,7 @@ sc_oberthur_read_file(struct sc_pkcs15_card *p15card, const char *in_path,
rv = sc_oberthur_read_file(p15card, in_path, out, out_len, 0);
}
};
-
+
sc_file_free(file);
if (rv < 0) {
@@ -329,12 +329,12 @@ sc_oberthur_read_file(struct sc_pkcs15_card *p15card, const char *in_path,
*out_len = sz;
- SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, rv);
+ LOG_FUNC_RETURN(ctx, rv);
}
-static int
-sc_oberthur_parse_tokeninfo (struct sc_pkcs15_card *p15card,
+static int
+sc_oberthur_parse_tokeninfo (struct sc_pkcs15_card *p15card,
unsigned char *buff, size_t len, int postpone_allowed)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -342,9 +342,9 @@ sc_oberthur_parse_tokeninfo (struct sc_pkcs15_card *p15card,
unsigned flags;
int ii;
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
+ LOG_FUNC_CALLED(ctx);
if (!buff || len < 0x24)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Cannot parse token info");
+ LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Cannot parse token info");
memset(label, 0, sizeof(label));
@@ -355,28 +355,28 @@ sc_oberthur_parse_tokeninfo (struct sc_pkcs15_card *p15card,
*(label + ii + 1) = '\0';
flags = *(buff + 0x22) * 0x100 + *(buff + 0x23);
-
+
p15card->tokeninfo->label = strdup(label);
p15card->tokeninfo->manufacturer_id = strdup("Oberthur/OpenSC");
if (flags & 0x01)
p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_PRN_GENERATION;
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "label %s", p15card->tokeninfo->label);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "manufacturer_id %s", p15card->tokeninfo->manufacturer_id);
-
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
+ sc_log(ctx, "label %s", p15card->tokeninfo->label);
+ sc_log(ctx, "manufacturer_id %s", p15card->tokeninfo->manufacturer_id);
+
+ LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}
-static int
-sc_oberthur_parse_containers (struct sc_pkcs15_card *p15card,
+static int
+sc_oberthur_parse_containers (struct sc_pkcs15_card *p15card,
unsigned char *buff, size_t len, int postpone_allowed)
{
struct sc_context *ctx = p15card->card->ctx;
size_t offs;
-
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
+
+ LOG_FUNC_CALLED(ctx);
while (Containers) {
struct container *next = Containers->next;
@@ -388,27 +388,27 @@ sc_oberthur_parse_containers (struct sc_pkcs15_card *p15card,
for (offs=0; offs < len;) {
struct container *cont;
unsigned char *ptr = buff + offs + 2;
-
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "parse contaniers offs:%i, len:%i", offs, len);
+
+ sc_log(ctx, "parse contaniers offs:%i, len:%i", offs, len);
if (*(buff + offs) != 'R')
return SC_ERROR_INVALID_DATA;
-
+
cont = (struct container *)calloc(sizeof(struct container), 1);
if (!cont)
return SC_ERROR_OUT_OF_MEMORY;
-
+
cont->exchange.id_pub = *ptr * 0x100 + *(ptr + 1); ptr += 2;
cont->exchange.id_prv = *ptr * 0x100 + *(ptr + 1); ptr += 2;
cont->exchange.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
-
+
cont->sign.id_pub = *ptr * 0x100 + *(ptr + 1); ptr += 2;
cont->sign.id_prv = *ptr * 0x100 + *(ptr + 1); ptr += 2;
cont->sign.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
-
+
memcpy(cont->uuid, ptr + 2, 36);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "UUID: %s; 0x%X, 0x%X, 0x%X", cont->uuid,
+ sc_log(ctx, "UUID: %s; 0x%X, 0x%X, 0x%X", cont->uuid,
cont->exchange.id_pub, cont->exchange.id_prv, cont->exchange.id_cert);
-
+
if (!Containers) {
Containers = cont;
}
@@ -417,59 +417,59 @@ sc_oberthur_parse_containers (struct sc_pkcs15_card *p15card,
Containers->prev = (void *)cont;
Containers = cont;
}
-
+
offs += *(buff + offs + 1) + 2;
}
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
+ LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}
-static int
-sc_oberthur_parse_publicinfo (struct sc_pkcs15_card *p15card,
+static int
+sc_oberthur_parse_publicinfo (struct sc_pkcs15_card *p15card,
unsigned char *buff, size_t len, int postpone_allowed)
{
struct sc_context *ctx = p15card->card->ctx;
size_t ii;
int rv;
- SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
+ LOG_FUNC_CALLED(ctx);
for (ii=0; ii<len; ii+=5) {
unsigned int file_id, size;
-
+
if(*(buff+ii) != 0xFF)
continue;
-
+
file_id = 0x100 * *(buff+ii + 1) + *(buff+ii + 2);
size = 0x100 * *(buff+ii + 3) + *(buff+ii + 4);
- sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, "add public object(file-id:%04X,size:%X)", file_id, size);
+ sc_log(ctx, "add public object(file-id:%04X,size:%X)", file_id, size);
switch (*(buff+ii + 1)) {
case BASE_ID_PUB_RSA :
rv = sc_pkcs15emu_oberthur_add_pubkey(p15card, file_id, size);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot parse public key info");
+ LOG_TEST_RET(ctx, rv, "Cannot parse public key info");
break;
case BASE_ID_CERT :
rv = sc_pkcs15emu_oberthur_add_cert(p15card, file_id);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot parse certificate info");
+ LOG_TEST_RET(ctx, rv, "Cannot parse certificate info");
break;
case BASE_ID_PUB_DES :
break;
case BASE_ID_PUB_DATA :
rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 0);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot parse data info");
+ LOG_TEST_RET(ctx, rv, "Cannot parse data info");
break;
default:
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Public object parse error");
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Public object parse error");
}
}
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
+ LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}
-static int
-sc_oberthur_parse_privateinfo (struct sc_pkcs15_card *p15card,
+static int
+sc_oberthur_parse_privateinfo (struct sc_pkcs15_card *p15card,
unsigned char *buff, size_t len, int postpone_allowed)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -477,17 +477,17 @@ sc_oberthur_parse_privateinfo (struct sc_pkcs15_card *p15card,
int rv;
int no_more_private_keys = 0, no_more_private_data = 0;
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
+ LOG_FUNC_CALLED(ctx);
for (ii=0; ii<len; ii+=5) {
unsigned int file_id, size;
if(*(buff+ii) != 0xFF)
continue;
-
+
file_id = 0x100 * *(buff+ii + 1) + *(buff+ii + 2);
size = 0x100 * *(buff+ii + 3) + *(buff+ii + 4);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "add private object (file-id:%04X, size:%X)", file_id, size);
+ sc_log(ctx, "add private object (file-id:%04X, size:%X)", file_id, size);
switch (*(buff+ii + 1)) {
case BASE_ID_PRV_RSA :
@@ -498,18 +498,18 @@ sc_oberthur_parse_privateinfo (struct sc_pkcs15_card *p15card,
if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed) {
struct sc_path path;
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "postpone adding of the private keys");
+ sc_log(ctx, "postpone adding of the private keys");
sc_format_path("5011A5A5", &path);
rv = sc_pkcs15_add_df(p15card, SC_PKCS15_PRKDF, &path);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Add PrkDF error");
+ LOG_TEST_RET(ctx, rv, "Add PrkDF error");
no_more_private_keys = 1;
}
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot parse private key info");
+ LOG_TEST_RET(ctx, rv, "Cannot parse private key info");
break;
case BASE_ID_PRV_DES :
break;
case BASE_ID_PRV_DATA :
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "*(buff+ii + 1):%X", *(buff+ii + 1));
+ sc_log(ctx, "*(buff+ii + 1):%X", *(buff+ii + 1));
if (no_more_private_data)
break;
@@ -517,33 +517,33 @@ sc_oberthur_parse_privateinfo (struct sc_pkcs15_card *p15card,
if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed) {
struct sc_path path;
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "postpone adding of the private data");
+ sc_log(ctx, "postpone adding of the private data");
sc_format_path("5011A6A6", &path);
rv = sc_pkcs15_add_df(p15card, SC_PKCS15_DODF, &path);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Add DODF error");
+ LOG_TEST_RET(ctx, rv, "Add DODF error");
no_more_private_data = 1;
}
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot parse private data info");
+ LOG_TEST_RET(ctx, rv, "Cannot parse private data info");
break;
default:
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Private object parse error");
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Private object parse error");
}
}
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
+ LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}
/* Public key info:
- * flags:2,
- * CN(len:2,value:<variable length>),
- * ID(len:2,value:(SHA1 value)),
+ * flags:2,
+ * CN(len:2,value:<variable length>),
+ * ID(len:2,value:(SHA1 value)),
* StartDate(Ascii:8)
* EndDate(Ascii:8)
- * ??(0x00:2)
+ * ??(0x00:2)
*/
-static int
-sc_pkcs15emu_oberthur_add_pubkey(struct sc_pkcs15_card *p15card,
+static int
+sc_pkcs15emu_oberthur_add_pubkey(struct sc_pkcs15_card *p15card,
unsigned int file_id, unsigned int size)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -555,29 +555,29 @@ sc_pkcs15emu_oberthur_add_pubkey(struct sc_pkcs15_card *p15card,
unsigned flags;
int rv;
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "public key(file-id:%04X,size:%X)", file_id, size);
+ LOG_FUNC_CALLED(ctx);
+ sc_log(ctx, "public key(file-id:%04X,size:%X)", file_id, size);
memset(&key_info, 0, sizeof(key_info));
memset(&key_obj, 0, sizeof(key_obj));
-
+
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
- rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add public key: read oberthur file error");
+ rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
+ LOG_TEST_RET(ctx, rv, "Failed to add public key: read oberthur file error");
/* Flags */
offs = 2;
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'tag'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'tag'");
flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
key_info.usage = sc_oberthur_decode_usage(flags);
if (flags & OBERTHUR_ATTR_MODIFIABLE)
key_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE;
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Public key key-usage:%04X", key_info.usage);
+ sc_log(ctx, "Public key key-usage:%04X", key_info.usage);
/* Label */
- if (offs + 2 > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'Label'");
+ if (offs + 2 > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'Label'");
len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (len) {
if (len > sizeof(key_obj.label) - 1)
@@ -585,40 +585,40 @@ sc_pkcs15emu_oberthur_add_pubkey(struct sc_pkcs15_card *p15card,
memcpy(key_obj.label, info_blob + offs + 2, len);
}
offs += 2 + len;
-
+
/* ID */
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'ID'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add public key: no 'ID'");
len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (!len || len > sizeof(key_info.id.value))
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_DATA, "Failed to add public key: invalie 'ID' length");
+ LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add public key: invalie 'ID' length");
memcpy(key_info.id.value, info_blob + offs + 2, len);
key_info.id.len = len;
-
+
/* Ignore Start/End dates */
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
sc_format_path(ch_tmp, &key_info.path);
-
+
key_info.native = 1;
key_info.key_reference = file_id & 0xFF;
key_info.modulus_length = size;
rv = sc_pkcs15emu_add_rsa_pubkey(p15card, &key_obj, &key_info);
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
+ LOG_FUNC_RETURN(ctx, rv);
}
/* Certificate info:
- * flags:2,
- * Label(len:2,value:),
- * ID(len:2,value:(SHA1 value)),
+ * flags:2,
+ * Label(len:2,value:),
+ * ID(len:2,value:(SHA1 value)),
* Subject in ASN.1(len:2,value:)
* Issuer in ASN.1(len:2,value:)
* Serial encoded in LV or ASN.1 FIXME
*/
-static int
+static int
sc_pkcs15emu_oberthur_add_cert(struct sc_pkcs15_card *p15card, unsigned int file_id)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -630,24 +630,24 @@ sc_pkcs15emu_oberthur_add_cert(struct sc_pkcs15_card *p15card, unsigned int file
int rv;
char ch_tmp[0x20];
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "add certificate(file-id:%04X)", file_id);
+ LOG_FUNC_CALLED(ctx);
+ sc_log(ctx, "add certificate(file-id:%04X)", file_id);
memset(&cinfo, 0, sizeof(cinfo));
memset(&cobj, 0, sizeof(cobj));
-
+
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
- rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add certificate: read oberthur file error");
+ rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
+ LOG_TEST_RET(ctx, rv, "Failed to add certificate: read oberthur file error");
- if (info_len < 2)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
+ if (info_len < 2)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
offs = 2;
/* Label */
- if (offs + 2 > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'CN'");
+ if (offs + 2 > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'CN'");
len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (len) {
if (len > sizeof(cobj.label) - 1)
@@ -655,13 +655,13 @@ sc_pkcs15emu_oberthur_add_cert(struct sc_pkcs15_card *p15card, unsigned int file
memcpy(cobj.label, info_blob + offs + 2, len);
}
offs += 2 + len;
-
+
/* ID */
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'ID'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'ID'");
len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (len > sizeof(cinfo.id.value))
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_DATA, "Failed to add certificate: invalie 'ID' length");
+ LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add certificate: invalie 'ID' length");
memcpy(cinfo.id.value, info_blob + offs + 2, len);
cinfo.id.len = len;
@@ -669,14 +669,14 @@ sc_pkcs15emu_oberthur_add_cert(struct sc_pkcs15_card *p15card, unsigned int file
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
sc_format_path(ch_tmp, &cinfo.path);
- rv = sc_oberthur_read_file(p15card, ch_tmp, &cert_blob, &cert_len, 1);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add certificate: read certificate error");
-
+ rv = sc_oberthur_read_file(p15card, ch_tmp, &cert_blob, &cert_len, 1);
+ LOG_TEST_RET(ctx, rv, "Failed to add certificate: read certificate error");
+
cinfo.value.value = cert_blob;
cinfo.value.len = cert_len;
rv = sc_oberthur_get_certificate_authority(&cinfo.value, &cinfo.authority);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add certificate: get certificate attributes error");
+ LOG_TEST_RET(ctx, rv, "Failed to add certificate: get certificate attributes error");
if (flags & OBERTHUR_ATTR_MODIFIABLE)
cobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
@@ -688,17 +688,17 @@ sc_pkcs15emu_oberthur_add_cert(struct sc_pkcs15_card *p15card, unsigned int file
/* Private key info:
- * flags:2,
- * CN(len:2,value:),
- * ID(len:2,value:(SHA1 value)),
+ * flags:2,
+ * CN(len:2,value:),
+ * ID(len:2,value:(SHA1 value)),
* StartDate(Ascii:8)
* EndDate(Ascii:8)
* Subject in ASN.1(len:2,value:)
* modulus(value:)
* exponent(length:1, value:3)
*/
-static int
-sc_pkcs15emu_oberthur_add_prvkey(struct sc_pkcs15_card *p15card,
+static int
+sc_pkcs15emu_oberthur_add_prvkey(struct sc_pkcs15_card *p15card,
unsigned int file_id, unsigned int size)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -712,82 +712,82 @@ sc_pkcs15emu_oberthur_add_prvkey(struct sc_pkcs15_card *p15card,
char ch_tmp[0x100];
int rv;
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "add private key(file-id:%04X,size:%04X)", file_id, size);
-
+ LOG_FUNC_CALLED(ctx);
+ sc_log(ctx, "add private key(file-id:%04X,size:%04X)", file_id, size);
+
memset(&kinfo, 0, sizeof(kinfo));
memset(&kobj, 0, sizeof(kobj));
memset(&ccont, 0, sizeof(ccont));
-
+
rv = sc_oberthur_get_friends (file_id, &ccont);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add private key: get friends error");
+ LOG_TEST_RET(ctx, rv, "Failed to add private key: get friends error");
if (ccont.id_cert) {
struct sc_pkcs15_object *objs[32];
int ii;
-
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "friend certificate %04X", ccont.id_cert);
+
+ sc_log(ctx, "friend certificate %04X", ccont.id_cert);
rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_CERT_X509, objs, 32);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add private key: get certificates error");
+ LOG_TEST_RET(ctx, rv, "Failed to add private key: get certificates error");
for (ii=0; ii<rv; ii++) {
struct sc_pkcs15_cert_info *cert = (struct sc_pkcs15_cert_info *)objs[ii]->data;
struct sc_path path = cert->path;
unsigned int id = path.value[path.len - 2] * 0x100 + path.value[path.len - 1];
-
+
if (id == ccont.id_cert) {
strncpy(kobj.label, objs[ii]->label, sizeof(kobj.label) - 1);
break;
}
}
- if (ii == rv)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCONSISTENT_PROFILE, "Failed to add private key: friend not found");
+ if (ii == rv)
+ LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_PROFILE, "Failed to add private key: friend not found");
}
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PRV, file_id | 0x100);
- rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add private key: read oberthur file error");
+ rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
+ LOG_TEST_RET(ctx, rv, "Failed to add private key: read oberthur file error");
if (info_len < 2)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'tag'");
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'tag'");
flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
offs = 2;
/* CN */
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'CN'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'CN'");
len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (len && !strlen(kobj.label)) {
- if (len > sizeof(kobj.label) - 1)
+ if (len > sizeof(kobj.label) - 1)
len = sizeof(kobj.label) - 1;
strncpy(kobj.label, (char *)(info_blob + offs + 2), len);
}
offs += 2 + len;
-
+
/* ID */
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'ID'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'ID'");
len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (!len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: zero length ID");
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: zero length ID");
else if (len > sizeof(kinfo.id.value))
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_DATA, "Failed to add private key: invalid ID length");
+ LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add private key: invalid ID length");
memcpy(kinfo.id.value, info_blob + offs + 2, len);
kinfo.id.len = len;
offs += 2 + len;
-
- /* Ignore Start/End dates */
+
+ /* Ignore Start/End dates */
offs += 16;
-
+
/* Subject encoded in ASN1 */
- if (offs > info_len)
+ if (offs > info_len)
return SC_ERROR_UNKNOWN_DATA_RECEIVED;
len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (len) {
kinfo.subject.value = malloc(len);
if (!kinfo.subject.value)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "Failed to add private key: memory allocation error");
+ LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Failed to add private key: memory allocation error");
kinfo.subject.len = len;
memcpy(kinfo.subject.value, info_blob + offs + 2, len);
}
@@ -796,7 +796,7 @@ sc_pkcs15emu_oberthur_add_prvkey(struct sc_pkcs15_card *p15card,
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PRV, file_id);
sc_format_path(ch_tmp, &kinfo.path);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Private key info path %s", ch_tmp);
+ sc_log(ctx, "Private key info path %s", ch_tmp);
kinfo.modulus_length = size;
kinfo.native = 1;
@@ -807,19 +807,19 @@ sc_pkcs15emu_oberthur_add_prvkey(struct sc_pkcs15_card *p15card,
if (flags & OBERTHUR_ATTR_MODIFIABLE)
kobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
- kobj.auth_id.len = sizeof(PinDomainID) > sizeof(kobj.auth_id.value)
+ kobj.auth_id.len = sizeof(PinDomainID) > sizeof(kobj.auth_id.value)
? sizeof(kobj.auth_id.value) : sizeof(PinDomainID);
memcpy(kobj.auth_id.value, PinDomainID, kobj.auth_id.len);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Parsed private key(reference:%i,usage:%X,flags:%X)", kinfo.key_reference, kinfo.usage, kobj.flags);
+ sc_log(ctx, "Parsed private key(reference:%i,usage:%X,flags:%X)", kinfo.key_reference, kinfo.usage, kobj.flags);
rv = sc_pkcs15emu_add_rsa_prkey(p15card, &kobj, &kinfo);
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
+ LOG_FUNC_RETURN(ctx, rv);
}
-static int
-sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *p15card,
+static int
+sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *p15card,
unsigned int file_id, unsigned int size, int private)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -832,54 +832,54 @@ sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *p15card,
int rv;
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Add data(file-id:%04X,size:%i,is-private:%i)", file_id, size, private);
+ sc_log(ctx, "Add data(file-id:%04X,size:%i,is-private:%i)", file_id, size, private);
memset(&dinfo, 0, sizeof(dinfo));
memset(&dobj, 0, sizeof(dobj));
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id | 0x100);
-
+
rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add data: read oberthur file error");
+ LOG_TEST_RET(ctx, rv, "Failed to add data: read oberthur file error");
- if (info_len < 2)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
+ if (info_len < 2)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add certificate: no 'tag'");
flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
offs = 2;
/* Label */
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'label'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'label'");
label = info_blob + offs + 2;
label_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (label_len > sizeof(dobj.label) - 1)
label_len = sizeof(dobj.label) - 1;
offs += 2 + *(info_blob + offs + 1);
-
+
/* Application */
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'application'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'application'");
app = info_blob + offs + 2;
app_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (app_len > sizeof(dinfo.app_label) - 1)
app_len = sizeof(dinfo.app_label) - 1;
offs += 2 + app_len;
-
+
/* OID encode like DER(ASN.1(oid)) */
- if (offs > info_len)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'OID'");
+ if (offs > info_len)
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'OID'");
oid_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
if (oid_len) {
oid = info_blob + offs + 2;
if (*oid != 0x06 || (*(oid + 1) != oid_len - 2))
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: invalid 'OID' format");
+ LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: invalid 'OID' format");
oid += 2;
oid_len -= 2;
}
-
+
snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id);
sc_format_path(ch_tmp, &dinfo.path);
-
+
memcpy(dobj.label, label, label_len);
memcpy(dinfo.app_label, app, app_len);
if (oid_len)
@@ -890,7 +890,7 @@ sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *p15card,
if (private) {
dobj.auth_id.len = sizeof(PinDomainID) > sizeof(dobj.auth_id.value)
- ? sizeof(dobj.auth_id.value) : sizeof(PinDomainID);
+ ? sizeof(dobj.auth_id.value) : sizeof(PinDomainID);
memcpy(dobj.auth_id.value, PinDomainID, dobj.auth_id.len);
dobj.flags |= SC_PKCS15_CO_FLAG_PRIVATE;
@@ -902,7 +902,7 @@ sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *p15card,
}
-static int
+static int
sc_pkcs15emu_oberthur_init(struct sc_pkcs15_card * p15card)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -913,20 +913,20 @@ sc_pkcs15emu_oberthur_init(struct sc_pkcs15_card * p15card)
int rv, ii, tries_left;
char serial[0x10];
unsigned char sopin_reference = 0x04;
-
+
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial, sizeof(serial), 0);
p15card->tokeninfo->serial_number = strdup(serial);
p15card->ops.parse_df = sc_awp_parse_df;
p15card->ops.clear = sc_awp_clear;
-
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Oberthur init: serial %s", p15card->tokeninfo->serial_number);
+
+ sc_log(ctx, "Oberthur init: serial %s", p15card->tokeninfo->serial_number);
sc_format_path(AWP_PIN_DF, &path);
rv = sc_select_file(card, &path, NULL);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Oberthur init failed: cannot select PIN dir");
-
+ LOG_TEST_RET(ctx, rv, "Oberthur init failed: cannot select PIN dir");
+
tries_left = -1;
rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT) {
@@ -934,13 +934,13 @@ sc_pkcs15emu_oberthur_init(struct sc_pkcs15_card * p15card)
rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
}
if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT)
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Invalid state of SO-PIN");
+ LOG_TEST_RET(ctx, rv, "Invalid state of SO-PIN");
/* add PIN */
memset(&auth_info, 0, sizeof(auth_info));
memset(&obj, 0, sizeof(obj));
- auth_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
+ auth_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
auth_info.auth_method = SC_AC_CHV;
auth_info.auth_id.len = 1;
auth_info.auth_id.value[0] = 0xFF;
@@ -950,19 +950,19 @@ sc_pkcs15emu_oberthur_init(struct sc_pkcs15_card * p15card)
auth_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
auth_info.attrs.pin.reference = sopin_reference;
auth_info.attrs.pin.pad_char = 0xFF;
- auth_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
- | SC_PKCS15_PIN_FLAG_INITIALIZED
+ auth_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
+ | SC_PKCS15_PIN_FLAG_INITIALIZED
| SC_PKCS15_PIN_FLAG_NEEDS_PADDING
| SC_PKCS15_PIN_FLAG_SO_PIN;
auth_info.tries_left = tries_left;
-
+
strncpy(obj.label, "SO PIN", SC_PKCS15_MAX_LABEL_SIZE-1);
obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
-
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
+
+ sc_log(ctx, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
sc_pkcs15_print_id(&auth_info.auth_id), auth_info.attrs.pin.reference);
rv = sc_pkcs15emu_add_pin_obj(p15card, &obj, &auth_info);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Oberthur init failed: cannot add PIN object");
+ LOG_TEST_RET(ctx, rv, "Oberthur init failed: cannot add PIN object");
tries_left = -1;
rv = sc_verify(card, SC_AC_CHV, 0x81, (unsigned char *)"", 0, &tries_left);
@@ -970,8 +970,8 @@ sc_pkcs15emu_oberthur_init(struct sc_pkcs15_card * p15card)
/* add PIN */
memset(&auth_info, 0, sizeof(auth_info));
memset(&obj, 0, sizeof(obj));
-
- auth_info.auth_id.len = sizeof(PinDomainID) > sizeof(auth_info.auth_id.value)
+
+ auth_info.auth_id.len = sizeof(PinDomainID) > sizeof(auth_info.auth_id.value)
? sizeof(auth_info.auth_id.value) : sizeof(PinDomainID);
memcpy(auth_info.auth_id.value, PinDomainID, auth_info.auth_id.len);
auth_info.auth_method = SC_AC_CHV;
@@ -982,45 +982,45 @@ sc_pkcs15emu_oberthur_init(struct sc_pkcs15_card * p15card)
auth_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
auth_info.attrs.pin.reference = 0x81;
auth_info.attrs.pin.pad_char = 0xFF;
- auth_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
- | SC_PKCS15_PIN_FLAG_INITIALIZED
+ auth_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
+ | SC_PKCS15_PIN_FLAG_INITIALIZED
| SC_PKCS15_PIN_FLAG_NEEDS_PADDING
| SC_PKCS15_PIN_FLAG_LOCAL;
auth_info.tries_left = tries_left;
-
+
strncpy(obj.label, PIN_DOMAIN_LABEL, SC_PKCS15_MAX_LABEL_SIZE-1);
obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
-
- sc_format_path(AWP_PIN_DF, &auth_info.path);
+
+ sc_format_path(AWP_PIN_DF, &auth_info.path);
auth_info.path.type = SC_PATH_TYPE_PATH;
-
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
+
+ sc_log(ctx, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
sc_pkcs15_print_id(&auth_info.auth_id), auth_info.attrs.pin.reference);
rv = sc_pkcs15emu_add_pin_obj(p15card, &obj, &auth_info);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Oberthur init failed: cannot add PIN object");
+ LOG_TEST_RET(ctx, rv, "Oberthur init failed: cannot add PIN object");
}
else if (rv != SC_ERROR_DATA_OBJECT_NOT_FOUND) {
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Oberthur init failed: cannot verify PIN");
+ LOG_TEST_RET(ctx, rv, "Oberthur init failed: cannot verify PIN");
}
for (ii=0; oberthur_infos[ii].name; ii++) {
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Oberthur init: read %s file", oberthur_infos[ii].name);
+ sc_log(ctx, "Oberthur init: read %s file", oberthur_infos[ii].name);
rv = sc_oberthur_read_file(p15card, oberthur_infos[ii].path,
&oberthur_infos[ii].content, &oberthur_infos[ii].len, 1);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Oberthur init failed: read oberthur file error");
-
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Oberthur init: parse %s file, content length %i",
+ LOG_TEST_RET(ctx, rv, "Oberthur init failed: read oberthur file error");
+
+ sc_log(ctx, "Oberthur init: parse %s file, content length %i",
oberthur_infos[ii].name, oberthur_infos[ii].len);
- rv = oberthur_infos[ii].parser(p15card, oberthur_infos[ii].content, oberthur_infos[ii].len,
+ rv = oberthur_infos[ii].parser(p15card, oberthur_infos[ii].content, oberthur_infos[ii].len,
oberthur_infos[ii].postpone_allowed);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Oberthur init failed: parse error");
+ LOG_TEST_RET(ctx, rv, "Oberthur init failed: parse error");
}
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
+ LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}
-static int
+static int
oberthur_detect_card(struct sc_pkcs15_card * p15card)
{
struct sc_card *card = p15card->card;
@@ -1032,13 +1032,13 @@ oberthur_detect_card(struct sc_pkcs15_card * p15card)
}
-int
-sc_pkcs15emu_oberthur_init_ex(struct sc_pkcs15_card * p15card,
+int
+sc_pkcs15emu_oberthur_init_ex(struct sc_pkcs15_card * p15card, struct sc_aid *aid,
struct sc_pkcs15emu_opt * opts)
{
- int rv;
-
- SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
+ int rv;
+
+ LOG_FUNC_CALLED(p15card->card->ctx);
if (opts && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK) {
rv = sc_pkcs15emu_oberthur_init(p15card);
}
@@ -1047,12 +1047,12 @@ sc_pkcs15emu_oberthur_init_ex(struct sc_pkcs15_card * p15card,
if (!rv)
rv = sc_pkcs15emu_oberthur_init(p15card);
}
-
- SC_FUNC_RETURN(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, rv);
+
+ LOG_FUNC_RETURN(p15card->card->ctx, rv);
}
-static int
+static int
sc_awp_parse_df(struct sc_pkcs15_card *p15card, struct sc_pkcs15_df *df)
{
struct sc_context *ctx = p15card->card->ctx;
@@ -1060,15 +1060,15 @@ sc_awp_parse_df(struct sc_pkcs15_card *p15card, struct sc_pkcs15_df *df)
size_t buf_len;
int rv;
- SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
+ LOG_FUNC_CALLED(ctx);
if (df->type != SC_PKCS15_PRKDF && df->type != SC_PKCS15_DODF)
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED);
+ LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
if (df->enumerated)
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
+ LOG_FUNC_RETURN(ctx, SC_SUCCESS);
rv = sc_oberthur_read_file(p15card, AWP_OBJECTS_LIST_PRV, &buf, &buf_len, 1);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Parse DF: read pribate objects info failed");
+ LOG_TEST_RET(ctx, rv, "Parse DF: read pribate objects info failed");
rv = sc_oberthur_parse_privateinfo(p15card, buf, buf_len, 0);
@@ -1076,17 +1076,17 @@ sc_awp_parse_df(struct sc_pkcs15_card *p15card, struct sc_pkcs15_df *df)
free(buf);
if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_SUCCESS);
+ LOG_FUNC_RETURN(ctx, SC_SUCCESS);
- SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Parse DF: private info parse error");
+ LOG_TEST_RET(ctx, rv, "Parse DF: private info parse error");
df->enumerated = 1;
- SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
+ LOG_FUNC_RETURN(ctx, rv);
}
static void
sc_awp_clear(struct sc_pkcs15_card *p15card)
{
- SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
+ LOG_FUNC_CALLED(p15card->card->ctx);
}
diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c
index 385ae38..20b6566 100644
--- a/src/libopensc/pkcs15-openpgp.c
+++ b/src/libopensc/pkcs15-openpgp.c
@@ -33,7 +33,7 @@
#include "pkcs15.h"
#include "log.h"
-int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static int sc_pkcs15emu_openpgp_add_data(sc_pkcs15_card_t *);
@@ -429,7 +429,7 @@ static int openpgp_detect_card(sc_pkcs15_card_t *p15card)
return SC_ERROR_WRONG_CARD;
}
-int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *p15card,
+int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
if (opts && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)
diff --git a/src/libopensc/pkcs15-piv.c b/src/libopensc/pkcs15-piv.c
index 8c107f5..8b7d8db 100644
--- a/src/libopensc/pkcs15-piv.c
+++ b/src/libopensc/pkcs15-piv.c
@@ -40,7 +40,7 @@
#define MANU_ID "piv_II "
-int sc_pkcs15emu_piv_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_piv_init_ex(sc_pkcs15_card_t *, struct sc_aid *aid, sc_pkcs15emu_opt_t *);
typedef struct objdata_st {
const char *id;
@@ -999,7 +999,7 @@ sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "DEE Adding pin %d label=%s",i, label);
prkey_info.modulus_length= ckis[i].pubkey_len;
r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
break;
- case SC_ALGORITHM_EC:
+ case SC_ALGORITHM_EC:
prkey_info.usage |= prkeys[i].usage_ec;
prkey_info.field_length = ckis[i].pubkey_len;
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "DEE added key_alg %2.2x prkey_obj.flags %8.8x",
@@ -1020,7 +1020,7 @@ sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "DEE Adding pin %d label=%s",i, label);
}
int sc_pkcs15emu_piv_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts)
+ struct sc_aid *aid, sc_pkcs15emu_opt_t *opts)
{
sc_card_t *card = p15card->card;
sc_context_t *ctx = card->ctx;
diff --git a/src/libopensc/pkcs15-postecert.c b/src/libopensc/pkcs15-postecert.c
index 6842bda..e79cd80 100644
--- a/src/libopensc/pkcs15-postecert.c
+++ b/src/libopensc/pkcs15-postecert.c
@@ -33,7 +33,7 @@
#include "pkcs15.h"
#include "log.h"
-int sc_pkcs15emu_postecert_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_postecert_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static int (*set_security_env) (sc_card_t *, const sc_security_env_t *, int);
@@ -354,6 +354,7 @@ static int postecert_detect_card(sc_pkcs15_card_t * p15card)
}
int sc_pkcs15emu_postecert_init_ex(sc_pkcs15_card_t * p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t * opts)
{
if (opts && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)
diff --git a/src/libopensc/pkcs15-pteid.c b/src/libopensc/pkcs15-pteid.c
index da9c088..9f1132d 100644
--- a/src/libopensc/pkcs15-pteid.c
+++ b/src/libopensc/pkcs15-pteid.c
@@ -50,7 +50,7 @@
#define IAS_CARD 0
#define GEMSAFE_CARD 1
-int sc_pkcs15emu_pteid_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_pteid_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static int sc_pkcs15emu_pteid_init(sc_pkcs15_card_t * p15card)
{
@@ -275,7 +275,7 @@ static int pteid_detect_card(sc_pkcs15_card_t *p15card)
return SC_ERROR_WRONG_CARD;
}
-int sc_pkcs15emu_pteid_init_ex(sc_pkcs15_card_t *p15card, sc_pkcs15emu_opt_t *opts)
+int sc_pkcs15emu_pteid_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid, sc_pkcs15emu_opt_t *opts)
{
if (opts != NULL && opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)
return sc_pkcs15emu_pteid_init(p15card);
diff --git a/src/libopensc/pkcs15-sc-hsm.c b/src/libopensc/pkcs15-sc-hsm.c
index 3ef8201..2ffed11 100644
--- a/src/libopensc/pkcs15-sc-hsm.c
+++ b/src/libopensc/pkcs15-sc-hsm.c
@@ -933,6 +933,7 @@ static int sc_pkcs15emu_sc_hsm_init (sc_pkcs15_card_t * p15card)
int sc_pkcs15emu_sc_hsm_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
if (opts && (opts->flags & SC_PKCS15EMU_FLAGS_NO_CHECK)) {
diff --git a/src/libopensc/pkcs15-starcert.c b/src/libopensc/pkcs15-starcert.c
index 96e0b8a..4e19e19 100644
--- a/src/libopensc/pkcs15-starcert.c
+++ b/src/libopensc/pkcs15-starcert.c
@@ -33,7 +33,7 @@
#define MANU_ID "Giesecke & Devrient GmbH"
#define STARCERT "StarCertV2201"
-int sc_pkcs15emu_starcert_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_starcert_init_ex(sc_pkcs15_card_t *, struct sc_aid *,sc_pkcs15emu_opt_t *);
typedef struct cdata_st {
const char *label;
@@ -270,6 +270,7 @@ static int sc_pkcs15emu_starcert_init(sc_pkcs15_card_t *p15card)
}
int sc_pkcs15emu_starcert_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
diff --git a/src/libopensc/pkcs15-syn.c b/src/libopensc/pkcs15-syn.c
index 0ccb944..853c4f6 100644
--- a/src/libopensc/pkcs15-syn.c
+++ b/src/libopensc/pkcs15-syn.c
@@ -32,52 +32,9 @@
#include "internal.h"
#include "asn1.h"
#include "pkcs15.h"
+#include "pkcs15-syn.h"
-extern int sc_pkcs15emu_westcos_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts);
-extern int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_infocamere_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_starcert_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_tcos_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_esteid_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_postecert_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_piv_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts);
-extern int sc_pkcs15emu_gemsafeGPK_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts);
-extern int sc_pkcs15emu_gemsafeV1_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts);
-extern int sc_pkcs15emu_actalis_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts);
-extern int sc_pkcs15emu_atrust_acos_init_ex(sc_pkcs15_card_t *p15card,
- sc_pkcs15emu_opt_t *opts);
-extern int sc_pkcs15emu_tccardos_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_pteid_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_oberthur_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_itacns_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_sc_hsm_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_dnie_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-extern int sc_pkcs15emu_gids_init_ex(sc_pkcs15_card_t *,
- sc_pkcs15emu_opt_t *);
-
-static struct {
- const char * name;
- int (*handler)(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
-} builtin_emulators[] = {
+struct sc_pkcs15_emulator_handler builtin_emulators[] = {
{ "westcos", sc_pkcs15emu_westcos_init_ex },
{ "openpgp", sc_pkcs15emu_openpgp_init_ex },
{ "infocamere", sc_pkcs15emu_infocamere_init_ex },
@@ -86,7 +43,7 @@ static struct {
{ "esteid", sc_pkcs15emu_esteid_init_ex },
{ "itacns", sc_pkcs15emu_itacns_init_ex },
{ "postecert", sc_pkcs15emu_postecert_init_ex },
- { "PIV-II", sc_pkcs15emu_piv_init_ex },
+ { "PIV-II", sc_pkcs15emu_piv_init_ex },
{ "gemsafeGPK", sc_pkcs15emu_gemsafeGPK_init_ex },
{ "gemsafeV1", sc_pkcs15emu_gemsafeV1_init_ex },
{ "actalis", sc_pkcs15emu_actalis_init_ex },
@@ -95,13 +52,14 @@ static struct {
{ "entersafe", sc_pkcs15emu_entersafe_init_ex },
{ "pteid", sc_pkcs15emu_pteid_init_ex },
{ "oberthur", sc_pkcs15emu_oberthur_init_ex },
- { "sc-hsm", sc_pkcs15emu_sc_hsm_init_ex },
+ { "sc-hsm", sc_pkcs15emu_sc_hsm_init_ex },
{ "dnie", sc_pkcs15emu_dnie_init_ex },
{ "gids", sc_pkcs15emu_gids_init_ex },
+ { "iasecc", sc_pkcs15emu_iasecc_init_ex },
{ NULL, NULL }
};
-static int parse_emu_block(sc_pkcs15_card_t *, scconf_block *);
+static int parse_emu_block(sc_pkcs15_card_t *, struct sc_aid *, scconf_block *);
static sc_pkcs15_df_t * sc_pkcs15emu_get_df(sc_pkcs15_card_t *p15card,
unsigned int type);
@@ -114,7 +72,7 @@ int sc_pkcs15_is_emulation_only(sc_card_t *card)
{
switch (card->type) {
case SC_CARD_TYPE_MCRD_ESTEID_V10:
- case SC_CARD_TYPE_MCRD_ESTEID_V11:
+ case SC_CARD_TYPE_MCRD_ESTEID_V11:
case SC_CARD_TYPE_MCRD_ESTEID_V30:
case SC_CARD_TYPE_IAS_PTEID:
case SC_CARD_TYPE_GEMSAFEV1_PTEID:
@@ -134,7 +92,7 @@ int sc_pkcs15_is_emulation_only(sc_card_t *card)
}
int
-sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
+sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card, struct sc_aid *aid)
{
sc_context_t *ctx = p15card->card->ctx;
scconf_block *conf_block, **blocks, *blk;
@@ -149,17 +107,17 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
if (!conf_block) {
/* no conf file found => try bultin drivers */
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "no conf file (or section), trying all builtin emulators\n");
+ sc_log(ctx, "no conf file (or section), trying all builtin emulators");
for (i = 0; builtin_emulators[i].name; i++) {
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "trying %s\n", builtin_emulators[i].name);
- r = builtin_emulators[i].handler(p15card, &opts);
+ sc_log(ctx, "trying %s", builtin_emulators[i].name);
+ r = builtin_emulators[i].handler(p15card, aid, &opts);
if (r == SC_SUCCESS)
/* we got a hit */
goto out;
}
} else {
/* we have a conf file => let's use it */
- int builtin_enabled;
+ int builtin_enabled;
const scconf_list *list, *item;
builtin_enabled = scconf_get_bool(conf_block, "enable_builtin_emulation", 1);
@@ -171,10 +129,10 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
/* go through the list of builtin drivers */
const char *name = item->data;
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "trying %s\n", name);
+ sc_log(ctx, "trying %s", name);
for (i = 0; builtin_emulators[i].name; i++)
if (!strcmp(builtin_emulators[i].name, name)) {
- r = builtin_emulators[i].handler(p15card, &opts);
+ r = builtin_emulators[i].handler(p15card, aid, &opts);
if (r == SC_SUCCESS)
/* we got a hit */
goto out;
@@ -182,10 +140,10 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
}
}
else if (builtin_enabled) {
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "no emulator list in config file, trying all builtin emulators\n");
+ sc_log(ctx, "no emulator list in config file, trying all builtin emulators");
for (i = 0; builtin_emulators[i].name; i++) {
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "trying %s\n", builtin_emulators[i].name);
- r = builtin_emulators[i].handler(p15card, &opts);
+ sc_log(ctx, "trying %s", builtin_emulators[i].name);
+ r = builtin_emulators[i].handler(p15card, aid, &opts);
if (r == SC_SUCCESS)
/* we got a hit */
goto out;
@@ -193,13 +151,13 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
}
/* search for 'emulate foo { ... }' entries in the conf file */
- sc_log(ctx, "searching for 'emulate foo { ... }' blocks\n");
+ sc_log(ctx, "searching for 'emulate foo { ... }' blocks");
blocks = scconf_find_blocks(ctx->conf, conf_block, "emulate", NULL);
sc_log(ctx, "Blocks: %p", blocks);
for (i = 0; blocks && (blk = blocks[i]) != NULL; i++) {
const char *name = blk->name->data;
sc_log(ctx, "trying %s", name);
- r = parse_emu_block(p15card, blk);
+ r = parse_emu_block(p15card, aid, blk);
if (r == SC_SUCCESS) {
free(blocks);
goto out;
@@ -222,14 +180,14 @@ out:
}
-static int parse_emu_block(sc_pkcs15_card_t *p15card, scconf_block *conf)
+static int parse_emu_block(sc_pkcs15_card_t *p15card, struct sc_aid *aid, scconf_block *conf)
{
sc_card_t *card = p15card->card;
sc_context_t *ctx = card->ctx;
sc_pkcs15emu_opt_t opts;
void *handle = NULL;
int (*init_func)(sc_pkcs15_card_t *);
- int (*init_func_ex)(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+ int (*init_func_ex)(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
int r;
const char *driver, *module_name;
@@ -260,13 +218,13 @@ static int parse_emu_block(sc_pkcs15_card_t *p15card, scconf_block *conf)
void *address;
unsigned int major = 0, minor = 0, fix = 0;
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Loading %s\n", module_name);
-
+ sc_log(ctx, "Loading %s", module_name);
+
/* try to open dynamic library */
handle = sc_dlopen(module_name);
if (!handle) {
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "unable to open dynamic library '%s': %s\n",
- module_name, sc_dlerror());
+ sc_log(ctx, "unable to open dynamic library '%s': %s",
+ module_name, sc_dlerror());
return SC_ERROR_INTERNAL;
}
@@ -274,8 +232,7 @@ static int parse_emu_block(sc_pkcs15_card_t *p15card, scconf_block *conf)
get_version = (const char *(*)(void)) sc_dlsym(handle, "sc_driver_version");
if (get_version) {
if (3 != sscanf(get_version(), "%u.%u.%u", &major, &minor, &fix)) {
- sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
- "unable to get modules version number\n");
+ sc_log(ctx, "unable to get modules version number");
sc_dlclose(handle);
return SC_ERROR_INTERNAL;
}
@@ -296,24 +253,22 @@ static int parse_emu_block(sc_pkcs15_card_t *p15card, scconf_block *conf)
address = sc_dlsym(handle, name);
if (address)
- init_func_ex = (int (*)(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *)) address;
+ init_func_ex = (int (*)(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *)) address;
}
}
/* try to initialize the pkcs15 structures */
if (init_func_ex)
- r = init_func_ex(p15card, &opts);
+ r = init_func_ex(p15card, aid, &opts);
else if (init_func)
r = init_func(p15card);
else
r = SC_ERROR_WRONG_CARD;
if (r >= 0) {
- sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "%s succeeded, card bound\n",
- module_name);
+ sc_log(card->ctx, "%s succeeded, card bound", module_name);
p15card->dll_handle = handle;
} else {
- sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "%s failed: %s\n",
- module_name, sc_strerror(r));
+ sc_log(card->ctx, "%s failed: %s", module_name, sc_strerror(r));
/* clear pkcs15 card */
sc_pkcs15_card_clear(p15card);
if (handle)
@@ -405,7 +360,7 @@ int sc_pkcs15emu_add_ec_pubkey(sc_pkcs15_card_t *p15card,
const sc_pkcs15_object_t *obj, const sc_pkcs15_pubkey_info_t *in_key)
{
sc_pkcs15_pubkey_info_t key = *in_key;
-
+
if (key.access_flags == 0)
key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
@@ -459,8 +414,7 @@ int sc_pkcs15emu_object_add(sc_pkcs15_card_t *p15card, unsigned int type,
data_len = sizeof(struct sc_pkcs15_data_info);
break;
default:
- sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL,
- "Unknown PKCS15 object type %d\n", type);
+ sc_log(p15card->card->ctx, "Unknown PKCS15 object type %d", type);
free(obj);
return SC_ERROR_INVALID_ARGUMENTS;
}
diff --git a/src/libopensc/pkcs15-syn.h b/src/libopensc/pkcs15-syn.h
new file mode 100644
index 0000000..8a52aa6
--- /dev/null
+++ b/src/libopensc/pkcs15-syn.h
@@ -0,0 +1,63 @@
+/*
+ * pkcs15-syn.c: PKCS #15 emulation of non-pkcs15 cards
+ *
+ * Copyright (C) 2003 Olaf Kirch <okir at suse.de>
+ * 2004 Nils Larsch <nlarsch at betrusted.com>
+ *
+ * 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
+ */
+
+#ifndef PKCS15_SYN_H
+#define PKCS15_SYN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <libopensc/types.h>
+#include <libopensc/pkcs15.h>
+
+int sc_pkcs15emu_westcos_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *, sc_pkcs15emu_opt_t *opts);
+int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_infocamere_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_starcert_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_tcos_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_esteid_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_postecert_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_piv_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *, sc_pkcs15emu_opt_t *opts);
+int sc_pkcs15emu_gemsafeGPK_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *, sc_pkcs15emu_opt_t *opts);
+int sc_pkcs15emu_gemsafeV1_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *, sc_pkcs15emu_opt_t *opts);
+int sc_pkcs15emu_actalis_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *, sc_pkcs15emu_opt_t *opts);
+int sc_pkcs15emu_atrust_acos_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *, sc_pkcs15emu_opt_t *opts);
+int sc_pkcs15emu_tccardos_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_entersafe_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_pteid_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_oberthur_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_itacns_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_sc_hsm_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_dnie_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_gids_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_iasecc_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+
+struct sc_pkcs15_emulator_handler {
+ const char *name;
+ int (*handler)(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/libopensc/pkcs15-tccardos.c b/src/libopensc/pkcs15-tccardos.c
index b8bb5e9..e8017d1 100644
--- a/src/libopensc/pkcs15-tccardos.c
+++ b/src/libopensc/pkcs15-tccardos.c
@@ -42,6 +42,7 @@
#define TC_CARDOS_PIN_MASK 0x3000
int sc_pkcs15emu_tccardos_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *,
sc_pkcs15emu_opt_t *opts);
static int read_file(struct sc_card *card, const char *file, u8 *buf,
@@ -348,6 +349,7 @@ static int sc_pkcs15_tccardos_init_func(sc_pkcs15_card_t *p15card)
}
int sc_pkcs15emu_tccardos_init_ex(sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts)
{
return sc_pkcs15_tccardos_init_func(p15card);
diff --git a/src/libopensc/pkcs15-tcos.c b/src/libopensc/pkcs15-tcos.c
index 2971288..f1415ff 100644
--- a/src/libopensc/pkcs15-tcos.c
+++ b/src/libopensc/pkcs15-tcos.c
@@ -35,6 +35,7 @@
int sc_pkcs15emu_tcos_init_ex(
sc_pkcs15_card_t *p15card,
+ struct sc_aid *,
sc_pkcs15emu_opt_t *opts);
static int insert_cert(
@@ -488,6 +489,7 @@ static int detect_unicard(
int sc_pkcs15emu_tcos_init_ex(
sc_pkcs15_card_t *p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t *opts
){
sc_card_t *card = p15card->card;
diff --git a/src/libopensc/pkcs15-westcos.c b/src/libopensc/pkcs15-westcos.c
index 20cfe8b..a85557a 100644
--- a/src/libopensc/pkcs15-westcos.c
+++ b/src/libopensc/pkcs15-westcos.c
@@ -31,7 +31,7 @@
#include "cardctl.h"
#include "common/compat_strlcpy.h"
-int sc_pkcs15emu_westcos_init_ex(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
+int sc_pkcs15emu_westcos_init_ex(sc_pkcs15_card_t *, struct sc_aid *, sc_pkcs15emu_opt_t *);
static int sc_pkcs15emu_westcos_init(sc_pkcs15_card_t * p15card)
{
@@ -239,6 +239,7 @@ static int westcos_detect_card(sc_pkcs15_card_t * p15card)
}
int sc_pkcs15emu_westcos_init_ex(sc_pkcs15_card_t * p15card,
+ struct sc_aid *aid,
sc_pkcs15emu_opt_t * opts)
{
int r;
diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c
index c0c7bc3..c1bf176 100644
--- a/src/libopensc/pkcs15.c
+++ b/src/libopensc/pkcs15.c
@@ -1223,7 +1223,7 @@ sc_pkcs15_bind(struct sc_card *card, struct sc_aid *aid,
sc_log(ctx, "PKCS#15 emulation enabled");
emu_first = scconf_get_bool(conf_block, "try_emulation_first", 0);
if (emu_first || sc_pkcs15_is_emulation_only(card)) {
- r = sc_pkcs15_bind_synthetic(p15card);
+ r = sc_pkcs15_bind_synthetic(p15card, aid);
if (r == SC_SUCCESS)
goto done;
r = sc_pkcs15_bind_internal(p15card, aid);
@@ -1233,7 +1233,7 @@ sc_pkcs15_bind(struct sc_card *card, struct sc_aid *aid,
r = sc_pkcs15_bind_internal(p15card, aid);
if (r == SC_SUCCESS)
goto done;
- r = sc_pkcs15_bind_synthetic(p15card);
+ r = sc_pkcs15_bind_synthetic(p15card, aid);
if (r < 0)
goto error;
}
@@ -1279,6 +1279,7 @@ __sc_pkcs15_search_objects(struct sc_pkcs15_card *p15card, unsigned int class_ma
struct sc_pkcs15_df *df = NULL;
unsigned int df_mask = 0;
size_t match_count = 0;
+ int r;
if (type)
class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
@@ -1315,9 +1316,12 @@ __sc_pkcs15_search_objects(struct sc_pkcs15_card *p15card, unsigned int class_ma
}
if (df->enumerated)
continue;
- /* Enumerate the DF's, so p15card->obj_list is
- * populated. */
- if (SC_SUCCESS != sc_pkcs15_parse_df(p15card, df))
+ /* Enumerate the DF's, so p15card->obj_list is populated. */
+ if (p15card->ops.parse_df)
+ r = p15card->ops.parse_df(p15card, df);
+ else
+ r = sc_pkcs15_parse_df(p15card, df);
+ if (r != SC_SUCCESS)
continue;
}
@@ -2022,11 +2026,6 @@ sc_pkcs15_parse_df(struct sc_pkcs15_card *p15card, struct sc_pkcs15_df *df)
sc_log(ctx, "called; path=%s, type=%d, enum=%d", sc_print_path(&df->path), df->type, df->enumerated);
- if (p15card->ops.parse_df) {
- r = p15card->ops.parse_df(p15card, df);
- LOG_FUNC_RETURN(ctx, r);
- }
-
if (df->enumerated)
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
diff --git a/src/libopensc/pkcs15.h b/src/libopensc/pkcs15.h
index b8aa659..42d4fce 100644
--- a/src/libopensc/pkcs15.h
+++ b/src/libopensc/pkcs15.h
@@ -945,7 +945,7 @@ typedef struct sc_pkcs15emu_opt {
#define SC_PKCS15EMU_FLAGS_NO_CHECK 0x00000001
-extern int sc_pkcs15_bind_synthetic(struct sc_pkcs15_card *);
+extern int sc_pkcs15_bind_synthetic(struct sc_pkcs15_card *, struct sc_aid *);
extern int sc_pkcs15_is_emulation_only(sc_card_t *);
int sc_pkcs15emu_object_add(struct sc_pkcs15_card *, unsigned int,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git
More information about the pkg-opensc-commit
mailing list