简体   繁体   English

Java:从密钥库文件确定密钥库的类型

[英]Java: Determine type of KeyStore from Keystore file

So I have an application in which I'm allowing the user to configure the server with HTTPS. 因此,我有一个允许用户使用HTTPS配置服务器的应用程序。 The server uses Undertow. 服务器使用Undertow。 To add a HTTPS handler to Undertow, I need to make a call to Keystore.getInstance("JKS") function which returns the implementation based on the provider. 要将HTTPS处理程序添加到Undertow,我需要调用Keystore.getInstance(“ JKS”)函数,该函数将基于提供程序返回实现。 Java natively supports only 3 providers(JKS, PKCS12 and JCEKS) but from my understanding, you can add your own provider of Keystore implementation. Java本机仅支持3个提供程序(JKS,PKCS12和JCEKS),但是据我了解,您可以添加自己的Keystore实现提供程序。

So my question is, given just the keystore file, is it possible to determine what type of Keystore it is? 所以我的问题是,仅给出密钥库文件,是否可以确定它是什么类型的密钥库? I cannot rely on file extension as PKCS12 keystores can be stored in .p12 file extension as well. 我不能依靠文件扩展名,因为PKCS12密钥库也可以存储在.p12文件扩展名中。 Is there I can get this value programmatically so that I can pass it to Keystore.getInstance() or do I have to just take that input from the user? 是否可以通过编程获取该值,以便将其传递给Keystore.getInstance(),还是必须仅从用户那里获取输入值?

Currently in WildFly there is in progress such feature using Elytron project. 当前在WildFly中,使用Elytron项目正在开发此类功能。 You can have a look [1]. 您可以看一下[1]。

Some of keystores can be distinguished by format pattern. 一些密钥库可以通过格式模式来区分。 But I think in your case easiest is to try to load one by one Keystore.getInstance("PKCS12"), Keystore.getInstance("JKS"), Keystore.getInstance("JCEKS") and see which one passes. 但是我认为,在您的情况下,最简单的方法是尝试一次加载一个Keystore.getInstance(“ PKCS12”),Keystore.getInstance(“ JKS”),Keystore.getInstance(“ JCEKS”)并查看哪一个通过。

Also I think user will be ok with providing keystore type. 我也认为用户可以提供密钥库类型。

[1] https://issues.jboss.org/browse/WFCORE-4058 [1] https://issues.jboss.org/browse/WFCORE-4058

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM