【问题标题】:Get X509Certificates from smart card without authentication无需身份验证即可从智能卡获取 X509Certificates
【发布时间】:2016-07-21 09:32:36
【问题描述】:

我想在不登录(无 PIN)的情况下从我的智能卡中检索 X509Certificate 列表。

我的代码如下:

    String conf = args[0];
    Provider p = new sun.security.pkcs11.SunPKCS11(conf);
    Security.addProvider(p);

    KeyStore ks = KeyStore.getInstance("PKCS11");

    1) ks.load(null, null);
    2) ks.load(null, "".toCharArray());

第一个测试 (1) 因 StackTrace 失败:

Exception in thread "main" java.io.IOException: load failed
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:763)
    at java.security.KeyStore.load(Unknown Source)
    at TestPKCS11.main(TestPKCS11.java:29)
Caused by: javax.security.auth.login.LoginException: no password provided, and n
o callback handler available for retrieving password
        at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1184)
        at sun.security.pkcs11.P11KeyStore.login(P11KeyStore.java:849)
        at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:751)

第二个 (2) 失败:

Exception in thread "main" java.io.IOException: load failed
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:763)
    at java.security.KeyStore.load(Unknown Source)
    at TestPKCS11.main(TestPKCS11.java:30)
Caused by: javax.security.auth.login.LoginException
        at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1238)
        at sun.security.pkcs11.P11KeyStore.login(P11KeyStore.java:849)
        at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:753)
        ... 2 more
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_PIN_INVALID
        at sun.security.pkcs11.wrapper.PKCS11.C_Login(Native Method)
        at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1222)

我的配置如下:

name=SmartCard
slotListIndex = 0
library=C:\gclib.dll
attributes(*,CKO_PUBLIC_KEY,*)={ CKA_TOKEN=true } 

注意:我有一个不需要 PIN 来显示证书的本地工具(经典客户端工具箱)。

【问题讨论】:

  • 我找到了两个解决这个问题的方法: 1. 使用 MSCapi。缺点:这仅适用于 Windows 机器,优点:无需添加自定义开发,并且适用于任何智能卡 1. 使用智能卡驱动程序。缺点:开发可能很棘手,我们必须为每个智能卡提供商/驱动程序实现。优点:适用于任何操作系统

标签: java x509certificate smartcard pkcs#11


【解决方案1】:

看起来 Sun 的提供商总是调用 Login,无论您是否想登录。坦率地说,唯一的选择可能是改变方法,例如使用其他方式访问 PKCS#11 设备(例如,我们的 SecureBlackbox 中有这样的机制)。

另一方面,在不登录设备的情况下检索信息的可能性是一种信息泄漏,因此获取列表或证书本身的可能性取决于特定的设备。在您的设备上有效的东西可能在其他设备上无效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多