我想使用SSL连接连接到我们的大学服务器。
在配置文件夹中有以下文件:
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文件做任何事情。这可能是问题所在吗?我遗漏了什么?
谢谢。
还有两件事:
systemProps.put( "javax.net.ssl.keyStorePassword", "pass");发布于 2012-11-22 02:22:14
试着像这样重新排序你的电话:
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);https://stackoverflow.com/questions/13504999
复制相似问题