Android HTTPS(4)直接用SSLSocket,黑名单,客户端证书
1.Warnings About Using SSLSocket Directly
  So far, the examples have focused on HTTPS using HttpsURLConnection. Sometimes apps need to use SSL separate from HTTP. For example, an email app might use SSL variants of SMTP, POP3, or IMAP. In those cases, the app would want to use SSLSocket directly, much the same way that HttpsURLConnection does internally.
  The techniques described so far to deal with certificate verification issues also apply to SSLSocket. In fact, when using a custom TrustManager, what is passed to HttpsURLConnection is an SSLSocketFactory. So if you need to use a custom TrustManager with an SSLSocket, follow the same steps and use thatSSLSocketFactory to create your SSLSocket.
  Caution: SSLSocket does not perform hostname verification. It is up the your app to do its own hostname verification, preferably by calling getDefaultHostnameVerifier() with the expected hostname. Further beware that HostnameVerifier.verify() doesn't throw an exception on error but instead returns a boolean result that you must explicitly check.
Here is an example showing how you can do this. It shows that when connecting to gmail.com port 443 without SNI support, you'll receive a certificate for mail.google.com. This is expected in this case, so check to make sure that the certificate is indeed for mail.google.com:
// Open SSLSocket directly to gmail.com
SocketFactory sf = SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) sf.createSocket("gmail.com", );
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
SSLSession s = socket.getSession(); // Verify that the certicate hostname is for mail.google.com
// This is due to lack of SNI support in the current SSLSocket.
if (!hv.verify("mail.google.com", s)) {
throw new SSLHandshakeException("Expected mail.google.com, "
"found " + s.getPeerPrincipal());
} // At this point SSLSocket performed certificate verificaiton and
// we have performed hostname verification, so it is safe to proceed. // ... use socket ...
socket.close();
2.Blacklisting
SSL relies heavily on CAs to issue certificates to only the properly verified owners of servers and domains. In rare cases, CAs are either tricked or, in the case of Comodo or DigiNotar, breached, resulting in the certificates for a hostname to be issued to someone other than the owner of the server or domain.
In order to mitigate this risk, Android has the ability to blacklist certain certificates or even whole CAs. While this list was historically built into the operating system, starting in Android 4.2 this list can be remotely updated to deal with future compromises.
3.Pinning
An app can further protect itself from fraudulently issued certificates by a technique known as pinning. This is basically using the example provided in the unknown CA case above to restrict an app's trusted CAs to a small set known to be used by the app's servers. This prevents the compromise of one of the other 100+ CAs in the system from resulting in a breach of the apps secure channel.
4.Client Certificates
  This article has focused on the user of SSL to secure communications with servers. SSL also supports the notion of client certificates that allow the server to validate the identity of a client. While beyond the scope of this article, the techniques involved are similar to specifying a custom TrustManager. See the discussion about creating a custom KeyManager in the documentation for HttpsURLConnection.
Android HTTPS(4)直接用SSLSocket,黑名单,客户端证书的更多相关文章
- Android : 关于HTTPS、TLS/SSL认证以及客户端证书导入方法
		
一.HTTPS 简介 HTTPS 全称 HTTP over TLS/SSL(TLS就是SSL的新版本3.1).TLS/SSL是在传输层上层的协议,应用层的下层,作为一个安全层而存在,翻译过来一般叫做传 ...
 - SVN 错误:Error validating server certificate for 'https://xxxxxxx':443... Mac os svn客户端证书验证缓存 解决
		
mac上的SVN今天突然间 不好使了 在进行SVN操作是报出警告信息 Error validating server certificate for 'https://xxxxxxx':443 - T ...
 - 转 Android HTTPS详解
		
目录(?)[-] 前言 HTTPS原理 SSLTLS协议作用 基本的运行过程 握手阶段的详细过程 客户端发出请求ClientHello 服务器回应ServerHello 客户端回应 服务器的最后回应 ...
 - 只用@property定义一个属性speed,子类不能直接用_speed,需要在interface的成员变量列表里写上_speed
		
//写法一: @interface Person : NSObject { } @property (nonatomic, strong) NSString *name; @end @implemen ...
 - Android Https双向认证 + GRPC
		
