KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Logger;
16 import org.bouncycastle.asn1.DERInteger;
17 import org.bouncycastle.asn1.DEROctetString;
18 import org.bouncycastle.asn1.x509.X509Name;
19 import org.ejbca.core.model.InternalResources;
20 import org.ejbca.util.Base64;
21
22 import com.novosec.pkix.asn1.cmp.CertConfirmContent;
23 import com.novosec.pkix.asn1.cmp.PKIBody;
24 import com.novosec.pkix.asn1.cmp.PKIHeader;
25 import com.novosec.pkix.asn1.cmp.PKIMessage;
26 import com.novosec.pkix.asn1.cmp.PKIStatusInfo;
27 import com.novosec.pkix.asn1.cmp.RevDetails;
28 import com.novosec.pkix.asn1.cmp.RevReqContent;
29 import com.novosec.pkix.asn1.crmf.CertTemplate;
30
31 /**
32  * Message class for CMP PKI confirm and CertCOnf messages
33  * @author tomas
34  * @version $Id: GeneralCmpMessage.java,v 1.4 2007/01/16 11:44:30 anatom Exp $
35  */

36 public class GeneralCmpMessage extends BaseCmpMessage {
37
38     private static final Logger log = Logger.getLogger(GeneralCmpMessage .class);
39     /** Internal localization of logs and errors */
40     private static final InternalResources intres = InternalResources.getInstance();
41     
42     /**
43      * Determines if a de-serialized file is compatible with this class.
44      *
45      * Maintainers must change this value if and only if the new version
46      * of this class is not compatible with old versions. See Sun docs
47      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
48      * /serialization/spec/version.doc.html> details. </a>
49      *
50      */

51     static final long serialVersionUID = 1000L;
52
53     public GeneralCmpMessage(PKIMessage msg) {
54         PKIBody body = msg.getBody();
55         int tag = body.getTagNo();
56         if (tag == 19) {
57             // this is a PKIConfirmContent
58
log.debug("Received a PKIConfirm message");
59             // This is a null message, so there is nothing to get here
60
//DERNull obj = body.getConf();
61
}
62         if (tag == 24) {
63             // this is a CertConfirmContent
64
log.debug("Received a Cert Confirm message");
65             CertConfirmContent obj = body.getCertConf();
66             PKIStatusInfo status = obj.getPKIStatus();
67             if (status != null) {
68                 int st = status.getStatus().getValue().intValue();
69                 if (st != 0) {
70                     String JavaDoc errMsg = intres.getLocalizedMessage("cmp.errorcertconfirmstatus", new Integer JavaDoc(st));
71                     log.error(errMsg);
72                     // TODO: if it is rejected, we should revoke the cert?
73
}
74             }
75         }
76         if (tag == 11) {
77             // this is a RevReqContent,
78
log.debug("Received a RevReqContent");
79             RevReqContent rr = body.getRr();
80             RevDetails rd = rr.getRevDetails(0);
81             CertTemplate ct = rd.getCertDetails();
82             DERInteger serno = ct.getSerialNumber();
83             X509Name issuer = ct.getIssuer();
84             if ( (serno != null) && (issuer != null) ) {
85                 String JavaDoc errMsg = intres.getLocalizedMessage("cmp.receivedrevreq", issuer.toString(), serno.getValue().toString(16));
86                 log.info(errMsg);
87             } else {
88                 String JavaDoc errMsg = intres.getLocalizedMessage("cmp.receivedrevreqnoissuer");
89                 log.info(errMsg);
90             }
91         }
92         setMessage(msg);
93         PKIHeader header = msg.getHeader();
94         DEROctetString os = header.getTransactionID();
95         if (os != null) {
96             byte[] val = os.getOctets();
97             if (val != null) {
98                 setTransactionId(new String JavaDoc(Base64.encode(val)));
99             }
100         }
101         os = header.getSenderNonce();
102         if (os != null) {
103             byte[] val = os.getOctets();
104             if (val != null) {
105                 setSenderNonce(new String JavaDoc(Base64.encode(val)));
106             }
107         }
108         setRecipient(header.getRecipient());
109         setSender(header.getSender());
110     }
111     
112 }
113
Popular Tags