1 13 14 package org.ejbca.core.ejb.ca.store; 15 16 import java.io.IOException ; 17 import java.security.cert.CRLException ; 18 import java.security.cert.X509CRL ; 19 import java.util.Date ; 20 21 import javax.ejb.CreateException ; 22 23 import org.apache.log4j.Logger; 24 import org.ejbca.core.ejb.BaseEntityBean; 25 import org.ejbca.util.Base64; 26 import org.ejbca.util.CertTools; 27 28 29 30 80 public abstract class CRLDataBean extends BaseEntityBean { 81 private static final Logger log = Logger.getLogger(CRLDataBean.class); 82 83 87 public abstract int getCrlNumber(); 88 89 92 public abstract void setCrlNumber(int crlNumber); 93 94 98 public abstract String getIssuerDN(); 99 100 105 public abstract void setIssuerDN(String issuerDN); 106 107 112 public abstract String getFingerprint(); 113 114 116 public abstract void setFingerprint(String fingerprint); 117 118 122 public abstract String getCaFingerprint(); 123 124 127 public abstract void setCaFingerprint(String caFingerprint); 128 129 133 public abstract long getThisUpdate(); 134 135 139 public abstract void setThisUpdate(long thisUpdate); 140 141 145 public abstract long getNextUpdate(); 146 147 151 public abstract void setNextUpdate(long nextUpdate); 152 153 157 public abstract String getBase64Crl(); 158 159 162 public abstract void setBase64Crl(String base64Crl); 163 164 170 public X509CRL getCRL() { 171 X509CRL crl = null; 172 try { 173 String b64Crl = getBase64Crl(); 174 crl = CertTools.getCRLfromByteArray(Base64.decode(b64Crl.getBytes())); 175 } catch (IOException ioe) { 176 log.error("Can't decode CRL.", ioe); 177 return null; 178 } catch (CRLException ce) { 179 log.error("Can't decode CRL.", ce); 180 return null; 181 } 182 return crl; 183 } 184 185 188 public void setCRL(X509CRL incrl) { 189 try { 190 String b64Crl = new String (Base64.encode((incrl).getEncoded())); 191 setBase64Crl(b64Crl); 192 } catch (CRLException ce) { 193 log.error("Can't extract DER encoded CRL.", ce); 194 } 195 } 196 197 200 public void setIssuer(String dn) { 201 setIssuerDN(CertTools.stringToBCDNString(dn)); 202 } 203 204 207 public void setThisUpdate(Date thisUpdate) { 208 if (thisUpdate == null) { 209 setThisUpdate(-1L); 210 } 211 212 setThisUpdate(thisUpdate.getTime()); 213 } 214 215 218 public void setNextUpdate(Date nextUpdate) { 219 if (nextUpdate == null) { 220 setNextUpdate(-1L); 221 } 222 223 setNextUpdate(nextUpdate.getTime()); 224 } 225 226 230 240 public CRLDataPK ejbCreate(X509CRL incrl, int number) 241 throws CreateException { 242 try { 244 String b64Crl = new String (Base64.encode(incrl.getEncoded())); 245 setBase64Crl(b64Crl); 246 setFingerprint(CertTools.getFingerprintAsString(incrl)); 247 248 setIssuerDN(CertTools.getIssuerDN(incrl)); 250 log.debug("Creating crldata, issuer=" + getIssuerDN()); 251 252 setCaFingerprint(null); 254 setCrlNumber(number); 255 setThisUpdate(incrl.getThisUpdate()); 256 setNextUpdate(incrl.getNextUpdate()); 257 } catch (CRLException ce) { 258 log.error("Can't extract DER encoded CRL.", ce); 259 260 return null; 261 } 262 263 CRLDataPK pk = new CRLDataPK(getFingerprint()); 264 265 return pk; 266 } 267 268 274 public void ejbPostCreate(X509CRL incrl, int number) { 275 } 277 } 278 | Popular Tags |