harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r398814 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/provider/cert/ test/java/common/java/security/cert/ test/java/common/org/apache/harmony/security/provider/cert/
Date Tue, 02 May 2006 05:35:54 GMT
Author: mloenko
Date: Mon May  1 22:35:36 2006
New Revision: 398814

URL: http://svn.apache.org/viewcvs?rev=398814&view=rev
Log:
fixes for HARMONY-419
[classlib][security] X.509 Certificate Factory provider throw NPE

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImplTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CertificateTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLImplTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CertImplTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImpl.java?rev=398814&r1=398813&r2=398814&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImpl.java
Mon May  1 22:35:36 2006
@@ -29,6 +29,7 @@
 
 import javax.security.auth.x500.X500Principal;
 
+import org.apache.harmony.security.x509.Extension;
 import org.apache.harmony.security.x509.Extensions;
 import org.apache.harmony.security.x509.TBSCertList;
 
@@ -119,7 +120,8 @@
         if (extensions == null) {
             return null;
         }
-        return extensions.getExtensionByOID(oid).getRawExtnValue();
+        Extension ext = extensions.getExtensionByOID(oid);
+        return (ext == null) ? null : ext.getRawExtnValue();
     }
 
     public boolean hasUnsupportedCriticalExtension() {
@@ -136,4 +138,3 @@
     public static void main(String[] args) {
     }
 }
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLImpl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLImpl.java?rev=398814&r1=398813&r2=398814&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CRLImpl.java
Mon May  1 22:35:36 2006
@@ -46,6 +46,7 @@
 
 import org.apache.harmony.crypto.utils.AlgNameMapper;
 import org.apache.harmony.security.x509.CertificateList;
+import org.apache.harmony.security.x509.Extension;
 import org.apache.harmony.security.x509.Extensions;
 import org.apache.harmony.security.x509.TBSCertList;
 
@@ -397,7 +398,8 @@
         if (extensions == null) {
             return null;
         }
-        return extensions.getExtensionByOID(oid).getRawExtnValue();
+        Extension ext = extensions.getExtensionByOID(oid);
+        return (ext == null) ? null : ext.getRawExtnValue();
     }
 
     public boolean hasUnsupportedCriticalExtension() {
@@ -407,4 +409,3 @@
         return extensions.hasUnsupportedCritical();
     }
 }
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertImpl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertImpl.java?rev=398814&r1=398813&r2=398814&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertImpl.java
Mon May  1 22:35:36 2006
@@ -46,6 +46,7 @@
 
 import org.apache.harmony.crypto.utils.AlgNameMapper;
 import org.apache.harmony.security.x509.Certificate;
+import org.apache.harmony.security.x509.Extension;
 import org.apache.harmony.security.x509.Extensions;
 import org.apache.harmony.security.x509.TBSCertificate;
 
@@ -417,7 +418,8 @@
         if (extensions == null) {
             return null;
         }
-        return extensions.getExtensionByOID(oid).getRawExtnValue();
+        Extension ext = extensions.getExtensionByOID(oid);
+        return (ext == null) ? null : ext.getRawExtnValue();
     }
 
     public boolean hasUnsupportedCriticalExtension() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CertificateTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CertificateTest.java?rev=398814&r1=398813&r2=398814&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CertificateTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/cert/X509CertificateTest.java
Mon May  1 22:35:36 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;
@@ -33,6 +34,7 @@
 
 import javax.security.auth.x500.X500Principal;
 
+import org.apache.harmony.misc.Base64;
 import org.apache.harmony.security.cert.TestUtils;
 
 import junit.framework.Test;
