【问题标题】:wss4j: - Cannot find key for alias: monitwss4j: - 找不到别名的键:monit
【发布时间】:2009-10-20 08:47:05
【问题描述】:

当我在 client-config.wsdd 中为 WSDoAllSender 和 WSDoAllReceiver 定义(使用轴 1.4 和 wss4j)不同的 signaturePropFiles 时,我使用不同的证书定义了不同的密钥库,我可以使用不同的证书来发送和接收。但是当我使用相同的 signaturePropFiles' 和相同的密钥库时。当我尝试发送消息时收到此消息:

  org.apache.ws.security.components.crypto.CryptoBase -- Cannot find key for alias: [monit] in keystore of type [jks] from provider [SUN version 1.5] with size [2] and aliases: {other, monit}
- Error during Signature: ; nested exception is:
        org.apache.ws.security.WSSecurityException: Signature creation failed; nested exception is:
        java.lang.Exception: Cannot find key for alias: [monit]
org.apache.ws.security.WSSecurityException: Error during Signature: ; nested exception is:
        org.apache.ws.security.WSSecurityException: Signature creation failed; nested exception is:
        java.lang.Exception: Cannot find key for alias: [monit]
        at org.apache.ws.security.action.SignatureAction.execute(SignatureAction.java:60)
        at org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:202)
        at org.apache.ws.axis.security.WSDoAllSender.invoke(WSDoAllSender.java:168)
        at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
        at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
        at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:127)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:2443)
        at org.apache.axis.client.Call.invoke(Call.java:2366)
        at org.apache.axis.client.Call.invoke(Call.java:1812)
        at cz.xxx.opf.model.wsclient.ModelWebServiceSoapBindingStub.getStatus(ModelWebServiceSoapBindingStub.java:213)
        at cz.xxx.opf.wsgemonitor.monitor.util.MonitorUtil.checkStatus(MonitorUtil.java:18)
        at cz.xxx.opf.wsgemonitor.monitor.Test02WsMonitor.runTest(Test02WsMonitor.java:23)
        at cz.xxx.opf.wsgemonitor.Main.main(Main.java:75)
Caused by: org.apache.ws.security.WSSecurityException: Signature creation failed; nested exception is:
        java.lang.Exception: Cannot find key for alias: [monit]
        at org.apache.ws.security.message.WSSecSignature.computeSignature(WSSecSignature.java:721)
        at org.apache.ws.security.message.WSSecSignature.build(WSSecSignature.java:780)
        at org.apache.ws.security.action.SignatureAction.execute(SignatureAction.java:57)
        ... 15 more
Caused by: java.lang.Exception: Cannot find key for alias: [monit]
        at org.apache.ws.security.components.crypto.CryptoBase.getPrivateKey(CryptoBase.java:214)
        at org.apache.ws.security.message.WSSecSignature.computeSignature(WSSecSignature.java:713)
        ... 17 more

如何在同一个密钥库中拥有两个 wss4j 证书?为什么当我在一个密钥库中有两个证书时它找不到我的证书。

关于 PWCallback (CallbackHandler) 的两个证书我有相同的密码

我的属性文件:

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=keystore
org.apache.ws.security.crypto.merlin.keystore.alias=monit
org.apache.ws.security.crypto.merlin.alias.password=***
org.apache.ws.security.crypto.merlin.file=key.jks

我的客户端配置.wsdd:

  <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
 <globalConfiguration>  
  <requestFlow>
   <handler name="WSSecurity" type="java:org.apache.ws.axis.security.WSDoAllSender">
        <parameter name="user" value="monit"/>
        <parameter name="passwordCallbackClass" value="cz.xxx.opf.common.ws.PWCallback"/>
        <parameter name="action" value="Signature"/>
        <parameter name="signaturePropFile" value="monit.properties"/>
        <parameter name="signatureKeyIdentifier" value="DirectReference" />
        <parameter name="mustUnderstand" value="0"/>
   </handler>
     <handler type="java:org.apache.axis.handlers.JWSHandler">
        <parameter name="scope" value="session"/>
     </handler>
     <handler type="java:org.apache.axis.handlers.JWSHandler">
        <parameter name="scope" value="request"/>
        <parameter name="extension" value=".jwr"/>
     </handler>
   </requestFlow>
   <responseFlow>  
        <handler name="DoSecurityReceiver" type="java:org.apache.ws.axis.security.WSDoAllReceiver">
            <parameter name="user" value="other"/>  
            <parameter name="passwordCallbackClass" value="cz.xxx.opf.common.ws.PWCallback"/>
            <parameter name="action" value="Signature"/>
            <parameter name="signaturePropFile" value="other.properties"/>
            <parameter name="signatureKeyIdentifier" value="DirectReference" />  
        </handler>  
   </responseFlow>

 </globalConfiguration>

 <transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender">  

 </transport>
</deployment>

来自 keytool 的列表: keytool -keystore monit-key.jks -v -list

Enter keystore password:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 2 entries

Alias name: other
Creation date: Jul 22, 2009
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
....

Alias name: monit
Creation date: Oct 19, 2009
Entry type: trustedCertEntry

【问题讨论】:

    标签: java certificate wss4j


    【解决方案1】:

    我在几个月前解决了这个问题,如果有人需要的话。问题是我在密钥库中没有私钥。

    【讨论】:

    • 你已经给出了 org.apache.ws.security.crypto.merlin.alias.password=*** \n 你在 Keystore 中的私钥到底是什么意思?
    • 它根本与 org.apache.ws.security.crypto.merlin.alias.password 属性无关。正如我写的那样,私钥不在密钥库中。为了签署消息,您需要发件人的私钥。密钥库中只有公钥。正如您在上面的列表中看到的(keytool -keystore monit-key.jks -v -list)。相关密钥(monit)的条目类型是trustedCertEntry,我想它只是带有公钥的存储证书。重要的是只有公钥在密钥库中。
    • 感谢@feiroox 的澄清。看起来你可以在这里澄清我的问题。我对类似的问题感到震惊。我从客户端获得了证书,并将该证书导入到我的 KeyStore(myKey.jks) 文件中,别名为“mykey”。当我列出 JKS 文件时,它是一个“trustedCertEntry”。但是当我尝试在我用 Apache CXF 和 WSS4J 实现的配置中使用该别名时,它给了我一个错误——>找不到别名的密钥:[mykey]。那么如何为给定的证书或密钥库(mykey.jks)添加或生成密钥(假设是公钥)?感谢您的回复..
    • 顺便说一句,我按照下面的 URL 使用 WSS4J 实现数字签名 --> sites.google.com/site/ddmwsst/ws-security-impl
    • 很抱歉我没来过这里。最好在 stackoverflow.com 上提问。如果我错了或没有时间,其他人可能会帮助您,它也可以为其他人服务。但我想你现在已经想通了。
    【解决方案2】:

    我使用的是 Sun 的 jdk,当我将其更改为 IBM JDK 时出现问题,然后问题就消失了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 2016-01-13
      • 2017-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多