java 如何创建自定义 SSLSocketFactory?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6078492/
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
How to create custom SSLSocketFactory?
提问by yegor256
I'm trying to create my own implementation of javax.net.ssl.SSLSocketFactory
, in order to catch all HTTP/SSL requests, send by a third-party library, and log them. This is how the factory is called in that library (it's commons-httpclient):
我正在尝试创建自己的 实现javax.net.ssl.SSLSocketFactory
,以捕获所有 HTTP/SSL 请求,由第三方库发送,并记录它们。这是在该库中调用工厂的方式(它是 commons-httpclient):
import javax.net.ssl.SSLSocketFactory;
// ...
return SSLSocketFactory.getDefault().createSocket(host, port);
Current implementation used is com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl
. How can I change it to my own custom class?
当前使用的实现是com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl
. 如何将其更改为我自己的自定义类?
回答by Rui Gon?alves
From http://download.oracle.com/javase/1.4.2/docs/api/javax/net/ssl/SSLSocketFactory.html:
从http://download.oracle.com/javase/1.4.2/docs/api/javax/net/ssl/SSLSocketFactory.html:
(...) The default implementation can be changed by setting the value of the "ssl.SocketFactory.provider" security property (in the Java security properties file) to the desired class.
(...) 可以通过将“ssl.SocketFactory.provider”安全属性(在 Java 安全属性文件中)的值设置为所需的类来更改默认实现。
More information about defining your own security policy file can be found at http://download.oracle.com/javase/1.4.2/docs/guide/security/PolicyFiles.html.
有关定义您自己的安全策略文件的更多信息,请访问http://download.oracle.com/javase/1.4.2/docs/guide/security/PolicyFiles.html。
It seems that you can only change that property at the JSM level, and not for each project. In Windows, you can find that file at Java\jre6\lib\security\java.security.
似乎您只能在 JSM 级别更改该属性,而不能针对每个项目更改该属性。在 Windows 中,您可以在 Java\jre6\lib\security\java.security 中找到该文件。