2

我有 .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

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

4

1 回答 1

3

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.
}
于 2018-03-12T18:00:25.187 回答