Ignoring HTTPS certificates
Our Development setups won't have valid or trusted certificates. When do you want test our webserver code over HTTPS, we need to handle these certificates with special code.
The common approach is to import these HTTPS certificates into JDK cacerts or override the trust store:
In Java:
System.setProperty("javax.net.ssl.trustStore","clientTrustStore.key");
System.setProperty("javax.net.ssl.trustStorePassword","qwerty");
If you are working with many such systems or test setups in LAN or internet, it is time taking to import these certificates in our trust stores. So we can allow a setting in our code to ignore these certificates with below code snippets.
HostnameVerifier hostNameVerifier = new HostnameVerifier()
{ public boolean verify(String s, SSLSession sslSession)
{
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hostNameVerifier); TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager()
{
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null;
} public void checkClientTrusted(X509Certificate[] certs, String authType)
{
} public void checkServerTrusted(X509Certificate[] certs, String authType)
{
}
}
}; // Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
logger.fine("Socket factory initialized");
System.out.println("Ignoring server certificates");
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed initializing socket factory to ignore certificates.", e);
}
In Java using Apache Commons HTTP Util:
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyhttps);
In PHP using PHP CURL:
//open connection
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url); // ignore certs
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
Ignoring HTTPS certificates的更多相关文章
- HTTPS证书申请相关笔记
申请免费的HTTPS证书相关资料 参考资料: HTTPS 检测 苹果ATS检测 什么是ECC证书? 渠道2: Let's Encrypt 优点 缺点 Let's Encrypt 的是否支持非80,44 ...
- fiddler 解决不能抓https包的问题
新解决方案 重置Fiddler,具体步骤: Tools > Fiddler Options > HTTPS > “Certificates generated by MakeCert ...
- python pycurl模块
一.pycurl概述 PycURl是一个C语言写的libcurl的python绑定库.libcurl 是一个自由的,并且容易使用的用在客户端的 URL 传输库.它的功能很强大,在PyCURL的主页上介 ...
- Curl的编译
下载 curl的官网:https://curl.haxx.se/ libcurl就是一个库,curl就是使用libcurl实现的. curl是一个exe,也可以说是整个项目的名字,而libcurl就是 ...
- 在PHP中使用CURL,“撩”服务器只需几行——php curl详细解析和常见大坑
在PHP中使用CURL,"撩"服务器只需几行--php curl详细解析和常见大坑 七夕啦,作为开发,妹子没得撩就"撩"下服务器吧,妹子有得撩的同学那就左拥妹子 ...
- python3 获取阿里云ECS 实例及监控的方法
#!/usr/bin/env python3.5 # -*- coding:utf8 -*- try: import httplib except ImportError: import http.c ...
- 解决python2.x用urllib2证书验证错误, _create_unverified_context
解决以下错误: 错误1:AttributeError: 'module' object has no attribute '_create_unverified_context', 错误2:URLEr ...
- python之cookie, cookiejar 模拟登录绕过验证
0.思路 如果懒得模拟登录,或者模拟登录过于复杂(多步交互或复杂验证码)则人工登录后手动复制cookie(或者代码读取浏览器cookie),缺点是容易过期. 如果登录是简单的提交表单,代码第一步模拟登 ...
- 在PHP中使用CURL,“撩”服务器只需几行
在PHP中使用CURL,“撩”服务器只需几行https://segmentfault.com/a/1190000006220620 七夕啦,作为开发,妹子没得撩就“撩”下服务器吧,妹子有得撩的同学那就 ...
随机推荐
- poj1502 最短路
题意:有n个处理器,给出n*n的邻接矩阵的一半,表示相互之间传输信息的花费(另一半与给出的一半对称,即双向都可传输),x表示不能传输,问从第一个处理器传输到所有处理器的最小花费总和是多少. 就是跑一遍 ...
- java Pattern
public class Test{ //匹配替换掉order by之后的字符串 public static void main(String[] args) { Pattern pattern = ...
- Oracle RAC 并发与架构
10g RAC进程总概 一. RAC 并发 RAC 的本质是一个数据库,运行在多台计算机上的数据库,它的主要任务是数据库就是事务处理,它通过 Distributed Lock Management(D ...
- 对象属性操作-包含kvc---ios
#import <Foundation/Foundation.h> @class Author; @interface Books : NSObject{ @private NSStrin ...
- sql server 常用的系统存储过程
系统存储过程 说明 sp_databases 列出服务上的所有数据库 sp_helpdb 报告有关指定数据库或所有数据库的信息 sp_renamedb 更改数据库的名称 sp_tables 返回当 ...
- Apache ab并发负载压力测试
由于现在网站都需要能够承受高并发要求的能力,所以当我们写完代码后,如果需要上线,最好都经过压力测试后,这样比较好 运行: 在Windows系统下,打开cmd命令行窗口,定位到apache安装目录的bi ...
- ImageView及其子类
ImageView及其子类 (1)ImageView继承自View组件,任何Drawable对象都可以用ImageView来显示,ImageView派生出来了ImageButton.ZoomButto ...
- 阅读layim代码小记,实现可以更改用户签名的方法
用layim原版的时候发现,用户的签名是不能直接修改的,如下: 其实要改也很简单,查看一下源代码,然后加一个input进去,可是,加完之后是这样的: 没关系,给它一个样式,让它乖乖的“隐藏“起来. / ...
- 数据接口管理工具 thx RAP
RAP是数据接口管理工具.在开发时前端将请求转至RAP,由RAP提供模拟数据:而后端使用RAP测试接口的正确性.这样RAP就成为了开发过程中的强 依赖,进而确保接口文档的实时正确性.RAP采用JSON ...
- Protocol Buffer Java实例
大家要先下载protobuffer,在这里: https://code.google.com/p/protobuf/downloads/list 注意,需要下载两个,一个是complier,另外一个是 ...