gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:42:15 27 4
gpt4 key购买 nike

遵循描述的例程 on this card reader project ,并使用 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 提高安全级别.但是在我的例子中,那些用于选择和读取的 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 响应),因此无法判断它可能使用哪种协议(protocol)。 到目前为止,所有命令似乎都被错误地拒绝了length error (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),我不能'不要说出它们的实际含义/编码。

GPO 命令可能如下所示:

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

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

关于c# - Girocard-Maestro 智能卡读卡器问题,读取持卡人姓名和 IBAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34355279/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com