如何使用通用访问卡连接到 HTTPS 服务器
我需要编写一个 java 程序来连接到 HTTPS 服务器(DoD 网站)。 该网站需要 CAC(DoD 通用访问卡)身份验证。 如果您通过浏览器访问此站点,请先插入 CAC,然后输入 PIN。
我需要在java中以编程方式完成身份验证过程(有点像浏览器)。 如何从 CAC 检索信息? 我一直在谷歌搜索并阅读 Java PKCS#11 参考指南。 似乎 Sun PKCS#11 Provider 可以做到这一点,但您需要本机 PKCS#11 令牌实现。
我对吗? 以前有人这样做过吗? 任何建议或评论将不胜感激。
I need to write a java program to connect to a HTTPS server (DoD website). The website requires CAC (DoD common access card) authentication. If you access this site via browser, you insert your CAC first, and then enter a PIN.
I need to accomplish the authentication process programmatically in java (kind of acting like browser). How do I retrieve the information from the CAC? I have been Googling around and read the Java PKCS#11 Reference Guide. Seems like Sun PKCS#11 Provider can do it, but you need the native PKCS#11 token implementation.
Am I right? Has anybody done this before? Any suggestion or comment will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要安装 PKCS #11 支持。 这是读卡器可能附带的一些本机代码,它提供了 .dll(或 .so),该 .dll(或 .so)提供了 PKCS #11 接口。 系统上的其他软件(例如 Mozilla 产品和 Sun 的 PKCS #11 提供程序)使用此库。 (Microsoft 产品通常使用不同的接口“CAPI”。)
然后,按照 PKCS #11 参考指南, 设置
SunPKCS11
提供程序。 我必须在设置中提供的唯一属性是安装的本机“库”的位置以及该提供程序的“名称”后缀。 “name”属性附加到“SunPKCS11-”,因此如果您指定“CAC”作为名称,则可以稍后使用Security.getProvider("SunPKCS11-CAC" 查找
。Provider
)然后,您可以使用标准 JSSE 系统属性
javax.net.ssl.keyStore
(值为"NONE"
)和javax.net.ssl。 keyStoreType
(值为“PKCS11”
),让 JSSE 能够访问 CAC 上的密钥材料。 您不需要设置密码属性,因为本机代码应在需要时提示用户输入 PIN。需要注意的是,CAC 只能提供用户的“最终实体”证书。 为了构建可信链,大多数服务器希望客户端发送任何中间证书。 解决这个问题是可能的,但很复杂,因为它涉及实现您自己的
javax.net.ssl.X509KeyManager
。 如果您使用的服务器需要完整的链,请发布后续问题。First, you need to install PKCS #11 support. This is some native code that probably came with your card reader that provides a .dll (or .so) that provides a PKCS #11 interface. Other software on the system, like Mozilla products and Sun's PKCS #11 provider, uses this library. (Microsoft products often use a different interface, "CAPI".)
Then, following the directions in the PKCS #11 Reference Guide, set up a
SunPKCS11
provider. The only properties that I had to supply in my setup are the location of the native "library" that was installed, and the "name" suffix for this provider. The "name" property is appended to "SunPKCS11-", so if you specify "CAC" for the name, you can lookup theProvider
later withSecurity.getProvider("SunPKCS11-CAC")
.Then, you can use the standard JSSE system properties
javax.net.ssl.keyStore
(with a value of"NONE"
) andjavax.net.ssl.keyStoreType
(with a value of"PKCS11"
) to give the JSSE access to the key material on the CAC. You don't need to set the password property, because the native code should prompt the user for their PIN when needed.The caveat is that only the user's "end entity" certificate is available from the CAC. To build a trusted chain, most servers expect the client to send any intermediate certificates. Working around this is possible, but complicated, as it involves implementing your own
javax.net.ssl.X509KeyManager
. If the server you are working with requires a complete chain, please post a follow-up question.