Java 应用程序的密钥库/信任库的默认位置是哪个?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4097432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which is the default location for keystore/truststore of Java applications?
提问by yura
I am writing an application that uses SSL. Hence, I have a dummy keystore and a dummy truststore I want to supply to my customer. Is there any default folder to put them inside my distribution? e.g. docs, lib, bin...etc. Where is usually the keystore put on the server and where is usually truststore put on the client?
我正在编写一个使用 SSL 的应用程序。因此,我有一个虚拟密钥库和一个虚拟信任库,我想提供给我的客户。是否有任何默认文件夹可以将它们放入我的发行版中?例如 docs、lib、bin...等。密钥库通常放在服务器上的什么位置,而信任库通常放在客户端的什么位置?
Thanks
谢谢
采纳答案by Bruno
In Java, according to the JSSE Reference Guide, there is no default for the keystore
, the default for the truststore
is "jssecacerts, if it exists. Otherwise, cacerts".
在 Java 中,根据JSSE 参考指南, 没有默认值keystore
,默认值truststore
是“ jssecacerts,如果存在。否则,cacerts”。
A few applications use ~/.keystore
as a default keystore, but this is not without problems (mainly because you might not want all the application run by the user to use that trust store).
一些应用程序~/.keystore
用作默认密钥库,但这并非没有问题(主要是因为您可能不希望用户运行的所有应用程序都使用该信任库)。
I'd suggest using application-specific values that you bundle with your application instead, it would tend to be more applicable in general.
我建议使用与应用程序捆绑在一起的特定于应用程序的值,它通常更适用。
回答by Kristian Benoit
Like bruno said, you're better configuring it yourself. Here's how I do it. Start by creating a properties file (/etc/myapp/config.properties).
就像布鲁诺说的,你最好自己配置它。这是我如何做到的。首先创建一个属性文件 (/etc/myapp/config.properties)。
javax.net.ssl.keyStore = /etc/myapp/keyStore
javax.net.ssl.keyStorePassword = 123456
Then load the properties to your environment from your code. This makes your application configurable.
然后将属性从您的代码加载到您的环境中。这使您的应用程序可配置。
FileInputStream propFile = new FileInputStream("/etc/myapp/config.properties");
Properties p = new Properties(System.getProperties());
p.load(propFile);
System.setProperties(p);