Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 92576 invoked from network); 20 Oct 2006 11:59:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Oct 2006 11:59:16 -0000 Received: (qmail 8179 invoked by uid 500); 20 Oct 2006 11:59:15 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 8154 invoked by uid 500); 20 Oct 2006 11:59:15 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 8140 invoked by uid 99); 20 Oct 2006 11:59:15 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Oct 2006 04:59:15 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Oct 2006 04:59:14 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id D8F161A981A; Fri, 20 Oct 2006 04:58:53 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: harmony-commits@incubator.apache.org From: smishura@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061020115853.D8F161A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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