記錄一次解決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.pswp.cn/news/278275.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278275.shtml
英文地址,請注明出處:http://en.pswp.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…