2013-02-22 4 views
2

공급 업체가 제어하는 ​​SOAP 웹 서비스 용 클라이언트를 빌드하고 있습니다. 불행히도 그들의 dev 서버에는 검증 할 수없는 안전하지 않은 (자체 서명 된) 인증서가 있습니다. Apache Axis는 요청할 때마다 실패합니다. SSL 유효성 검사 오류를 무시할 수있는 방법이 있습니까? 분명히 생산을 위해 이것을하고 싶지는 않지만 내 개발 환경에서 좋을 것입니다.Axis 클라이언트에서 유효하지 않은 인증서 무시

+0

거기에 관련된 StackOverflow 답변 - 나도 근무 : http://stackoverflow.com/questions/10913185/ignore-certification/authentication-on-axis-client-for-wcf-service#10913791 –

답변

1

를, 무엇을 궁극적으로 사용자 지정 프로토콜 처리기를 설치하고 특정과 연결되었다 일 ServiceClient :

private void configureServiceClient(ServiceClient client) { 
     SSLContext ctx; 
     try { 
      KeyStore truststore = KeyStore.getInstance("JKS"); 
      truststore.load(getClass().getResourceAsStream("/truststore.jks"), 
        "latitude".toCharArray()); 

      ctx = SSLContext.getInstance("SSL"); 
      TrustManagerFactory tmf = TrustManagerFactory 
        .getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
      tmf.init(truststore); 
      ctx.init(null, tmf.getTrustManagers(), null); 
     } catch (Exception e) { 
      logger.error("Exception loading Bold trust store", e); 
      throw new RuntimeException(e); 
     } 

     SSLProtocolSocketFactory sslFactory = new SSLProtocolSocketFactory(ctx); 
     Protocol prot = new Protocol("https", 
       (ProtocolSocketFactory) sslFactory, 443); 
     client.getOptions().setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, 
       prot); 
} 
이것의 장점은 새 인증서 내가라면 가능성이 길 아래에 물건을 파손 한 수 내 응용 프로그램에 대한 SSL 연결을 모두 무시하라고 요구하지 않았다이었다

발사됐다. 이 인증서는 새로운 인증서가 발급 될 경우 확실히 중단되지만 모든 인증서가 아니라 하나의 연결입니다.

2

당신이 요청 호출하기 전에 아래의 코드를 삽입, 인증서 유효성 검사를 해제하십시오 - 솔루션의 숫자를 시도 후

// Create a trust manager that does not validate certificate chains 
    final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { 
      @Override 
      public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
       return null; 
      } 

      @Override 
      public void checkClientTrusted(X509Certificate[] certs, String authType) { 
      } 

      @Override 
      public void checkServerTrusted(X509Certificate[] certs, String authType) { 
      } 
     } 
    }; 

    // Install the all-trusting trust manager 
    try { 
     SSLContext sc = SSLContext.getInstance("SSL"); 
     sc.init(null, trustAllCerts, null); 
     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 
    } catch (Exception ex) { 
     // take action 
    } 
+0

이것은 실제로 그러나 나를 위해 일하지 않았다, 나는 일을 끝낸 것을 게시했다. 나는 당신이 제안한 것을 이해하고 그것이 왜 나에게 효과가 없었는지 확신 할 수 없다. –

+3

재미 있지만, 기본 SSL 소켓 팩토리를 설정하면 작동하지 않지만 대신 SSLContext.setDefault (sc);를 수행하면 작동합니다. Oracle Java 1.6 – user1516873

관련 문제