Source Code Cross Referenced for TSTInfo.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » security » x509 » tsp » 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.x509.tsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.    
018:         */
019:
020:        package org.apache.harmony.security.x509.tsp;
021:
022:        import java.math.BigInteger;
023:        import java.util.Date;
024:
025:        import org.apache.harmony.security.asn1.ASN1Boolean;
026:        import org.apache.harmony.security.asn1.ASN1Explicit;
027:        import org.apache.harmony.security.asn1.ASN1GeneralizedTime;
028:        import org.apache.harmony.security.asn1.ASN1Implicit;
029:        import org.apache.harmony.security.asn1.ASN1Integer;
030:        import org.apache.harmony.security.asn1.ASN1Oid;
031:        import org.apache.harmony.security.asn1.ASN1Sequence;
032:        import org.apache.harmony.security.asn1.ASN1Type;
033:        import org.apache.harmony.security.asn1.BerInputStream;
034:        import org.apache.harmony.security.asn1.ObjectIdentifier;
035:        import org.apache.harmony.security.internal.nls.Messages;
036:        import org.apache.harmony.security.x509.Extensions;
037:        import org.apache.harmony.security.x509.GeneralName;
038:
039:        /**
040:         * As defined in Time-Stamp Protocol (TSP) 
041:         * (http://www.ietf.org/rfc/rfc3161.txt)
042:         * 
043:         * TSTInfo ::= SEQUENCE  {
044:         *    version                      INTEGER  { v1(1) },
045:         *    policy                       TSAPolicyId,
046:         *    messageImprint               MessageImprint,
047:         *      -- MUST have the same value as the similar field in
048:         *      -- TimeStampReq
049:         *    serialNumber                 INTEGER,
050:         *     -- Time-Stamping users MUST be ready to accommodate integers
051:         *     -- up to 160 bits.
052:         *    genTime                      GeneralizedTime,
053:         *    accuracy                     Accuracy                 OPTIONAL,
054:         *    ordering                     BOOLEAN             DEFAULT FALSE,
055:         *    nonce                        INTEGER                  OPTIONAL,
056:         *      -- MUST be present if the similar field was present
057:         *      -- in TimeStampReq.  In that case it MUST have the same value.
058:         *    tsa                          [0] GeneralName          OPTIONAL,
059:         *    extensions                   [1] IMPLICIT Extensions   OPTIONAL
060:         * }
061:         *  
062:         * TSAPolicyId ::= OBJECT IDENTIFIER
063:         * 
064:         * "tsa [0] GeneralName OPTIONAL" is EXPLICIT and the word EXPLICIT is omitted. 
065:         */
066:        public class TSTInfo {
067:
068:            private final int version;
069:
070:            private final String policy;
071:
072:            private final MessageImprint messageImprint;
073:
074:            private final BigInteger serialNumber;
075:
076:            private final Date genTime;
077:
078:            private final int[] accuracy;
079:
080:            private final Boolean ordering;
081:
082:            private final BigInteger nonce;
083:
084:            private final GeneralName tsa;
085:
086:            private final Extensions extensions;
087:
088:            public TSTInfo(int version, String policy,
089:                    MessageImprint messageImprint, BigInteger serialNumber,
090:                    Date genTime, int[] accuracy, Boolean ordering,
091:                    BigInteger nonce, GeneralName tsa, Extensions extensions) {
092:                this .version = version;
093:                this .policy = policy;
094:                this .messageImprint = messageImprint;
095:                this .serialNumber = serialNumber;
096:                this .genTime = genTime;
097:                this .accuracy = accuracy;
098:                this .ordering = ordering;
099:                this .nonce = nonce;
100:                this .tsa = tsa;
101:                this .extensions = extensions;
102:            }
103:
104:            public String toString() {
105:                StringBuffer res = new StringBuffer();
106:                res.append("-- TSTInfo:");
107:                res.append("\nversion:  ");
108:                res.append(version);
109:                res.append("\npolicy:  ");
110:                res.append(policy);
111:                res.append("\nmessageImprint:  ");
112:                res.append(messageImprint);
113:                res.append("\nserialNumber:  ");
114:                res.append(serialNumber);
115:                res.append("\ngenTime:  ");
116:                res.append(genTime);
117:                res.append("\naccuracy:  ");
118:                if (accuracy != null) {
119:                    res.append(accuracy[0] + " sec, " + accuracy[1]
120:                            + " millis, " + accuracy[2] + " micros");
121:                }
122:                res.append("\nordering:  ");
123:                res.append(ordering);
124:                res.append("\nnonce:  ");
125:                res.append(nonce);
126:                res.append("\ntsa:  ");
127:                res.append(tsa);
128:                res.append("\nextensions:  ");
129:                res.append(extensions);
130:                res.append("\n-- TSTInfo End\n");
131:                return res.toString();
132:            }
133:
134:            /**
135:             * @return Returns the accuracy.
136:             */
137:            public int[] getAccuracy() {
138:                return accuracy;
139:            }
140:
141:            /**
142:             * @return Returns the extensions.
143:             */
144:            public Extensions getExtensions() {
145:                return extensions;
146:            }
147:
148:            /**
149:             * @return Returns the genTime.
150:             */
151:            public Date getGenTime() {
152:                return genTime;
153:            }
154:
155:            /**
156:             * @return Returns the messageImprint.
157:             */
158:            public MessageImprint getMessageImprint() {
159:                return messageImprint;
160:            }
161:
162:            /**
163:             * @return Returns the nonce.
164:             */
165:            public BigInteger getNonce() {
166:                return nonce;
167:            }
168:
169:            /**
170:             * @return Returns the ordering.
171:             */
172:            public Boolean getOrdering() {
173:                return ordering;
174:            }
175:
176:            /**
177:             * @return Returns the policy.
178:             */
179:            public String getPolicy() {
180:                return policy;
181:            }
182:
183:            /**
184:             * @return Returns the serialNumber.
185:             */
186:            public BigInteger getSerialNumber() {
187:                return serialNumber;
188:            }
189:
190:            /**
191:             * @return Returns the tsa.
192:             */
193:            public GeneralName getTsa() {
194:                return tsa;
195:            }
196:
197:            /**
198:             * @return Returns the version.
199:             */
200:            public int getVersion() {
201:                return version;
202:            }
203:
204:            /**
205:                 Accuracy ::= SEQUENCE {
206:                        seconds        INTEGER           OPTIONAL,
207:                        millis     [0] INTEGER  (1..999) OPTIONAL,
208:                        micros     [1] INTEGER  (1..999) OPTIONAL  }
209:             */
210:            public static final ASN1Sequence ACCURACY = new ASN1Sequence(
211:                    new ASN1Type[] { ASN1Integer.getInstance(),
212:                            ASN1Integer.getInstance(),
213:                            ASN1Integer.getInstance() }) {
214:                {
215:                    setOptional(0);
216:                    setOptional(1);
217:                    setOptional(2);
218:                }
219:
220:                protected Object getDecodedObject(BerInputStream in) {
221:                    Object[] values = (Object[]) in.content;
222:
223:                    int[] accuracy = new int[3];
224:                    for (int i = 0; i < 3; i++) {
225:                        if (values[i] != null) {
226:                            accuracy[i] = ASN1Integer.toIntValue(values[i]);
227:                            if (i > 0 && (accuracy[i] < 0 || accuracy[i] > 999)) {
228:                                throw new RuntimeException(
229:                                // Msg: "Time-stamp accuracy value is incorrect: {}"
230:                                        Messages.getString("security.1A3",
231:                                                accuracy[i]));
232:                            }
233:                        }
234:                    }
235:                    return accuracy;
236:                }
237:
238:                protected void getValues(Object object, Object[] values) {
239:                    int[] accuracy = (int[]) object;
240:                    for (int i = 0; i < 3; i++) {
241:                        if (i > 0 && (accuracy[i] < 0 || accuracy[i] > 999)) {
242:                            throw new RuntimeException(
243:                            // Msg: "Time-stamp accuracy value is incorrect: {0}"
244:                                    Messages.getString("security.1A3",
245:                                            accuracy[i]));
246:                        }
247:                        values[i] = BigInteger.valueOf(accuracy[i])
248:                                .toByteArray();
249:                    }
250:                }
251:            };
252:
253:            public static final ASN1Sequence ASN1 = new ASN1Sequence(
254:                    new ASN1Type[] { ASN1Integer.getInstance(), // version
255:                            ASN1Oid.getInstance(), // policy
256:                            MessageImprint.ASN1, // messageImprint
257:                            ASN1Integer.getInstance(), // serialNumber
258:                            ASN1GeneralizedTime.getInstance(), // genTime
259:                            ACCURACY, // accuracy
260:                            ASN1Boolean.getInstance(), // ordering  
261:                            ASN1Integer.getInstance(), // nonce
262:                            new ASN1Explicit(0, GeneralName.ASN1), // tsa
263:                            new ASN1Implicit(1, Extensions.ASN1) }) {// extensions
264:                {
265:                    setOptional(5);
266:                    setDefault(Boolean.FALSE, 6);
267:                    setOptional(7);
268:                    setOptional(8);
269:                    setOptional(9);
270:                }
271:
272:                protected Object getDecodedObject(BerInputStream in) {
273:                    Object[] values = (Object[]) in.content;
274:
275:                    BigInteger nonce = (values[7] == null) ? null
276:                            : new BigInteger((byte[]) values[7]);
277:
278:                    return new TSTInfo(ASN1Integer.toIntValue(values[0]),
279:                            ObjectIdentifier.toString((int[]) values[1]),
280:                            (MessageImprint) values[2], new BigInteger(
281:                                    (byte[]) values[3]), (Date) values[4],
282:                            (int[]) values[5], (Boolean) values[6], nonce,
283:                            (GeneralName) values[8], (Extensions) values[9]);
284:                }
285:
286:                protected void getValues(Object object, Object[] values) {
287:                    TSTInfo info = (TSTInfo) object;
288:
289:                    values[0] = ASN1Integer.fromIntValue(info.version);
290:                    values[1] = ObjectIdentifier.toIntArray(info.policy);
291:                    values[2] = info.messageImprint;
292:                    values[3] = info.serialNumber.toByteArray();
293:                    values[4] = info.genTime;
294:                    values[5] = info.accuracy;
295:                    values[6] = info.ordering;
296:                    values[7] = (info.nonce == null) ? null : info.nonce
297:                            .toByteArray();
298:                    values[8] = info.tsa;
299:                    values[9] = info.extensions;
300:                }
301:            };
302:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.