1 13 package org.ejbca.core.protocol.cmp; 14 15 import java.io.IOException ; 16 import java.security.InvalidKeyException ; 17 import java.security.NoSuchAlgorithmException ; 18 import java.security.NoSuchProviderException ; 19 import java.security.PrivateKey ; 20 import java.security.cert.CRL ; 21 import java.security.cert.Certificate ; 22 import java.security.cert.CertificateEncodingException ; 23 import java.security.cert.X509Certificate ; 24 25 import org.apache.log4j.Logger; 26 import org.bouncycastle.asn1.DERInteger; 27 import org.bouncycastle.asn1.DERUTF8String; 28 import org.bouncycastle.asn1.x509.X509Name; 29 import org.ejbca.core.model.ca.SignRequestException; 30 import org.ejbca.core.model.ra.NotFoundException; 31 import org.ejbca.core.protocol.FailInfo; 32 import org.ejbca.core.protocol.IRequestMessage; 33 import org.ejbca.core.protocol.IResponseMessage; 34 import org.ejbca.core.protocol.ResponseStatus; 35 36 import com.novosec.pkix.asn1.cmp.ErrorMsgContent; 37 import com.novosec.pkix.asn1.cmp.PKIBody; 38 import com.novosec.pkix.asn1.cmp.PKIFreeText; 39 import com.novosec.pkix.asn1.cmp.PKIHeader; 40 import com.novosec.pkix.asn1.cmp.PKIMessage; 41 import com.novosec.pkix.asn1.cmp.PKIStatusInfo; 42 43 44 49 public class CmpErrorResponseMessage extends BaseCmpMessage implements IResponseMessage { 50 51 private static Logger log = Logger.getLogger(CrmfMessageHandler.class); 52 61 static final long serialVersionUID = 10002L; 62 63 64 private byte[] responseMessage = null; 65 private String failText = null; 66 private FailInfo failInfo = null; 67 private ResponseStatus status = null; 68 private int requestId = 0; 69 private int requestType = 23; 71 public void setCertificate(Certificate cert) { 72 } 73 74 public void setCrl(CRL crl) { 75 } 76 77 public void setIncludeCACert(boolean incCACert) { 78 } 79 80 public byte[] getResponseMessage() throws IOException , 81 CertificateEncodingException { 82 return responseMessage; 83 } 84 85 public void setStatus(ResponseStatus status) { 86 this.status = status; 87 } 88 89 public ResponseStatus getStatus() { 90 return status; 91 } 92 93 public void setFailInfo(FailInfo failInfo) { 94 this.failInfo = failInfo; 95 } 96 97 public FailInfo getFailInfo() { 98 return failInfo; 99 } 100 101 public void setFailText(String failText) { 102 this.failText = failText; 103 } 104 105 public String getFailText() { 106 return failText; 107 } 108 109 public boolean create() throws IOException , InvalidKeyException , 110 NoSuchAlgorithmException , NoSuchProviderException , 111 SignRequestException, NotFoundException { 112 X509Name sender = X509Name.getInstance(getSender().getName()); 113 X509Name recipient = X509Name.getInstance(getRecipient().getName()); 114 PKIHeader myPKIHeader = CmpMessageHelper.createPKIHeader(sender, recipient, getSenderNonce(), getRecipientNonce(), getTransactionId()); 115 PKIStatusInfo myPKIStatusInfo = new PKIStatusInfo(new DERInteger(2)); if (failInfo != null) { 117 myPKIStatusInfo.setFailInfo(failInfo.getAsBitString()); 118 } 119 if (failText != null) { 120 myPKIStatusInfo.setStatusString(new PKIFreeText(new DERUTF8String(failText))); 121 } 122 PKIBody myPKIBody = null; 123 log.debug("Create error message from requestType: "+requestType); 124 if (requestType==0 || requestType==2) { 125 myPKIBody = CmpMessageHelper.createCertRequestRejectBody(myPKIHeader, myPKIStatusInfo, requestId, requestType); 126 } else { 127 ErrorMsgContent myErrorContent = new ErrorMsgContent(myPKIStatusInfo); 128 myPKIBody = new PKIBody(myErrorContent, 23); } 130 PKIMessage myPKIMessage = new PKIMessage(myPKIHeader, myPKIBody); 131 if ((getPbeDigestAlg() != null) && (getPbeMacAlg() != null) && (getPbeKeyId() != null) && (getPbeKey() != null) ) { 132 responseMessage = CmpMessageHelper.protectPKIMessageWithPBE(myPKIMessage, getPbeKeyId(), getPbeKey(), getPbeDigestAlg(), getPbeMacAlg(), getPbeIterationCount()); 133 } else { 134 responseMessage = CmpMessageHelper.pkiMessageToByteArray(myPKIMessage); 135 } 136 return true; 137 } 138 139 public boolean requireSignKeyInfo() { 140 return false; 141 } 142 143 public boolean requireEncKeyInfo() { 144 return false; 145 } 146 147 public void setSignKeyInfo(X509Certificate cert, PrivateKey key, 148 String provider) { 149 } 150 151 public void setEncKeyInfo(X509Certificate cert, PrivateKey key, 152 String provider) { 153 } 154 155 public void setSenderNonce(String senderNonce) { 156 super.setSenderNonce(senderNonce); 157 } 158 159 public void setRecipientNonce(String recipientNonce) { 160 super.setRecipientNonce(recipientNonce); 161 } 162 163 public void setTransactionId(String transactionId) { 164 super.setTransactionId(transactionId); 165 } 166 167 public void setRecipientKeyInfo(byte[] recipientKeyInfo) { 168 } 169 170 public void setPreferredDigestAlg(String digest) { 171 } 172 173 public void setRequestType(int reqtype) { 174 this.requestType = reqtype; 175 } 176 177 public void setRequestId(int reqid) { 178 this.requestId = reqid; 179 } 180 181 183 public void setProtectionParamsFromRequest(IRequestMessage reqMsg) { 184 } 185 } 186 | Popular Tags |