记录一次解决httpcline请求https报handshake_failure错误

概述

当使用httpclinet发起https请求时报如下错误:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failureat com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1657)at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:932)at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096)at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1107)at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:261)at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118)at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357)at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218)at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)

未解决参照url

访问https,抛出的异常javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
使用HttpClient发送HTTPS请求以及配置Tomcat支持SSL

分析过程

背景交待

由于证书是字自签自发,并且加固过,相信很多人会问为什么加固, 因为你如果不加固的话https将在ff中无法访问,错误如下:
记录一次解决httpcline请求https报handshake_failure错误

解决方案参照Tomcat6+JDK6如何加固,解决Logjam attack

解决过程分析

不加固是否可以直接访问

经测试 不加固的情况访问没有问题

加固后不能访问原因分析

因为加固主要是指定了protocols和ciphers,所以请求时是否也可以指定protocols和ciphers,查阅官方文档发现如下信息
记录一次解决httpcline请求https报handshake_failure错误
通过在httpclient请求之前设置protocols和ciphers,代码如下:

        System.setProperty("https.protocols", "与server.xml中的protocols一致");System.setProperty("https.cipherSuites", "与server.xml中的ciphers一致");

重新发起请求,发现还是报错

分析设置是否生效

通过debug httpclinet下HttpClientBuilder类的源代码发现如下
记录一次解决httpcline请求https报handshake_failure错误
则将代码增加如下粗体:
HttpClients.custom().useSystemProperties().setDefaultRequestConfig(defaultRequestConfig).setSslcontext(sslcontext).build();
重新发起请求,发现还是报错

查询本地支持的协议及算法

代码如下:

