1 13 14 package org.ejbca.util.cert; 15 16 import java.io.ByteArrayInputStream ; 17 import java.io.IOException ; 18 import java.math.BigInteger ; 19 import java.security.cert.X509CRL ; 20 21 import org.apache.log4j.Logger; 22 import org.bouncycastle.asn1.ASN1InputStream; 23 import org.bouncycastle.asn1.ASN1OctetString; 24 import org.bouncycastle.asn1.DERInteger; 25 import org.bouncycastle.asn1.DERObject; 26 import org.bouncycastle.asn1.x509.CRLNumber; 27 import org.bouncycastle.asn1.x509.X509Extensions; 28 29 35 public class CrlExtensions { 36 private static Logger log = Logger.getLogger(CrlExtensions.class); 37 38 42 public static BigInteger getCrlNumber(X509CRL crl) { 43 BigInteger ret = BigInteger.valueOf(0); 44 try { 45 DERObject obj = CrlExtensions.getExtensionValue(crl, X509Extensions.CRLNumber.getId()); 46 DERInteger crlnum = CRLNumber.getInstance(obj); 47 ret = crlnum.getPositiveValue(); 48 } catch (IOException e) { 49 log.error("Error reading CRL number extension: ", e); 50 } 51 return ret; 52 } 53 56 protected static DERObject getExtensionValue(X509CRL crl, String oid) 57 throws IOException { 58 if (crl == null) { 59 return null; 60 } 61 byte[] bytes = crl.getExtensionValue(oid); 62 if (bytes == null) { 63 return null; 64 } 65 ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream (bytes)); 66 ASN1OctetString octs = (ASN1OctetString) aIn.readObject(); 67 aIn = new ASN1InputStream(new ByteArrayInputStream (octs.getOctets())); 68 return aIn.readObject(); 69 } 71 72 } 73 | Popular Tags |