harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r396822 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/cert/ test/java/common/java/security/cert/ test/java/common/org/apache/harmony/security/cert/
Date Tue, 25 Apr 2006 09:39:56 GMT
Author: smishura
Date: Tue Apr 25 02:39:52 2006
New Revision: 396822

URL: http://svn.apache.org/viewcvs?rev=396822&view=rev
Log:
Fixing default implementation of java.security.cert.X509CRL + modifying regression test.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/cert/X509CRL.java
  (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CRLTest.java
  (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/cert/TestUtils.java
  (contents, props changed)

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/cert/X509CRL.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/cert/X509CRL.java?rev=396822&r1=396821&r2=396822&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/cert/X509CRL.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/cert/X509CRL.java
Tue Apr 25 02:39:52 2006
@@ -21,6 +21,7 @@
 
 package java.security.cert;
 
+import java.io.ByteArrayInputStream;
 import java.math.BigInteger;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
@@ -119,7 +120,20 @@
      * @com.intel.drl.spec_ref
      */
     public X500Principal getIssuerX500Principal() {
-        throw new RuntimeException("Method should be overriden.");
+        try {
+            // TODO if there is no X.509 certificate provider installed
+            // should we try to access Harmony X509CRLImpl via classForName?
+            CertificateFactory factory = CertificateFactory
+                    .getInstance("X.509");
+
+            X509CRL crl = (X509CRL) factory
+                    .generateCRL(new ByteArrayInputStream(getEncoded()));
+
+            return crl.getIssuerX500Principal();
+
+        } catch (Exception e) {
+            throw new RuntimeException("Failed to get X500Principal issuer", e);
+        }
     }
 
     /**

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/cert/X509CRL.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CRLTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CRLTest.java?rev=396822&r1=396821&r2=396822&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CRLTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CRLTest.java
Tue Apr 25 02:39:52 2006
@@ -33,6 +33,10 @@
 import java.util.Date;
 import java.util.Set;
 
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.harmony.security.cert.TestUtils;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -217,15 +221,17 @@
     }
 
     /**
-     * getIssuerX500Principal() method testing. Check if the default
-     * implementation throws RuntimeException.
+     * @tests java.security.cert.X509CRL#getIssuerX500Principal()
      */
     public void testGetIssuerX500Principal() {
-        try {
-            tbt_crl.getIssuerX500Principal();
-            fail("The default implementation shoult throw RuntimeException.");
-        } catch (RuntimeException e) {
-        }
+        // return valid encoding
+        TBTCRL crl = new TBTCRL() {
+            public byte[] getEncoded() {
+                return TestUtils.getX509CRL_v1();
+            };
+        };
+
+        assertEquals(new X500Principal("CN=Z"), crl.getIssuerX500Principal());
     }
 
     /**

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CRLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/cert/TestUtils.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/cert/TestUtils.java?rev=396822&r1=396821&r2=396822&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/cert/TestUtils.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/cert/TestUtils.java
Tue Apr 25 02:39:52 2006
@@ -368,4 +368,48 @@
             //
             0x03, 0x02, 0x00, 0x01 };
     }
+    
+    /**
+     * Returns X.509 CRL encoding corresponding to version v1.
+     * 
+     * CRL encoding was created by hands according to X.509 CRL ASN.1
+     * notation. The CRL encoding has the following encoded field values:<br> 
+     * - version: 1<br>
+     * - issuer: CN=Z<br>
+     * - thisUpdate: 01 Jan 2001 01:02:03<br>
+     * 
+     * @return X.509 CRL encoding corresponding to version v1.
+     */
+    public static byte[] getX509CRL_v1() {
+        return new byte[] {
+                //CertificateList: SEQUENCE
+                0x30, 0x35, 
+                
+                // TBSCertList: SEQUENCE  
+                0x30, 0x27,
+                // Version: INTEGER OPTIONAL
+                // 0x02, 0x01, 0x01, - missed here cause it is v1
+                // signature: AlgorithmIdentifier
+                0x30, 0x06, // SEQUENCE
+                0x06, 0x01, 0x01, // OID
+                0x01, 0x01, 0x11, // ANY
+                // issuer: Name                   
+                0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
+                0x03, 0x13, 0x01, 0x5A, // CN=Z 
+                // thisUpdate: ChoiceOfTime
+                // GeneralizedTime: 01 Jan 2001 01:02:03
+                0x18, 0x0F, 0x32, 0x30, 0x30, 0x31, 0x30, 0x31, 0x30, 0x31,
+                0x30, 0x31, 0x30, 0x32, 0x30, 0x33, 0x5A,
+                
+                // nextUpdate - missed
+                // revokedCertificates - missed
+                // crlExtensions - missed
+                
+                // signatureAlgorithm: AlgorithmIdentifier
+                0x30, 0x06, // SEQUENCE
+                0x06, 0x01, 0x01, //OID
+                0x01, 0x01, 0x11, //ANY
+                // signature: BIT STRING  
+                0x03, 0x02, 0x00, 0x01 };
+    }
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/cert/TestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message