2009-08-13 7 views
2

을 통해 HTTPS를 통해 파일을 다운로드 내가 때문에자바 여기

  int status = client.executeMethod(get); 

나는 다음과 같은 오류를 얻을 라인의

/** 
* A simple example that uses HttpClient to perform a GET using Basic 
* Authentication. Can be run standalone without parameters. 
* 
* You need to have JSSE on your classpath for JDK prior to 1.4 
* 
* @author Michael Becke 
*/ 
public class BasicAuthenticationExample { 

    /** 
    * Constructor for BasicAuthenticatonExample. 
    */ 
    public BasicAuthenticationExample() { 
     super(); 
    } 

    public static void main(String[] args) throws Exception { 
     HttpClient client = new HttpClient(); 

     client.getState().setCredentials(
       new AuthScope("login.website.com", 443), 
       new UsernamePasswordCredentials("login id", "password") 
       ); 

     GetMethod get = new GetMethod(
       "https://url to the file"); 

     get.setDoAuthentication(true); 

     try { 
      // execute the GET 
      int status = client.executeMethod(get); 

      // print the status and response 
      System.out.println(status + "\n" + 
        get.getResponseBodyAsString()); 

     } finally { 
      // release any connection resources used by the method 
      get.releaseConnection(); 
     } 
    } 
} 

이제 웹에서 복사 된 코드

Exception in thread "main" 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 
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source) 
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source) 
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source) 
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source) 
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source) 
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source) 
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(Unknown Source) 
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(Unknown Source) 
at java.io.BufferedOutputStream.flushBuffer(Unknown Source) 
at java.io.BufferedOutputStream.flush(Unknown Source) 
at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:828) 
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2116) 
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096) 
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) 
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) 
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) 
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) 
at BasicAuthenticationExample.main(BasicAuthenticationExample.java:38) 
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
at sun.security.validator.PKIXValidator.doBuild(Unknown Source) 
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) 
at sun.security.validator.Validator.validate(Unknown Source) 
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source) 
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) 
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) 
... 18 more 
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source) 
at java.security.cert.CertPathBuilder.build(Unknown Source) 
... 24 more 

이제이 오류의 원인은 내 서버에서 보낸 인증서가 신뢰할 수있는 인증서 목록에없는 것입니다. 제 질문은 인증서를 신뢰할 수있는 목록으로 가져 오는 방법입니다.

감사 Pranabesh는

답변

3

이 페이지는 귀하의 질문에 대답하는 것 같다.

신뢰할 수있는 저장소에 인증서를 실제로 추가하고 싶지 않을 수도 있습니다 (테스트 전용 인 경우). 따라서 disable certificate validation도 가능합니다.

+2

감사를 실행하여 다음과 같이 키 도구를 사용할 수 있습니다. –

+2

남자, 어떤 만족스러운 피드백;) –

2

신뢰할 수있는 인증서가 포함 된 키 저장소가 필요합니다. Java의 keytool 명령을 사용하여이를 수행 할 수 있습니다.

  • 대체 키 스토어의 위치에 시스템 속성 javax.net.ssl.trustStore 설정 (Windows의 홈 디렉토리 또는 사용자 디렉토리에 .keystore)

    • 기본 Java 키 저장소에 추가 (:이 작업을 수행 할 수있는 몇 가지 방법이 있습니다 키 스토어 당신이 원하는 방식으로로드 할 수 있습니다 java -Djavax.net.ssl.trustStore=/path/to/keystore 같은)
    • 자신의 SSLSocketFactory 구현을 빌드 (이 확실히 가장 복잡하다)

    키 스토어 그냥 파일 그쪽입니다 다양한 경우에 사용할 수있는 키 및/또는 인증서 (이 경우 응용 프로그램에서 신뢰해야하는 인증서)가 들어 있습니다. 다른 명령 줄 옵션을 보려면

    keytool -importcert -file /path/to/certificate/file -keystore /path/to/keystore 
    

    단지 lot.You 아마 나에게 직장을 얻을 도움이

    keytool -help