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");