harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r521100 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/x509/ test/api/java/org/apache/harmony/security/tests/java/security/cert/ test/support/common/java/org/apache/harmony/security/...
Date Thu, 22 Mar 2007 03:09:58 GMT
Author: smishura
Date: Wed Mar 21 20:09:57 2007
New Revision: 521100

URL: http://svn.apache.org/viewvc?view=rev&rev=521100
Log:
Fix and regression test for HARMONY-3384:
([classlib][security]java.security.cert.X509Certificate.toString() throws NullPointerException)

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/AuthorityKeyIdentifier.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/X509Certificate2Test.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/TestUtils.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/AuthorityKeyIdentifier.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/AuthorityKeyIdentifier.java?view=diff&rev=521100&r1=521099&r2=521100
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/AuthorityKeyIdentifier.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/AuthorityKeyIdentifier.java
Wed Mar 21 20:09:57 2007
@@ -118,8 +118,14 @@
         protected Object getDecodedObject(BerInputStream in) throws IOException {
             Object[] values = (Object[]) in.content;
 
+            byte[] enc = (byte[]) values[2];
+            BigInteger authorityCertSerialNumber = null;
+            if (enc != null) {
+                authorityCertSerialNumber = new BigInteger(enc);
+            }
+
             return new AuthorityKeyIdentifier((byte[]) values[0],
-                    (GeneralNames) values[1], new BigInteger((byte[]) values[2]));
+                    (GeneralNames) values[1], authorityCertSerialNumber);
         }
 
         protected void getValues(Object object, Object[] values) {
@@ -128,7 +134,9 @@
 
             values[0] = akid.keyIdentifier;
             values[1] = akid.authorityCertIssuer;
-            values[2] = akid.authorityCertSerialNumber.toByteArray();
+            if (akid.authorityCertSerialNumber != null) {
+                values[2] = akid.authorityCertSerialNumber.toByteArray();
+            }
         }
     };
 }

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/X509Certificate2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/X509Certificate2Test.java?view=diff&rev=521100&r1=521099&r2=521100
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/X509Certificate2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/X509Certificate2Test.java
Wed Mar 21 20:09:57 2007
@@ -17,15 +17,18 @@
 
 package org.apache.harmony.security.tests.java.security.cert;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.io.ObjectInputStream;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Vector;
 
-import tests.support.resource.Support_Resources;
+import org.apache.harmony.security.tests.support.cert.TestUtils;
 
-import junit.framework.TestCase;
+import tests.support.resource.Support_Resources;
 
 public class X509Certificate2Test extends junit.framework.TestCase {
 	private X509Certificate pemCert = null;
@@ -62,4 +65,23 @@
 			fail("Unable to obtain X509Certificate");
 		}
 	}
-}
\ No newline at end of file
+    
+    /**
+     * Test for X.509 Certificate provider
+     */
+    public void test_toString() throws Exception {
+
+        // Regression for HARMONY-3384
+        CertificateFactory certFact = CertificateFactory.getInstance("X509");
+        pemCert = (X509Certificate) certFact
+                .generateCertificate(new ByteArrayInputStream(TestUtils
+                        .getX509Certificate_v3()));
+
+        // extension value is empty sequence
+        byte[] extnValue = pemCert.getExtensionValue("2.5.29.35");
+        assertTrue(Arrays.equals(new byte[] { 0x04, 0x02, 0x30, 0x00 },
+                extnValue));
+        assertNotNull(pemCert.toString());
+        // End regression for HARMONY-3384
+    }
+}

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/TestUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/TestUtils.java?view=diff&rev=521100&r1=521099&r2=521100
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/TestUtils.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/TestUtils.java
Wed Mar 21 20:09:57 2007
@@ -387,7 +387,105 @@
             //
             0x03, 0x02, 0x00, 0x01 };
     }
