1 13 14 package org.ejbca.core.protocol; 15 16 17 import java.io.IOException ; 18 import java.security.InvalidKeyException ; 19 import java.security.NoSuchAlgorithmException ; 20 import java.security.NoSuchProviderException ; 21 import java.security.PrivateKey ; 22 import java.security.cert.CRL ; 23 import java.security.cert.Certificate ; 24 import java.security.cert.CertificateEncodingException ; 25 import java.security.cert.CertificateException ; 26 import java.security.cert.X509Certificate ; 27 28 import org.apache.log4j.Logger; 29 import org.ejbca.core.model.ca.SignRequestException; 30 import org.ejbca.core.model.ra.NotFoundException; 31 import org.ejbca.util.CertTools; 32 33 34 39 public class X509ResponseMessage implements IResponseMessage { 40 49 static final long serialVersionUID = -2157072605987735912L; 50 51 private static Logger log = Logger.getLogger(X509ResponseMessage.class); 52 53 54 private Certificate cert = null; 55 56 57 private ResponseStatus status = ResponseStatus.SUCCESS; 58 59 60 private FailInfo failInfo = null; 61 62 63 private String failText = null; 64 65 70 public void setCertificate(Certificate cert) { 71 this.cert = cert; 72 } 73 74 79 public void setCrl(CRL crl) { 80 } 82 83 86 public void setIncludeCACert(boolean incCACert) { 87 } 89 90 95 public Certificate getCertificate() throws CertificateEncodingException , CertificateException , IOException { 96 return CertTools.getCertfromByteArray(getResponseMessage()); 97 } 98 99 104 public byte[] getResponseMessage() throws IOException , CertificateEncodingException { 105 return cert.getEncoded(); 106 } 107 108 113 public void setStatus(ResponseStatus status) { 114 this.status = status; 115 } 116 117 122 public ResponseStatus getStatus() { 123 return status; 124 } 125 126 131 public void setFailInfo(FailInfo failInfo) { 132 this.failInfo = failInfo; 133 } 134 135 140 public FailInfo getFailInfo() { 141 return failInfo; 142 } 143 144 public void setFailText(String failText) { 145 this.failText = failText; 146 } 147 148 public String getFailText() { 149 return this.failText; 150 } 151 152 169 public boolean create() 170 throws IOException , InvalidKeyException , NoSuchAlgorithmException , NoSuchProviderException , SignRequestException, NotFoundException { 171 172 if (status.equals(ResponseStatus.SUCCESS)) { 173 log.debug("Creating a STATUS_OK message."); 174 } else { 175 if (status.equals(ResponseStatus.FAILURE)) { 176 log.debug("Creating a STATUS_FAILED message (or throwing an exception)."); 177 if (failInfo.equals(FailInfo.WRONG_AUTHORITY)) { 178 throw new SignRequestException(failText); 179 } 180 if (failInfo.equals(FailInfo.INCORRECT_DATA)) { 181 throw new NotFoundException(failText); 182 } 183 184 } else { 185 log.debug("Creating a STATUS_PENDING message."); 186 } 187 } 188 return true; 189 } 190 191 197 public boolean requireSignKeyInfo() { 198 return false; 199 } 200 201 207 public boolean requireEncKeyInfo() { 208 return false; 209 } 210 211 221 public void setSignKeyInfo(X509Certificate cert, PrivateKey key, String provider) { 222 } 223 224 234 public void setEncKeyInfo(X509Certificate cert, PrivateKey key, String provider) { 235 } 236 237 242 public void setSenderNonce(String senderNonce) { 243 } 244 245 250 public void setRecipientNonce(String recipientNonce) { 251 } 252 253 258 public void setTransactionId(String transactionId) { 259 } 260 261 267 public void setRecipientKeyInfo(byte[] recipientKeyInfo) { 268 } 269 270 272 public void setPreferredDigestAlg(String digest) { 273 } 274 275 277 public void setRequestType(int reqtype) { 278 } 279 280 282 public void setRequestId(int reqid) { 283 } 284 285 287 public void setProtectionParamsFromRequest(IRequestMessage reqMsg) { 288 } 289 } 290 | Popular Tags |