Loading KeyStore C:\Tool\jdk1.7.0_71\jre\lib\security\jssecacerts...
Opening connection to www.google.com:443...
Starting SSL handshake... javax.net.ssl.SSLException: java.lang.UnsupportedOperationException
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1842)
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1825)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1346)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at InstallCert.main(InstallCert.java:73)
Caused by: java.lang.UnsupportedOperationException
at InstallCert$SavingTrustManager.getAcceptedIssuers(InstallCert.java:159)
at sun.security.ssl.AbstractTrustManagerWrapper.checkAlgorithmConstraints(SSLContextImpl.java:926)
at sun.security.ssl.AbstractTrustManagerWrapper.checkAdditionalTrust(SSLContextImpl.java:872)
at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(SSLContextImpl.java:814)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1421)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:878)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:814)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
... 2 more Server sent 1 certificate(s): 1 Subject CN=www.amazon.com, OU=Cyber, O=Amazon, L=Newark, ST=NY, C=US
Issuer CN=www.amazon.com, OU=Cyber, O=Amazon, L=Newark, ST=NY, C=US
sha1 c4 1e 51 d5 ae e6 e5 0b 34 5b 99 24 39 8c df e7 2e 57 77 5d
md5 6d 89 00 ac 2e 72 71 c2 9a 95 7b 6c f2 1d bd 26 Enter certificate to add to trusted keystore or 'q' to quit: [1]

Error Info

 import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager; public class InstallCert { public static void main(String[] args) throws Exception {
args[0]="www.google.com";
String host;
int port;
char[] passphrase;
//System.setProperty("javax.net.ssl.trustStore", "C:\\Users\\PL62716\\workspace\\urlAutoConnect\\jssecacerts");
if ((args.length == 1) || (args.length == 2)) {
String[] c = args[0].split(":");
host = c[0];
port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
String p = (args.length == 1) ? "changeit" : args[1];
passphrase = p.toCharArray();
} else {
System.out
.println("Usage: java InstallCert <host>[:port] [passphrase]");
return;
} File file = new File("jssecacerts");
if (file.isFile() == false) {
char SEP = File.separatorChar;
File dir = new File(System.getProperty("java.home") + SEP + "lib"
+ SEP + "security");
file = new File(dir, "jssecacerts");
if (file.isFile() == false) {
file = new File(dir, "cacerts");
}
}
System.out.println("Loading KeyStore " + file + "...");
InputStream in = new FileInputStream(file);
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(in, passphrase);
in.close(); SSLContext context = SSLContext.getInstance("TLS");
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
X509TrustManager defaultTrustManager = (X509TrustManager) tmf
.getTrustManagers()[0];
SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
context.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory factory = context.getSocketFactory(); System.out
.println("Opening connection to " + host + ":" + port + "...");
SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
socket.setSoTimeout(10000);
try {
System.out.println("Starting SSL handshake...");
socket.startHandshake();
socket.close();
System.out.println();
System.out.println("No errors, certificate is already trusted");
} catch (SSLException e) {
System.out.println();
e.printStackTrace(System.out);
} X509Certificate[] chain = tm.chain;
if (chain == null) {
System.out.println("Could not obtain server certificate chain");
return;
} BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in)); System.out.println();
System.out.println("Server sent " + chain.length + " certificate(s):");
System.out.println();
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
MessageDigest md5 = MessageDigest.getInstance("MD5");
for (int i = 0; i < chain.length; i++) {
X509Certificate cert = chain[i];
System.out.println(" " + (i + 1) + " Subject "
+ cert.getSubjectDN());
System.out.println(" Issuer " + cert.getIssuerDN());
sha1.update(cert.getEncoded());
System.out.println(" sha1 " + toHexString(sha1.digest()));
md5.update(cert.getEncoded());
System.out.println(" md5 " + toHexString(md5.digest()));
System.out.println();
} System.out
.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
String line = reader.readLine().trim();
int k;
try {
k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;
} catch (NumberFormatException e) {
System.out.println("KeyStore not changed");
return;
} X509Certificate cert = chain[k];
String alias = host + "-" + (k + 1);
ks.setCertificateEntry(alias, cert); OutputStream out = new FileOutputStream("jssecacerts");
ks.store(out, passphrase);
out.close(); System.out.println();
System.out.println(cert);
System.out.println();
System.out
.println("Added certificate to keystore 'jssecacerts' using alias '"
+ alias + "'");
} private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray(); private static String toHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 3);
for (int b : bytes) {
b &= 0xff;
sb.append(HEXDIGITS[b >> 4]);
sb.append(HEXDIGITS[b & 15]);
sb.append(' ');
}
return sb.toString();
} private static class SavingTrustManager implements X509TrustManager { private final X509TrustManager tm;
private X509Certificate[] chain; SavingTrustManager(X509TrustManager tm) {
this.tm = tm;
} public X509Certificate[] getAcceptedIssuers() {
//return new X509Certificate[0];
throw new UnsupportedOperationException();
} public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
throw new UnsupportedOperationException();
} public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
this.chain = chain;
tm.checkServerTrusted(chain, authType);
}
} }

Java Code

Resolve method :

        public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
//throw new UnsupportedOperationException();
}

