jmeter3.0 源码分析之:对HTTPS协议的支持
来源:互联网 发布:中巴关系 知乎 编辑:程序博客网 时间:2024/06/08 11:41
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方法,截取代码如下:
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的支持是默认信任所有证书的。
1 0
- jmeter3.0 源码分析之:对HTTPS协议的支持
- 添加对https协议的支持
- 客户端对HTTPS协议的支持方案
- Tomcat对https的支持
- iOS对https的支持
- 让 svn 支持 https 协议的 checkout
- 让svn支持https协议的checkout
- Go支持https协议的简单例子
- tomcat配置https协议的支持
- Loadrunner支持https协议
- Jexus支持HTTPS协议
- TOMCAT8支持HTTPS协议
- HTTPS之SSL/TLS协议分析
- 配置apache对 https 的支持
- Nginx服务器配置对https的支持
- android 内置webview 对https的支持
- 基于OKHttp实现对Https的支持
- iOS上实现对HTTPS的支持
- JAVA反射机制深入学习(一)Java反射概念解析
- 算法分析(2)Insertion Sort
- iOS多线程的初步研究(六)-- NSOperation
- _thiscall与_cdecl调用方式
- 浅谈 UITableView
- jmeter3.0 源码分析之:对HTTPS协议的支持
- Configuring Fair Scheduler in Hadoop Cluster
- bzoj4260 Codechef REBXOR
- 实现自己的printf函数(2)
- Java 加密解密基础
- leetcode_137 Single Number II
- 几编有关证书、数据加密解密和签名的好文章
- JAVA设计模式(01_1):创建型-工厂模式【工厂方法模式】(Factory Method)
- bzoj1853【SCOI2010】幸运数字