如何创建自定义SSLSocketFactory? [英] How to create custom SSLSocketFactory?

查看:2102
本文介绍了如何创建自定义SSLSocketFactory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建自己的

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):

import javax.net.ssl.SSLSocketFactory;
// ...
return SSLSocketFactory.getDefault().createSocket(host, port);

当前使用的实现是com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.如何将其更改为自己的自定义类?

Current implementation used is com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl. How can I change it to my own custom class?

推荐答案

来自

(...)默认实现可以是 通过设置 "ssl.SocketFactory.provider"安全性 属性(在Java安全性中 属性文件)添加到所需的类.

(...) 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.

有关定义自己的安全策略文件的更多信息,请参见 http://download.oracle.com/javase/1.4.2/docs/guide/security/PolicyFiles.html .

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.

似乎您只能在JSM级别更改该属性,而不能为每个项目更改.在Windows中,您可以在Java \ jre6 \ lib \ security \ java.security中找到该文件.

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.

这篇关于如何创建自定义SSLSocketFactory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