我有这段代码:
String auth = username + ":" + password;
URL url = new URL(hostname + path);
TrustManager[] trustAllCerts = new TrustManager[] { new SSLTrustManager() };
HostnameVerifier hostnameVerifier = new SSLHostnameVerifier();
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "Basic " + auth);
conn.connect();
我遇到的问题是:使用IBM JDK 6,一切正常,IBM JDB 7失败并出现错误:
IBMJSSEProvider2 Build-Level: -20110720
keyStore is: C:\Program Files\IBM\Java70\jre\lib\security\cacerts
keyStore type is: jks
keyStore provider is:
init keystore
SSLContextImpl: Using X509ExtendedKeyManager com.ibm.jsse2.tc
SSLContextImpl: Using X509TrustManager com.ibm.cmsng.iem.SSLTrustManager
trigger seeding of SecureRandom
done seeding SecureRandom
Installed Providers =
IBMJSSE2
IBMJCE
IBMJGSSProvider
IBMCertPath
IBMSASL
IBMXMLCRYPTO
IBMXMLEnc
IBMSPNEGO
SUN
JsseJCE: Using KeyAgreement ECDH from provider IBMJCE version 1.7
JsseJCE: Using signature SHA1withECDSA from provider IBMJCE version 1.7
JsseJCE: Using signature NONEwithECDSA from provider IBMJCE version 1.7
JsseJCE: Using KeyFactory EC from provider IBMJCE version 1.7
JsseJCE: Using KeyPairGenerator EC from provider TBD via init
JsseJce: EC is available
JsseJCE: Using cipher AES/CBC/NoPadding from provider TBD via init
JsseJCE: Using SecureRandom from provider IBMJCE version 1.7
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
可能是什么问题? 我使用相同的主机:端口组合,没有变化。 IBM JDK中从版本6到7的SSL支持有哪些变化?我也尝试过使用Oracle的Java 8,但再次没有成功。
答案 0 :(得分:1)
java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method)
问题与TLS无关,但TCP连接已失败。 可能是您在不同系统上使用Java 6和Java 7程序,而第二个程序与目标主机没有连接。它也可能是IPv4连接有效但不是IPv6,但名称服务器同时返回IPv4和IPv6,Java 6使用IPv4,而Java 7则使用IPv6地址(并且失败)。