openpgp: match application, not ATR

fixes #391
closes #507
This commit is contained in:
Frank Morgner 2015-07-29 00:26:19 +02:00
parent b28c48afe0
commit d20290d2b3
2 changed files with 31 additions and 2 deletions

View File

@ -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)
{
@ -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;
}
@ -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 */

View File

@ -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 },
@ -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 },