使用 HTTP 4.1.1 的 ClientCustomSSL
谁能告诉我我们是否必须创建 my.keystore 文件,否则它将被创建。当我在 jsp 文件所在的同一目录(webapp 目录)中创建此文件时,我在 jsp 文件中使用此代码。
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File("my.keystore"));
try {
trustStore.load(instream, "nopassword".toCharArray());
} finally {
instream.close();
}
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
我收到错误
java.io.FileNotFoundException: my.keystore (The system cannot find the file spec
ified)
那么我应该把这个文件放在哪里。这是两个文件(即 jsp 文件和 my.keystore)的路径
C:\workspace\search-ui\search-ui\src\main\webapp
Can anybody tell me whether we have to create my.keystore file or it will be created. And when I created this file in the same directory(webapp directory) where my jsp file is and I am using this code in my jsp file.
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File("my.keystore"));
try {
trustStore.load(instream, "nopassword".toCharArray());
} finally {
instream.close();
}
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
And I got the error
java.io.FileNotFoundException: my.keystore (The system cannot find the file spec
ified)
So where should I put this file. this is the path for both of the file, that jsp file and my.keystore
C:\workspace\search-ui\search-ui\src\main\webapp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议将密钥库添加到类路径中,然后通过
将密钥库放在 webapp 下但不在 WEB-INF 下加载它是不安全的,因为任何人都可以下载它。此外,当使用相对文件路径时,通过 new File() 加载文件会在工作目录中查找 Java 进程(请参阅 JavaDoc)。这很可能位于您正在使用的 Servlet 容器的目录层次结构下的某个位置。
I would recommend adding the keystore to the classpath and then load it via
Putting the keystore under webapp but not under WEB-INF is insecure since anyone could just download it. Also, loading a file via
new File()
looks in the working directory for the Java process when a relative file path is used (see the JavaDoc). This is most likely somewhere under the directory hierarchy of the Servlet container you are using.除非您的服务器需要客户端身份验证,否则您根本不需要密钥库。是吗?
You don't need a keystore at all unless your server requires client authentication. Does it?