use of org.kse.gui.dialogs.sign.RevokedEntry in project keystore-explorer by kaikramer.
the class SignCrlAction method signCrl.
private X509CRL signCrl(BigInteger number, Date effectiveDate, Date nextUpdate, X509Certificate caCert, PrivateKey caPrivateKey, String signatureAlgorithm, Map<BigInteger, RevokedEntry> mapRevokedCertificate, String provider) throws NoSuchAlgorithmException, OperatorCreationException, CRLException, IOException {
X509v2CRLBuilder crlGen = new JcaX509v2CRLBuilder(caCert.getSubjectX500Principal(), effectiveDate);
crlGen.setNextUpdate(nextUpdate);
if (mapRevokedCertificate != null) {
Iterator<Map.Entry<BigInteger, RevokedEntry>> it = mapRevokedCertificate.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<BigInteger, RevokedEntry> pair = it.next();
RevokedEntry entry = pair.getValue();
crlGen.addCRLEntry(entry.getUserCertificateSerial(), entry.getRevocationDate(), entry.getReason());
}
}
JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils();
crlGen.addExtension(Extension.authorityKeyIdentifier, false, extUtils.createAuthorityKeyIdentifier(caCert.getPublicKey()));
crlGen.addExtension(Extension.cRLNumber, false, new CRLNumber(number));
X509CRLHolder crl = crlGen.build(new JcaContentSignerBuilder(signatureAlgorithm).setProvider(provider).build(caPrivateKey));
return new JcaX509CRLConverter().setProvider(BOUNCY_CASTLE.jce()).getCRL(crl);
}
use of org.kse.gui.dialogs.sign.RevokedEntry in project keystore-explorer by kaikramer.
the class SignCrlAction method doAction.
@Override
protected void doAction() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return;
}
KeyStore keyStore = currentState.getKeyStore();
String provider = BOUNCY_CASTLE.jce();
if (history.getExplicitProvider() != null) {
provider = history.getExplicitProvider().getName();
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
X509Certificate[] certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)));
KeyPairType keyPairType = KeyPairUtil.getKeyPairType(privateKey);
File filePrevious = getFilePrevious(certs[0], history);
X509CRL x509CRL = loadPreviousCrl(filePrevious, certs[0]);
DSignCrl dSignCrl = new DSignCrl(frame, kseFrame, keyPairType, privateKey, certs[0], x509CRL);
dSignCrl.setLocationRelativeTo(frame);
dSignCrl.setVisible(true);
Date effectiveDate = dSignCrl.getEffectiveDate();
if (effectiveDate != null) {
Date nextUpdate = dSignCrl.getNextUpdate();
BigInteger crlNumber = dSignCrl.getCrlNumber();
String signatureAlgorithm = dSignCrl.getSignatureType().jce();
Map<BigInteger, RevokedEntry> mapRevoked = dSignCrl.getMapRevokedEntry();
x509CRL = signCrl(crlNumber, effectiveDate, nextUpdate, certs[0], privateKey, signatureAlgorithm, mapRevoked, provider);
String newFileName = X509CertUtil.getShortName(certs[0]).toLowerCase();
DExportCrl dExportCrl = new DExportCrl(frame, newFileName);
dExportCrl.setLocationRelativeTo(frame);
dExportCrl.setVisible(true);
if (dExportCrl.exportSelected()) {
// export CRL .db
exportFile(x509CRL, filePrevious, false);
// export file .crl
exportFile(x509CRL, dExportCrl.getExportFile(), dExportCrl.pemEncode());
JOptionPane.showMessageDialog(frame, res.getString("SignCrlAction.SignCrlSuccessful.message"), res.getString("SignCrlAction.SignCrl.Title"), JOptionPane.INFORMATION_MESSAGE);
}
}
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
Aggregations