나는 자동 테스트를 처음으로 사용하고 있습니다. 그래서 API 테스트를위한 자동화 된 스크립트를 만드는 작업이 있습니다. 자체 서명 된 인증서로 https 요청을 만들어야합니다. 이 인증서는 p12 확장자와 암호 파일을 사용하여 관리자에게 알려주었습니다. 이 인증서를 .cer extension으로 내 보냈습니다. 신뢰 저장소를 만든 다음이 인증서를이 저장소로 가져옵니다. 스레드 "main"의 예외 javax.net.ssl.SSLHandshakeException : sun.security.validator.ValidatorException : 신뢰할 수있는 인증서를 찾을 수 없음
C:\Program Files (x86)\Java\jdk1.8.0_25\jre\bin>keytool -import -keystore clienttrust.jks -file marta.cer -storepass storepass
예외 :이 코드는 내가 다음 예외를 얻을 실행 한 후,
public void testSimpleHttpsClient() throws CertificateException, InterruptedException, UnrecoverableKeyException, NoSuchAlgorithmException,
IOException, KeyManagementException, KeyStoreException {
URL url = new URL("https://intstg1-kaakioskpublicapi.ptstaging.ptec/TLE/36171/player/info");
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
con.setRequestMethod("GET");
SSLContext sslContext = SSLContext.getInstance("TLS");
char[] passphrase = "storepass".toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(this.getClass().getResourceAsStream("clienttrust.jks"), passphrase);
System.out.println(ks);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);
System.out.println(tmf.toString());
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
public boolean verify(String s, SSLSession sslSession) {
return s.equals(sslSession.getPeerHost());
}
};
con.setHostnameVerifier(hostnameVerifier);
sslContext.init(null, tmf.getTrustManagers(), null);
con.setSSLSocketFactory(sslContext.getSocketFactory());
int responseCode = con.getResponseCode();
InputStream inputStream;
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = con.getInputStream();
} else {
inputStream = con.getErrorStream();
}
// Process the response
BufferedReader reader;
String line = null;
reader = new BufferedReader(new InputStreamReader(inputStream));
while((line = reader.readLine()) != null)
{
System.out.println(line);
}
inputStream.close();
}
그래서 다음은
코드입니다 sun.security.validator .ValidatorException : 신뢰할 수있는 인증서가 없습니다.at sun.security.ssl.Alerts.getSSLException (Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal (SSLSocketImpl.java:1917) at sun.security.ssl .Handshaker.fatalSE (Handshaker.java:301) at sun.security .ssl.Handshaker.fatalSE (Handshaker.java:295) at sun.security.ssl.ClientHandshaker.serverCertificate (ClientHandshaker.java:1471) at sun.security.ssl.ClientHandshaker.processMessage (ClientHandshaker.java:212) sun.security.ssl.Handshaker.processLoop (Handshaker.java:936) at sun.security.ssl.Handshaker.process_record (Handshaker.java:871) at sun.security.ssl.SSLSocketImpl.readRecord (SSLSocketImpl.java) : 1,043) sun.security.ssl.SSLSocketImpl.performInitialHandshake (SSLSocketImpl.java:1343에서 ) sun.security.ssl.SSLSocketImpl.startHandshake (SSLSocketImpl.java:1371에서 )에서 sun.security.ssl.SSLSocketImpl.startHandshake (SSLSocketImpl.java:1355) at sun.net.www.protocol.https.HttpsClient.afterConnect (HttpsClie nt.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect (AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0 (HttpURLConnection.java:1511) at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java:1439) at java.net.HttpURLConnection.getResponseCode (HttpURLConnection.java:480) at sun.net.www.protocol.https. HttpsURLConnectionImpl.getResponseCode (HttpsURLConnectionImpl.java:338) httpConnection.Connection.main에서 httpConnection.Connection.testSimpleHttpsClient에서 (Connection.java:179) (Connection.java:22) sun.reflect.NativeMethodAccessorImpl.invoke0에서 (기본 방법) at sun.reflect.NativeMet hodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)에서 java.lang.reflect.Method.invoke (Method.java:483)에서 com.intellij에서 . rt.execution.application.AppMain.main (AppMain.java:120) 발생 원인 : sun.security.validator.ValidatorException : 신뢰할 수있는 인증서가 없습니다. at sun.security.validator.SimpleValidator.buildTrustedChain (SimpleValidator.java:384) at sun.security.validator.SimpleValidator.engineValidate (SimpleValidator.java:133)at sun.security.validator.Validator.validate (Validator.java:260) at sun.security.ssl.X509TrustManagerImpl.validate (X509TrustManagerImpl. java : 324) at sun.security.ssl.X509TrustManager Impl.sun.security.ssl.ClientHandshaker.serverCertificate에서 sun.security.ssl.X509TrustManagerImpl.checkServerTrusted (X509TrustManagerImpl.java:124) 에서 checkTrusted (X509TrustManagerImpl.java:229) (ClientHandshaker.java:1453) ... 20 이상의
얘들 아,이 문제를 해결하는 방법을 설명해주세요.
[여기]를보고 (HTTP 있습니다 //ankursinghal86.blogspot합니다. jp/2014/06/authentication-with-client-certificate.html) –
Ankur-Singhal, 귀하의 조언에 감사드립니다. 나는 너에게 질문이있다. 내 인증서의 항목 유형은 'trustedCertEntry'이지만 기사에서는 - 항목 유형 : PrivateKeyEntry입니다. '입력 유형'이 중요합니까? – marta
사용중인'HostnameVerifier '가 안전하지 않습니다. 역방향 조회 (MITM 공격에 취약하므로)와 대조하여 호스트 이름 만 검사합니다. – Bruno