我有两个智能卡读卡器连接到我的电脑,每个都插有一张卡。使用PKCS 11 API我想知道智能卡的用户PIN是否被锁定。根据API documentation,我们必须检索包含CK_TOKEN_INFO
字段的结构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不正确吗?