如何使用 PKCS11Interop 获取加密令牌(智能卡)的密码失败计数



我有 .Net 应用程序使用 PKCS11Interop 库与加密令牌(智能卡(进行交互,用户可以在其中登录到令牌并生成密钥对和签名。

如果用户多次输入错误的密码,令牌将被锁定,如何获得剩余的尝试次数才能登录令牌。

在互联网上搜索时,我遇到了Net.Pkcs11Interop.HighLevelAPI.TokenInfo.TokenFlags,其中包含此信息

CKF_USER_PIN_COUNT_LOW 0x00010000 True if an incorrect user login
PIN has been entered at least
once since the last successful
authentication.
CKF_USER_PIN_FINAL_TRY 0x00020000 True if supplying an incorrect
user PIN will cause it to
become locked.
CKF_USER_PIN_LOCKED 0x00040000 True if the user PIN has been locked. User login to the token
is not possible

但这些是布尔值,我需要剩余的确切重试次数。

PKCS#11 API 不提供剩余的确切重试次数。正如您正确发现的那样,它确实通过TokenFlags提供了类似的信息:

// Get token info
TokenInfo tokenInfo = slot.GetTokenInfo();
if (tokenInfo.TokenFlags.UserPinCountLow)
{
    // An incorrect user login PIN has been entered at least once since the last successful authentication
}
if (tokenInfo.TokenFlags.UserPinFinalTry)
{
    // Supplying an incorrect user PIN will make it to become locked
}
if (tokenInfo.TokenFlags.UserPinLocked)
{
    // User PIN has been locked. User login to the token is not possible.
}

最新更新