use of org.bouncycastle.asn1.x509.CRLNumber in project oxAuth by GluuFederation.
the class CRLCertificateVerifier method getCrlNumber.
@SuppressWarnings({ "deprecation", "resource" })
private BigInteger getCrlNumber(X509CRL crl) throws IOException {
byte[] crlNumberExtensionValue = crl.getExtensionValue(X509Extensions.CRLNumber.getId());
if (crlNumberExtensionValue == null) {
return null;
}
DEROctetString octetString = (DEROctetString) (new ASN1InputStream(new ByteArrayInputStream(crlNumberExtensionValue)).readObject());
byte[] octets = octetString.getOctets();
DERInteger integer = (DERInteger) new ASN1InputStream(octets).readObject();
BigInteger crlNumber = integer.getPositiveValue();
return crlNumber;
}
use of org.bouncycastle.asn1.x509.CRLNumber in project poi by apache.
the class PkiTestUtils method generateCrl.
public static X509CRL generateCrl(X509Certificate issuer, PrivateKey issuerPrivateKey) throws CertificateEncodingException, IOException, CRLException, OperatorCreationException {
X509CertificateHolder holder = new X509CertificateHolder(issuer.getEncoded());
X509v2CRLBuilder crlBuilder = new X509v2CRLBuilder(holder.getIssuer(), new Date());
crlBuilder.setNextUpdate(new Date(new Date().getTime() + 100000));
JcaContentSignerBuilder contentBuilder = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC");
CRLNumber crlNumber = new CRLNumber(new BigInteger("1234"));
crlBuilder.addExtension(Extension.cRLNumber, false, crlNumber);
X509CRLHolder x509Crl = crlBuilder.build(contentBuilder.build(issuerPrivateKey));
return new JcaX509CRLConverter().setProvider("BC").getCRL(x509Crl);
}
use of org.bouncycastle.asn1.x509.CRLNumber in project keystore-explorer by kaikramer.
the class X509Ext method getDeltaCrlIndicatorStringValue.
private String getDeltaCrlIndicatorStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* deltaCRLIndicator EXTENSION ::= { SYNTAX BaseCRLNumber IDENTIFIED BY
* id-ce-deltaCRLIndicator }
*
* BaseCRLNumber ::= CRLNumber
*
* CRLNumber ::= ASN1Integer (0..MAX)
*/
// @formatter:on
CRLNumber crlNumber = CRLNumber.getInstance(value);
BigInteger crlNum = crlNumber.getCRLNumber();
return HexUtil.getHexString(crlNum) + NEWLINE;
}
use of org.bouncycastle.asn1.x509.CRLNumber in project keystore-explorer by kaikramer.
the class X509Ext method getCrlNumberStringValue.
private String getCrlNumberStringValue(byte[] value) throws IOException {
// @formatter:off
/* CRLNumber ::= ASN1Integer (0..MAX) */
// @formatter:on
StringBuilder sb = new StringBuilder();
CRLNumber crlNumber = CRLNumber.getInstance(value);
sb.append(HexUtil.getHexString(crlNumber.getCRLNumber()));
sb.append(NEWLINE);
return sb.toString();
}
use of org.bouncycastle.asn1.x509.CRLNumber in project xipki by xipki.
the class ImportCrl method importCa.
private int importCa(Connection conn) throws DataAccessException, ImportCrlException {
byte[] encodedCaCert;
try {
encodedCaCert = caCert.getEncoded();
} catch (CertificateEncodingException ex) {
throw new ImportCrlException("could not encode CA certificate");
}
String fpCaCert = HashAlgo.SHA1.base64Hash(encodedCaCert);
Integer issuerId = null;
CrlInfo crlInfo = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = null;
try {
sql = "SELECT ID,CRL_INFO FROM ISSUER WHERE S1C=?";
ps = datasource.prepareStatement(conn, sql);
ps.setString(1, fpCaCert);
rs = ps.executeQuery();
if (rs.next()) {
issuerId = rs.getInt("ID");
String str = rs.getString("CRL_INFO");
if (str == null) {
throw new ImportCrlException("RequestIssuer for the given CA of CRL exists, but not imported from CRL");
}
crlInfo = new CrlInfo(str);
}
} catch (SQLException ex) {
throw datasource.translate(sql, ex);
} finally {
releaseResources(ps, rs);
}
boolean addNew = (issuerId == null);
if (addNew) {
if (isDeltaCrl) {
throw new ImportCrlException("Given CRL is a deltaCRL for the full CRL with number " + baseCrlNumber + ", please import this full CRL first.");
} else {
crlInfo = new CrlInfo(crlNumber, null, useCrlUpdates, crl.getThisUpdate(), crl.getNextUpdate(), crlId);
}
} else {
if (crlNumber.compareTo(crlInfo.getCrlNumber()) < 0) {
// which enables the resume of importing process if error occurred.
throw new ImportCrlException("Given CRL is not newer than existing CRL.");
}
if (isDeltaCrl) {
BigInteger lastFullCrlNumber = crlInfo.getBaseCrlNumber();
if (lastFullCrlNumber == null) {
lastFullCrlNumber = crlInfo.getCrlNumber();
}
if (!baseCrlNumber.equals(lastFullCrlNumber)) {
throw new ImportCrlException("Given CRL is a deltaCRL for the full CRL with number " + crlNumber + ", please import this full CRL first.");
}
}
crlInfo.setCrlNumber(crlNumber);
crlInfo.setBaseCrlNumber(isDeltaCrl ? baseCrlNumber : null);
crlInfo.setThisUpdate(crl.getThisUpdate());
crlInfo.setNextUpdate(crl.getNextUpdate());
}
ps = null;
rs = null;
sql = null;
try {
// issuer exists
if (addNew) {
int maxId = (int) datasource.getMax(conn, "ISSUER", "ID");
issuerId = maxId + 1;
sql = "INSERT INTO ISSUER (ID,SUBJECT,NBEFORE,NAFTER,S1C,CERT,REV,RT,RIT,CRL_INFO)" + " VALUES(?,?,?,?,?,?,?,?,?,?)";
} else {
sql = "UPDATE ISSUER SET REV=?,RT=?,RIT=?,CRL_INFO=? WHERE ID=?";
}
ps = datasource.prepareStatement(conn, sql);
int offset = 1;
if (addNew) {
String subject = X509Util.getRfc4519Name(caCert.getSubjectX500Principal());
ps.setInt(offset++, issuerId);
ps.setString(offset++, subject);
ps.setLong(offset++, caCert.getNotBefore().getTime() / 1000);
ps.setLong(offset++, caCert.getNotAfter().getTime() / 1000);
ps.setString(offset++, fpCaCert);
ps.setString(offset++, Base64.encodeToString(encodedCaCert));
}
ps.setInt(offset++, (caRevInfo == null) ? 0 : 1);
Date revTime = null;
Date revInvTime = null;
if (caRevInfo != null) {
revTime = caRevInfo.getRevocationTime();
revInvTime = caRevInfo.getInvalidityTime();
}
if (revTime != null) {
ps.setLong(offset++, revTime.getTime() / 1000);
} else {
ps.setNull(offset++, Types.BIGINT);
}
if (revInvTime != null) {
ps.setLong(offset++, revInvTime.getTime() / 1000);
} else {
ps.setNull(offset++, Types.BIGINT);
}
// CRL info
try {
ps.setString(offset++, crlInfo.getEncoded());
} catch (IOException ex) {
throw new ImportCrlException("could not encode the Crlinfo", ex);
}
if (!addNew) {
ps.setInt(offset++, issuerId.intValue());
}
ps.executeUpdate();
return issuerId.intValue();
} catch (SQLException ex) {
throw datasource.translate(sql, ex);
} finally {
releaseResources(ps, rs);
}
}
Aggregations