SSL - SSLHandshakeException: No subject alternative names present
一、異常日誌
javax.net.ssl.SSLHandshakeException:
Caused by: java.security.cert.CertificateException: No subject alternative names present
at sun.security.util.HostnameChecker.matchIP(Unknown Source)
at sun.security.util.HostnameChecker.match(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 12 more
二、問題程式碼
public class SslHandshakeExc_NsanPresent{
public static void main(String[] args) throws Exception {
URL url = new URL("https://192.168.2.222:8443/wbsystem/login.jsp");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
is.close();
}
}
三、解決方案
public class SslHandshakeExc_NsanPresent{
public static void main(String[] args) throws Exception {
URL url = new URL("https://192.168.2.222:8443/wbsystem/login.jsp");
// 新增部分
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
// 新增部分
conn.setHostnameVerifier(new Servlet_test().new TrustAnyHostnameVerifier());
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
is.close();
}
// 定製Trust
static TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
// 定製Verifier
public class TrustAnyHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
}
相關文章
- SSL - SSLHandshakeException: No subject alternative names matching IP address foundException
- JDK安全證書一個錯誤訊息 No subject alternative names presentJDK
- 【java細節】Java程式碼忽略https證照:No subject alternative names presentJavaHTTP
- SSL - SSLHandshakeException: Unrecognized SSL message, plaintext connection?ExceptionZedAI
- SSL - SSLHandshakeException: unable to find valid certification path to requested targetException
- 解決 javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateExceptionJavaException
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解決方案JavaExceptionAI
- LangChain AlternativeLangChain
- RxSwift 之 SubjectSwift
- Oracle *namesOracle
- RxJava 系列-3:使用 SubjectRxJava
- .nil? .empty? .blank? .present? in Ruby on RailsAI
- 7-Overview-namesView
- RxJava2 系列-3:使用 SubjectRxJava
- DNS: More than just namesDNS
- CentOS 6 安裝 APC(Alternative PHP Cache)CentOSPHP
- Wilcoxon秩和檢驗的statistic和alternative
- [譯] 認識 rxjs 中的 SubjectJS
- RxJS 系列之四 - Subject 詳解JS
- [譯] 關於 RxJS 中的 SubjectJS
- 啟動網路卡時報:does not seem to be present
- Finding SAP table names and descriptions
- Oracle database的names(名字們)OracleDatabase
- The English names of various berries All In One
- Why NoSQL Should Be Called "SQL with Alternative Storage Models"SQL
- Rxjs 裡 Subject 和 BehaviorSubject 的區別JS
- 許可權系統設計(3)-- subject
- 30 天精通 RxJS (25):Subject 總結JS
- 自定義Push/Pop和Present/Dismiss轉場
- 自定義present和dismiss的轉場動畫動畫
- [Linux] device eth0 does not seem to presentLinuxdev
- MySQL為什麼要set namesMySql
- Alternative account/備選科目程式碼配置說明
- Provide an Alternative View to Data Using Splitter Window (轉)IDEView
- device eth0 does not seem to be present, delaying initializationdev
- Talk about the naming of spring bean namesSpringBean
- sqlzoo練習答案--SELECT names/zhSQL
- mysql lower-case-table-names引數MySql