Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ssl握手失败soap_Java_Ssl_Soap - Fatal编程技术网

Java ssl握手失败soap

Java ssl握手失败soap,java,ssl,soap,Java,Ssl,Soap,我通过使用ssl v3保护的cxf使用soap服务。 我从服务器下载.cer文件,并使用以下指令通过keytool创建JKS文件: keytool -import -v -file iban.cer -keystore iban.jks 在java代码中,我将此代码用于客户端配置: public void configureSSLOnTheClient(Object c) { org.apache.cxf.endpoint.Client client = Client

我通过使用ssl v3保护的cxf使用soap服务。 我从服务器下载.cer文件,并使用以下指令通过keytool创建JKS文件:

keytool -import -v -file iban.cer -keystore iban.jks
在java代码中,我将此代码用于客户端配置:

    public void configureSSLOnTheClient(Object c) {

        org.apache.cxf.endpoint.Client client = ClientProxy.getClient(c);
        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
        File truststore = new File("jks/iban.jks");                   

        try {
            TLSClientParameters tlsParams = new TLSClientParameters();
            tlsParams.setDisableCNCheck(true);


            KeyStore keyStore = KeyStore.getInstance("JKS");
            String trustpass = "password";

            keyStore.load(new FileInputStream(truststore), trustpass.toCharArray());

            log.info("Trust Manager Type:"+TrustManagerFactory.getDefaultAlgorithm());
            TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

            trustFactory.init(keyStore);
            TrustManager[] tm = trustFactory.getTrustManagers();
            tlsParams.setTrustManagers(tm);

            keyStore.load(new FileInputStream(truststore), trustpass.toCharArray());

            KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());

            keyFactory.init(keyStore, trustpass.toCharArray());
            KeyManager[] km = keyFactory.getKeyManagers();
            tlsParams.setKeyManagers(km);


            FiltersType filter = new FiltersType();
            filter.getInclude().add(".*_EXPORT_.*");
            filter.getInclude().add(".*_EXPORT1024_.*");
            filter.getInclude().add(".*_WITH_DES_.*");
            filter.getInclude().add(".*_WITH_NULL_.*");
            filter.getExclude().add(".*_DH_anon_.*");
            tlsParams.setCipherSuitesFilter(filter);

            httpConduit.setTlsClientParameters(tlsParams);

        } catch (KeyStoreException kse) {
            log.info("Security configuration failed with the following: KeyStoreException " + kse.getCause());
            kse.printStackTrace();
        } catch (NoSuchAlgorithmException nsa) {
            log.info("Security configuration failed with the following: NoSuchAlgorithmException" + nsa.getCause());
            nsa.printStackTrace();
        } catch (FileNotFoundException fnfe) {
            log.info("Security configuration failed with the following: FileNotFoundException" + fnfe.getCause());
        } catch (UnrecoverableKeyException uke) {
            log.info("Security configuration failed with the following: UnrecoverableKeyException" + uke.getCause());
        } catch (CertificateException ce) {
            log.info("Security configuration failed with the following: CertificateException" + ce.getCause());
        } catch (GeneralSecurityException gse) {
            log.info("Security configuration failed with the following: GeneralSecurityException" + gse.getCause());
        } catch (IOException ioe) {
            log.info("Security configuration failed with the following: IOException" + ioe.getCause());
        }

    }
对于调用此代码的服务:

 String address = "https://xxxxxxxxxx/IBANSpecEnquiry/IBANSpec?wsdl";
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setServiceClass(IBANEnquirySpec.class);
    proxyFactory.setAddress(address);

    IBANEnquirySpec client = (IBANEnquirySpec) proxyFactory.create();
    configureSSLOnTheClient(client);
    Message04 message04 = client.getIBANSpec(message01);
运行代码时,出现以下错误:

 Interceptor for {http://WebServices/}IBANEnquirySpecService#{http://WebServices/}getIBANSpec has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at  org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingIntercept    or.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:570)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:479)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:136)
at com.sun.proxy.$Proxy143.getIBANSpec(Unknown Source)
at  ir.tejaratBank.service.impl.IBANClientManagerImpl.getIBANSpec(IBANClientManagerImpl.java:259)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
. 
.
.
.
Caused by: javax.net.ssl.SSLHandshakeException: SSLHandshakeException invoking https://192.168.65.118:443/IBANSpecEnquiry/IBANSpec?wsdl: Received fatal alert: handshake_failure
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1347)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1331)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
... 128 more
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.setupWrappedStream(URLConnectionHTTPConduit.java:174)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1290)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.onFirstWrite(HTTPConduit.java:1246)
at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.onFirstWrite(URLConnectionHTTPConduit.java:201)
at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
at org.apache.cxf.io.AbstractThresholdOutputStream.write(AbstractThresholdOutputStream.java:69)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1303)
... 131 more
我搜索这个错误,我意识到这个错误是坏的信任存储。
但是我不知道如何生成正确的信任库。

要生成信任库,请尝试使用以下方法:

keytool -import -alias youralias -file [path to certificate]/iban.cer -keystore [path to truststore.jks]/truststore.jks -storetype JKS
keytool -import -v -file iban.cer -keystore %JAVA_HOME%/jre/lib/security/cacerts -alias youralias
但更好的做法是,不要使用所有这些ssl配置,而是使用以下方法将证书导入java cacerts信任存储:

keytool -import -alias youralias -file [path to certificate]/iban.cer -keystore [path to truststore.jks]/truststore.jks -storetype JKS
keytool -import -v -file iban.cer -keystore %JAVA_HOME%/jre/lib/security/cacerts -alias youralias

该错误并不总是表示存在信任存储问题。 如果您使用的是Java 8,SSLv3可能会由于试图避免狮子狗攻击而被禁用


请参阅此相关帖子:

谢谢。我尝试在您的指导下创建jks文件,但结果没有发生任何事情。对不起,我回复晚了。生成信任库的另一种方法是使用openssl,这很容易,我相信您可以通过一个小的google搜索找到它的工作原理,但我也怀疑它是否会起作用,因为我猜您遇到的问题与信任库无关,我想这是与您使用的java版本的兼容性问题。。。我建议您尝试研究一下。顺便说一下,我通常对通过https进行Web服务调用的客户端所做的只是将证书导入客户端正在使用的java bin文件夹中的cacerts密钥库,使用我在回答中建议的第二个命令,不知道这是否有帮助,但我认为值得一试。我也有同样的问题,你的问题解决了吗?