如何使用wss4j库验证soap签名

斯里兰卡Mehrotra

我有一条肥皂消息如下

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" env:mustUnderstand="1">
         <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="X509-3FE116EADE4A5ACE1C14636491396431">MIIEwjCCBCugAwIBAgIEUZF6sjANBgkqhkiG9w0BAQUFADCBmDEZMBcGA1UEChMQR3J1cG8gVGuYSBTPLrZBFdug27AhMqAzvjmp8G4Aj65E0QKDrnFIU4KTMyhSIFRzL5fATWsohdLXqcebHf+XmlNSQ==</wsse:BinarySecurityToken>
         <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-3FE116EADE4A5ACE1C14636491396595">
            <ds:SignedInfo>
               <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
               <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
               <ds:Reference URI="#id-3FE116EADE4A5ACE1C14636491396564">
                  <ds:Transforms>
                     <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                  </ds:Transforms>
                  <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                  <ds:DigestValue>hsrhNdt06tOUYlbV4gmkEwZEpXg=</ds:DigestValue>
               </ds:Reference>
            </ds:SignedInfo>
            <ds:SignatureValue>rtBv9+NmGZ58HN1XaWXZDQs2DpoiRCONt3XTM6N/R4SyrVK8ltbZebl0WnBQ==</ds:SignatureValue>
            <ds:KeyInfo Id="KI-3FE116EADE4A5ACE1C14636491396452">
               <wsse:SecurityTokenReference wsu:Id="STR-3FE116EADE4A5ACE1C14636491396483">
                  <wsse:Reference URI="#X509-3FE116EADE4A5ACE1C14636491396431" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" />
               </wsse:SecurityTokenReference>
            </ds:KeyInfo>
         </ds:Signature>
      </wsse:Security>
      <add:MessageID xmlns:add="http://schemas.xmlsoap.org/ws/2004/08/addressing">urn:uuid:b43ab47f-8ecb-4ac4-8b36-ee3649a734bf</add:MessageID>
   </env:Header>
   <env:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-3FE116EADE4A5ACE1C14636491396564">
      <request>
         <param1>234</param1>
         <param2>sdf2342</param2>
      </request>
   </env:Body>
</env:Envelope>

如何使用wss4j验证消息签名我想在Java程序中而不是在axiscxf之类的框架中执行此操作

斯里兰卡Mehrotra

如果签名与消息不对应,则将抛出WsSecurityException。

public void processSoapSecurityHeader(String soapRequest, String keyStore, String keyStorePwd, String alias) throws Exception {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, new  ByteArrayInputStream(soapRequest.getBytes()));
    FileInputStream is = new FileInputStream(keyStore);
    KeyPair keypair = null;
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    keystore.load(is, keyStorePwd.toCharArray());
    Certificate cert = null;
    Key key = keystore.getKey(alias, keyStorePwd.toCharArray());
    if (key instanceof PrivateKey) {
      cert = keystore.getCertificate(alias);
      PublicKey publicKey = cert.getPublicKey();
      keypair = new KeyPair(publicKey, (PrivateKey) key);
    }
     Properties properties = new Properties();
     properties.setProperty("org.apache.ws.security.crypto.provider", "org.apache.ws.security.components.crypto.Merlin");
     Crypto crypto = CryptoFactory.getInstance(properties);
     keystore.setKeyEntry(alias, keypair.getPrivate(), keyStorePwd.toCharArray(), new Certificate[]{cert});
     ((Merlin) crypto).setKeyStore(keystore);
     crypto.loadCertificate(new ByteArrayInputStream(cert.getEncoded()));
     WSSecurityEngine engine = new WSSecurityEngine();
     WSSConfig config = WSSConfig.getNewInstance();
     config.setWsiBSPCompliant(false);
     engine.setWssConfig(config);
     List<WSSecurityEngineResult> res = engine.processSecurityHeader(toDocument(soapMessage), null, null, crypto);
     for (WSSecurityEngineResult ers : res) {
           LOG.trace("Details of security header after validation {}" , ers.toString());
     }
     LOG.debug("Validation code executed");
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用wss4j库验证soap签名

来自分类Dev

使用CXF和WSS4J创建信封签名

来自分类Dev

WSS4j 1.5:如何跳过密码验证?

来自分类Dev

如何使用WSS4J拦截器以Web服务方法获取经过身份验证的用户

来自分类Dev

WSS4J中密钥库的可配置位置

来自分类Dev

如何使用 WSS4J 在 KeyInfo 元素中生成 X509Data 和 KeyValue

来自分类Dev

带有Spring WS的WSS4J(用户/密码身份验证+ .cert)

来自分类Dev

JAX-WS CXF WSS4J在运行时添加证书以进行消息签名

来自分类Dev

cxf + wss4j + maven NoSuchMethod错误

来自分类Dev

CXF 3.X和WSS4J 2.X中的CallbackHandler

来自分类Dev

SoapFault MustUnderstand标头,CXF WSS4J没有提供加密属性文件

来自分类Dev

如何使用PyKCS11库验证签名数据

来自分类Dev

如何使用PyKCS11库验证签名数据

来自分类Dev

Xades4j验证信封签名

来自分类Dev

使用crypto ++库验证openssl签名

来自分类Dev

如何使用args4j验证选项?

来自分类Dev

如何使用 IdentityServer4 验证 x509 签名凭据

来自分类Dev

如何在time4j库中使用PrettyTime?

来自分类Dev

如何使用 slf4j 登录公共共享库?

来自分类Dev

使用twitter4j库时未发现身份验证挑战

来自分类Dev

使用twitter4j库时未发现身份验证挑战

来自分类Dev

如何使用log4j登录xfire以获取XML SOAP中的请求和响应

来自分类Dev

如何使用尊重验证库验证$ _FILES

来自分类Dev

如何验证PARes签名?

来自分类Dev

如何验证PARes签名?

来自分类Dev

如何使用OpenSSL验证Jarsigner创建的* .SF / *。RSA签名

来自分类Dev

如何使用python和openssl验证Webhook签名

来自分类Dev

如何使用C#验证.jar Java Applet签名

来自分类Dev

使用SHA256withRSA签名后如何验证signatureBytes?

Related 相关文章

热门标签

归档