[java-opensaml COMMIT] in /trunk/opensaml-xmlsec-impl/src/test: java/org/opensaml/xmlsec/keyinfo/KeyInfoSupportTest.j...

noreply at shibboleth.net noreply at shibboleth.net
Thu Feb 14 23:36:09 EST 2013


Author: scantor
Date: Thu Feb 14 23:36:08 2013
New Revision: 3221

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3221&view=rev
Log:
Port java-xmltooling r784-785.

Added:
    trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/impl/DEREncodedKeyValueTest.java   (with props)
    trunk/opensaml-xmlsec-impl/src/test/resources/data/org/opensaml/xmlsec/keyinfo/impl/DEREncodedKeyValue.xml   (with props)
    trunk/opensaml-xmlsec-impl/src/test/resources/data/org/opensaml/xmlsec/keyinfo/impl/X509CertificatesWithDigest.xml   (with props)
Modified:
    trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupportTest.java
    trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/impl/BasicKeyInfoGeneratorTest.java
    trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/impl/CertChainX509DataTest.java

Modified: trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupportTest.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupportTest.java?rev=3221&r1=3220&r2=3221&view=diff
==============================================================================
--- trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupportTest.java (original)
+++ trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/keyinfo/KeyInfoSupportTest.java Thu Feb 14 23:36:08 2013
@@ -22,6 +22,7 @@
 import org.testng.Assert;
 import java.math.BigInteger;
 import java.security.KeyException;
+import java.security.NoSuchAlgorithmException;
 import java.security.PublicKey;
 import java.security.cert.CRLException;
 import java.security.cert.CertificateEncodingException;
@@ -29,6 +30,7 @@
 import java.security.interfaces.DSAParams;
 import java.security.interfaces.DSAPublicKey;
 import java.security.interfaces.RSAPublicKey;
+import java.security.spec.InvalidKeySpecException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -40,6 +42,7 @@
 import org.opensaml.security.crypto.KeySupport;
 import org.opensaml.security.x509.X509Support;
 import org.opensaml.xmlsec.keyinfo.KeyInfoSupport;
+import org.opensaml.xmlsec.signature.DEREncodedKeyValue;
 import org.opensaml.xmlsec.signature.DSAKeyValue;
 import org.opensaml.xmlsec.signature.Exponent;
 import org.opensaml.xmlsec.signature.G;
@@ -52,10 +55,12 @@
 import org.opensaml.xmlsec.signature.X509CRL;
 import org.opensaml.xmlsec.signature.X509Certificate;
 import org.opensaml.xmlsec.signature.X509Data;
+import org.opensaml.xmlsec.signature.X509Digest;
 import org.opensaml.xmlsec.signature.X509IssuerSerial;
 import org.opensaml.xmlsec.signature.X509SKI;
 import org.opensaml.xmlsec.signature.X509SubjectName;
 import org.opensaml.xmlsec.signature.Y;
+import org.opensaml.xmlsec.signature.support.SignatureConstants;
 
 import com.google.common.base.Strings;
 
@@ -90,6 +95,9 @@
      * AF:B9:F9:1D:C2:45:18:CC:B8:21:E2:A7:47:BC:49:BD:19:B5:78:28
      */
     private final String cert1SKIPlainBase64 = "r7n5HcJFGMy4IeKnR7xJvRm1eCg=";
+    
+    /** Test cert 1 SHA-1 digest. */
+    private final String cert1DigestBase64 = "EmkP8ttMw28A/JoA3KcO11eez7Q=";
 
     /** Test cert 1. */
     private final String cert1 = "MIICgjCCAeugAwIBAgIBEzANBgkqhkiG9w0BAQUFADBAMQswCQYDVQQGEwJVUzEa"
@@ -266,7 +274,7 @@
     }
 
     /**
-     * Test converting XML X509Certificate to java.security.cert.X509Certificte.
+     * Test converting XML X509Certificate to java.security.cert.X509Certificate.
      * 
      * @throws CertificateException
      */
@@ -522,7 +530,7 @@
         Assert.assertEquals(javaKey, javaDSAPubKey1, "Inserted DSA public key was not the expected value");
 
         keyInfo.getKeyValues().clear();
-    }
+    }    
 
     /** Tests adding a public key as a KeyValue to KeyInfo. */
     @Test
@@ -547,6 +555,60 @@
         keyInfo.getKeyValues().clear();
     }
 
+    /** Tests adding a public key as a DEREncodedKeyValue to KeyInfo. */
+    @Test
+    public void testAddDEREncodedDSAPublicKey() {
+       keyInfo.getXMLObjects(DEREncodedKeyValue.DEFAULT_ELEMENT_NAME).clear();
+        
+        try {
+            KeyInfoSupport.addDEREncodedPublicKey(keyInfo, javaDSAPubKey1);
+        } catch (NoSuchAlgorithmException e) {
+            Assert.fail("Unsupported key algorithm: " + e);
+        } catch (InvalidKeySpecException e) {
+            Assert.fail("Unsupported key specification: " + e);
+        }
+        DEREncodedKeyValue kv = (DEREncodedKeyValue) keyInfo.getXMLObjects(DEREncodedKeyValue.DEFAULT_ELEMENT_NAME).get(0);
+        Assert.assertNotNull(kv, "KeyValue was null");
+        
+        DSAPublicKey javaKey = null;
+        try {
+            javaKey = (DSAPublicKey) KeyInfoSupport.getKey(kv);
+        } catch (KeyException e) {
+            Assert.fail("Extraction of Java key failed: " + e);
+        }
+        
+        Assert.assertEquals(javaDSAPubKey1, javaKey, "Inserted RSA public key was not the expected value");
+        
+        keyInfo.getXMLObjects(DEREncodedKeyValue.DEFAULT_ELEMENT_NAME).clear();

[... 305 lines stripped ...]


More information about the commits mailing list