harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r369769 - in /incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7: ./ ContentInfo.java SignedData.java SignerInfo.java
Date Tue, 17 Jan 2006 13:00:37 GMT
Author: geirm
Date: Tue Jan 17 05:00:32 2006
New Revision: 369769

URL: http://svn.apache.org/viewcvs?rev=369769&view=rev
Log:
refactor package name

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/ContentInfo.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignedData.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignerInfo.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/ContentInfo.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/ContentInfo.java?rev=369769&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/ContentInfo.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/ContentInfo.java
Tue Jan 17 05:00:32 2006
@@ -0,0 +1,152 @@
+/*
+ *  Copyright 2005 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 Boris Kuznetsov
+* @version $Revision$
+*/
+package org.apache.harmony.security.pkcs7;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.harmony.security.asn1.ASN1Any;
+import org.apache.harmony.security.asn1.ASN1Explicit;
+import org.apache.harmony.security.asn1.ASN1OctetString;
+import org.apache.harmony.security.asn1.ASN1Oid;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+/**
+ * As defined in PKCS #7: Cryptographic Message Syntax Standard
+ * (http://www.rsasecurity.com/rsalabs/node.asp?id=2129)
+ * 
+ * ContentInfo ::= SEQUENCE {
+ *       contentType  ContentType,
+ *       content      [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
+ *     }
+ */
+
+public class ContentInfo {
+
+    // OIDs
+    public static final int[] DATA = new int[] {1, 2, 840, 113549, 1, 7, 1};
+    public static final int[] SIGNED_DATA = new int[] {1, 2, 840, 113549, 1, 7, 2};
+    public static final int[] ENVELOPED_DATA = new int[] {1, 2, 840, 113549, 1, 7, 3};
+    public static final int[] SIGNED_AND_ENVELOPED_DATA = new int[] {1, 2, 840, 113549, 1,
7, 4};
+    public static final int[] DIGESTED_DATA = new int[] {1, 2, 840, 113549, 1, 7, 5};
+    public static final int[] ENCRYPTED_DATA = new int[] {1, 2, 840, 113549, 1, 7, 6};
+
+    private int[] oid;
+    private Object content;
+    private byte[] encoding;
+
+    public ContentInfo(int[] oid, Object content) {
+        this.oid = oid;
+        this.content = content;
+    }
+
+    private ContentInfo(int[] oid, Object content, byte[] encoding) {
+        this.oid = oid;
+        this.content = content;
+        this.encoding = encoding;
+    }
+
+    public SignedData getSignedData() {
+        if (Arrays.equals(oid, SIGNED_DATA)) {
+            return (SignedData)content;
+        }
+        return null;
+    }
+
+    public byte[] getEncoded() {
+        if (encoding == null) {
+            encoding = ASN1.encode(this);
+        }
+        // Note: this is internal object and can not be accessible from
+        // public API, so encoding is not copied. The classes which use
+        // this class should copy encoding before passing it out.
+        return encoding;
+    }
+    
+    public String toString() {
+        StringBuffer res = new StringBuffer();
+        res.append("==== ContentInfo:");
+        res.append("\n== ContentType (OID): ");
+        for (int i = 0; i< oid.length; i++) {
+            res.append(oid[i]);
+            res.append(' ');
+        }
+        res.append("\n== Content: ");       
+        if (content != null) {
+            res.append("\n");
+            res.append(content.toString()); 
+        }    
+        res.append("\n== Content End");
+        res.append("\n==== ContentInfo End\n");
+        return res.toString();
+    }
+
+    public static final ASN1Sequence ASN1 = 
+        new ASN1Sequence(new ASN1Type[] {
+                ASN1Oid.getInstance(),
+                new ASN1Explicit(0, ASN1Any.getInstance())
+                })  {    
+        {
+            setOptional(1); // content is optional
+        }
+        
+        protected void getValues(Object object, Object[] values) {
+            ContentInfo ci = (ContentInfo) object;
+            values[0] = ci.oid;
+            if (ci.content != null) {
+                if (Arrays.equals(ci.oid, DATA)) {
+                    if (ci.content != null) {
+                        values[1] = 
+                            ASN1OctetString.getInstance().encode(ci.content);
+                    }
+                } else if (ci.content instanceof SignedData) {
+                    values[1] = SignedData.ASN1.encode(ci.content);
+                } else {
+                    values[1] = ci.content;
+                }
+            }
+        }
+
+        protected Object getDecodedObject(BerInputStream in) throws IOException {
+            Object[] values = (Object[]) in.content;
+            int[] oid = (int[]) values[0];
+            if (Arrays.equals(oid, DATA)) {
+                if (values[1] != null) {  
+                    return new ContentInfo(oid, 
+                            ASN1OctetString.getInstance().decode((byte[])values[1]),
+                            in.getEncoded());
+                }  else {
+                    return new ContentInfo((int[])values[0], null,
+                            in.getEncoded());
+                }
+            }
+            if (Arrays.equals(oid, SIGNED_DATA)) {
+                return new ContentInfo((int[])values[0],
+                        SignedData.ASN1.decode((byte[])values[1]),
+                        in.getEncoded());
+            }
+            return new ContentInfo((int[])values[0], (byte[])values[1],
+                    in.getEncoded());
+        } 
+   };    
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignedData.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignedData.java?rev=369769&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignedData.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignedData.java
Tue Jan 17 05:00:32 2006
@@ -0,0 +1,129 @@
+/*
+ *  Copyright 2005 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 Boris Kuznetsov
+* @version $Revision$
+*/
+package org.apache.harmony.security.pkcs7;
+
+import java.util.List;
+
+import org.apache.harmony.security.asn1.ASN1Any;
+import org.apache.harmony.security.asn1.ASN1Implicit;
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1SetOf;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+import com.openintel.drl.security.x509.AlgorithmIdentifier;
+import com.openintel.drl.security.x509.Certificate;
+
+/**
+ * As defined in PKCS #7: Cryptographic Message Syntax Standard
+ * (http://www.rsasecurity.com/rsalabs/node.asp?id=2129)
+ * 
+ * SignedData ::= SEQUENCE { 
+ *   version Version, 
+ *   digestAlgorithms DigestAlgorithmIdentifiers,
+ *   contentInfo ContentInfo,
+ *   certificates
+ *     [0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL,
+ *   crls 
+ *     [1] IMPLICIT CertificateRevocationLists OPTIONAL,
+ *   signerInfos SignerInfos }
+ *  
+ */
+
+public class SignedData {
+
+    private int version;
+
+    private List digestAlgorithms;
+    private ContentInfo contentInfo;
+    private List certificates;
+    private List crls;
+    private List signerInfos;
+
+    public SignedData(int version, List digestAlgorithms, ContentInfo contentInfo,
+            List certificates, List crls, List signerInfos) {
+        this.version = version;
+        this.digestAlgorithms = digestAlgorithms;
+        this.contentInfo = contentInfo;
+        this.certificates = certificates;
+        this.crls = crls;
+        this.signerInfos = signerInfos;
+    }
+
+    public List getCertificates() {
+        return certificates;
+    }
+
+    public List getSignerInfos() {
+        return signerInfos;
+    }
+
+    public String toString() {
+        StringBuffer res = new StringBuffer();
+        res.append("---- SignedData:");
+        res.append("\nversion: ");
+        res.append(version);
+        res.append("\ndigestAlgorithms: ");
+        res.append(digestAlgorithms.toString());
+        res.append("\ncontentInfo: ");
+        res.append(contentInfo.toString());
+        res.append("\ncertificates: ");
+        if (certificates != null) {
+            res.append(certificates.toString());
+        }
+        res.append("\ncrls: ");
+        if (crls != null) {
+            res.append(crls.toString());
+        }
+        res.append("\nsignerInfos:\n");
+        res.append(signerInfos.toString());
+        res.append("\n---- SignedData End\n]");
+        return res.toString();
+    }
+
+    public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] {
+            ASN1Integer.getInstance(), 
+            new ASN1SetOf(AlgorithmIdentifier.ASN1),
+            ContentInfo.ASN1,
+            new ASN1Implicit(0, new ASN1SetOf(Certificate.ASN1)),
+            new ASN1Implicit(1, new ASN1SetOf(ASN1Any.getInstance())),
+            new ASN1SetOf(SignerInfo.ASN1) 
+			}) {
+        {
+            setOptional(3); // certificates is optional
+            setOptional(4); // crls is optional
+        }
+
+        protected Object getDecodedObject(BerInputStream in) {
+            Object[] values = (Object[]) in.content;
+            return new SignedData(
+                        ASN1Integer.toIntValue(values[0]),
+                        (List) values[1], 
+                        (ContentInfo) values[2],
+                        (List) values[3], 
+                        (List) values[4], 
+                        (List) values[5]
+                    );
+        }
+    };
+
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignerInfo.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignerInfo.java?rev=369769&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignerInfo.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/pkcs7/SignerInfo.java
Tue Jan 17 05:00:32 2006
@@ -0,0 +1,223 @@
+/*
+ *  Copyright 2005 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 Boris Kuznetsov
+* @version $Revision$
+*/
+package org.apache.harmony.security.pkcs7;
+
+import java.math.BigInteger;
+import java.util.List;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.harmony.security.asn1.ASN1Implicit;
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1OctetString;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1SetOf;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+import com.openintel.drl.security.x501.AttributeTypeAndValue;
+import com.openintel.drl.security.x501.Name;
+import com.openintel.drl.security.x509.AlgorithmIdentifier;
+
+/**
+ * As defined in PKCS #7: Cryptographic Message Syntax Standard
+ * (http://www.rsasecurity.com/rsalabs/node.asp?id=2129)
+ * 
+ * SignerInfo ::= SEQUENCE {
+ *   version Version,
+ *   issuerAndSerialNumber IssuerAndSerialNumber,
+ *   digestAlgorithm DigestAlgorithmIdentifier,
+ *   authenticatedAttributes
+ *     [0] IMPLICIT Attributes OPTIONAL,
+ *   digestEncryptionAlgorithm
+ *     DigestEncryptionAlgorithmIdentifier,
+ *   encryptedDigest EncryptedDigest,
+ *   unauthenticatedAttributes
+ *     [1] IMPLICIT Attributes OPTIONAL
+ *  }
+ * 
+ */
+public class SignerInfo {
+
+    private int version;
+    private X500Principal issuer;
+    private BigInteger serialNumber;
+    
+    private AlgorithmIdentifier digestAlgorithm;
+    private AuthenticatedAttributes authenticatedAttributes;
+    private AlgorithmIdentifier digestEncryptionAlgorithm;
+    private byte[] encryptedDigest;
+    private List unauthenticatedAttributes;
+
+    public SignerInfo(int version,
+            Object[] issuerAndSerialNumber,
+            AlgorithmIdentifier digestAlgorithm,
+            AuthenticatedAttributes authenticatedAttributes,
+            AlgorithmIdentifier digestEncryptionAlgorithm,
+            byte[] encryptedDigest,
+            List unauthenticatedAttributes
+            ) {
+        this.version = version;
+        this.issuer = new X500Principal(((Name)issuerAndSerialNumber[0]).getEncoded());
+        this.serialNumber = BigInteger.valueOf(ASN1Integer.toIntValue(issuerAndSerialNumber[1]));
+        this.digestAlgorithm = digestAlgorithm;
+        this.authenticatedAttributes = authenticatedAttributes;
+        this.digestEncryptionAlgorithm = digestEncryptionAlgorithm;
+        this.encryptedDigest = encryptedDigest;
+        this.unauthenticatedAttributes = unauthenticatedAttributes;
+    }
+
+    public X500Principal getIssuer() {
+    	return issuer;
+    }
+    
+    public BigInteger getSerialNumber() {
+    	return serialNumber;
+    }    
+    
+    public String getDigestAlgorithm() {
+        return digestAlgorithm.getAlgorithm();
+    }
+
+    public String getdigestAlgorithm() {
+        return digestAlgorithm.getAlgorithm();
+    }
+
+    public String getDigestEncryptionAlgorithm() {
+        return digestEncryptionAlgorithm.getAlgorithm();
+    }
+
+    public List getAuthenticatedAttributes() {
+        if (authenticatedAttributes == null) {
+            return null;
+        }
+        return authenticatedAttributes.getAttributes();
+    }
+
+    public byte[] getEncodedAuthenticatedAttributes() {
+        if (authenticatedAttributes == null) {
+            return null;
+        }
+        return authenticatedAttributes.getEncoded();
+    }
+
+    public byte[] getEncryptedDigest() {
+        return encryptedDigest;
+    }
+
+    
+    public String toString() {
+        StringBuffer res = new StringBuffer();
+        res.append("-- SignerInfo:");
+        res.append("\n version : ");
+        res.append(version);
+        res.append("\nissuerAndSerialNumber:  ");
+        res.append(issuer);
+        res.append("   ");
+        res.append(serialNumber);
+        res.append("\ndigestAlgorithm:  ");
+        res.append(digestAlgorithm.toString());
+        res.append("\nauthenticatedAttributes:  ");
+        if (authenticatedAttributes != null) {
+            res.append(authenticatedAttributes.toString());
+        }
+        res.append("\ndigestEncryptionAlgorithm: ");
+        res.append(digestEncryptionAlgorithm.toString());
+        res.append("\nunauthenticatedAttributes: ");
+        if (unauthenticatedAttributes != null) {
+            res.append(unauthenticatedAttributes.toString());
+        }
+        res.append("\n-- SignerInfo End\n");
+        return res.toString();
+    }
+
+    public static final ASN1Sequence ASN1 = 
+        new ASN1Sequence(new ASN1Type[] {
+                ASN1Integer.getInstance(),         //version
+                new ASN1Sequence(new ASN1Type[]    //issuerAndSerialNumber
+                        {Name.ASN1,                    //issuer
+                        ASN1Integer.getInstance()      //serialNumber
+                        }
+                ),
+                AlgorithmIdentifier.ASN1,           //digestAlgorithm
+                new ASN1Implicit(0, AuthenticatedAttributes.ASN1),//authenticatedAttributes
+                AlgorithmIdentifier.ASN1,            //digestEncryptionAlgorithm
+                ASN1OctetString.getInstance(),       //encryptedDigest
+                 new ASN1Implicit(1, new ASN1SetOf(
+                         AttributeTypeAndValue.ASN1)),//unauthenticatedAttributes
+                })  {
+        {
+            setOptional(3); // authenticatedAttributes is optional
+            setOptional(6); // unauthenticatedAttributes is optional
+        }
+
+        protected Object getDecodedObject(BerInputStream in) {
+            Object[] values = (Object[]) in.content;
+            return new SignerInfo(
+                        ASN1Integer.toIntValue(values[0]),
+                        (Object[]) values[1], 
+                        (AlgorithmIdentifier) values[2],
+                        (AuthenticatedAttributes) values[3], 
+                        (AlgorithmIdentifier) values[4], 
+                        (byte[]) values[5],
+                        (List) values[6]
+                    );
+        }
+   };
+}
+
+/**
+ * 
+ * As defined in PKCS #7: Cryptographic Message Syntax Standard
+ * (http://www.rsasecurity.com/rsalabs/node.asp?id=2129):
+ * authenticatedAttributes is a set of attributes that are signed (i.e., authenticated) by
the signer
+ */
+class AuthenticatedAttributes {
+    private byte[] encoding;
+    private List authenticatedAttributes;
+    
+    public AuthenticatedAttributes(byte[] encoding, List authenticatedAttributes) {
+        this.encoding = encoding;
+        this.authenticatedAttributes = authenticatedAttributes;
+    }
+    public List getAttributes() {
+        return authenticatedAttributes;
+    }
+
+    /**
+     * Returns ASN.1 encoded form of this authenticatedAttributes.
+     * @return a byte array containing ASN.1 encode form.
+     */
+    public byte[] getEncoded() {
+        if (encoding == null) {
+            encoding = ASN1.encode(this);
+        }
+        return encoding;
+    }
+
+    public static final ASN1SetOf ASN1 =
+        new ASN1SetOf(AttributeTypeAndValue.ASN1) {
+        public Object getDecodedObject(BerInputStream in) {
+            Object[] values = (Object[]) in.content;
+            return new AuthenticatedAttributes(in.getEncoded(), (List) values[0]);
+        }
+    };
+}
\ No newline at end of file



Mime
View raw message