https网站主机地址与证书地址不一致,浏览器校验通过原因

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xyjincan/article/details/88680121

https网站主机地址与证书地址不一致,浏览器校验通过原因

证书详细信息中含有 使用者可选名称

如图证书颁发给 cloudflare-dns.com ,但url中实际地址却是1.1.1.1

https网站主机地址与证书地址

使用者可选名称
IP Address=1.1.1.1

使用者可选名称

展开阅读全文

android https 证书校验问题

12-03

在做C/S https请求时,服务端加入了证书校验。我在发送请求时已经做了信任所有证书的动作,但是获取返回数据,进行数据流操作时,报javax.net.ssl.SSLException: Connection closed by peer异常,求大神指点!!!rn代码如下:rnrn public static Response connect(Request request)rn rn Response response = new Response();rn response.setCorrespondingRequest(request);rn HttpURLConnection httpConn = null;rn rn System.setProperty("http.keepAlive", "false");rnrn tryrn rn SSLContext sc = SSLContext.getInstance("SSL");rn rn sc.init(null, new TrustManager[] new MyTrustManager() , null);rn HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());rn HttpsURLConnection.setDefaultHostnameVerifier(new MyHostnameVerifier());rnrn URL url = new URL(request.getUrl());rn rn if (!url.getProtocol().toLowerCase().equals("https"))rn rn httpConn = (HttpURLConnection) url.openConnection();rn rn elsern rn httpConn = getHttpsConn(url);rn rn rn httpConn.setDoInput(true);rn httpConn.setDoOutput(true);rn httpConn.setUseCaches(false);rn rn // set request method.rn setRequestMethod(request, httpConn);rn rn // set request property.rn setRequestProperty(request, httpConn);rn rn httpConn.setConnectTimeout(CONNECT_TIMEOUT);rn httpConn.setReadTimeout(READ_TIMEOUT);rn rn if (request.getBody() != null)rn rn // set request content.rn Logger.i(TAG, "request body : \n" + request.getBody());rn byte[] data = request.getBody().getBytes("UTF-8");rn rn // write data.rn [color=#FF0000] OutputStream os = httpConn.getOutputStream();[/color]rn if (request.isGZip())rn rn GZIPOutputStream gzos = new GZIPOutputStream(os);rn gzos.write(data);rn gzos.flush();rn gzos.close();rn rn elsern rn os.write(data);rn os.flush();rn rn os.close();rn rn rn // get response code.rn int responseCode = initResponseCode(response, httpConn);rn // connect OK(200) or Created(201)rn rn rn catch 省略rn rn rnrn红色OutputStream os = httpConn.getOutputStream();报异常。 论坛

校验地址问题,谁帮找找原因

07-10

[code=java]//==============================================================================rn//rn// @author Slivern// @date 2013-6-18rn//rn//==============================================================================rnpackage org.slive.validator;rnrnimport java.util.regex.Matcher;rnimport java.util.regex.Pattern;rnrn/**rn * ValidatorUtil supplies many ordinary validation functions,such as: rn * rn * ipv4 address validatern * device mac address validatern * rn * @author Slivern */rnpublic class ValidateUtilrnrn public static final String IPV4_REGEX = "([1-9]|[1-9]\\d|1\\d2|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d2|2[0-4]\\d|25[0-5]))3";rn public static final String MAC_REGEX = "([0-9A-Fa-f]2)(-[0-9A-Fa-f]2)5";rn public static final String R_1_65535_REGEX = "([1-9](\\d0,3))|([1-5](\\d4))|(6553[0-5])|(655[0-2]\\d)|(65[0-4](\\d2))|(6[0-4](\\d3))";rn public static final String IPV4_PORT_REGEX = IPV4_REGEX + "(\\/)" + R_1_65535_REGEX;rn public static final String UDP_IPV4_PORT_REGEX = "([uU][dD][pP])(\\:)" + IPV4_PORT_REGEX;rn public static final String TCP_IPV4_PORT_REGEX = "([tT][cC][pP])(\\:)" + IPV4_PORT_REGEX;rn rn /**rn * Legal ipv4 address follow as: "xxx(1-255).xxx.xxx.xxx(0-255)"rn * @param ipv4 ipv4 addressrn * @return if ipv4 is null, it will return false;rn * @see #IP_REGEXrn */rn public static boolean ipV4Validate(String ipv4)rn return ipv4Validate(ipv4,IPV4_REGEX);rn rn rn /**rn * Legal device mac address follow as: "xx-xx-xx-xx-xx(0-9a-f)"rn * @param mac device mac addressrn * @return if mac is null, it will return false;rn * @see #MAC_REGEXrn */rn public static boolean macValidate(String mac)rn return ipv4Validate(mac,MAC_REGEX);rn rn rn /**rn * Legal address follow as:"udp:127.0.0.1/1080"rn * @param udpIpv4Portrn * @see #UDP_IPV4_PORT_REGEXrn */rn public static boolean udpIpv4PortValidate(String udpIpv4Port)rn return ipv4Validate(udpIpv4Port,UDP_IPV4_PORT_REGEX);rn rn rn /**rn * Legal address follow as:"tcp:127.0.0.1/1080"rn * @param tcpIpv4Portrn * @see #TCP_IPV4_PORT_REGEXrn */rn public static boolean tcpIpv4PortValidate(String tcpIpv4Port)rn return ipv4Validate(tcpIpv4Port,TCP_IPV4_PORT_REGEX);rn rn rn /**rn * Legal address follow as:"127.0.0.1/1080"rn * @param ipv4Portrn * @see #IPV4_PORT_REGEXrn */rn public static boolean ipv4PortValidate(String ipv4Port)rn return ipv4Validate(ipv4Port,IPV4_PORT_REGEX);rn rnrn private static boolean ipv4Validate(String addr,String regex) rn if(addr == null)rn return false;rn rn elsern Pattern p = Pattern.compile(regex);rn Matcher m = p.matcher(addr);rn boolean b = m.matches();rn return b;rn// return Pattern.matches(regex, addr.trim());rn rn rn rn public static void main(String[] args) rn for (int i = 0; i < 65537; i++) rn if(!("" + i).matches(R_1_65535_REGEX)) // 校验是否是1-65535的范围内rn rn System.out.println(i);rn rn rn rn // TODOrn System.out.println();rn String udpAddr = "udp:127.0.0.1/655";rn// String udpAddr = "udp:127.0.0.1/65535"; //此地址会出错,y?rn System.out.println("UdpAddr validates result:" + udpIpv4PortValidate(udpAddr));rn rn String tcpAddr = "tcp:10.8.9.116/10000";rn System.out.println("TcpAddr validates result:" + tcpIpv4PortValidate(tcpAddr));rn rn rnrn[/code]rnrn如上代码,测试检验是否形如“udp|tcp:xxx.xxx.xxx.xxx/xxx(1-65535)”等的地址是否是有效的,检验"udp:127.0.0.1/655"时没问题,检验"udp:127.0.0.1/65535"时却出错了(单单测试检验1-65535是否有效却没问题),哪位大侠帮忙找找原因?rnrn[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/11.gif][/img]rn 论坛

没有更多推荐了,返回首页