From 75c1254e22cee73dfc43ffd762dda9d84a55c30b Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 9 Jan 2011 10:17:16 +0000 Subject: [PATCH] Initial modifications to support OpenPGP v2.0 (CryptoStick) * Correct naming: openpgp not opengpg * Set the card name from ATR table * Add card type enums * Currently OpenPGP is read-only. git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5072 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/libopensc/card-openpgp.c | 18 +++++++++++++----- src/libopensc/cards.h | 3 ++- src/libopensc/ctx.c | 2 +- src/libopensc/pkcs15-openpgp.c | 5 ++++- src/libopensc/pkcs15-syn.c | 2 ++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c index 4c6285ba..a8fba4ea 100644 --- a/src/libopensc/card-openpgp.c +++ b/src/libopensc/card-openpgp.c @@ -18,6 +18,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + * Specifications: + * http://www.g10code.de/docs/openpgp-card-1.1.pdf + * http://www.g10code.de/docs/openpgp-card-2.0.pdf + */ + #include "config.h" #include @@ -29,7 +35,8 @@ #include "cardctl.h" static struct sc_atr_table pgp_atrs[] = { - { "3b:fa:13:00:ff:81:31:80:45:00:31:c1:73:c0:01:00:00:90:00:b1", NULL, NULL, SC_CARD_TYPE_OPENPGP_GENERIC, 0, NULL }, + { "3b:fa:13:00:ff:81:31:80:45:00:31:c1:73:c0:01:00:00:90:00:b1", NULL, "OpenPGP card v1.0/1.1", SC_CARD_TYPE_OPENPGP_V1, 0, NULL }, + { "3b:da:18:ff:81:b1:fe:75:1f:03:00:31:c5:73:c0:01:40:00:90:00:0c", NULL, "CryptoStick v1.2 (OpenPGP v2.0)", SC_CARD_TYPE_OPENPGP_V2, 0, NULL }, { NULL, NULL, NULL, 0, 0, NULL } }; @@ -115,9 +122,11 @@ pgp_match_card(sc_card_t *card) int i; i = _sc_match_atr(card, pgp_atrs, &card->type); - if (i < 0) - return 0; - return 1; + if (i >= 0) { + card->name = pgp_atrs[i].name; + return 1; + } + return 0; } static int @@ -133,7 +142,6 @@ pgp_init(sc_card_t *card) priv = calloc (1, sizeof *priv); if (!priv) return SC_ERROR_OUT_OF_MEMORY; - card->name = "OpenPGP"; card->drv_data = priv; card->cla = 0x00; diff --git a/src/libopensc/cards.h b/src/libopensc/cards.h index c8fc24e7..5ab07366 100644 --- a/src/libopensc/cards.h +++ b/src/libopensc/cards.h @@ -101,7 +101,8 @@ enum { /* openpgp driver */ SC_CARD_TYPE_OPENPGP_BASE = 9000, - SC_CARD_TYPE_OPENPGP_GENERIC, + SC_CARD_TYPE_OPENPGP_V1, + SC_CARD_TYPE_OPENPGP_V2, /* jcop driver */ SC_CARD_TYPE_JCOP_BASE = 10000, diff --git a/src/libopensc/ctx.c b/src/libopensc/ctx.c index c6075005..512a382e 100644 --- a/src/libopensc/ctx.c +++ b/src/libopensc/ctx.c @@ -62,7 +62,7 @@ static const struct _sc_driver_entry internal_card_drivers[] = { { "asepcos", (void *(*)(void)) sc_get_asepcos_driver }, { "starcos", (void *(*)(void)) sc_get_starcos_driver }, { "tcos", (void *(*)(void)) sc_get_tcos_driver }, - { "opengpg", (void *(*)(void)) sc_get_openpgp_driver }, + { "openpgp", (void *(*)(void)) sc_get_openpgp_driver }, { "jcop", (void *(*)(void)) sc_get_jcop_driver }, #ifdef ENABLE_OPENSSL { "oberthur", (void *(*)(void)) sc_get_oberthur_driver }, diff --git a/src/libopensc/pkcs15-openpgp.c b/src/libopensc/pkcs15-openpgp.c index 646e5d54..9abb1974 100644 --- a/src/libopensc/pkcs15-openpgp.c +++ b/src/libopensc/pkcs15-openpgp.c @@ -236,7 +236,10 @@ failed: sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Failed to initialize OpenPGP e static int openpgp_detect_card(sc_pkcs15_card_t *p15card) { - return strcmp(p15card->card->name, "OpenPGP"); + if (p15card->card->type == SC_CARD_TYPE_OPENPGP_V1 || p15card->card->type == SC_CARD_TYPE_OPENPGP_V2) + return SC_SUCCESS; + else + return SC_ERROR_WRONG_CARD; } int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *p15card, diff --git a/src/libopensc/pkcs15-syn.c b/src/libopensc/pkcs15-syn.c index c6f9f570..0bf1baa9 100644 --- a/src/libopensc/pkcs15-syn.c +++ b/src/libopensc/pkcs15-syn.c @@ -107,6 +107,8 @@ int sc_pkcs15_is_emulation_only(sc_card_t *card) case SC_CARD_TYPE_MCRD_ESTEID_V30: case SC_CARD_TYPE_IAS_PTEID: case SC_CARD_TYPE_GEMSAFEV1_PTEID: + case SC_CARD_TYPE_OPENPGP_V1: + case SC_CARD_TYPE_OPENPGP_V2: return 1; default: return 0;