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.ASN1EncodableVector;
023: import org.bouncycastle.asn1.ASN1Sequence;
024: import org.bouncycastle.asn1.ASN1TaggedObject;
025: import org.bouncycastle.asn1.DERBitString;
026: import org.bouncycastle.asn1.DEREncodable;
027: import org.bouncycastle.asn1.DERInteger;
028: import org.bouncycastle.asn1.DERObject;
029: import org.bouncycastle.asn1.DERSequence;
030:
031: /**
032: * ASN.1 structure DER En/DeCoder.
033: *
034: * <pre>
035: * PKIStatusInfo ::= SEQUENCE {
036: * status PKIStatus, (INTEGER)
037: * statusString PKIFreeText OPTIONAL,
038: * failInfo PKIFailureInfo OPTIONAL (BIT STRING)
039: * }
040: *
041: * PKIStatus:
042: * granted (0), -- you got exactly what you asked for
043: * grantedWithMods (1), -- you got something like what you asked for
044: * rejection (2), -- you don't get it, more information elsewhere in the message
045: * waiting (3), -- the request body part has not yet been processed, expect to hear more later
046: * revocationWarning (4), -- this message contains a warning that a revocation is imminent
047: * revocationNotification (5), -- notification that a revocation has occurred
048: * keyUpdateWarning (6) -- update already done for the oldCertId specified in CertReqMsg
049: *
050: * PKIFailureInfo:
051: * badAlg (0), -- unrecognized or unsupported Algorithm Identifier
052: * badMessageCheck (1), -- integrity check failed (e.g., signature did not verify)
053: * badRequest (2), -- transaction not permitted or supported
054: * badTime (3), -- messageTime was not sufficiently close to the system time, as defined by local policy
055: * badCertId (4), -- no certificate could be found matching the provided criteria
056: * badDataFormat (5), -- the data submitted has the wrong format
057: * wrongAuthority (6), -- the authority indicated in the request is different from the one creating the response token
058: * incorrectData (7), -- the requester's data is incorrect (for notary services)
059: * missingTimeStamp (8), -- when the timestamp is missing but should be there (by policy)
060: * badPOP (9) -- the proof-of-possession failed
061: *
062: * </pre>
063: */
064: public class PKIStatusInfo implements DEREncodable {
065: DERInteger status;
066: PKIFreeText statusString;
067: DERBitString failInfo;
068:
069: public static PKIStatusInfo getInstance(ASN1TaggedObject obj,
070: boolean explicit) {
071: return getInstance(ASN1Sequence.getInstance(obj, explicit));
072: }
073:
074: public static PKIStatusInfo getInstance(Object obj) {
075: if (obj instanceof PKIStatusInfo) {
076: return (PKIStatusInfo) obj;
077: } else if (obj instanceof ASN1Sequence) {
078: return new PKIStatusInfo((ASN1Sequence) obj);
079: }
080:
081: throw new IllegalArgumentException("unknown object in factory");
082: }
083:
084: public PKIStatusInfo(ASN1Sequence seq) {
085: this .status = DERInteger.getInstance(seq.getObjectAt(0));
086:
087: this .statusString = null;
088: this .failInfo = null;
089:
090: if (seq.size() > 2) {
091: this .statusString = PKIFreeText.getInstance(seq
092: .getObjectAt(1));
093: this .failInfo = DERBitString
094: .getInstance(seq.getObjectAt(2));
095: } else if (seq.size() > 1) {
096: Object obj = seq.getObjectAt(1);
097:
098: if (obj instanceof ASN1Sequence)
099: this .statusString = PKIFreeText.getInstance(obj);
100: else
101: this .failInfo = DERBitString.getInstance(obj);
102: }
103: }
104:
105: public PKIStatusInfo(DERInteger status) {
106: this .status = status;
107: }
108:
109: public DERInteger getStatus() {
110: return status;
111: }
112:
113: public PKIFreeText getStatusString() {
114: return statusString;
115: }
116:
117: public void setStatusString(PKIFreeText statusString) {
118: this .statusString = statusString;
119: }
120:
121: public DERBitString getFailInfo() {
122: return failInfo;
123: }
124:
125: public void setFailInfo(DERBitString failInfo) {
126: this .failInfo = failInfo;
127: }
128:
129: public DERObject getDERObject() {
130: ASN1EncodableVector v = new ASN1EncodableVector();
131:
132: v.add(status);
133:
134: if (statusString != null)
135: v.add(statusString);
136:
137: if (failInfo != null)
138: v.add(failInfo);
139:
140: return new DERSequence(v);
141: }
142:
143: public String toString() {
144: String s = "PKIStatusInfo: (status = " + this .getStatus();
145:
146: if (this .getStatusString() != null)
147: s += ", statusString: " + this .getStatusString();
148:
149: if (this .getFailInfo() != null)
150: s += ", failInfo: " + this .getFailInfo();
151:
152: s += ")";
153:
154: return s;
155: }
156: }
|