KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > protocol > cmp > CmpRevokeResponseMessage


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.core.protocol.cmp;
14
15 import java.io.ByteArrayOutputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.security.InvalidKeyException JavaDoc;
18 import java.security.NoSuchAlgorithmException JavaDoc;
19 import java.security.NoSuchProviderException JavaDoc;
20 import java.security.PrivateKey JavaDoc;
21 import java.security.cert.CRL JavaDoc;
22 import java.security.cert.Certificate JavaDoc;
23 import java.security.cert.CertificateEncodingException JavaDoc;
24 import java.security.cert.X509Certificate JavaDoc;
25
26 import org.apache.log4j.Logger;
27 import org.bouncycastle.asn1.DERInteger;
28 import org.bouncycastle.asn1.DEROutputStream;
29 import org.bouncycastle.asn1.DERUTF8String;
30 import org.bouncycastle.asn1.x509.X509Name;
31 import org.ejbca.core.model.ca.SignRequestException;
32 import org.ejbca.core.model.ra.NotFoundException;
33 import org.ejbca.core.protocol.FailInfo;
34 import org.ejbca.core.protocol.IRequestMessage;
35 import org.ejbca.core.protocol.IResponseMessage;
36 import org.ejbca.core.protocol.ResponseStatus;
37
38 import com.novosec.pkix.asn1.cmp.PKIBody;
39 import com.novosec.pkix.asn1.cmp.PKIFreeText;
40 import com.novosec.pkix.asn1.cmp.PKIHeader;
41 import com.novosec.pkix.asn1.cmp.PKIMessage;
42 import com.novosec.pkix.asn1.cmp.PKIStatusInfo;
43 import com.novosec.pkix.asn1.cmp.RevRepContent;
44
45
46 /**
47  * A very simple confirmation message, no protection and a nullbody
48  * @author tomas
49  * @version $Id: CmpRevokeResponseMessage.java,v 1.2 2006/11/09 11:03:14 anatom Exp $
50  */

51 public class CmpRevokeResponseMessage extends BaseCmpMessage implements IResponseMessage {
52
53     /**
54      * Determines if a de-serialized file is compatible with this class.
55      *
56      * Maintainers must change this value if and only if the new version
57      * of this class is not compatible with old versions. See Sun docs
58      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
59      * /serialization/spec/version.doc.html> details. </a>
60      *
61      */

62     static final long serialVersionUID = 10002L;
63
64     private static final Logger log = Logger.getLogger(CmpRevokeResponseMessage .class);
65
66     /** The encoded response message */
67     private byte[] responseMessage = null;
68     private String JavaDoc failText = null;
69     private FailInfo failInfo = FailInfo.BAD_REQUEST;
70     private ResponseStatus status = ResponseStatus.FAILURE;
71
72     public void setCertificate(Certificate JavaDoc cert) {
73     }
74
75     public void setCrl(CRL JavaDoc crl) {
76     }
77
78     public void setIncludeCACert(boolean incCACert) {
79     }
80
81     public byte[] getResponseMessage() throws IOException JavaDoc,
82             CertificateEncodingException JavaDoc {
83         return responseMessage;
84     }
85
86     public void setStatus(ResponseStatus status) {
87         this.status = status;
88     }
89
90     public ResponseStatus getStatus() {
91         return status;
92     }
93
94     public void setFailInfo(FailInfo failInfo) {
95         this.failInfo = failInfo;
96     }
97
98     public FailInfo getFailInfo() {
99         return failInfo;
100     }
101
102     public void setFailText(String JavaDoc failText) {
103         this.failText = failText;
104     }
105
106     public String JavaDoc getFailText() {
107         return failText;
108     }
109
110     public boolean create() throws IOException JavaDoc, InvalidKeyException JavaDoc,
111             NoSuchAlgorithmException JavaDoc, NoSuchProviderException JavaDoc,
112             SignRequestException, NotFoundException {
113
114         X509Name sender = X509Name.getInstance(getSender().getName());
115         X509Name recipient = X509Name.getInstance(getRecipient().getName());
116         PKIHeader myPKIHeader = CmpMessageHelper.createPKIHeader(sender, recipient, getSenderNonce(), getRecipientNonce(), getTransactionId());
117
118         PKIStatusInfo myPKIStatusInfo = new PKIStatusInfo(new DERInteger(0)); // 0 = accepted
119
if (status != ResponseStatus.SUCCESS) {
120             log.debug("Creating a rejection message");
121             myPKIStatusInfo = new PKIStatusInfo(new DERInteger(2)); // 2 = rejection
122
myPKIStatusInfo.setFailInfo(failInfo.getAsBitString());
123             if (failText != null) {
124                 myPKIStatusInfo.setStatusString(new PKIFreeText(new DERUTF8String(failText)));
125             }
126         }
127         RevRepContent myRevrepMessage = new RevRepContent(myPKIStatusInfo);
128
129         PKIBody myPKIBody = new PKIBody(myRevrepMessage, 12); // 12 = RevRepContent
130
PKIMessage myPKIMessage = new PKIMessage(myPKIHeader, myPKIBody);
131
132         if ((getPbeDigestAlg() != null) && (getPbeMacAlg() != null) && (getPbeKeyId() != null) && (getPbeKey() != null) ) {
133             responseMessage = CmpMessageHelper.protectPKIMessageWithPBE(myPKIMessage, getPbeKeyId(), getPbeKey(), getPbeDigestAlg(), getPbeMacAlg(), getPbeIterationCount());
134         } else {
135             ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
136             DEROutputStream mout = new DEROutputStream( baos );
137             mout.writeObject( myPKIMessage );
138             mout.close();
139             responseMessage = baos.toByteArray();
140         }
141         return true;
142     }
143
144     public boolean requireSignKeyInfo() {
145         return false;
146     }
147
148     public boolean requireEncKeyInfo() {
149         return false;
150     }
151
152     public void setSignKeyInfo(X509Certificate JavaDoc cert, PrivateKey JavaDoc key,
153             String JavaDoc provider) {
154     }
155
156     public void setEncKeyInfo(X509Certificate JavaDoc cert, PrivateKey JavaDoc key,
157             String JavaDoc provider) {
158     }
159
160     public void setSenderNonce(String JavaDoc senderNonce) {
161         super.setSenderNonce(senderNonce);
162     }
163
164     public void setRecipientNonce(String JavaDoc recipientNonce) {
165         super.setRecipientNonce(recipientNonce);
166     }
167
168     public void setTransactionId(String JavaDoc transactionId) {
169         super.setTransactionId(transactionId);
170     }
171
172     public void setRecipientKeyInfo(byte[] recipientKeyInfo) {
173     }
174
175     public void setPreferredDigestAlg(String JavaDoc digest) {
176     }
177
178     public void setRequestType(int reqtype) {
179     }
180
181     public void setRequestId(int reqid) {
182     }
183
184     /** @see org.ejca.core.protocol.IResponseMessage
185      */

186     public void setProtectionParamsFromRequest(IRequestMessage reqMsg) {
187     }
188 }
189
Popular Tags