2017-07-10 24 views
0

私は、サービスとパスワードによって作成された証明書が必要な外部SOAP Webサービスへの接続を試みる、マイクロサービス内のSpringブートサービスに入っています。これはWindowsで書かれていますが、Unix上で実行する必要があります。今、私はWindows用にいくつかのものをハードコードしました。これは私が私の側のためにコード化されたものですが、私はhttpConn.getInputStream上のエラー()取得しています:内部ファイルSSL証明書でパスワードが失敗しました

「sun.security.validator.ValidatorException:PKIXパスの構築に失敗しました:sun.security.provider.certpathを。 SunCertPathBuilderException:要求されたターゲットへの有効な証明書パスを見つけることができません "。

誰かが私が行方不明を理解するのを助けることができますか?

public String getSoapData(String contentType) throws IOException, NoSuchAlgorithmException, KeyManagementException, CertificateException, KeyStoreException { 
    StringBuilder retVal = new StringBuilder(); 

    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); 

    // get user password and file input stream 
    char[] password = "MYPass".toCharArray(); 

    java.io.FileInputStream fis = null; 
    //X509Certificate caCert = null; 
    //CertificateFactory cf = CertificateFactory.getInstance("X.509"); 

    try { 
     fis = new java.io.FileInputStream("C:\\MyCerts\\dev_HubExplorer1.pfx"); 
     ks.load(fis, password); 
     //caCert = (X509Certificate)cf.generateCertificate(fis); 
     //ks.setCertificateEntry("caCert", caCert); 
    } catch (Exception e) { 
     Common.screenPrint("Exception while importing certificate:%s%s", Common.CRLF, e.getMessage()); 
    } finally { 
     if (fis != null) { 
      fis.close(); 
     } 
    }  

    tmf.init(ks); 

    //TODO (GWL) Need to get this from a configuration file/db. 
    SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); 
    sslContext.init(null, tmf.getTrustManagers(), new java.security.SecureRandom()); 

    URL url = new URL(_publicRecordURL); 
    HttpsURLConnection httpConn = (HttpsURLConnection) url.openConnection(); 
    httpConn.setSSLSocketFactory(sslContext.getSocketFactory()); 
    byte[] bytes = _requestTemplate.getBytes(); 

    // Set the appropriate HTTP parameters. 
    httpConn.setRequestProperty("Content-Length", String.valueOf(bytes.length)); 
    httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8"); 
    httpConn.setRequestProperty("SOAPAction",_soapAction); 
    httpConn.setRequestProperty("Accept","text/xml"); 
    httpConn.setRequestMethod("POST"); 
    httpConn.setDoOutput(true); 
    httpConn.setDoInput(true); 

    //Everything's set up; send the XML that was read in to b. 
    OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream()); 
    writer.write(_requestTemplate); 
    writer.flush(); 

    //Read the response and write it to standard out. 
    InputStreamReader isr = new InputStreamReader(httpConn.getInputStream()); 
    BufferedReader in = new BufferedReader(isr); 

    String inputLine; 

    while ((inputLine = in.readLine()) != null) { 
     retVal.append(inputLine + Common.CRLF); 
     System.out.println(inputLine); 
    } 

    in.close(); 

    return retVal.toString(); 
} 

答えて

0

あなたはこの問題の解決策を得るために、このstackoverflow答えをたどることができます。

https://stackoverflow.com/a/12146838/7801800

+0

はすでに、それが証明書を受け入れることを得るように見えることはできません..私は証明書を知っていることをしようとしました同じサービスに問題なく接続するために.NET内で使用しているので、パスワードで動作します。 keytool -import -alias example -keystore C:¥Program Files¥x86¥Java¥jre1.8.0_131¥lib¥security¥cacerts -file dev_HubExplorer1.pfx – Switch

+0

私は明らかに検索できますが、その解決策は機能していません。時間、私は助けを探しています。 – Switch

+0

keytoolエラー:java.lang.Exception:X.509証明書が入力されていません – Switch

関連する問題