我有两个智能卡读卡器连接到我的计算机上,每个读卡器都插入了一张卡。使用PKCS 11 API,我想知道智能卡的用户PIN是否已锁定。根据documentation接口,我们必须检索结构CK_TOKEN_INFO的一个对象,该对象包含flags字段。在那里,如果个人识别码被锁定,则设置位标志CKF_SO_PIN_LOCKED。
我的问题是,如果我有一个锁定的智能卡和一个解锁的智能卡,flags字段不会改变。我知道我的两个芯片卡中有一个具有锁定的用户PIN。我输入了6次错误的PIN,我们用来写在智能卡上的程序告诉我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有误吗?
发布于 2018-01-02 23:44:52
我试过他的评论中提到的jariq工具,似乎我们使用的API实现确实有一个bug。你可以在下面的图片中看到它。它显示两张卡都没有被锁定。但其中一个是锁着的。谢谢你贾里克。

https://stackoverflow.com/questions/48061087
复制相似问题