我继承了一些 WSS4J 安全网络服务代码。它基于这个流行的教程:http://distributedsenses.blogspot.com/2008/09/configuring-cxf-for-web-service.html
现在服务器端正在与其他客户端一起工作,但我的不是。 :(
我为tomcat生成一个keystore,导出公钥,安装到服务器上。但是当我尝试调用时,服务器回复错误 No certificates were found for decryption (KeyId)
现在我没有对代码做一些更改,但我确实更改了包名称(我认为这对 SOAP 调用无关紧要)——我没有更改 namespace 。
我什至在服务器上导出了证书以确保我正确导入了它,并且它与客户端上的公钥完全匹配。所以我知道服务器有我的证书。
这是我的拦截器
<bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor" id="TimestampSignEncrypt_Request"> <constructor-arg> <map> <entry key="action" value="Timestamp Signature Encrypt"/> <entry key="user" value="clientwin"/> <entry key="encryptionUser" value="tomcat2"/> <entry key="signatureKeyIdentifier" value="DirectReference"/> <entry key="signaturePropFile" value="clientSign.properties"/> <entry key="encryptionPropFile" value="clientEncrypt.properties"/> <entry key="passwordCallbackClass" value="ClientKeystorePasswordCallback"/> <entry key="signatureParts" value="{Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body"/> <entry key="encryptionParts" value="{Element}{http://www.w3.org/2000/09/xmldsig#}Signature;{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body"/> <entry key="encryptionSymAlgorithm" value="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/> <entry key="encryptionKeyTransportAlgorithm" value="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/> <entry key="signatureAlgorithm" value="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> </map> </constructor-arg> </bean>
还有我的 clientSign.properties
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=changeit
org.apache.ws.security.crypto.merlin.keystore.alias=clientwin
org.apache.ws.security.crypto.merlin.file=C:\\apache-tomcat-7.0.55\\ssl\\.keystore
我收到此错误的任何原因。我知道我的公钥在服务器的信任库中。这适用于其他客户。知道我做错了什么吗?
最佳答案
首先,让我们了解发生了什么以及出了什么问题。客户端,我,正在向服务器发送加密请求。我需要使用服务器公钥来加密消息。这是上面的“encryptionUser”属性。它的值是将服务器公钥导入我的 keystore 时使用的别名。服务器将使用其私钥来解密消息。
没有找到用于解密的证书 (KeyId) 的原因是您(客户端)用来加密消息的公钥与服务器拥有的私钥不匹配。您需要要求服务器使用 keytool,导出它的公钥,然后导入它(使用 keytool)并且您使用的别名需要与 xml 中的 encryptionUser 匹配。
在我的例子中,用于加密所有内容的 key 对不同于用于 SOAP 调用本身的 HTTPS 的 key 对。因此,使用 InstallCert,或者只是在查看 WSDL 无效时从我的 Web 浏览器中保存证书。
希望这对以后的菜鸟有所帮助!
关于java - org.apache.ws.security.WSSecurityException : General security error (No certificates were found for decryption (KeyId)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25046942/