Source Code Cross Referenced for SignerInfo.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » security » pkcs7 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.security.pkcs7 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Boris Kuznetsov
020:         * @version $Revision$
021:         */package org.apache.harmony.security.pkcs7;
022:
023:        import java.io.IOException;
024:        import java.math.BigInteger;
025:        import java.util.List;
026:
027:        import javax.security.auth.x500.X500Principal;
028:
029:        import org.apache.harmony.security.asn1.ASN1Implicit;
030:        import org.apache.harmony.security.asn1.ASN1Integer;
031:        import org.apache.harmony.security.asn1.ASN1OctetString;
032:        import org.apache.harmony.security.asn1.ASN1Sequence;
033:        import org.apache.harmony.security.asn1.ASN1SetOf;
034:        import org.apache.harmony.security.asn1.ASN1Type;
035:        import org.apache.harmony.security.asn1.BerInputStream;
036:        import org.apache.harmony.security.internal.nls.Messages;
037:        import org.apache.harmony.security.x501.AttributeTypeAndValue;
038:        import org.apache.harmony.security.x501.Name;
039:        import org.apache.harmony.security.x509.AlgorithmIdentifier;
040:
041:        /**
042:         * As defined in PKCS #7: Cryptographic Message Syntax Standard
043:         * (http://www.ietf.org/rfc/rfc2315.txt)
044:         * 
045:         * SignerInfo ::= SEQUENCE {
046:         *   version Version,
047:         *   issuerAndSerialNumber IssuerAndSerialNumber,
048:         *   digestAlgorithm DigestAlgorithmIdentifier,
049:         *   authenticatedAttributes
050:         *     [0] IMPLICIT Attributes OPTIONAL,
051:         *   digestEncryptionAlgorithm
052:         *     DigestEncryptionAlgorithmIdentifier,
053:         *   encryptedDigest EncryptedDigest,
054:         *   unauthenticatedAttributes
055:         *     [1] IMPLICIT Attributes OPTIONAL
056:         *  }
057:         * 
058:         */
059:        public class SignerInfo {
060:
061:            private int version;
062:            private X500Principal issuer;
063:            private BigInteger serialNumber;
064:
065:            private AlgorithmIdentifier digestAlgorithm;
066:            private AuthenticatedAttributes authenticatedAttributes;
067:            private AlgorithmIdentifier digestEncryptionAlgorithm;
068:            private byte[] encryptedDigest;
069:            private List unauthenticatedAttributes;
070:
071:            public SignerInfo(int version, Object[] issuerAndSerialNumber,
072:                    AlgorithmIdentifier digestAlgorithm,
073:                    AuthenticatedAttributes authenticatedAttributes,
074:                    AlgorithmIdentifier digestEncryptionAlgorithm,
075:                    byte[] encryptedDigest, List unauthenticatedAttributes) {
076:                this .version = version;
077:                this .issuer = ((Name) issuerAndSerialNumber[0])
078:                        .getX500Principal();
079:                this .serialNumber = BigInteger.valueOf(ASN1Integer
080:                        .toIntValue(issuerAndSerialNumber[1]));
081:                this .digestAlgorithm = digestAlgorithm;
082:                this .authenticatedAttributes = authenticatedAttributes;
083:                this .digestEncryptionAlgorithm = digestEncryptionAlgorithm;
084:                this .encryptedDigest = encryptedDigest;
085:                this .unauthenticatedAttributes = unauthenticatedAttributes;
086:            }
087:
088:            public X500Principal getIssuer() {
089:                return issuer;
090:            }
091:
092:            public BigInteger getSerialNumber() {
093:                return serialNumber;
094:            }
095:
096:            public String getDigestAlgorithm() {
097:                return digestAlgorithm.getAlgorithm();
098:            }
099:
100:            public String getdigestAlgorithm() {
101:                return digestAlgorithm.getAlgorithm();
102:            }
103:
104:            public String getDigestEncryptionAlgorithm() {
105:                return digestEncryptionAlgorithm.getAlgorithm();
106:            }
107:
108:            public List getAuthenticatedAttributes() {
109:                if (authenticatedAttributes == null) {
110:                    return null;
111:                }
112:                return authenticatedAttributes.getAttributes();
113:            }
114:
115:            public byte[] getEncodedAuthenticatedAttributes() {
116:                if (authenticatedAttributes == null) {
117:                    return null;
118:                }
119:                return authenticatedAttributes.getEncoded();
120:            }
121:
122:            public byte[] getEncryptedDigest() {
123:                return encryptedDigest;
124:            }
125:
126:            public String toString() {
127:                StringBuffer res = new StringBuffer();
128:                res.append("-- SignerInfo:"); //$NON-NLS-1$
129:                res.append("\n version : "); //$NON-NLS-1$
130:                res.append(version);
131:                res.append("\nissuerAndSerialNumber:  "); //$NON-NLS-1$
132:                res.append(issuer);
133:                res.append("   "); //$NON-NLS-1$
134:                res.append(serialNumber);
135:                res.append("\ndigestAlgorithm:  "); //$NON-NLS-1$
136:                res.append(digestAlgorithm.toString());
137:                res.append("\nauthenticatedAttributes:  "); //$NON-NLS-1$
138:                if (authenticatedAttributes != null) {
139:                    res.append(authenticatedAttributes.toString());
140:                }
141:                res.append("\ndigestEncryptionAlgorithm: "); //$NON-NLS-1$
142:                res.append(digestEncryptionAlgorithm.toString());
143:                res.append("\nunauthenticatedAttributes: "); //$NON-NLS-1$
144:                if (unauthenticatedAttributes != null) {
145:                    res.append(unauthenticatedAttributes.toString());
146:                }
147:                res.append("\n-- SignerInfo End\n"); //$NON-NLS-1$
148:                return res.toString();
149:            }
150:
151:            public static final ASN1Sequence ISSUER_AND_SERIAL_NUMBER = new ASN1Sequence(
152:                    new ASN1Type[] { Name.ASN1, // issuer
153:                            ASN1Integer.getInstance(), // serialNumber
154:                    }) {
155:                // method to encode
156:                public void getValues(Object object, Object[] values) {
157:                    Object[] issAndSerial = (Object[]) object;
158:                    values[0] = issAndSerial[0];
159:                    values[1] = issAndSerial[1];
160:                }
161:            };
162:
163:            public static final ASN1Sequence ASN1 = new ASN1Sequence(
164:                    new ASN1Type[] {
165:                            ASN1Integer.getInstance(), //version
166:                            ISSUER_AND_SERIAL_NUMBER,
167:                            AlgorithmIdentifier.ASN1, //digestAlgorithm
168:                            new ASN1Implicit(0, AuthenticatedAttributes.ASN1),//authenticatedAttributes
169:                            AlgorithmIdentifier.ASN1, //digestEncryptionAlgorithm
170:                            ASN1OctetString.getInstance(), //encryptedDigest
171:                            new ASN1Implicit(1, new ASN1SetOf(
172:                                    AttributeTypeAndValue.ASN1)),//unauthenticatedAttributes
173:                    }) {
174:                {
175:                    setOptional(3); // authenticatedAttributes is optional
176:                    setOptional(6); // unauthenticatedAttributes is optional
177:                }
178:
179:                protected void getValues(Object object, Object[] values) {
180:                    SignerInfo si = (SignerInfo) object;
181:                    values[0] = new byte[] { (byte) si.version };
182:                    try {
183:                        values[1] = new Object[] {
184:                                new Name(si.issuer.getName()),
185:                                si.serialNumber.toByteArray() };
186:                    } catch (IOException e) {
187:                        // The exception is never thrown, because si.issuer
188:                        // is created using Name.getX500Principal(). 
189:                        // Throw a RuntimeException just to be safe.
190:                        throw new RuntimeException(
191:                        // Msg: "Failed to encode issuer name
192:                                Messages.getString("security.1A2"), e);
193:                    }
194:                    values[2] = si.digestAlgorithm;
195:                    values[3] = si.authenticatedAttributes;
196:                    values[4] = si.digestEncryptionAlgorithm;
197:                    values[5] = si.encryptedDigest;
198:                    values[6] = si.unauthenticatedAttributes;
199:                }
200:
201:                protected Object getDecodedObject(BerInputStream in) {
202:                    Object[] values = (Object[]) in.content;
203:                    return new SignerInfo(ASN1Integer.toIntValue(values[0]),
204:                            (Object[]) values[1],
205:                            (AlgorithmIdentifier) values[2],
206:                            (AuthenticatedAttributes) values[3],
207:                            (AlgorithmIdentifier) values[4],
208:                            (byte[]) values[5], (List) values[6]);
209:                }
210:            };
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.