Source Code Cross Referenced for PKIHeader.java in  » Authentication-Authorization » ejbca » com » novosec » pkix » asn1 » cmp » 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 » Authentication Authorization » ejbca » com.novosec.pkix.asn1.cmp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
002:        //
003:        // Author: Maik Stohn
004:        //
005:        // Permission is hereby granted, free of charge, to any person obtaining a copy of this 
006:        // software and associated documentation files (the "Software"), to deal in the Software 
007:        // without restriction, including without limitation the rights to use, copy, modify, merge, 
008:        // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 
009:        // to whom the Software is furnished to do so, subject to the following conditions: 
010:        //
011:        // The above copyright notice and this permission notice shall be included in all copies or 
012:        // substantial portions of the Software. 
013:        //
014:        // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
015:        // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
016:        // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
017:        // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
018:        // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
019:
020:        package com.novosec.pkix.asn1.cmp;
021:
022:        import java.util.Enumeration;
023:        import java.util.Vector;
024:
025:        import org.bouncycastle.asn1.ASN1EncodableVector;
026:        import org.bouncycastle.asn1.ASN1Sequence;
027:        import org.bouncycastle.asn1.ASN1TaggedObject;
028:        import org.bouncycastle.asn1.DEREncodable;
029:        import org.bouncycastle.asn1.DERGeneralizedTime;
030:        import org.bouncycastle.asn1.DERInteger;
031:        import org.bouncycastle.asn1.DERObject;
032:        import org.bouncycastle.asn1.DEROctetString;
033:        import org.bouncycastle.asn1.DERSequence;
034:        import org.bouncycastle.asn1.DERTaggedObject;
035:        import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
036:        import org.bouncycastle.asn1.x509.GeneralName;
037:
038:        /**
039:         * ASN.1 structure DER En/DeCoder.
040:         *
041:         * <pre>
042:         *  PKIHeader ::= SEQUENCE {
043:         *      pvno                INTEGER     { ietf-version2 (1) },
044:         *      sender              GeneralName,                        -- identifies the sender
045:         *      recipient           GeneralName,                        -- identifies the intended recipient
046:         *      messageTime     [0] GeneralizedTime         OPTIONAL,   -- time of production of this message
047:         *      protectionAlg   [1] AlgorithmIdentifier     OPTIONAL,   -- algorithm used for calculation of protection bits
048:         *      senderKID       [2] KeyIdentifier           OPTIONAL,   -- (OCTET STRING)
049:         *      recipKID        [3] KeyIdentifier           OPTIONAL,   -- (OCTET STRING) to identify specific keys used for protection
050:         *      transactionID   [4] OCTET STRING            OPTIONAL,   -- identifies the transaction; i.e., this will be the same in corresponding request, response and confirmation messages
051:         *      senderNonce     [5] OCTET STRING            OPTIONAL,
052:         *      recipNonce      [6] OCTET STRING            OPTIONAL,   -- nonces used to provide replay protection, senderNonce is inserted by the creator of this message; recipNonce is a nonce previously inserted in a related message by the intended recipient of this message
053:         *      freeText        [7] PKIFreeText             OPTIONAL,   -- this may be used to indicate context-specific instructions (this field is intended for human consumption)
054:         *      generalInfo     [8] SEQUENCE SIZE (1..MAX) OF
055:         *                             InfoTypeAndValue     OPTIONAL    -- this may be used to convey context-specific information (this field not primarily intended for human consumption)
056:         *  }     
057:         *
058:         * </pre>
059:         */
060:        public class PKIHeader implements  DEREncodable {
061:            DERInteger pvno;
062:            GeneralName sender;
063:            GeneralName recipient;
064:            DERGeneralizedTime messageTime;
065:            AlgorithmIdentifier protectionAlg;
066:            DEROctetString senderKID;
067:            DEROctetString recipKID;
068:            DEROctetString transactionID;
069:            DEROctetString senderNonce;
070:            DEROctetString recipNonce;
071:            PKIFreeText freeText;
072:            Vector generalInfos = new Vector();
073:
074:            public static PKIHeader getInstance(ASN1TaggedObject obj,
075:                    boolean explicit) {
076:                return getInstance(ASN1Sequence.getInstance(obj, explicit));
077:            }
078:
079:            public static PKIHeader getInstance(Object obj) {
080:                if (obj instanceof  PKIHeader) {
081:                    return (PKIHeader) obj;
082:                } else if (obj instanceof  ASN1Sequence) {
083:                    return new PKIHeader((ASN1Sequence) obj);
084:                }
085:
086:                throw new IllegalArgumentException("unknown object in factory");
087:            }
088:
089:            public PKIHeader(ASN1Sequence seq) {
090:                Enumeration e = seq.getObjects();
091:
092:                pvno = DERInteger.getInstance(e.nextElement());
093:                sender = GeneralName.getInstance(e.nextElement());
094:                recipient = GeneralName.getInstance(e.nextElement());
095:
096:                while (e.hasMoreElements()) {
097:                    ASN1TaggedObject tagObj = (ASN1TaggedObject) e
098:                            .nextElement();
099:
100:                    switch (tagObj.getTagNo()) {
101:                    case 0:
102:                        messageTime = DERGeneralizedTime.getInstance(tagObj
103:                                .getObject());
104:                        break;
105:                    case 1:
106:                        protectionAlg = AlgorithmIdentifier.getInstance(tagObj
107:                                .getObject());
108:                        break;
109:                    case 2:
110:                        senderKID = (DEROctetString) DEROctetString
111:                                .getInstance(tagObj);
112:                        break;
113:                    case 3:
114:                        recipKID = (DEROctetString) DEROctetString
115:                                .getInstance(tagObj);
116:                        break;
117:                    case 4:
118:                        transactionID = (DEROctetString) DEROctetString
119:                                .getInstance(tagObj);
120:                        break;
121:                    case 5:
122:                        senderNonce = (DEROctetString) DEROctetString
123:                                .getInstance(tagObj);
124:                        break;
125:                    case 6:
126:                        recipNonce = (DEROctetString) DEROctetString
127:                                .getInstance(tagObj);
128:                        break;
129:                    case 7:
130:                        freeText = PKIFreeText.getInstance(tagObj.getObject());
131:                        break;
132:                    case 8:
133:                        ASN1Sequence s = (ASN1Sequence) tagObj.getObject();
134:                        for (int i = 0; i < s.size(); i++)
135:                            generalInfos.addElement(InfoTypeAndValue
136:                                    .getInstance(s.getObjectAt(i)));
137:                        break;
138:                    }
139:                }
140:            }
141:
142:            public PKIHeader(DERInteger pvno, GeneralName sender,
143:                    GeneralName recipient) {
144:                this .pvno = pvno;
145:                this .sender = sender;
146:                this .recipient = recipient;
147:            }
148:
149:            public DERInteger getPvno() {
150:                return pvno;
151:            }
152:
153:            public GeneralName getSender() {
154:                return sender;
155:            }
156:
157:            public GeneralName getRecipient() {
158:                return recipient;
159:            }
160:
161:            public void setMessageTime(DERGeneralizedTime messageTime) {
162:                this .messageTime = messageTime;
163:            }
164:
165:            public DERGeneralizedTime getMessageTime() {
166:                return messageTime;
167:            }
168:
169:            public void setProtectionAlg(AlgorithmIdentifier protectionAlg) {
170:                this .protectionAlg = protectionAlg;
171:            }
172:
173:            public AlgorithmIdentifier getProtectionAlg() {
174:                return protectionAlg;
175:            }
176:
177:            public void setSenderKID(DEROctetString senderKID) {
178:                this .senderKID = senderKID;
179:            }
180:
181:            public DEROctetString getSenderKID() {
182:                return senderKID;
183:            }
184:
185:            public void setRecipKID(DEROctetString recipKID) {
186:                this .recipKID = recipKID;
187:            }
188:
189:            public DEROctetString getRecipKID() {
190:                return recipKID;
191:            }
192:
193:            public void setTransactionID(DEROctetString transactionID) {
194:                this .transactionID = transactionID;
195:            }
196:
197:            public DEROctetString getTransactionID() {
198:                return transactionID;
199:            }
200:
201:            public void setSenderNonce(DEROctetString senderNonce) {
202:                this .senderNonce = senderNonce;
203:            }
204:
205:            public DEROctetString getSenderNonce() {
206:                return senderNonce;
207:            }
208:
209:            public void setRecipNonce(DEROctetString recipNonce) {
210:                this .recipNonce = recipNonce;
211:            }
212:
213:            public DEROctetString getRecipNonce() {
214:                return recipNonce;
215:            }
216:
217:            public void setFreeText(PKIFreeText freeText) {
218:                this .freeText = freeText;
219:            }
220:
221:            public PKIFreeText getFreeText() {
222:                return freeText;
223:            }
224:
225:            public void addGeneralInfo(InfoTypeAndValue generalInfo) {
226:                this .generalInfos.addElement(generalInfo);
227:            }
228:
229:            public InfoTypeAndValue getGeneralInfo(int nr) {
230:                if (generalInfos.size() > nr)
231:                    return (InfoTypeAndValue) generalInfos.elementAt(nr);
232:
233:                return null;
234:            }
235:
236:            public DERObject getDERObject() {
237:                ASN1EncodableVector v = new ASN1EncodableVector();
238:
239:                v.add(pvno);
240:                v.add(sender);
241:                v.add(recipient);
242:
243:                if (messageTime != null)
244:                    v.add(new DERTaggedObject(true, 0, messageTime));
245:
246:                if (protectionAlg != null)
247:                    v.add(new DERTaggedObject(true, 1, protectionAlg));
248:
249:                if (senderKID != null)
250:                    v.add(new DERTaggedObject(true, 2, senderKID));
251:
252:                if (recipKID != null)
253:                    v.add(new DERTaggedObject(true, 3, recipKID));
254:
255:                if (transactionID != null)
256:                    v.add(new DERTaggedObject(true, 4, transactionID));
257:
258:                if (senderNonce != null)
259:                    v.add(new DERTaggedObject(true, 5, senderNonce));
260:
261:                if (recipNonce != null)
262:                    v.add(new DERTaggedObject(true, 6, recipNonce));
263:
264:                if (freeText != null)
265:                    v.add(new DERTaggedObject(true, 7, freeText));
266:
267:                if (generalInfos.size() > 0) {
268:                    ASN1EncodableVector giv = new ASN1EncodableVector();
269:
270:                    for (int i = 0; i < generalInfos.size(); i++)
271:                        giv.add((InfoTypeAndValue) generalInfos.elementAt(i));
272:
273:                    v.add(new DERTaggedObject(true, 8, new DERSequence(giv)));
274:                }
275:
276:                return new DERSequence(v);
277:            }
278:
279:            public String toString() {
280:                String s = "PKIHeader: ( pvno: " + pvno + ", sender: " + sender
281:                        + ", recipient: " + recipient + ", ";
282:
283:                if (messageTime != null)
284:                    s += "messageTime: " + messageTime + ", ";
285:
286:                if (protectionAlg != null)
287:                    s += "protectionAlg: " + protectionAlg + ", ";
288:
289:                if (senderKID != null)
290:                    s += "senderKID: " + senderKID + ", ";
291:
292:                if (recipKID != null)
293:                    s += "recipKID: " + recipKID + ", ";
294:
295:                if (transactionID != null)
296:                    s += "transactionID: " + transactionID + ", ";
297:
298:                if (senderNonce != null)
299:                    s += "senderNonce: " + senderNonce + ", ";
300:
301:                if (recipNonce != null)
302:                    s += "recipNonce: " + recipNonce + ", ";
303:
304:                if (freeText != null)
305:                    s += "freeText: " + freeText + ", ";
306:
307:                if (generalInfos.size() > 0) {
308:                    s += "generalInfo: (";
309:                    for (int i = 0; i < generalInfos.size(); i++)
310:                        s += generalInfos.elementAt(i) + ", ";
311:                    s += ")";
312:                }
313:
314:                return s;
315:            }
316:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.