Skip to content

Commit

Permalink
openpgp: match application, not ATR
Browse files Browse the repository at this point in the history
fixes #391
closes #507
  • Loading branch information
Frank Morgner committed Sep 16, 2015
1 parent b28c48a commit d20290d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion src/libopensc/card-openpgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ struct pgp_priv_data {
sc_security_env_t sec_env;
};

/* ABI: check if card's ATR matches one of driver's */
/* ABI: check if card's ATR matches one of driver's
* or if the OpenPGP application is present */
static int
pgp_match_card(sc_card_t *card)
{
Expand All @@ -321,6 +322,24 @@ pgp_match_card(sc_card_t *card)
if (i >= 0) {
card->name = pgp_atrs[i].name;
return 1;
} else {
sc_path_t partial_aid;
unsigned char aid[16];

/* select application "OpenPGP" */
sc_format_path("D276:0001:2401", &partial_aid);
partial_aid.type = SC_PATH_TYPE_DF_NAME;
if (SC_SUCCESS == iso_ops->select_file(card, &partial_aid, NULL)) {
/* read information from AID */
i = sc_get_data(card, 0x004F, aid, sizeof aid);
if (i == 16) {
if (((aid[6] << 8) | aid[7]) >= 0x0200)
card->type = SC_CARD_TYPE_OPENPGP_V2;
else
card->type = SC_CARD_TYPE_OPENPGP_V1;
return 1;
}
}
}
return 0;
}
Expand Down Expand Up @@ -368,6 +387,16 @@ pgp_init(sc_card_t *card)
return SC_ERROR_OBJECT_NOT_FOUND;
}

if (file->namelen != 16) {
/* explicitly get the full aid */
r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
if (r < 0) {
pgp_finish(card);
return r;
}
file->namelen = r;
}

/* read information from AID */
if (file->namelen == 16) {
/* OpenPGP card spec 1.1 & 2.0, section 4.2.1 & 4.1.2.1 */
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ 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 },
{ "openpgp", (void *(*)(void)) sc_get_openpgp_driver },
{ "jcop", (void *(*)(void)) sc_get_jcop_driver },
#ifdef ENABLE_OPENSSL
{ "oberthur", (void *(*)(void)) sc_get_oberthur_driver },
Expand Down Expand Up @@ -112,6 +111,7 @@ static const struct _sc_driver_entry internal_card_drivers[] = {
{ "PIV-II", (void *(*)(void)) sc_get_piv_driver },
{ "itacns", (void *(*)(void)) sc_get_itacns_driver },
{ "isoApplet", (void *(*)(void)) sc_get_isoApplet_driver },
{ "openpgp", (void *(*)(void)) sc_get_openpgp_driver },
/* The default driver should be last, as it handles all the
* unrecognized cards. */
{ "default", (void *(*)(void)) sc_get_default_driver },
Expand Down

0 comments on commit d20290d

Please sign in to comment.