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 org.bouncycastle.asn1.ASN1TaggedObject;
023: import org.bouncycastle.asn1.DEREncodable;
024: import org.bouncycastle.asn1.DERNull;
025: import org.bouncycastle.asn1.DERObject;
026: import org.bouncycastle.asn1.DERTaggedObject;
027: import org.bouncycastle.asn1.pkcs.CertificationRequest;
028: import org.bouncycastle.asn1.x509.X509CertificateStructure;
029:
030: import com.novosec.pkix.asn1.crmf.CertReqMessages;
031:
032: /**
033: * ASN.1 structure DER En/DeCoder.
034: *
035: * <pre>
036: * PKIBody ::= CHOICE {
037: * ir [0] CertReqMessages, --Initialization Request
038: * ip [1] CertRepMessage, --Initialization Response
039: * cr [2] CertReqMessages, --Certification Request
040: * cp [3] CertRepMessage, --Certification Response
041: * p10cr [4] CertificationRequest, --imported from [PKCS10]
042: * popdecc [5] POPODecKeyChallContent, --pop Challenge
043: * popdecr [6] POPODecKeyRespContent, --pop Response
044: * kur [7] CertReqMessages, --Key Update Request
045: * kup [8] CertRepMessage, --Key Update Response
046: * krr [9] CertReqMessages, --Key Recovery Request
047: * krp [10] KeyRecRepContent, --Key Recovery Response
048: * rr [11] RevReqContent, --Revocation Request
049: * rp [12] RevRepContent, --Revocation Response
050: * ccr [13] CertReqMessages, --Cross-Cert. Request
051: * ccp [14] CertRepMessage, --Cross-Cert. Response
052: * ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
053: * cann [16] CertAnnContent, --Certificate Ann. (X509Certificate)
054: * rann [17] RevAnnContent, --Revocation Ann.
055: * crlann [18] CRLAnnContent, --CRL Announcement
056: * conf [19] PKIConfirmContent, --Confirmation (NULL)
057: * nested [20] NestedMessageContent, --Nested Message (PKIMessage)
058: * genm [21] GenMsgContent, --General Message
059: * genp [22] GenRepContent, --General Response
060: * error [23] ErrorMsgContent --Error Message
061: * certConf[24] CertConfirmContent --Certificate Confirm
062: * }
063: *
064: * </pre>
065: */
066: public class PKIBody implements DEREncodable {
067: DEREncodable obj;
068: int tag;
069:
070: public PKIBody(DEREncodable obj, int tag) {
071: this .obj = obj;
072: this .tag = tag;
073: }
074:
075: public int getTagNo() {
076: return tag;
077: }
078:
079: public CertReqMessages getIr() {
080: if (this .tag != 0)
081: return null;
082: return (CertReqMessages) this .obj;
083: }
084:
085: public CertRepMessage getIp() {
086: if (this .tag != 1)
087: return null;
088: return (CertRepMessage) this .obj;
089: }
090:
091: public CertReqMessages getCr() {
092: if (this .tag != 2)
093: return null;
094: return (CertReqMessages) this .obj;
095: }
096:
097: public CertRepMessage getCp() {
098: if (this .tag != 3)
099: return null;
100: return (CertRepMessage) this .obj;
101: }
102:
103: public CertificationRequest getP10cr() {
104: if (this .tag != 4)
105: return null;
106: return (CertificationRequest) this .obj;
107: }
108:
109: public POPODecKeyChallContent getPopdecc() {
110: if (this .tag != 5)
111: return null;
112: return (POPODecKeyChallContent) this .obj;
113: }
114:
115: public POPODecKeyRespContent getPopdecr() {
116: if (this .tag != 6)
117: return null;
118: return (POPODecKeyRespContent) this .obj;
119: }
120:
121: public CertReqMessages getKur() {
122: if (this .tag != 7)
123: return null;
124: return (CertReqMessages) this .obj;
125: }
126:
127: public CertRepMessage getKup() {
128: if (this .tag != 8)
129: return null;
130: return (CertRepMessage) this .obj;
131: }
132:
133: public CertReqMessages getKrr() {
134: if (this .tag != 9)
135: return null;
136: return (CertReqMessages) this .obj;
137: }
138:
139: public KeyRecRepContent getKrp() {
140: if (this .tag != 10)
141: return null;
142: return (KeyRecRepContent) this .obj;
143: }
144:
145: public RevReqContent getRr() {
146: if (this .tag != 11)
147: return null;
148: return (RevReqContent) this .obj;
149: }
150:
151: public RevRepContent getRp() {
152: if (this .tag != 12)
153: return null;
154: return (RevRepContent) this .obj;
155: }
156:
157: public CertReqMessages getCcr() {
158: if (this .tag != 13)
159: return null;
160: return (CertReqMessages) this .obj;
161: }
162:
163: public CertRepMessage getCcp() {
164: if (this .tag != 14)
165: return null;
166: return (CertRepMessage) this .obj;
167: }
168:
169: public CAKeyUpdAnnContent getCkuann() {
170: if (this .tag != 15)
171: return null;
172: return (CAKeyUpdAnnContent) this .obj;
173: }
174:
175: public X509CertificateStructure getCann() {
176: if (this .tag != 16)
177: return null;
178: return (X509CertificateStructure) this .obj;
179: }
180:
181: public RevAnnContent getRann() {
182: if (this .tag != 17)
183: return null;
184: return (RevAnnContent) this .obj;
185: }
186:
187: public CRLAnnContent getCrlann() {
188: if (this .tag != 18)
189: return null;
190: return (CRLAnnContent) this .obj;
191: }
192:
193: public DERNull getConf() {
194: if (this .tag != 19)
195: return null;
196: return (DERNull) this .obj;
197: }
198:
199: public PKIMessage getNested() {
200: if (this .tag != 20)
201: return null;
202: return (PKIMessage) this .obj;
203: }
204:
205: public GenMsgContent getGenm() {
206: if (this .tag != 21)
207: return null;
208: return (GenMsgContent) this .obj;
209: }
210:
211: public GenRepContent getGenp() {
212: if (this .tag != 22)
213: return null;
214: return (GenRepContent) this .obj;
215: }
216:
217: public ErrorMsgContent getError() {
218: if (this .tag != 23)
219: return null;
220: return (ErrorMsgContent) this .obj;
221: }
222:
223: public CertConfirmContent getCertConf() {
224: if (this .tag != 24)
225: return null;
226: return (CertConfirmContent) this .obj;
227: }
228:
229: public static PKIBody getInstance(DERObject obj) {
230: return getInstance((ASN1TaggedObject) obj, true);
231: }
232:
233: public static PKIBody getInstance(ASN1TaggedObject tagObj,
234: boolean explicit) {
235: int tag = tagObj.getTagNo();
236:
237: switch (tag) {
238: case 0:
239: return new PKIBody(CertReqMessages.getInstance(tagObj
240: .getObject()), 0);
241: case 1:
242: return new PKIBody(CertRepMessage.getInstance(tagObj
243: .getObject()), 1);
244: case 2:
245: return new PKIBody(CertReqMessages.getInstance(tagObj
246: .getObject()), 2);
247: case 3:
248: return new PKIBody(CertRepMessage.getInstance(tagObj
249: .getObject()), 3);
250: case 4:
251: return new PKIBody(tagObj.getObject(), 4);
252: case 5:
253: return new PKIBody(POPODecKeyChallContent
254: .getInstance(tagObj.getObject()), 5);
255: case 6:
256: return new PKIBody(POPODecKeyRespContent.getInstance(tagObj
257: .getObject()), 6);
258: case 7:
259: return new PKIBody(CertReqMessages.getInstance(tagObj
260: .getObject()), 7);
261: case 8:
262: return new PKIBody(CertRepMessage.getInstance(tagObj
263: .getObject()), 8);
264: case 9:
265: return new PKIBody(CertReqMessages.getInstance(tagObj
266: .getObject()), 9);
267: case 10:
268: return new PKIBody(KeyRecRepContent.getInstance(tagObj
269: .getObject()), 10);
270: case 11:
271: return new PKIBody(RevReqContent.getInstance(tagObj
272: .getObject()), 11);
273: case 12:
274: return new PKIBody(RevRepContent.getInstance(tagObj
275: .getObject()), 12);
276: case 13:
277: return new PKIBody(CertReqMessages.getInstance(tagObj
278: .getObject()), 13);
279: case 14:
280: return new PKIBody(CertRepMessage.getInstance(tagObj
281: .getObject()), 14);
282: case 15:
283: return new PKIBody(CAKeyUpdAnnContent.getInstance(tagObj
284: .getObject()), 15);
285: case 16:
286: return new PKIBody(X509CertificateStructure
287: .getInstance(tagObj.getObject()), 16);
288: case 17:
289: return new PKIBody(RevAnnContent.getInstance(tagObj
290: .getObject()), 17);
291: case 18:
292: return new PKIBody(CRLAnnContent.getInstance(tagObj
293: .getObject()), 18);
294: case 19:
295: return new PKIBody(tagObj.getObject(), 19);
296: case 20:
297: return new PKIBody(PKIMessage.getInstance(tagObj
298: .getObject()), 20);
299: case 21:
300: return new PKIBody(GenMsgContent.getInstance(tagObj
301: .getObject()), 21);
302: case 22:
303: return new PKIBody(GenRepContent.getInstance(tagObj
304: .getObject()), 22);
305: case 23:
306: return new PKIBody(ErrorMsgContent.getInstance(tagObj
307: .getObject()), 23);
308: case 24:
309: return new PKIBody(CertConfirmContent.getInstance(tagObj
310: .getObject()), 24);
311: }
312:
313: throw new IllegalArgumentException("unknown tag: " + tag);
314: }
315:
316: public DERObject getDERObject() {
317: return new DERTaggedObject(true, tag, obj);
318: }
319:
320: public String toString() {
321: return "PKIBody: (" + obj + ")";
322: }
323: }
|