PKCS 11为我的芯片卡返回错误的令牌信息

问题描述 投票:2回答:1

我有两个智能卡读卡器连接到我的电脑,每个都插有一张卡。使用PKCS 11 API我想知道智能卡的用户PIN是否被锁定。根据API documentation,我们必须检索包含CK_TOKEN_INFO字段的struct flags的对象。在那里,如果PIN被锁定,则设置位标志CKF_SO_PIN_LOCKED

我的问题是,如果我有一个锁定的智能卡和一个未锁定的智能卡,flags字段不会改变。我知道我的两张芯片卡中有一张锁定了用户PIN码。我输入了错误的PIN 6次,我们用来在智能卡上写的程序告诉我PIN确实被锁定了。然而,两张卡的flags字段相同。

这是一个演示该问题的最小程序:

  #include <iostream>
  #include <vector>
  #include "cm-pkcs11.h"

  unsigned long slotCount = 0ul;
  CK_RV result;

  std::vector<CK_SLOT_ID> vecSlotIds;

  int main() {

    result = C_Initialize(nullptr);

    result = C_GetSlotList(CK_TRUE, nullptr, &slotCount);

    std::cout << "Found " << slotCount << " slots" << std::endl;

    vecSlotIds.resize(slotCount);
    result = C_GetSlotList(CK_TRUE, vecSlotIds.data(), &slotCount);

    for (const auto& id : vecSlotIds) {
      CK_TOKEN_INFO tokenInfo = {};
      result = C_GetTokenInfo(id, &tokenInfo);
      std::cout << "id: " << id << ", flags: " << tokenInfo.flags << std::endl;
    }

    return 0;
  }

输出是:

Found 2 slots id: 1, flags: 1037 id: 2, flags: 1037

如你所见,两个flags是相同的。我在这里使用的API不正确吗?

smartcard pkcs#11
1个回答
1
投票

我已经尝试过他的评论中提到的工具jariq,看起来我们使用的API实现确实存在一个错误。您可以在下面的图片中看到它。它说这两张卡都没有上锁。但其中一个被锁定了。谢谢jariq。

The tool uses our pkcs11.so and shows also that the card is not locked. But it is locked.

© www.soinside.com 2019 - 2024. All rights reserved.