@@ -44,6 +46,36 @@
  */
 public class X509CertificateTest extends TestCase {
 
+    // Base64 encoded form of ASN.1 DER encoded X.509 Certificate
+    // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt)
+    // (generated by using of classes from 
+    // org.apache.harmony.security.x509 package)
+    static String base64cert =
+          "MIIByzCCATagAwIBAgICAiswCwYJKoZIhvcNAQEFMB0xGzAZBgNVBAoT"
+        + "EkNlcnRpZmljYXRlIElzc3VlcjAeFw0wNjA0MjYwNjI4MjJaFw0zMzAz"
+        + "MDExNjQ0MDlaMB0xGzAZBgNVBAoTEkNlcnRpZmljYXRlIElzc3VlcjCB"
+        + "nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAkLGLsPdSPDMyP1OUOKu+"
+        + "U3cvbNK5RGaQ3bXc5aDjvApx43BcaoXgt6YD/5yXz0OsIooj5yA37+bY"
+        + "JGcVrvFD5FMPdDd3vjNPQOep0MzG4CdbkaZde5SigPabOMQYS4oUyLBx"
+        + "W3LGG0mUODe5AGGqtqXU0GlKg4K2je6cCtookCUCAwEAAaMeMBwwGgYD"
+        + "VR0RAQH/BBAwDoEMcmZjQDgyMi5OYW1lMAsGCSqGSIb3DQEBBQOBgQBZ"
+        + "pVXj01dOpqnZErU+Qb50j8lJD1dIaz1eJTvJCSadj7ziV1VtnnapI07c"
+        + "XEa7ONzcHQTYTG10poHfOK/a0BaULF3GlctDESilwQYbW5BdfpAlZpbH"
+        + "AFLcUDh6Eq50kc+0A/anh/j3mgBNuvbIMo7hHNnZB6k/prswm2BszyLD"
+        + "yw==";
+
+    // Base64 encoded form of ASN.1 DER encoded X.509 CRL
+    // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt)
+    // (generated by using of classes from 
+    // org.apache.harmony.security.x509 package)
+    static String base64crl = 
+          "MIHXMIGXAgEBMAkGByqGSM44BAMwFTETMBEGA1UEChMKQ1JMIElzc3Vl"
+        + "chcNMDYwNDI3MDYxMzQ1WhcNMDYwNDI3MDYxNTI1WjBBMD8CAgIrFw0w"
+        + "NjA0MjcwNjEzNDZaMCowCgYDVR0VBAMKAQEwHAYDVR0YBBUYEzIwMDYw"
+        + "NDI3MDYxMzQ1LjQ2OFqgDzANMAsGA1UdFAQEBAQEBDAJBgcqhkjOOAQD"
+        + "AzAAMC0CFQCk0t0DTyu82QpajbBlxX9uXvUDSgIUSBN4g+xTEeexs/0k"
+        + "9AkjBhjF0Es=";
+
     // has stub implementation for abstract methods
     private static class MyX509Certificate extends X509Certificate {
 
@@ -222,6 +254,25 @@
         assertNull(new MyX509Certificate().getIssuerAlternativeNames());
     }
 
+    /**
+     * @tests java.security.cert.X509Certificate#getExtensionValue()
+     */
+    public void testGetExtensionValue() throws Exception {
+        // Regression for HARMONY-419
+        ByteArrayInputStream is = null;
+        CertificateFactory certFactory = CertificateFactory
+                .getInstance("X.509");
+        is = new ByteArrayInputStream(Base64.decode(base64cert.getBytes()));
+        X509Certificate cert = (X509Certificate) certFactory
+                .generateCertificate(is);
+        cert.getExtensionValue("1.1.1.1");
+
+        is = new ByteArrayInputStream(Base64.decode(base64crl.getBytes()));
+        X509CRL crl = (X509CRL) certFactory.generateCRL(is);
+        crl.getExtensionValue("1.1.1.1");
+    }
+    
+    
     public static Test suite() {
         return new TestSuite(X509CertificateTest.class);
     }

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImplTest.java?rev=398814&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImplTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLEntryImplTest.java
Mon May  1 22:35:36 2006
@@ -0,0 +1,80 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Alexander Y. Kleymenov
+ * @version $Revision$
+ */
+
+package org.apache.harmony.security.provider.cert;
+
+import java.math.BigInteger;
+import java.util.Date;
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.harmony.security.x509.Extension;
+import org.apache.harmony.security.x509.Extensions;
+import org.apache.harmony.security.x509.TBSCertList;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * X509CRLEntryImplTest test
+ */
+public class X509CRLEntryImplTest extends TestCase {
+
+    /**
+     * getExtensionValue(String oid) method testing.
+     */
+    public void testGetExtensionValue() throws Exception {
+        // revoked certificate issuer
+        X500Principal issuer = 
+            new X500Principal("O=Certificate Issuer");
+        // revoked sertificate serial number
+        BigInteger serialNumber = BigInteger.valueOf(555);
+        // crl entry extensions
+        Extensions crlEntryExtensions = new Extensions();
+        // add reason code extension which OID is 2.5.29.21
+        // see RFC 3280 http://www.ietf.org/rfc/rfc3280.txt
+        crlEntryExtensions.addExtension(new Extension.ReasonCode(1));
+        // crl entry
+        X509CRLEntryImpl crlEntry = new X509CRLEntryImpl(
+                new TBSCertList.RevokedCertificate(
+                        serialNumber,
+                        new Date(),
+                        crlEntryExtensions
+                    ),
+                issuer
+            );
+        assertNotNull(crlEntry.getExtensionValue("2.5.29.21"));
+        assertNull("Null value should be returned in the case of "
+                + "nonexisting extension",
+                // demand absent Invalidity Date extension
+                // which OID is 2.5.29.24 (RFC 3280)
+                crlEntry.getExtensionValue("2.5.29.24"));
+    }
+
+    public static Test suite() {
+        return new TestSuite(X509CRLEntryImplTest.class);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+}
+

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLImplTest.java?rev=398814&r1=398813&r2=398814&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLImplTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CRLImplTest.java
Mon May  1 22:35:36 2006
@@ -30,6 +30,7 @@
 import java.security.Signature;
 import java.security.cert.CRLException;
 import java.security.cert.CertificateFactory;
+import java.security.cert.X509CRLEntry;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -547,9 +548,10 @@
     /**
      * getExtensionValue(String oid) method testing.
      */
-    public void testGetExtensionValue() {
-        System.out.println("getExtensionValue: "
-                + crl.getExtensionValue("2.5.29.20"));
+    public void testGetExtensionValue() throws Exception {
+        assertNotNull(crl.getExtensionValue("2.5.29.20"));
+        assertNull("Null value should be returned in the case of "
+                + "nonexisting extension", crl.getExtensionValue("1.1.1.1"));
     }
     
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CertImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CertImplTest.java?rev=398814&r1=398813&r2=398814&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CertImplTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/provider/cert/X509CertImplTest.java
Mon May  1 22:35:36 2006
@@ -647,9 +647,12 @@
                 } else {
                     printAsHex(20, "", " ", certExtnValue);
                 }
-                //fail("The values for extension "+id+" differ.");
+                fail("The values for extension "+id+" differ.");
             }
         }
+        assertNull("Null value should be returned in the case of "
+                + "nonexisting extension", 
+                certificate.getExtensionValue("1.1.1.1"));
     }
     
     /**



Mime
View raw message