-    
+
+    /**
+     * Returns X.509 certificate encoding corresponding to version v3.
+     * 
+     * Certificate encoding was created by hands according to X.509 Certificate
+     * ASN.1 notation. The certificate encoding has the following encoded
+     * field values:<br> 
+     * - version: 3<br>
+     * - serialNumber: 5<br>
+     * - issuer: CN=Z<br>
+     * - notBefore: 13 Dec 1999 14:15:16<br>
+     * - notAfter: 01 Jan 2000 00:00:00<br>
+     * - subject: CN=Y<br>
+     * - extensions:
+     *       1) AuthorityKeyIdentifier(OID=2.5.29.35): no values in it(empty sequence) 
+     * 
+     * @return X.509 certificate encoding corresponding to version v3.
+     */
+    public static byte[] getX509Certificate_v3() {
+        return new byte[] {
+        // Certificate: SEQUENCE
+            0x30, 0x7D,
+
+            //
+            // TBSCertificate: SEQUENCE {
+            //
+            0x30, 0x6E,
+
+            // version: [0] EXPLICIT Version DEFAULT v1
+            (byte) 0xA0, 0x03, 0x02, 0x01, 0x02,
+
+            // serialNumber: CertificateSerialNumber
+            0x02, 0x01, 0x05,
+
+            // signature: AlgorithmIdentifier
+            0x30, 0x07, // SEQUENCE
+            0x06, 0x02, 0x03, 0x05,//OID
+            0x01, 0x01, 0x07, //ANY
+
+            //issuer: Name
+            0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
+            0x13, 0x01, 0x5A, // CN=Z
+
+            //validity: Validity
+            0x30, 0x1E, // SEQUENCE
+            // notBefore: UTCTime
+            0x17, 0x0D, 0x39, 0x39, 0x31, 0x32, 0x31, 0x33, 0x31, 0x34, 0x31,
+            0x35, 0x31, 0x36, 0x5A, // 13 Dec 1999 14:15:16
+            // notAfter:  UTCTime
+            0x17, 0x0D, 0x30, 0x30, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30,
+            0x30, 0x30, 0x30, 0x5A, // 01 Jan 2000 00:00:00
+
+            //subject: Name
+            0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
+            0x13, 0x01, 0x59, // CN=Y
+            //SubjectPublicKeyInfo  ::=  SEQUENCE  {
+            //    algorithm            AlgorithmIdentifier,
+            //    subjectPublicKey     BIT STRING  }
+            0x30, 0x0D, // SEQUENCE
+            0x30, 0x07, // SEQUENCE
+            0x06, 0x02, 0x03, 0x05,//OID
+            0x01, 0x01, 0x07, //ANY
+            0x03, 0x02, 0x00, 0x01, // subjectPublicKey
+
+            // issuerUniqueID - missed
+            // subjectUniqueID - missed
+            // extensions : [3]  EXPLICIT Extensions OPTIONAL
+            (byte) 0xA3, 0x10,
+            // Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
+            0x30, 0x0E,
+            // Extension  ::=  SEQUENCE  {
+            // extnID      OBJECT IDENTIFIER,
+            // critical    BOOLEAN DEFAULT FALSE,
+            // extnValue   OCTET STRING  }
+
+            // 1) AuthorityKeyIdentifier extension (see HARMONY-3384)
+            0x30, 0x0C,
+            0x06, 0x03, 0x55, 0x1D, 0x23, // OID = 2.5.29.35
+            0x01, 0x01, 0x00, // critical = FALSE
+            0x04, 0x02, 0x30, 0x00, // extnValue: MUST be empty sequence
+            // missed: keyIdentifier
+            // missed: authorityCertIssuer
+            // missed" authorityCertSerialNumber
+
+            // } end TBSCertificate
+
+            //
+            // signatureAlgorithm: AlgorithmIdentifier
+            //
+            0x30, 0x07, // SEQUENCE
+            0x06, 0x02, 0x03, 0x05,//OID
+            0x01, 0x01, 0x07, //ANY
+
+            //
+            // signature: BIT STRING  
+            //
+            0x03, 0x02, 0x00, 0x01 };
+    }
+
     /**
      * Returns X.509 CRL encoding corresponding to version v1.
      * 



Mime
View raw message