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 七夕啦,作为开发,妹子没得撩就“撩”下服务器吧,妹子有得撩的同学那就 ...
随机推荐
- 《C标准库》——之<ctype.h>
在没读<ctype.h>的源码之前,我一直以为我们平时用的isalnum.isdigit.isalpha等这些函数,是靠判断写出来的. 比如: int isdigit(int c){ re ...
- c 深度剖析 4
1 预处理 1#define 1.不能用 #define 定义注释,因为注释先于预处理被处理. 2 .宏定义表达式 1,注意展开后结合顺序,尽量多加括号 2,常量定义时注意是否溢出 1 #define ...
- hive 常见面试题
(笔者自己做记录) 1.Hive内外部表的区别删除表是否影响外部数据2.Hive如何做到权限管理hive下可以修改配置后创建用户管理,但是仅仅是为了防止误操而已,如果要真的为了安全操作建议使用 Ker ...
- hbase(ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet)
今天启动clouder manager集群时候hbase list出现 (ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException ...
- cron 配置计划任务的书写格式(quartz 时间配置)
一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素. 按顺序依次为 1.秒(0~59) 2.分钟(0~59) 3.小时(0~23) 4.天(月)(0~31,但是你需要考虑你月的天数) 5 ...
- Anroid 异常:is not valid; is your activity running?
本文转载于:http://blog.csdn.net/biangren/article/details/7514722 是由于有activity时依附于另一个activity的,当被依附的activi ...
- m3u8文件简介
1. M3U8文件概念 M3U8文件是指UTF-8编码格式的M3U文件.M3U文件是记录了一个索引纯文本文件,打开它时播放软件并不是播放它,而是根据它的索引找到对应的音视频文件的网络地址进行在线播 ...
- 【转】IOS学习笔记29—提示框第三方库之MBProgressHUD
原文网址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...
- rsyslog日志服务的配置文件分析
基于rsyslog日志服务的日志 在不同的LINUX系统,实现的软件略有不同. syslog,rsyslog,syslog-ng,用于实现系统日志的管理. [root@asianux4 ~]# rpm ...
- 你可能不知道的 Linux 命令行网络监控工具
http://developer.51cto.com/art/201505/476651_2.htm 对任何规模的业务来说,网络监控工具都 是一个重要的功能.网络监控的目标可能千差万别.比如,监控活动 ...