com.sun.xml.wss.XWSSecurityException: 找不到别名的证书



我正在尝试加密SOAP请求。问题是 reuest 是正确的签名,但在加密方面,我收到以下错误:

这是在 spring-ws 文档 (https://docs.spring.io/spring-ws/site/reference/html/security.html(:

7.2.4.2. 加密 要加密传出的 SOAP 消息,安全策略文件应包含一个 Encrypt 元素。此元素可以进一步 携带一个加密目标元素,该元素指示 消息应加密,并使用对称密钥指示 应使用共享密钥而不是常规公钥来 加密邮件。您可以阅读其他元素的描述 这里。

XwsSecurityInterceptor将触发加密密钥回调 注册处理程序以检索加密信息。 在 Spring-WS 中,有一个类处理这个特定的 回调:KeyStoreCallbackHandler。

我的错误:

2019-10-16 19:56:52.482 ERROR 5264 --- [nio-8080-exec-1] j.e.resource.xml.webservices.security    : WSS0221: Unable to locate matching certificate for Key Encryption using Callback Handler.
2019-10-16 19:56:52.494 ERROR 5264 --- [nio-8080-exec-1] com.sun.xml.wss.logging.impl.filter      : WSS1413: Error extracting certificate 
com.sun.xml.wss.XWSSecurityException: Unable to locate certificate for the alias ''
at com.sun.xml.wss.impl.misc.DefaultSecurityEnvironmentImpl.getCertificate(DefaultSecurityEnvironmentImpl.java:365) ~[xws-security-3.0.jar:3.0-FCS]

我的代码:

@Bean
public XwsSecurityInterceptor securityInterceptor() {
XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
securityInterceptor.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
try{
securityInterceptor.setCallbackHandler(callback());
securityInterceptor.afterPropertiesSet();

}
catch (Exception e)  {
System.out.println("display Expensionm: " + e);
}
return securityInterceptor;
}
@Bean
public KeyStoreCallbackHandler callback() throws Exception{
KeyStoreCallbackHandler callbackHandler = new KeyStoreCallbackHandler();

callbackHandler.setPrivateKeyPassword("sopasswordo");
callbackHandler.setDefaultAlias("test");
callbackHandler.setKeyStore(keyStoreFactoryBean());
callbackHandler.setTrustStore(TrustFactoryBean());
return callbackHandler;
}

@Bean
public KeyStore keyStoreFactoryBean(){
KeyStoreFactoryBean keyStoreFactoryBean = new KeyStoreFactoryBean();
keyStoreFactoryBean.setPassword("sotore_passwordo");
//keyStoreFactoryBean.setType("JKS");
System.out.println("1");
keyStoreFactoryBean.setLocation(new FileSystemResource("C:\Users\miha_\OneDrive\Dokumenti\Job\Lj\Spring\Porting\target\classes\softnet.jks"));
try{
keyStoreFactoryBean.afterPropertiesSet();
}catch (Exception e){
System.out.println("e: "+e );
}
return  keyStoreFactoryBean.getObject();
}
@Bean
public KeyStore TrustFactoryBean(){
KeyStoreFactoryBean trustFactory = new KeyStoreFactoryBean();
trustFactory.setPassword("sostore_passwordo");
//keyStoreFactoryBean.setType("JKS");
System.out.println("1");
trustFactory.setLocation(new FileSystemResource("C:\Users\miha_\OneDrive\Dokumenti\Job\Lj\Spring\Porting\target\classes\trust.jks"));
try{
trustFactory.afterPropertiesSet();
}catch (Exception e){
System.out.println("e: "+e );
}
return  trustFactory.getObject();
}
@Override
public void addInterceptors(List interceptors) {
interceptors.add(securityInterceptor());
}

我不知道未设置enrypt证书的别名,并且未检索证书。我设置了默认别名,但我想我还缺少其他东西。

我的政策:

<xwss:SecurityConfiguration xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
<xwss:Sign includeTimestamp="false" />
<xwss:Encrypt />
</xwss:SecurityConfiguration>

xwss:Encrypt 元素由客户端与服务器的公钥(证书(一起使用,以初始化共享密钥(对称密钥(的交换。

您需要在客户机密钥库中提供服务器证书的别名(服务器的公钥(。

例:

<xwss:Encrypt>
<xwss:X509Token certificateAlias="myServerPubCert"/>
</xwss:Encrypt>

您还必须向 xwss:sign 元素提供客户端私钥的别名。

例:

<xwss:Sign includeTimestamp="false">
<xwss:X509Token certificateAlias="myClientPrivKey"/>
</xwss:Sign>

最新更新