You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2020/09/14 15:02:50 UTC

[ws-wss4j] 02/02: Adding a RSA-SHA512 testcase for Signature

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-wss4j.git

commit 1765c4149d700cac8aea5c1a3b78f2bdee8b6e71
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Sep 14 15:27:59 2020 +0100

    Adding a RSA-SHA512 testcase for Signature
---
 .../org/apache/wss4j/common/WSS4JConstants.java    |  2 ++
 .../apache/wss4j/dom/message/SignatureTest.java    | 35 +++++++++++++++++-----
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/ws-security-common/src/main/java/org/apache/wss4j/common/WSS4JConstants.java b/ws-security-common/src/main/java/org/apache/wss4j/common/WSS4JConstants.java
index d3768b2..66e3e3d 100644
--- a/ws-security-common/src/main/java/org/apache/wss4j/common/WSS4JConstants.java
+++ b/ws-security-common/src/main/java/org/apache/wss4j/common/WSS4JConstants.java
@@ -130,6 +130,8 @@ public class WSS4JConstants {
         "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
     public static final String RSA_SHA256 =
         "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
+    public static final String RSA_SHA512 =
+        "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512";
     public static final String SHA1 =
         "http://www.w3.org/2000/09/xmldsig#sha1";
     public static final String SHA256 =
diff --git a/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java b/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java
index aad51d2..bd8e96d 100644
--- a/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java
+++ b/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java
@@ -540,16 +540,37 @@ public class SignatureTest {
 
         Document signedDoc = builder.build(crypto);
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Signed message with IssuerSerial key identifier:");
-            String outputString =
-                XMLUtils.prettyDocumentToString(signedDoc);
-            LOG.debug(outputString);
-        }
-        LOG.info("After Signing IS....");
+        String outputString = XMLUtils.prettyDocumentToString(signedDoc);
+        LOG.debug(outputString);
+        assertTrue(outputString.contains(WSConstants.RSA_SHA256));
+
         verify(signedDoc);
     }
 
+    @Test
+    public void testX509SignatureSha512() throws Exception {
+        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+        WSSecHeader secHeader = new WSSecHeader(doc);
+        secHeader.insertSecurityHeader();
+
+        WSSecSignature builder = new WSSecSignature(secHeader);
+        builder.setUserInfo("wss40", "security");
+        builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+        builder.setSignatureAlgorithm(WSConstants.RSA_SHA512);
+        builder.setDigestAlgo("http://www.w3.org/2001/04/xmlenc#sha256");
+        LOG.info("Before Signing IS....");
+
+        Crypto wssCrypto = CryptoFactory.getInstance("wss40.properties");
+        Document signedDoc = builder.build(wssCrypto);
+
+        String outputString = XMLUtils.prettyDocumentToString(signedDoc);
+        LOG.debug(outputString);
+        assertTrue(outputString.contains(WSConstants.RSA_SHA512));
+
+        LOG.info("After Signing IS....");
+        secEngine.processSecurityHeader(doc, null, null, wssCrypto);
+    }
+
     /**
      * A test for "SignatureAction does not set DigestAlgorithm on WSSecSignature instance"
      */