Girocard-Maestro 智能卡 reader 问题,读取持卡人姓名和 IBAN

Girocard-Maestro Smartcard reader issues, to read Card Holder Name and IBAN

按照 on this card reader project, and using this AID List 描述的例程,我能够读取 VISA 卡而没有任何问题强制执行 AID 列表。现在我在阅读德国的 EC-Karten (Sparkasse Girocard) 时遇到了问题。

  1. 当我尝试强制读取 AID 列表时,使用

           foreach (byte[] aid in aidList)
           {
    
               byte[] atrValue = this.cardUpdater.GetAttribute(SCARD_ATTR_VALUE.ATR_STRING);
               string strATR = ByteArrayToString(atrValue);
    
    
               APDUCommand apduSelectEMVApl = null;
               APDUResponse apdu2 = null;
    
               apduSelectEMVApl = new APDUCommand(0x00, 0xA4, 0x04, 0x00, aid, 95);
               apdu2 = this.cardUpdater.Transmit(apduSelectEMVApl);
    
              if (apdu2.SW1 == 0x90)
               {
                   //Label = ASCIIEncoding.ASCII.GetString(apdu2.Data, 15, apdu2.Data[14]);
                   //found it!
                   m_EMVAID = aid;
                   if (apdu2.Data[0] == 0x6f)  //fci template
                   {
                       ExtractData(ReadTagData(apdu2.Data, 0));
                   }
                   return true;
    
               }
    
           }
        return false;
    

Note: AID Successfuly read for selection is A0000003591010028001

如果我没有将 APDU 命令的长度参数专门设置为 95,而不是所有项目中看到的标准 0(以获得最大长度),它不会响应 90-00(成功)。我只是通过迭代找到了这个值,看看哪个长度是可以接受的。为什么?

通过这个程序,我能够读取 BIC 和卡类型 ("girocard"),以及 PDOL 等数据:

9F33029F35019F4001

然后我尝试按照 this post 提高安全级别。但是那些 select 和读取的 APDU 命令在我的情况下不会抛出 90-00(而是 6700)。

  1. 我尝试通过

    获取SFI记录
        APDUCommand apduGPO = new APDUCommand(0x80, 0xa8, 0, 0, new byte[] { 0x83, 0 }, 0);
        APDUResponse apdu1 = this.cardUpdater.Transmit(apduGPO);
        if (apdu1.SW1 != 0x90) throw new Exception("Read GPO Data fail");
        //two possible forms, 0x80 and 0x77
        if (apdu1.Data[0] == 0x80)
        {
            for (int i = 4; i < apdu1.Data.Length; i += 4)
            {
                byte sfi = (byte)((apdu1.Data[i] >> 3) & 0xf);
                byte lowRange = apdu1.Data[i + 1];
                byte hiRange = apdu1.Data[i + 2];
                byte[] records = new byte[hiRange - lowRange + 1];
                for (int j = lowRange; j <= hiRange; j++)
                    records[j - lowRange] = (byte)j;
                sfiRecords.Add(new SFIRecords(sfi, records));
            }
        }
        else if (apdu1.Data[0] == 0x77)
        {
            //look for the application file locator AFL
            int a, tag;
            for (a = 2; (tag = ReadTag(apdu1.Data, a)) != 0x94; a = SkipTag(apdu1.Data, a)) ;
            if (tag == 0x94)
            {
                //found it
                a++;
                int len = apdu1.Data[a++];
                for (int i = a; i < a + len; i += 4)
                {
                    byte sfi = (byte)((apdu1.Data[i] >> 3) & 0xf);
                    byte lowRange = apdu1.Data[i + 1];
                    byte hiRange = apdu1.Data[i + 2];
                    byte[] records = new byte[hiRange - lowRange + 1];
                    for (int j = lowRange; j <= hiRange; j++)
                        records[j - lowRange] = (byte)j;
                    sfiRecords.Add(new SFIRecords(sfi, records));
                }
            }
        }
        else
            throw new Exception("Unknown GPO template");
    

正如我从包括 Openscdp's Initiate Application Process 在内的许多其他来源读到的,但将 PDOL 发送为

       APDUCommand apduGPO = new APDUCommand(0x80, 0xa8, 0, 0, pdol, 0);
       APDUResponse apdu1 = this.cardUpdater.Transmit(apduGPO);

        APDUCommand apduGPO = new APDUCommand(0x80, 0xa8, 0, 0, new byte[]{0x83, 0x00}, 0);
        APDUResponse apdu1 = this.cardUpdater.Transmit(apduGPO);

在 apduGPOResponse 上不再继续(再次出现错误 6700,抛出异常读取 GPO 失败,结果不成功),因此我无法将 SFI 记录添加到列表中以进一步迭代数据[0 ] 并查找要阅读的记录。没有 90-00 响应。

想知道我错过了什么吗?

已更新

