From 41537cc827340f2fa1bcc41cb29ca46b9dc7af76 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 5 Jan 2012 15:14:35 +0900 Subject: [PATCH] check DF name on SELECT command --- ChangeLog | 2 ++ src/openpgp-do.c | 8 +++++--- src/openpgp.c | 13 ++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca30a90..185631e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2012-01-05 Niibe Yutaka + * src/openpgp.c (cmd_select_file): Check DF name. + * tool/pinpadtest.py: Rename from pinpad-test.py. 2011-12-28 Niibe Yutaka diff --git a/src/openpgp-do.c b/src/openpgp-do.c index c297939..714a0d0 100644 --- a/src/openpgp-do.c +++ b/src/openpgp-do.c @@ -417,10 +417,12 @@ do_kgtime_all (uint16_t tag, int with_tag) } const uint8_t openpgpcard_aid[] = { - 0xd2, 0x76, 0x00, 0x01, 0x24, 0x01, - 0x02, 0x00, /* Version 2.0 */ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* To be overwritten */ + 0xd2, 0x76, /* D: National, 276: DEU ISO 3166-1 */ + 0x00, 0x01, 0x24, /* Registered Application Provider Identifier */ + 0x01, /* Application: OpenPGPcard */ + 0x02, 0x00, /* Version 2.0 */ /* v. id */ /* serial number */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* To be overwritten */ }; static int diff --git a/src/openpgp.c b/src/openpgp.c index 9eb7f94..527503e 100644 --- a/src/openpgp.c +++ b/src/openpgp.c @@ -529,16 +529,19 @@ cmd_read_binary (void) static void cmd_select_file (void) { - if (cmd_APDU[2] == 4) /* Selection by DF name: it must be OpenPGP card */ + if (cmd_APDU[2] == 4) /* Selection by DF name */ { DEBUG_INFO (" - select DF by name\r\n"); - /* - * P2 == 0, LC=6, name = D2 76 00 01 24 01 - */ + /* name = D2 76 00 01 24 01 */ + if (cmd_APDU[4] != 6 || memcmp (openpgpcard_aid, &cmd_APDU[5], 6) != 0) + { + GPG_NO_FILE() + return; + } file_selection = FILE_DF_OPENPGP; - if (cmd_APDU[3] == 0x0c) /* No FCI */ + if ((cmd_APDU[3] & 0x0c) == 0x0c) /* No FCI */ GPG_SUCCESS (); else {