1 19 20 package net.sourceforge.jcetaglib.taglib.x509; 21 22 import net.sourceforge.jcetaglib.lib.Clean; 23 import net.sourceforge.jcetaglib.lib.X509Cert; 24 import org.bouncycastle.jce.provider.BouncyCastleProvider; 25 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.TagSupport ; 28 import java.io.FileOutputStream ; 29 import java.math.BigInteger ; 30 import java.security.PrivateKey ; 31 import java.security.Security ; 32 import java.security.cert.X509CRL ; 33 import java.security.cert.X509Certificate ; 34 35 61 62 public class CreateCRL extends TagSupport { 63 private BigInteger [] certs; 64 65 private String crlfile; 66 private int crlnumber = 1; 67 private long crlperiod = 24; 69 private String signfile; private String signentry; private StringBuffer signpassword; 73 private String signaturealgorithm = "MD5WithRSAEncryption"; 74 75 public int doEndTag() throws JspException { 76 Security.addProvider(new BouncyCastleProvider()); 78 79 try { 80 PrivateKey CAprivateKey = X509Cert.getPrivateFromP12(signfile, signentry, signpassword); 82 X509Certificate caCert = X509Cert.getCertificateFromP12(signfile, signentry, signpassword); 83 84 X509CRL crl = X509Cert.CreateCRL(certs 86 , crlnumber 87 , crlperiod 88 , signaturealgorithm 89 , caCert 90 , CAprivateKey); 91 92 FileOutputStream fos = new FileOutputStream (crlfile); 94 fos.write(crl.getEncoded()); 95 fos.close(); 96 } catch (Exception e) { 97 throw new JspException ("JCE Exception: Unable to generate CRL: " 98 + e.getMessage(), e); 99 } 100 101 return EVAL_PAGE; 102 } 104 public void release() { 105 Clean.blank(signpassword); 107 108 super.release(); 109 } 111 118 public void setCerts(BigInteger [] certs) { 119 this.certs = certs; 120 } 121 122 129 public void setCrlfile(String crlfile) { 130 this.crlfile = crlfile; 131 } 132 133 140 public void setCrlnumber(int crlnumber) { 141 this.crlnumber = crlnumber; 142 } 143 144 151 public void setCrlperiod(long crlperiod) { 152 this.crlperiod = crlperiod; 153 } 154 155 162 public void setSignfile(String signfile) { 163 this.signfile = signfile; 164 } 165 166 173 public void setSignentry(String signentry) { 174 this.signentry = signentry; 175 } 176 177 184 public void setSignpassword(StringBuffer signpassword) { 185 this.signpassword = signpassword; 186 } 187 188 195 public void setSignaturealgorithm(String signaturealgorithm) { 196 this.signaturealgorithm = signaturealgorithm; 197 } 198 } | Popular Tags |