【问题标题】:org.apache.ws.security.WSSecurityException: General security error (No certificates were found for decryption (KeyId))org.apache.ws.security.WSSecurityException:一般安全错误(未找到用于解密的证书(KeyId))
【发布时间】:2014-07-30 21:06:24
【问题描述】:

我继承了一些 WSS4J 安全 Web 服务的代码。它基于这个流行的教程:http://distributedsenses.blogspot.com/2008/09/configuring-cxf-for-web-service.html

现在服务器端正在与其他客户端一起工作,但我的不是。 :(

我为 tomcat 生成了一个密钥库,导出了公钥,并将其安装在服务器上。但是当我尝试调用时,服务器回复错误没有找到用于解密的证书(KeyId)

现在我没有对代码进行一些更改,但我确实更改了包名称(我认为这对 SOAP 调用并不重要)——我没有更改名称空间。

我什至在服务器上导出了证书,以确保我正确导入它,并且它与客户端上的公钥完全匹配。所以我知道服务器有我的证书。

这是我的 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>

还有我的 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

我收到此错误的任何原因。我知道我的公钥在服务器的信任库中。这适用于其他客户。知道我做错了什么吗?

【问题讨论】:

    标签: java web-services security encryption wss4j


    【解决方案1】:

    首先,让我们了解发生了什么以及出了什么问题。客户端,我,正在向服务器发送加密请求。我需要使用服务器公钥来加密消息。这是上面的“encryptionUser”属性。它的值是将服务器公钥导入我的密钥库时使用的别名。服务器将使用其私钥解密消息。

    任何未找到用于解密的证书 (KeyId) 的原因是您(客户端)用于加密您的消息的公钥与服务器拥有的私钥不匹配。你需要让服务器使用keytool,导出它的公钥,然后你导入它(使用keytool)并且你使用的别名需要匹配xml中的encryptionUser。

    在我的例子中,用于加密所有内容的密钥对与用于 SOAP 调用本身的 HTTPS 的密钥对不同。因此,使用 InstallCert,或者只是从我的 Web 浏览器中保存证书,同时查看 WSDL 不工作。

    希望这对将来的一些菜鸟有所帮助!

    【讨论】:

    • 实际上,它确实帮助了我。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    相关资源
    最近更新 更多