harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r466079 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/internal/nls/ main/java/common/org/apache/harmony/security/pkcs7/ test/impl/java/org/apache/harmony/security/tests/pk...
Date Fri, 20 Oct 2006 11:58:53 GMT
Author: smishura
Date: Fri Oct 20 04:58:48 2006
New Revision: 466079

URL: http://svn.apache.org/viewvc?view=rev&rev=466079
Log:
Apply patch for HARMONY-1915 ([classlib][security] Implemented encoding of PKCS#7 SignerInfo.)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs7/
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs7/SignerInfoTest.java
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/pkcs7/SignerInfo.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties?view=diff&rev=466079&r1=466078&r2=466079
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
Fri Oct 20 04:58:48 2006
@@ -341,4 +341,5 @@
 security.19F='key' is neither DSAPublicKey nor DSAPrivateKey
 security.1A0=ATTENTION: InvalidKeySpecException in engineGeneratePrivate: {0}
 security.1A1=ATTENTION: InvalidKeySpecException in engineGeneratePublic: {0}
+security.1A2=Failed to encode issuer name
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/pkcs7/SignerInfo.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/pkcs7/SignerInfo.java?view=diff&rev=466079&r1=466078&r2=466079
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/pkcs7/SignerInfo.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/pkcs7/SignerInfo.java
Fri Oct 20 04:58:48 2006
@@ -21,6 +21,7 @@
 */
 package org.apache.harmony.security.pkcs7;
 
+import java.io.IOException;
 import java.math.BigInteger;
 import java.util.List;
 
@@ -33,6 +34,7 @@
 import org.apache.harmony.security.asn1.ASN1SetOf;
 import org.apache.harmony.security.asn1.ASN1Type;
 import org.apache.harmony.security.asn1.BerInputStream;
+import org.apache.harmony.security.internal.nls.Messages;
 import org.apache.harmony.security.x501.AttributeTypeAndValue;
 import org.apache.harmony.security.x501.Name;
 import org.apache.harmony.security.x509.AlgorithmIdentifier;
@@ -150,14 +152,25 @@
         return res.toString();
     }
 
+    
+    public static final ASN1Sequence ISSUER_AND_SERIAL_NUMBER = 
+            new ASN1Sequence(new ASN1Type[] { 
+                Name.ASN1,                       // issuer
+                ASN1Integer.getInstance(),       // serialNumber
+            }) 
+        {
+            // method to encode
+            public void getValues(Object object, Object[] values) {
+                Object [] issAndSerial = (Object[])object;
+                values[0] = issAndSerial[0];
+                values[1] = issAndSerial[1];
+        }
+    };
+    
     public static final ASN1Sequence ASN1 = 
         new ASN1Sequence(new ASN1Type[] {
                 ASN1Integer.getInstance(),         //version
-                new ASN1Sequence(new ASN1Type[]    //issuerAndSerialNumber
-                        {Name.ASN1,                    //issuer
-                        ASN1Integer.getInstance()      //serialNumber
-                        }
-                ),
+                ISSUER_AND_SERIAL_NUMBER,
                 AlgorithmIdentifier.ASN1,           //digestAlgorithm
                 new ASN1Implicit(0, AuthenticatedAttributes.ASN1),//authenticatedAttributes
                 AlgorithmIdentifier.ASN1,            //digestEncryptionAlgorithm
@@ -170,6 +183,27 @@
             setOptional(6); // unauthenticatedAttributes is optional
         }
 
+        protected void getValues(Object object, Object[] values) {
+            SignerInfo si = (SignerInfo) object;
+            values[0] = new byte[] {(byte)si.version};
+            try {
+                values[1] = new Object[] { new Name(si.issuer.getName()),
+                        si.serialNumber.toByteArray() };
+            } catch (IOException e) {
+                // The exception is never thrown, because si.issuer
+                // is created using Name.getX500Principal(). 
+                // Throw a RuntimeException just to be safe.
+                throw new RuntimeException(
+                        // Msg: "Failed to encode issuer name
+                        Messages.getString("security.1A2"), e);
+            } 
+            values[2] = si.digestAlgorithm;
+            values[3] = si.authenticatedAttributes;
+            values[4] = si.digestEncryptionAlgorithm;
+            values[5] = si.encryptedDigest;
+            values[6] = si.unauthenticatedAttributes;
+        }
+ 
         protected Object getDecodedObject(BerInputStream in) {
             Object[] values = (Object[]) in.content;
             return new SignerInfo(

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs7/SignerInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs7/SignerInfoTest.java?view=auto&rev=466079
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs7/SignerInfoTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs7/SignerInfoTest.java
Fri Oct 20 04:58:48 2006
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.pkcs7;
+
+import java.math.BigInteger;
+
+import javax.security.auth.x500.X500Principal;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.pkcs7.SignerInfo;
+import org.apache.harmony.security.x501.Name;
+import org.apache.harmony.security.x509.AlgorithmIdentifier;
+
+public class SignerInfoTest extends TestCase {
+
+    public void testEncode() throws Exception {
+
+        Object[] issuerAndSerialNumber = new Object[] { new Name("CN=test"),
+                BigInteger.TEN.toByteArray() };
+
+        SignerInfo signerInfo = new SignerInfo(1, issuerAndSerialNumber,
+                new AlgorithmIdentifier("1.3.14.3.2.26"),// SHA1 OID
+                null, new AlgorithmIdentifier("1.2.840.10040.4.1"),// DSA OID
+                new byte[] { 0x01 },// signature
+                null);
+
+        byte[] encoding = SignerInfo.ASN1.encode(signerInfo);
+
+        signerInfo = (SignerInfo) SignerInfo.ASN1.decode(encoding);
+
+        assertEquals(new X500Principal("CN=test"), signerInfo.getIssuer());
+        assertEquals(new BigInteger("10"), signerInfo.getSerialNumber());
+    }
+}

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



Mime
View raw message