Override getAcceptedIssuers Method

Normal log :

Loading KeyStore C:\Tool\jdk1.7.0_71\jre\lib\security\jssecacerts...
Opening connection to www.google.com:443...
Starting SSL handshake... No errors, certificate is already trusted Server sent 1 certificate(s): 1 Subject CN=www.amazon.com, OU=Cyber, O=Amazon, L=Newark, ST=NY, C=US
Issuer CN=www.amazon.com, OU=Cyber, O=Amazon, L=Newark, ST=NY, C=US
sha1 c4 1e 51 d5 ae e6 e5 0b 34 5b 99 24 39 8c df e7 2e 57 77 5d
md5 6d 89 00 ac 2e 72 71 c2 9a 95 7b 6c f2 1d bd 26 Enter certificate to add to trusted keystore or 'q' to quit: [1]

Issue Fixed Log

javax.net.ssl.SSLException: java.lang.UnsupportedOperationException的更多相关文章

  1. 微信证书 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

    这几天在做微信退款接口,按照api写完之后,在本地测试了下没有问题,于是交给测试让他们在测试环境开测.他们说退款没有成功,感觉去查日志,发现后台报了 javax.net.ssl.SSLExceptio ...

  2. 解决 javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair

    解决这个异常的重点就在于下载两个jar包: bcprov-ext-jdk15on-1.52 bcprov-jdk15on-1.52 传送门:https://stackoverflow.com/ques ...

  3. presto——java.sql.SQLException: Error executing query与javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?异常问题

    使用presto的时候以mysql为presto的数据源 安装的presto是0.95版本:使用的presto-jdbc是0.202的,这里使用jdbc去访问时候,connection可以链接成功,但 ...

  4. JAVA连接MySQ报错:Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version

    Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version at sun.security.ssl.Al ...

  5. SO2O連接報錯javax.net.ssl.SSLException: Received fatal alert: protocol_version)

    原文:https://blog.csdn.net/gudejundd/article/details/89640741 1.什么是TLSSSL 是“Secure Sockets Layer”的缩写,中 ...

  6. java.lang.UnsupportedOperationException: Not supported by BasicDataSource

    场景: SpringMVC+Hibernate+Maven 问题: 在src/main/resources 目录中添加hibernate.properties文件, 则如果存在这句hibernate. ...

  7. java.lang.UnsupportedOperationException:This parser does not support specification "null" version "null"

    java.lang.UnsupportedOperationException: This parser does not support specification "null" ...

  8. 【java】在分页查询结果中对最后的结果集List进行操作add()或remove()操作,报错:java.lang.UnsupportedOperationException

    场景: 在分页查询结果中对最后的结果集List进行操作add()或remove()操作,报错:java.lang.UnsupportedOperationException 错误: java.lang ...

  9. Cause: java.lang.UnsupportedOperationException

    运行web项目的时候出现以下错误: ### Cause: java.lang.UnsupportedOperationException    at org.mybatis.spring.MyBati ...

随机推荐

  1. 基于toyix的进程和轻权进程的学习

    我们在平时的计算机课上学习过进程,知道程序的执行的背后其实就是进程在进行一些操作.大家都知道打开windows的任务管理器可以看到正在运行的进程,当程序卡死时,可以在任务管理器里强制关闭相关程序的进程 ...

  2. hdu 畅通工程

    http://acm.hdu.edu.cn/showproblem.php?pid=1863 #include <cstdio> #include <cstring> #inc ...

  3. Codeforces 540D Bad Luck Island

    http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...

  4. Altium Designer (protel) 各版本“故障”随谈

    Altium 的版本很多,每个版本都或多或少有些可容忍或可不容忍的问题,此贴只是希望各位能将遇到的问题写出来,只是希望 给还在使用 altium 的网友一些参考,也希望有些能被 altium 所接受@ ...

  5. Ugly Number II 解答

    Question Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime ...

  6. javascript定时器:setTimeout与setInterval

    概述: setTimeout:在指定的延迟时间之后调用一个函数或者执行一个代码片段,只执行一次: setInterval:周期性地调用一个函数(function)或者执行一段代码,重复执行: 语法格式 ...

  7. spark1.1.0学习路线

          经过一段时间授课,积累下不少的spark知识.想逐步汇总成资料,分享给小伙伴们.对于想视频学习的小伙伴,能够訪问炼数成金站点的<spark大数据平台>课程.每周的课程是原理加实 ...

  8. UIApplication的作用

    1.设置app图标右上角的数字2.设置状态栏的属性(样式.是否要显示)3.打开某个链接\发短信\打电话4.keyWindow : 访问程序的主窗口(一个程序只能有一个主窗口)5.windows : 访 ...

  9. <经验杂谈>C#/.Net中xml的Serialization序列化与DeSerializetion反序列化

    1.先讲概念:.Net Framework提供了对应的System.Xml.Seriazliation.XmlSerializer负责把对象序列化到XML,和从XML中反序列化为对象.Serializ ...

  10. Asp.Net HttpApplication请求管道与Session(一)

    1.请求处理顺序执行事件 /********************请求处理顺序执行事件**********************/ /// <summary> /// 请求入站 /// ...