简体   繁体   English

org.apache.ws.security.WSSecurityException:常规安全错误(未找到用于解密的证书(KeyId))

[英]org.apache.ws.security.WSSecurityException: General security error (No certificates were found for decryption (KeyId))

I have inherited some code that is a WSS4J secure webservice. 我继承了一些WSS4J安全Web服务代码。 It is based off of this popular tutorial: http://distributedsenses.blogspot.com/2008/09/configuring-cxf-for-web-service.html 它基于以下流行教程: http : //distributedsenses.blogspot.com/2008/09/configuring-cxf-for-web-service.html

Now the server side is working with other clients, but mine is not. 现在服务器端正在与其他客户端一起工作,但是我的却没有。 :( :(

I generated a keystore for tomcat, exported the public key, and installed it on the server. 我为tomcat生成了一个密钥库,导出了公钥,并将其安装在服务器上。 But when I tried the call, the server replies with the error No certificates were found for decryption (KeyId) 但是,当我尝试呼叫时,服务器回复错误,未找到用于解密的证书(KeyId)

Now I made some no changes to the code, but I did change the package names (I don't think that matters for SOAP calls) -- I did NOT change the namespaces. 现在,我没有对代码进行任何更改,但是我确实更改了程序包名称(我认为这对SOAP调用无关紧要)-我没有更改名称空间。

I even exported the cert on the server to make sure that i imported it correctly, and it matches exactly the public key on the client. 我什至在服务器上导出了证书,以确保我正确导入了它,并且它与客户端上的公钥完全匹配。 So I know the server has my cert. 因此,我知道服务器具有我的证书。

Here is my OutInterceptor 这是我的OutInterceptor

  <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> 

And my clientSign.properties 还有我的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

Any reason why I am getting this error. 我收到此错误的任何原因。 I KNOW my public key is in the server's truststore. 我知道我的公钥在服务器的信任库中。 And this works for other clients. 这适用于其他客户。 Any Idea what I am doing wrong? 知道我在做什么错吗?

First, let's understand what's happening and what is going wrong. 首先,让我们了解正在发生的事情和出了什么问题。 The client, me, is sending an encrypted request to the server. 我的客户端正在向服务器发送加密的请求。 I need to use the Servers public key to encrypt the message. 我需要使用服务器的公共密钥来加密消息。 This is the "encryptionUser" property above. 这是上面的“ encryptionUser”属性。 It's value is the alias used when importing servers public key into my keystore. 它的值是将服务器公钥导入我的密钥库时使用的别名。 The server will use its private key to decrypt the message. 服务器将使用其私钥来解密消息。

The reason for any No certificates were found for decryption (KeyId) is that the public key you (the client) are using to encrypt your message, does not match the private key the server has. 未找到任何用于解密的证书(KeyId)的原因是您(客户端)用于加密消息的公钥与服务器拥有的私钥不匹配。 You need to ask the server to use keytool, export its public key, and then you import it (using keytool) and the alias you use needs to match encryptionUser in the xml. 您需要要求服务器使用keytool,导出其公共密钥,然后导入它(使用keytool),并且所使用的别名需要与xml中的encryptionUser匹配。

In my case, the keypair used to encrypt everything was different from the keypair used for HTTPS of the SOAP call itself. 以我为例,用于加密所有内容的密钥对与用于SOAP调用本身的HTTPS的密钥对不同。 So using InstallCert, or simply saving the cert from my web browser while looking at the WSDL as not working. 因此,使用InstallCert,或者只是在从Web浏览器中保存证书,同时将WSDL视为无效。

Hope this helps some noob in the future! 希望这对将来的菜鸟有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “未找到用于解密的证书”(Apache CXF,WS-Security) - “No certificates were found for decryption” (Apache CXF, WS-Security) 造成原因:org.apache.wss4j.common.ext.WSSecurityException:找不到用于加密的用户服务器证书 - Caused by: org.apache.wss4j.common.ext.WSSecurityException: No certificates for user server were found for encryption ColdFusion / Java-找不到类:org.apache.ws.security.WSConstants - ColdFusion/Java - Class not found: org.apache.ws.security.WSConstants WSSecurityException - 发现处理错误的错误 <wsse:Security> 头 - WSSecurityException - An error was discovered processing the <wsse:Security> header 使用具有WS-Security的Apache Axis的Web服务客户端。 找不到用户名安全令牌 - WebService Client using Apache Axis with WS-Security. No Username Security Token found WSSecurityException:无法对安全令牌进行身份验证或授权 - WSSecurityException: The security token could not be authenticated or authorized spring-ws-security中有关org.apache.santuario:xmlsec的Maven依赖项收敛不匹配 - Maven dependency convergence mismatch in spring-ws-security regarding org.apache.santuario:xmlsec 无法创建加密类org.apache.ws.security.components.crypto.Merlin - Cannot create Crypto class org.apache.ws.security.components.crypto.Merlin 使用Apache CXF的WS-Security UsernameToken - WS-Security UsernameToken with Apache CXF Apache CXF和WS-Security - 密码回调 - Apache CXF and WS-Security - Password Callback
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM