簡體   English   中英

Java SSLSocket:PKIX路徑構建失敗

[英]Java SSLSocket: PKIX path building failed

我想使用SSL連接連接到我們的大學服務器。

我在配置文件夾中有以下文件:
-client.policy
-uni_keystore.jks
-uni_server.cer
-uni_truststore.jks

client.policy文件包含以下內容:

grant { 
  permission java.security.AllPermission ;
};

與服務器的連接已建立,但是當我嘗試從服務器讀取時,出現異常:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: 
  PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
  unable to find valid certification path to requested target

這是我連接到服務器的方式(我修剪了try / catch塊以縮短代碼):

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();

String configPath = "C:/eclipse/workspace/uniproject/";

Properties systemProps = System.getProperties();
systemProps.put( "javax.net.ssl.trustStore", configPath+"uni_truststore.jks");
systemProps.put( "javax.net.ssl.keyStore", configPath+"uni_keystore.jks");
System.setProperties(systemProps);

s = (SSLSocket) factory.createSocket(UNI_ADDRESS, UNI_PORT);

我正在通過我的VPN連接到服務器。

這就是我嘗試讀取的方式(我修剪了try / catch塊以縮短代碼):

InputStream istream = s.getInputStream();
BufferedReader reader = new BufferedReader( new InputStreamReader(istream) );

String data;
do {
    // this lines throws exception
    data = reader.readLine();
    System.out.println(data);
}
while(data != null);

我沒有對代碼中的client.policy和uni_server.cer文件做任何事情。 這可能是問題嗎? 我想念什么?

謝謝。


還有2件事:

-我安裝了認證(在發布此信息之前,我還沒有)
-我添加了一行:

systemProps.put( "javax.net.ssl.keyStorePassword", "pass");

嘗試像這樣對電話重新排序:

String configPath = "C:/eclipse/workspace/uniproject/";
Properties systemProps = System.getProperties();
systemProps.put( "javax.net.ssl.trustStore", configPath+"uni_truststore.jks");
systemProps.put( "javax.net.ssl.keyStore", configPath+"uni_keystore.jks");
System.setProperties(systemProps);

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
s = (SSLSocket) factory.createSocket(UNI_ADDRESS, UNI_PORT);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM