【问题标题】:Can't access all KeyStore aliases on USB Token无法访问 USB 令牌上的所有 KeyStore 别名
【发布时间】:2023-04-08 09:49:01
【问题描述】:

我曾经使用此代码访问用于在 USB 令牌上进行 PDF 签名的证书链:

this._keyStore = KeyStore.getInstance("PKCS11");
this._keyStore.load(null, myPassword);
Enumeration<String> aliases = this._keyStore.aliases();
while (aliases.hasMoreElements()) {
    String nextElement = (String) aliases.nextElement();
    System.out.println("Enumeration element : "+nextElement);
try
{
    this._privateKey = (PrivateKey) this._keyStore.getKey(nextElement, pass);
    this._certificatesChain = (X509Certificate[]) this._keyStore.getCertificateChain(nextElement);
    if (this._certificatesChain.length == 0) 
    {
        //Let's try another
        continue;
    }
    if (this._certificatesChain[0].getKeyUsage()[1]) 
    {
        //I want to use this
        break;
    }
}
catch (Exception e){continue;}

我收到了一个新的 USB 令牌,它不能用于此。似乎使用 PKCS11 只会读取 Token 上的两个证书之一,这不是我应该用于签名的那个。

我想出的最佳解决方案是在 Keystore.getInstance() 调用中使用“Windows-MY”,它可以访问所有证书(即使是那些不是来自 Token 的证书,但让我们交叉手指)。 这样做的最大缺点是,这样做会为整个签名过程创建两个 PIN 提示:第一次是我编写的提示用户输入 PIN 的提示;第二次是我尝试签名时——这次是使用 Windows 风格的提示符。

有没有办法使用 PKCS11 密钥库实例访问所有证书,或者避免 Windows 提示?

【问题讨论】:

  • 它是标准的 USB 存储密钥,还是加密设备?在第二种情况下,Pin 对于安全问题是正常的。
  • 这是一个 USB 签名令牌。

标签: java digital-signature keystore signing pkcs#11


【解决方案1】:

我考虑删除该帖子,因为我的代码中的其他地方有错误,但如果有人需要,我将把它留在这里:

问题是我用来读取证书的 dll (incryptoki2.dll) 不再适用于来自同一制造商的新密钥。切换到 bit4ipki.dll,现在我可以读取证书了。

【讨论】:

    猜你喜欢
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    相关资源
    最近更新 更多