Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 17391 invoked from network); 22 Aug 2006 05:01:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Aug 2006 05:01:50 -0000 Received: (qmail 84387 invoked by uid 500); 22 Aug 2006 05:01:49 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 84355 invoked by uid 500); 22 Aug 2006 05:01:49 -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 84343 invoked by uid 99); 22 Aug 2006 05:01:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Aug 2006 22:01:49 -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; Mon, 21 Aug 2006 22:01:48 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 733B71A981D; Mon, 21 Aug 2006 22:01:28 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r433520 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10: CertificationRequestInfoTest.java CertificationRequestTest.java Date: Tue, 22 Aug 2006 05:01:27 -0000 To: harmony-commits@incubator.apache.org From: mloenko@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060822050128.733B71A981D@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: mloenko Date: Mon Aug 21 22:01:27 2006 New Revision: 433520 URL: http://svn.apache.org/viewvc?rev=433520&view=rev Log: integrating new tests from HARMONY-1234 Tests for org.apache.harmony.security.pkcs10 Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java?rev=433520&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestInfoTest.java Mon Aug 21 22:01:27 2006 @@ -0,0 +1,85 @@ +/* + * 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.pkcs10; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import junit.framework.TestCase; + +import org.apache.harmony.security.pkcs10.CertificationRequestInfo; +import org.apache.harmony.security.x501.AttributeTypeAndValue; +import org.apache.harmony.security.x501.AttributeValue; +import org.apache.harmony.security.x501.Name; +import org.apache.harmony.security.x509.AlgorithmIdentifier; +import org.apache.harmony.security.x509.SubjectPublicKeyInfo; + + +public class CertificationRequestInfoTest extends TestCase { + + /** + * Test method for CertificationRequestInfo. Creates + * CertificationRequestInfo, gets its values, encodes and decodes the + * encoded form. + * + */ + public void testCertificationRequestInfo() throws IOException { + int version = 2;// X.509 v3 + Name subject = new Name("O=subject"); + SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo( + new AlgorithmIdentifier("1.2.840.113549.1.1.2"), new byte[4]); + List attributes = new ArrayList(); + // 1.2.840.113549.1.9.1 is OID of EMAILADDRESS + attributes.add(new AttributeTypeAndValue("1.2.840.113549.1.9.1", + new AttributeValue("a@b.com", false))); + + CertificationRequestInfo certReqInfo = new CertificationRequestInfo( + version, subject, spki, attributes); + + // check what we have constructed + assertEquals(version, certReqInfo.getVersion()); + assertEquals(subject.getName(X500Principal.RFC1779), certReqInfo + .getSubject().getName(X500Principal.RFC1779)); + assertTrue(Arrays.equals(spki.getEncoded(), certReqInfo + .getSubjectPublicKeyInfo().getEncoded())); + assertEquals(attributes, certReqInfo.getAttributes()); + + // decode the encoded CertificationRequestInfo + byte[] encoding = certReqInfo.getEncoded(); + CertificationRequestInfo decoded = + (CertificationRequestInfo) CertificationRequestInfo.ASN1 + .decode(encoding); + + // check what was decoded + assertEquals(certReqInfo.getVersion(), decoded.getVersion()); + assertEquals(certReqInfo.getSubject().getName(X500Principal.CANONICAL), + decoded.getSubject().getName(X500Principal.CANONICAL)); + assertTrue(Arrays.equals(certReqInfo.getSubjectPublicKeyInfo() + .getEncoded(), decoded.getSubjectPublicKeyInfo().getEncoded())); + + AttributeTypeAndValue certReqInfoATaV = (AttributeTypeAndValue) certReqInfo + .getAttributes().get(0); + AttributeTypeAndValue decodedATaV = (AttributeTypeAndValue) decoded + .getAttributes().get(0); + assertEquals(certReqInfoATaV.getType(), decodedATaV.getType()); + } +} + Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java?rev=433520&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/pkcs10/CertificationRequestTest.java Mon Aug 21 22:01:27 2006 @@ -0,0 +1,86 @@ +/* + * 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.pkcs10; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.harmony.security.pkcs10.CertificationRequest; +import org.apache.harmony.security.pkcs10.CertificationRequestInfo; +import org.apache.harmony.security.x501.AttributeTypeAndValue; +import org.apache.harmony.security.x501.AttributeValue; +import org.apache.harmony.security.x501.Name; +import org.apache.harmony.security.x509.AlgorithmIdentifier; +import org.apache.harmony.security.x509.SubjectPublicKeyInfo; + + + +public class CertificationRequestTest extends TestCase { + + /** + * Test method for 'com.openintel.drl.security.pkcs10.CertificationRequest'. + * Creates CertificationRequest, gets its values, encodes and decodes the + * encoded form. + * + */ + public void testCertificationRequest() throws IOException { + int version = 2;// v3 + Name subject = new Name("O=subject"); + SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo( + new AlgorithmIdentifier("1.2.840.113549.1.1.2"), new byte[4]); + List attributes = new ArrayList(); + // 1.2.840.113549.1.9.1 is OID of EMAILADDRESS + attributes.add(new AttributeTypeAndValue("1.2.840.113549.1.9.1", + new AttributeValue("a@b.com", false))); + CertificationRequestInfo certReqInfo = new CertificationRequestInfo( + version, subject, spki, attributes); + AlgorithmIdentifier signatureAlgId = new AlgorithmIdentifier( + "1.2.3.44.555"); + byte[] signature = { (byte) 0x01, (byte) 0x02, (byte) 0x03, + (byte) 0x04, (byte) 0x05 }; + + CertificationRequest certReq = new CertificationRequest(certReqInfo, + signatureAlgId, signature); + + // check what we have constructed + assertEquals(certReqInfo, certReq.getInfo()); + assertEquals(signatureAlgId, certReq.getAlgId()); + assertTrue(Arrays.equals(signature, certReq.getSignature())); + + // decode the encoded CSR + byte[] encoding = certReq.getEncoded(); + CertificationRequest decoded = (CertificationRequest) CertificationRequest.ASN1 + .decode(encoding); + + // check what was decoded + CertificationRequestInfo decodedCRinfo = certReq.getInfo(); + + assertEquals(certReqInfo.getSubject(), decodedCRinfo.getSubject()); + assertEquals(certReqInfo.getSubjectPublicKeyInfo(), decodedCRinfo + .getSubjectPublicKeyInfo()); + assertEquals(certReqInfo.getVersion(), decodedCRinfo.getVersion()); + assertEquals(certReqInfo.getAttributes(), decodedCRinfo.getAttributes()); + + assertEquals(certReq.getAlgId(), decoded.getAlgId()); + assertTrue(Arrays.equals(certReq.getSignature(), decoded.getSignature())); + } +} +