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
- LangChain AlternativeLangChain
- RxJava 系列-3:使用 SubjectRxJava
- 7-Overview-namesView
- DNS: More than just namesDNS
- CF566A Matching Names
- set names utf8;
- lower_case_table_names
- [譯] 認識 rxjs 中的 SubjectJS
- RxJava2 系列-3:使用 SubjectRxJava
- Wilcoxon秩和檢驗的statistic和alternative
- 30 天精通 RxJS (25):Subject 總結JS
- Rxjs 裡 Subject 和 BehaviorSubject 的區別JS
- The English names of various berries All In One
- Talk about the naming of spring bean namesSpringBean
- 自定義Push/Pop和Present/Dismiss轉場
- 【文獻閱讀】ES as a Scalable Alternative to RL(OpenAI 17)OpenAI
- 30 天精通 RxJS (23):Subject, BehaviorSubject, ReplaySubject, AsyncSubjectJS
- Subject 在 SAP Spartacus Popover Component 中的應用
- Shiro中Subject物件的建立與繫結流程分析物件
- JSnaughty: Recovering Clear, Natural Identifiers from Obfuscated JS NamesJSIDE
- kafka ssl sasl_ssl 配置Kafka
- ssl
- “getfacl: Removing leading '/' from absolute path names”解決辦法REM
- MySQL8.0的坑之lower_case_table_namesMySql
- Vesta 安裝SSL – HTTPS SSL 教程HTTP
- axios跨域問題 No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.iOS跨域Header
- JAXBContext版本衝突java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present atContextJavaExceptionXML
- PostgreSQL DBA(108) - pgAdmin(Don't do this:Don't use upper names)SQL
- IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokensExceptionHTTP
- phpStudy安裝ssl證照 – HTTPS SSL 教程PHPHTTP
- Tomcat 安裝SSL證書 – HTTPS SSL 教程TomcatHTTP
- Nginx的SSL配置優化 – HTTPS SSL 教程Nginx優化HTTP