public class HttpsTest {public static void main(String[] args) {SSLContext sc;try {sc = SSLContext.getInstance("TLS");// 实现一个X509TrustManager接口,用于绕过验证,不用修改里面的方法X509TrustManager trustManager = new X509TrustManager() {@Overridepublic void checkClientTrusted(java.security.cert.X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException {}@Overridepublic void checkServerTrusted(java.security.cert.X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException {}@Overridepublic java.security.cert.X509Certificate[] getAcceptedIssuers() {return null;}};sc.init(null, new TrustManager[] { trustManager }, null);System.out.println("缺省安全套接字使用的协议: " + sc.getProtocol());  // 获取SSLContext实例相关的SSLEngine  SSLEngine en = sc.createSSLEngine();  System.out  .println("支持的协议: " + Arrays.asList(en.getSupportedProtocols()));  System.out.println("启用的协议: " + Arrays.asList(en.getEnabledProtocols()));  System.out.println("支持的加密套件: "  + Arrays.asList(en.getSupportedCipherSuites()));  System.out.println("启用的加密套件: "  + Arrays.asList(en.getEnabledCipherSuites())); } catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}
}
然后在httpclient请求之前设置protocols和ciphers,
    System.setProperty("https.protocols", "其值为服务器和本地相同的");System.setProperty("https.cipherSuites", "其值为服务器和本地相同的");

重新发起请求,请求成功。

版本说明

httpclinet:4.3.1
jdk:1.6
tomcat:6

httpclient发起请求代码

访问 https://gitee.com/die/help_common.git中的httpclinet进行下载

参考文章

HttpClient如何指定CipherSuites

转载于:https://blog.51cto.com/2074199/2088928

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278275.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

桌面程序explorer_备份Internet Explorer 7搜索提供程序列表

桌面程序explorerIf you are both an IE user and a fan of using custom search providers in your search box, you might be interested to know how you can back up that list and/or restore it on another computer. Yes, this article is boring, but we’re trying to…

C++内联函数(inline function)

c从c中继承的一个重要特征就是效率。假如c的效率明显低于c的效率,那么就会有很大的一批程序员不去使用c了。 在c中我们经常把一些短并且执行频繁的计算写成宏,而不是函数,这样做的理由是为了执行效率,宏可以避免函数调用的开销&am…

GreenPlum数据库故障恢复测试

本文介绍gpdb的master故障及恢复测试以及segment故障恢复测试。 环境介绍:Gpdb版本:5.5.0 二进制版本操作系统版本: centos linux 7.0Master segment: 192.168.1.225/24 hostname: mfsmasterStadnby segemnt: 192.168.1.227/24 hostname: ser…

书评:Just the Computer Essentials(Vista)

Normally we try and focus on articles about how to customize your computer, but today we’ll take a break from that and do a book review. This is something I’ve not done before, so any suggestions or questions will be welcomed in the comments. 通常&#x…

RxSwift笔记七其他操作符

简介 git地址: https://github.com/ReactiveX/RxSwift参考资料:http://t.swift.gg/d/2-rxswiftReactiveX是通过可观察的流实现异步编程的一种API,它结合了观察者模式、迭代器模式和函数式编程的精华,RxSwift 是 ReactiveX 编程思想的一种实现。 复制代码…

python学习

为了学会能学&#xff0c;不负时间&#xff0c;为了那简练的美&#xff01; 为了一片新天地。 /t 对齐 python : # 99乘法表i 0while i < 9 : i 1 j 0 while j < i : j 1 print(j ,* , i,"" , i*j , end\t) #空格不能对齐 制表符…

hey 安装_如何在助理扬声器上调整“ Hey Google”的灵敏度

hey 安装Vantage_DS/ShutterstockVantage_DS / ShutterstockThe Google Assistant is a useful tool that allows you to control your smart home, check the weather, and more. Unfortunately, the Assistant might not hear you in a noisy environment or it might activa…

EXCEL如何进行多条件的数据查找返回

在使用EXCEL时经常会碰到一个表里的同一款产品每天的销量都不一样&#xff0c;然后我们需要查导出每一款产品每天的销量&#xff0c;即一对多条件查找。这个教复杂&#xff0c;我们要用到好几个函数的综合&#xff0c;下面小编来教你吧。 工具/原料 EXCEL软件&#xff08;本文使…

如何将Google幻灯片转换为PowerPoint

If someone sent you a presentation on Google Slides, but you’d rather work on it in Microsoft PowerPoint, you can easily convert it to a .pptx file in just a few simple steps. Here’s how it’s done. 如果有人在Google幻灯片上向您发送了演示文稿&#xff0c;但…

Linux 常用命令:文本查看篇

前言 Linux常用命令中&#xff0c;除了cat还有很多其他用于文本查看的命令。本文将简单介绍一下这些文本查看的命令。 全文本显示--cat cat可能是常用的一个文本查看命令了&#xff0c;使用方法也很简单&#xff1a; cat file #全文本显示在终端cat -n file #显示全文本&#…

XP调整禁用页面文件

NOTE: You shouldn’t disable your page file unless you really really know what you are doing. 注意&#xff1a;除非您真的很清楚自己在做什么&#xff0c;否则不应该禁用页面文件。 If your computer has 1 GB of RAM or more, disabling the page file can speed up XP…

复制数据库

1.首先手动创建新的数据库 CREATE DATABASE new-DB DEFAULT CHARACTER SET utf8mb4; 2.使用mysqldump命令。结果&#xff0c;会连同数据一起复制过去。 mysqldump old-DB -u root -pXX --add-drop-table | mysql new-DB -u root -pXX转载于:https://www.cnblogs.com/clcliangc…

labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable

最近在做MaskRCNN 在自己的数据&#xff08;labelme&#xff09;转为COCOjson格式遇到问题&#xff1a;TypeError: Object of type int64 is not JSON serializable 原因是numpy的数据类型不能被json兼容 最简单的做法是自己写一个序列类 class MyEncoder(json.JSONEncoder):de…

如何在Windows 10的命令提示符中更改目录

One of the first things you’ll need to learn as you become more familiar with Command Prompt on Windows 10 is how to change directories in the operating system’s file system. There are a few ways you can do this, so we’ll walk you through them. 随着您对…

jQuery 购物车

html代码 <!--shoppingCar start--> <table id"TB"> <tr> <td colspan"7" class"title"> <div class"img_box"> <div class"logo_box"> <img src"img/jd…

MySQL优化总结

2019独角兽企业重金招聘Python工程师标准>>> 从这几天看MySQL性能优化来看&#xff0c;基本的思路就是分分分&#xff0e;&#xff0e;&#xff0e; 1&#xff0c;分读&#xff0c;用缓存来分摊读表的压力; 2&#xff0c;读写分离&#xff0c;主从分离&#xff0c;写…

疯狂java讲义

封装&#xff1a; 封装&#xff1a;将对象状态信息隐藏在对象内部&#xff0c;不允许外部程序直接访问对象内部信息&#xff0c;而是用类所提供的方法访问和操作。访问控制符&#xff1a;private&#xff08;当前类访问权&#xff09; ,protected&#xff08;子类访问&#xff…

将背景色添加到Word 2007文档中

Instead of using the standard white background with Word documents, here is how to add some background color to spice up your documents. 代替在Word文档中使用标准的白色背景&#xff0c;这是如何添加一些背景颜色来为文档增添色彩。 Open your word document and ch…

jquery实现增删改(伪)-老男孩作业day13

使用jquery进行&#xff0c;文件的编写&#xff0c;实现自增id,删除&#xff0c;添加&#xff0c;编辑模式。 jquery放在本地&#xff0c;src"jquery_js.js" 可以改成其他&#xff0c;或者在线的路径 readme<!DOCTYPE html> <html lang"en"> &…

uoj#119. 【UR #8】决战圆锥曲线(线段树+复杂度分析)

题解 传送门 题解 然而要我来说我感觉只是个爆搜啊…… //minamoto #include<bits/stdc.h> #define R register #define ll long long #define ls (p<<1) #define rs (p<<1|1) #define fp(i,a,b) for(R int ia,Ib1;i<I;i) #define fd(i,a,b) for(R int ia…