IP直连的好处
- 省去DNS解析过程,减少耗时;
- 就近接入,减少耗时;
- 避免DNS劫持;
- 终端有多个IP接入时,有容灾能力;
HTTPS IP直连问题小结_leelit笔记本-CSDN博客_https ip
- 证书HOST校验问题; 证书校验用的是域名校验,而不是iP地址,OkHostnameVerifier替换为域名;
- SNI问题; 一个域名对应多个iP地址,证书校验时没有找到自己设置的IP地址,报错,在SSLSocketFactory的实现类中设置自己的域名;
- 连接复用问题; 具体判断是否可复用问题在RealConnection#isEligible();
- 兼容性问题;
- Session复用问题
boolean equalsNonHost(Address that) {
return this.dns.equals(that.dns)
&& this.proxyAuthenticator.equals(that.proxyAuthenticator)
&& this.protocols.equals(that.protocols)
&& this.connectionSpecs.equals(that.connectionSpecs)
&& this.proxySelector.equals(that.proxySelector)
&& equal(this.proxy, that.proxy)
&& equal(this.sslSocketFactory, that.sslSocketFactory)
&& equal(this.hostnameVerifier, that.hostnameVerifier)
&& equal(this.certificatePinner, that.certificatePinner)
&& this.url().port() == that.url().port();
}
&& equal(this.sslSocketFactory, that.sslSocketFactory) && equal(this.hostnameVerifier, that.hostnameVerifier)
https 不支持ip地址?的确不支持。为啥呢?
拿百度地址为例。访问百度的ip地址,就提示证书不信任,不匹配。原因是:一般来说证书都是以域名为标示的,跟访问的ip地址肯定不匹配。如图