我的java版本是
java版“1.7.0_51”
Java(TM)SE运行时环境(版本1.7.0_51-b13)
Java HotSpot(TM)64位服务器VM(内置24.51-b03,混合模式)
我有一台服务器/设备有不受信任的证书。当我使用HttpURLConnection连接到此设备时,它会抛出空指针异常,如下所示。
update51引入了许多安全性,但我相信它应该弹出不受信任的证书而不是NPException的对话框。看起来像是Oracle java update51中的一个明显错误。我在bugs.sun.com中创建了一个错误,但我没看到我的bug id在他们的bug数据库中可见。
重现的步骤。
-----------------------------------------------启动----------------------------------------
package com.xyz;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Test {
public static void main(String[] args) throws IOException {
DMTrustManager.installDeployTrustManager();
URL url = new URL("https://hostname/admin/version.xml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader br =
new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String input;
while ((input = br.readLine()) != null){
System.out.println(input);
}
}
}
---------------------------代码片段结束---------------- ------
将URL替换为具有不受信任证书的服务器IP地址。
我看到以下异常。
--------------------------------例外的开始----------- ---------
java.lang.NullPointerException
at com.sun.deploy.security.DeployManifestChecker.printWarningsIfRequired(Unknown Source)
at com.sun.deploy.security.TrustDeciderDialog.doShowDialog(Unknown Source)
at com.sun.deploy.security.TrustDeciderDialog.showDialog(Unknown Source)
at com.sun.deploy.security.TrustDeciderDialog.showDialog(Unknown Source)
at com.sun.deploy.security.X509Extended7DeployTrustManager.checkServerTrusted(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
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)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.cisco.launcher.Test.main(Test.java:17)
Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Java couldn't trust Server
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
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)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.xyz.Test.main(Test.java:17)
Caused by: java.security.cert.CertificateException: Java couldn't trust Server
at com.sun.deploy.security.X509Extended7DeployTrustManager.checkServerTrusted(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
... 12 more
----------------------------------------------- --end -------------------------------------------
进一步说明:
我看到doShowDialog()
中的com.sun.deploy.security.TrustDeciderDialog
功能在printWarningsIfRequired
课程中对DeployManifestChecker
进行了新的调用。
static void printWarningsIfRequired(URL paramURL, AppInfo paramAppInfo)
{
String str1 = (String)ToolkitStore.get().getAppContext().get("deploy-" + paramURL);
Resource localResource = ResourceProvider.get().getCachedResource(paramURL, str1);
///但是这里str1本身为null或者Map没有任何名为“deploy-”+ paramURL的键。所以我猜它失败了。
在我看来,对此功能的调用只能在webstart中使用,而不能用于独立应用程序。
...
...