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 七夕啦,作为开发,妹子没得撩就“撩”下服务器吧,妹子有得撩的同学那就 ...
随机推荐
- Linux1.0源代码编译过程
根据源代码包中的readme文件及http://chfj007.blog.163.com/blog/static/173145044201191195856806/?suggestedreading& ...
- LAMT基于mod_proxy方式的负载均衡集群
一.apache服务器 # httpd -D DUMP_MODULES | grep proxy查看是否有 proxy_balancer_module (shared)模块 二.编辑配置文件 1.编 ...
- 关于setInterval()里的this和细节
setInterval(fn,t);里的fn中,要使用外部类的this,则需要先将this保存起来,再使用保存的this,不能直接使用this,里面的this是指向window对象,记住setInte ...
- 编码规范(一)之Code Templates的设置(转)
编码规范(一)之Code Templates的设置 基于公司的主流开发工具为eclipse,但每个人都有自己的编码习惯,为了统一格式,这里通过三个方面:设置Code Templates.Checkst ...
- Java——异常
/* * 异常: 是在运行时期 发生的 不正常情况. * 在java中类的形式对不正常情况进行了描述和封装对象. * * 描述不正常的情况类,就成为异常. * * 问题很多,就意味着描述 ...
- Java 操作Excel 之Poi(第一讲)
1.Poi 简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能.HSSF - 提供读写Micros ...
- 如何让div水平垂直居中
引子 我们经常遇到需要把div中的内容进行水平和垂直居中.所以,这里介绍一种方法,可以使div水平居中和垂直居中. 代码: <!DOCTYPE html> <html lang=&q ...
- js里的setTimeout和setInterval之后的页面是空白,阻塞浏览器的document对象,但是不阻塞script方法
js里的setTimeout和setInterval是否进程阻塞? 阻塞浏览器的document对象,但是不阻塞script方法 当你在setTimeout中使用document.write时是不行的 ...
- python有序查找算法:二分法
二分法是一种快速查找的方法,时间复杂度低,逻辑简单易懂,总的来说就是不断的除以2除以2... 例如需要查找有序数组arr里面的某个关键字key的位置,那么首先确认arr的中位数或者中点center,下 ...
- python数据类型之str用法
1.首字母大写 语法:S.capitalize() -> str title = "today is a good day" title_ca = title.capital ...