harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r434011 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/x509/Time.java test/impl/java/org/apache/harmony/security/tests/x509/TimeTest.java
Date Wed, 23 Aug 2006 11:38:42 GMT
Author: smishura
Date: Wed Aug 23 04:38:35 2006
New Revision: 434011

URL: http://svn.apache.org/viewvc?rev=434011&view=rev
Log:
Apply updated patch for HARMONY-1253 ([classlib][security] X.509 ASN.1 framework incorrectly
encodes the dates after 2050.)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/TimeTest.java
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/Time.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/Time.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/Time.java?rev=434011&r1=434010&r2=434011&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/Time.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/x509/Time.java
Wed Aug 23 04:38:35 2006
@@ -42,13 +42,18 @@
  */
 public class Time {
     
+    private static final long JAN_01_2050 = 2524608000000L;
+    
     public static final ASN1Choice ASN1 = new ASN1Choice(new ASN1Type[] {
             ASN1GeneralizedTime.getInstance(), ASN1UTCTime.getInstance() }) {
 
         public int getIndex(java.lang.Object object) {
-            return 1; // always code as ASN1UTCTime ()
-            // FIXME: But it is correct only if the Date to encode 
-            // is before 2050. See rfc 3280 p.22
+            // choose encoding method (see RFC 3280 p. 22)
+            if (((java.util.Date) object).getTime() < JAN_01_2050) {
+                return 1; // it is before 2050, so encode as UTCTime
+            } else {
+                return 0; // it is after 2050, encode as GeneralizedTime
+            }
         }
 
         public Object getObjectToEncode(Object object) {

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/TimeTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/TimeTest.java?rev=434011&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/TimeTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/TimeTest.java
Wed Aug 23 04:38:35 2006
@@ -0,0 +1,52 @@
+/*
+ *  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.
+ */
+
+package org.apache.harmony.security.tests.x509;
+
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.asn1.ASN1Constants;
+import org.apache.harmony.security.x509.Time;
+
+/**
+ * Time test
+ */
+public class TimeTest extends TestCase {
+
+    /**
+     * Tests the result of encoding work on the data before and after 2050.
+     */
+    public void test_Encoding() throws Exception {
+
+        long march2006 = 1143115180000L;
+        long march2332 = 11431151800000L;
+
+        // verify that date before 2050 encoded as UTCTime
+        byte[] enc = Time.ASN1.encode(new Date(march2006));
+        assertEquals("UTCTime", ASN1Constants.TAG_UTCTIME, enc[0]);
+
+        // verify that date after 2050 encoded as GeneralizedTime
+        enc = Time.ASN1.encode(new Date(march2332));
+        assertEquals("GeneralizedTime", ASN1Constants.TAG_GENERALIZEDTIME,
+                enc[0]);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(TimeTest.class);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/x509/TimeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message