keywords:android https 双向认证android GRPC https 双向认证 ManagedChannel channel = OkHttpChannelBuilder.for ...
 - CommandoVM-虚拟机映像文件 | VM打开直接用
		
呵呵!自从火眼发布了这个CommandoVM,想必大家应该都挺激动,然而实际操作一下,基本炸裂-- 因为并没有给类似于kali这种直接安装的现成镜像,而是要通过github的脚本去完全网络安装 实际操 ...
 - 如何使用charles对Android Https进行抓包
		
Charles.png charles是一款在Mac下常用的截取网络封包工具,对Android Http进行抓包,只要对手机设置代理即可,但对Android Https进行抓包还是破费一些功夫,网 ...
 - Netty为什么不直接用AtomicXXX,而要用AtomicXXXFieldUpdater去更新变量呢?
		
更多技术分享可关注我 前言 如果仔细阅读过Netty的线程调度模型的源码,或者NIO线程对象及其线程池的创建源码,那么肯定会遇到类似“AtomicIntegerFieldUpdater”的身影,不禁想 ...
 - 服务之间的调用为啥不直接用 HTTP 而用 RPC?
		
什么是 RPC?RPC原理是什么? 什么是 RPC? RPC(Remote Procedure Call)-远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.比 ...
 
随机推荐
- 【BZOJ】【3172】【TJOI2013】单词
			
AC自动机 Orz zyf 玛雅一开始连题意都没看懂……意思就是给你一篇文章的N个单词,问每个单词在这篇文章中各出现了几次?(这篇文章=N个单词) 那么我们建个AC自动机……对于每个单词来说,它出现的 ...
 - 【BZOJ】【4003】【JLOI2015】城池攻占
			
可并堆 QAQ改了一下午……最终弃疗求助zyf……居然被秒了QAQ真是弱到不行(zyf太神了Orz) 还是先考虑部分分的做法: 1.$n,m\leq 3000$:可以暴力模拟每个骑士的攻打过程,也可以 ...
 - 【BZOJ】【3439】Kpm的MC密码
			
Trie树/可持久化线段树 神题啊……搞了我一下午= =(其实第233个提交也是我的) 我一开始的思路:这个找kpm串的过程,其实就跟在AC自动机上沿fail倒着往下走是差不多的(看当前是哪些点的后缀 ...
 - 一个利用window.name实现的windowStorage
			
//key:value|key:value var windowStorage = { _inited: false, _data: {}, init: function(str) { var tmp ...
 - mysql存储过程和函数使用实例
			
1.需求:根据输入的年份,月份,和当前系统的年份比较,不满1年按1年计算,多出1年11个月也按1年计算. 2.计算得出来的使用年份,计算车辆残值. 3.存储过程 DELIMITER $$ USE `d ...
 - 接口、抽象类、方法复写、类Equals方法重写
			
接口: /* * Java接口中的數據成員必須初始化,該成員有隱藏的final.satic.常量, * 一次賦值后不可在賦值 * 成員方法訪問修飾符必須是公共修飾符,可以顯示聲明也可以不聲明 * 成員 ...
 - delphi  网络函数
			
Delphi网络函数 unit net; interfaceusessysutils,windows,dialogs,winsock,classes,comobj,wininet; //得到本机的局域 ...
 - HDU5008 Boring String Problem(后缀数组)
			
练习一下字符串,做一下这道题. 首先是关于一个字符串有多少不同子串的问题,串由小到大排起序来应该是按照sa[i]的顺序排出来的产生的. 好像abbacd,排序出来的后缀是这样的 1---abbacd ...
 - HDU 4825 Xor Sum(二进制的字典树,数组模拟)
			
题目 //居然可以用字典树...//用cin,cout等输入输出会超时 //这是从别处复制来的 #include<cstdio> #include<algorithm> #in ...
 - MySQL数据库优化总结
			
对于一个以数据为中心的应用,数据库的好坏直接影响到程序的性能,因此数据库性能至关重要.一般来说,要保证数据库的效率,要做好以下四个方面的工作:数 据库设计.sql语句优化.数据库参数配置.恰当的硬件资 ...