jmeter3.0 源码分析之:对HTTPS协议的支持
2016-05-27 23:20
471 查看
jmeter 3.0 的readme里有这样一句话:
Apache JMeter interfaces with the
Java Secure Socket Extension (JSSE) API to provide
- HTTPS support
于是查看了jmeter源码,想看看jmeter是如何对https做支持的。
首先从 org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl类入手:
重点关注sample方法,截取代码如下:
接着我们看看LazySchemeSocketFactory类
这里又使用了HC4TrustAllSSLSocketFactory类:
到这里可以看出,jmeter对https的支持是默认信任所有证书的。
Apache JMeter interfaces with the
Java Secure Socket Extension (JSSE) API to provide
- HTTPS support
于是查看了jmeter源码,想看看jmeter是如何对https做支持的。
首先从 org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl类入手:
重点关注sample方法,截取代码如下:
public class HTTPHC4Impl extends HTTPHCAbstractImpl { @Override protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRedirect, int frameDepth) { //... HttpClient httpClient = setupClient(url, res); } private HttpClient setupClient(URL url, SampleResult res) { //... MeasuringConnectionManager connManager = new MeasuringConnectionManager( createSchemeRegistry(), resolver, TIME_TO_LIVE, VALIDITY_AFTER_INACTIVITY_TIMEOUT); } /** * Setup LazySchemeSocketFactory * @see "https://bz.apache.org/bugzilla/show_bug.cgi?id=58099" */ private static SchemeRegistry createSchemeRegistry() { final SchemeRegistry registry = new SchemeRegistry(); registry.register( new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); //$NON-NLS-1$ registry.register( new Scheme("https", 443, new LazySchemeSocketFactory())); //$NON-NLS-1$ return registry; } }
接着我们看看LazySchemeSocketFactory类
public final class LazySchemeSocketFactory implements SchemeLayeredSocketFactory{ /** * @throws SSLInitializationException */ private static SchemeLayeredSocketFactory checkAndInit() throws SSLInitializationException { LOG.info("Setting up HTTPS TrustAll Socket Factory"); try { return new HC4TrustAllSSLSocketFactory(); } catch (GeneralSecurityException e) { LOG.warn("Failed to initialise HTTPS HC4TrustAllSSLSocketFactory", e); return SSLSocketFactory.getSocketFactory(); } } }
这里又使用了HC4TrustAllSSLSocketFactory类:
public class HC4TrustAllSSLSocketFactory extends SSLSocketFactory { private static final TrustStrategy TRUSTALL = new TrustStrategy(){ @Override public boolean isTrusted(X509Certificate[] chain, String authType) { return true; } }; private javax.net.ssl.SSLSocketFactory factory; /** * Create an SSL factory which trusts all certificates and hosts. * {@link SSLSocketFactory#SSLSocketFactory(TrustStrategy, org.apache.http.conn.ssl.X509HostnameVerifier)} * @throws GeneralSecurityException if there's a problem setting up the security */ public HC4TrustAllSSLSocketFactory() throws GeneralSecurityException { this(new HttpSSLProtocolSocketFactory((JsseSSLManager)JsseSSLManager.getInstance(), JsseSSLManager.CPS)); } /** * Create an SSL factory which trusts all certificates and hosts. * {@link SSLSocketFactory#SSLSocketFactory(TrustStrategy, org.apache.http.conn.ssl.X509HostnameVerifier)} * @param factory javax.net.ssl.SSLSocketFactory * @throws GeneralSecurityException if there's a problem setting up the security */ protected HC4TrustAllSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory) throws GeneralSecurityException { super(TRUSTALL, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); this.factory = factory; } }
到这里可以看出,jmeter对https的支持是默认信任所有证书的。
相关文章推荐
- 2016国内最值得期待的响应式前端框架pintuer(拼图)--http://www.pintuer.com
- GSM Hacking:如何对GSM/GPRS网络测试进行测试?
- HTTP协议浅尝
- RQMURLUtility是否支持http协议?
- μtorrent提示找不到元素 element not found && 印象笔记无法同步
- 《将博客搬至CSDN》
- 机器学习中使用的神经网络第十讲笔记
- 第一章 计算机网络概论
- 安装完ubuntu后没有无线网络解决办法
- vertica-copy数据报网络错误
- 常见的几个网络安全工具
- [置顶] Xutils中httputils请求(Post请求)
- HTTP状态301、404、200、304等的意思
- Android利用tcpdump和wireshark抓取网络数据包
- I/O多路复用之select/poll/epoll
- 并发服务器
- iOS下的实际网络连接状态检测
- Linux下的TCP/IP编程----实践篇
- Linux---ubuntu重启网络服务
- I/O复用和I/O模型