有服务器A和客户端B两台机器A上运行的服务对外开放https,其中数字证书(XXX.crt)是通过系统(RedHat)自带的OpenSSL模块产生客户端B为自身的PC,Java环境运作正常。%JAVA_HOME%:D:/Program Files/Java/jdk1.6.0_03/写一个测试类testporj.java,如下:import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;public class testporj {
/**
* @param args
* @throws IOException
* @throws IOException
*/ public static void main(String[] args) throws IOException {
try {
URL url = new URL("https://32.12.21.41/ConnTest/conntest?merchant_id=12345678");
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlconn.getInputStream()));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行,报错:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target通过keytool导入数字证书
keytool -import -file d:/XXX.crt -keystore D:/Program Files/Java/jdk1.6.0_03/jre/lib/security/cacerts
输入密码并信任证书后导入成功:提示“认证已添加至keystore中”再次运行,报错:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
服务器端应该是正常的,因为已有很多用户正常连接进来(使用相同的数字证书XXX.crt)。我想搭一台测试机,像上面那样一直不能连接成功
请问是哪里的问题?
谢谢!!!
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;public class testporj {
/**
* @param args
* @throws IOException
* @throws IOException
*/ public static void main(String[] args) throws IOException {
try {
URL url = new URL("https://32.12.21.41/ConnTest/conntest?merchant_id=12345678");
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlconn.getInputStream()));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行,报错:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target通过keytool导入数字证书
keytool -import -file d:/XXX.crt -keystore D:/Program Files/Java/jdk1.6.0_03/jre/lib/security/cacerts
输入密码并信任证书后导入成功:提示“认证已添加至keystore中”再次运行,报错:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
服务器端应该是正常的,因为已有很多用户正常连接进来(使用相同的数字证书XXX.crt)。我想搭一台测试机,像上面那样一直不能连接成功
请问是哪里的问题?
谢谢!!!
谢谢。这篇文章我也找到过,是固定返回一个假的结果绕过了服务端的某一项验证,感觉不能解决根本问题。不过我还是会试试。TO 5楼:
提示“认证已添加至keystore中”,说明证书导入是成功的!