gpt4 book ai didi

java - Soap with CXF,设置SSL和TLS协议(protocol)版本

转载 作者:太空宇宙 更新时间:2023-11-03 14:08:08 24 4
gpt4 key购买 nike

根据下面的代码,如何设置协议(protocol)为TLSv1.2,TLSv1,SSLv3?

使用 SoapUi,我可以使用以下配置请求服务:-Dsoapui.https.protocols=TLSv1.2,TLSv1,SSLv3

使用 CXF,我收到“javax.net.ssl.SSLHandshakeException:没有合适的协议(protocol)(协议(protocol)被禁用或密码套件不合适)”

如果我要删除 SSLv3,则输出为“javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure”

抱歉我对 Soap 和 SSL 的了解不多...

URL wsdlLocation = this.getClass().getResource("service.wsdl");

Service service = new Service(wsdlLocation);
Soap stub = service.getSoap();

BindingProvider bp = (BindingProvider) stub;

Map<String, Object> context = bp.getRequestContext();

context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://url.to.service/service");

Client client = ClientProxy.getClient(stub);

HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
try {
TLSClientParameters tlsParams = new TLSClientParameters();
tlsParams.setDisableCNCheck(true);
tlsParams.setSecureSocketProtocol("SSLv3");

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

File truststore = new File("/home/user/keystore.jks");
keyStore.load(new FileInputStream(truststore), trustpass.toCharArray());
TrustManagerFactory trustFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(keyStore);
TrustManager[] tm = trustFactory.getTrustManagers();
tlsParams.setTrustManagers(tm);

truststore = new File("/home/user/keystore.jks");
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 (Exception e) {
LOG.error(e.getMessage());
}

最佳答案

我遇到了同样的问题并通过更改协议(protocol)名称从tlsParams.setSecureSocketProtocol("SSL");tlsParams.setSecureSocketProtocol("TLSv1");

注意在更改之前,您应该先确定哪个协议(protocol)版本(SSLv1?SSLv2?TLSv1 ....)。请引用determine the protocol name and version

另外,如果此解决方法对您不起作用,请参阅 possible causes希望这对你和其他人有用

关于java - Soap with CXF,设置SSL和TLS协议(protocol)版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36871615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com