我 运行 这段代码直接强制读取所有可能的值,而不使用 GPO:

        APDUCommand apduReadAll = null;
        APDUResponse apdu1 = null;
         for (var sfi = 1; sfi <= 31; sfi++)
        {
            for (var rec = 1; rec <= 16; rec++)
            {

                for (byte le = 0; le < 255; le++)
                {
                    apduReadAll = new APDUCommand(0x00, 0xB2, (byte)rec, (byte)((sfi << 3) | 4), null, le);
                    apdu1 = this.cardUpdater.Transmit(apduReadAll);

                    if (apdu1.SW1 == 0x90)
                    {
                        Console.WriteLine("SFI " + sfi.ToString() + " record #" + rec);
                        if (apdu1.Data[0] == 0x70 || apdu1.Data[0] == 0x77)
                        {
                            Console.WriteLine("Chalk one here " + sfi.ToString() + " record #" + rec + " len " + le);
                            try
                            {
                                ExtractData(ReadTagData(apdu1.Data, 0));
                            }

                            catch
                            {

                            }
                            //if (!String.IsNullOrEmpty(NumberString) && !String.IsNullOrEmpty(Name) &&
                            //    !String.IsNullOrEmpty(ExpiryString) && !String.IsNullOrEmpty(CardType) &&
                            //    !String.IsNullOrEmpty(Label))
                            //    return;  //we have all info we need
                        }
                    }
                }
            }
        }
        foreach (TagData tag in Properties)
         {
             Console.WriteLine(tag.Name + " " + tag.DataString);
             strAllData += tag.Name + " " + tag.DataString + "\r\n";
         }

在结果中我找到了一些我需要的信息(现在我可以直接指向我需要加速这个过程的数据),以及一些其他有趣的信息:

Application Label girocard
Application Priority Indicator 02 
Application Identifier (AID) - card A0 00 00 00 59 45 43 01 00 
Application Label girocard
Application Priority Indicator 04 
Application Identifier (AID) - card A0 00 00 03 59 10 10 02 80 01 
Application Label girocard
Application Priority Indicator 04 
Application Identifier (AID) - card A0 00 00 00 04 30 60 
Application Label Maestro
Application Priority Indicator 07 
Application Identifier (AID) - card D2 76 00 00 25 45 50 02 00 
Application Label GeldKarte
Application Identifier (AID) - card A0 00 00 04 86 01 01 
Application Label girocard
Application Priority Indicator 05 

我将运行同样的程序与提到的从网卡返回的AID值进行比较,看看会发生什么,以便更好地理解。感谢您为我指明正确的方向。

为什么我需要将 Le 设置为 95 而不是 0(以获得最大长度)?

原因是该项目中 Transmit() 的实现有问题。当您传递一个 Le 设置为 0 的 APDUCommand 对象时,它会错误地将这种情况视为 Le 不存在,因此不会发送 Le 字段。参见 CardNative.cs on line 446。因此,

...Transmit(new APDUCommand(0x00, 0xA4, 0x04, 0x00, new byte[] { 1, 2, 3, 4, 5 }, 0));

导致将以下 APDU 发送到卡:

00 A4 0400 05 0102030405

然而,您真正想要的是以下 APDU(它有一个 Le 字段):

00 A4 0400 05 0102030405 00

这可以通过区分 Le 不存在(表示没有预期的响应数据,Ne = 0)和 Le 为 0(表示预期最多 256 字节的响应数据,Ne = 256)这两种情况来解决。

接下来是什么命令?

由于您没有透露所选应用程序的 AID(甚至更好的是 SELECT 响应),因此无法判断它可能使用哪种协议。 到目前为止所有命令似乎都因长度错误 (SW = 0x6700) 而被拒绝,这似乎与第一个问题中的问题有关。

由于您引用的 AID 列表表明 Girocard 应用程序符合某种形式的 EMV,并且您收到了 9F33029F35019F4001 的 PDOL 值,您可以尝试发出 GET PROCESSING OPTIONS 命令(类似于您目前正在努力)。由于卡片提供了PDOL,需要在GPO命令中将PDOL相关的数据对象填入期望值。

PDOL 列出了以下元素:

  • 9F33(2 个字节)
  • 9F35(1 字节)
  • 9F40(1 字节)

所以您可以尝试创建一个 PDOL 相关数据对象,用零填充所有这些元素:

0000 00 00

请注意,您的卡片可能需要一些特定的值。由于 PDOL 中的数据对象与其在 EMV 中的定义不匹配(9F33(终端功能)的长度应为 3,而 9F40(附加终端功能)的长度应为 5),我不能'不要告诉他们实际的 meaning/coding.

GPO 命令可能如下所示:

APDUCommand apduGPO = new APDUCommand(0x80, 0xa8, 0, 0, new byte[] { 0x83, 4, 0, 0, 0, 0 }, 0);

同样,这只有在您解决了 Le 字段的问题后才有效。