Search in sources :

Example 1 with X509CertWithDbId

use of org.xipki.ca.api.X509CertWithDbId in project xipki by xipki.

the class RequestorEntryWrapper method setDbEntry.

public void setDbEntry(RequestorEntry dbEntry) {
    this.dbEntry = ParamUtil.requireNonNull("dbEntry", dbEntry);
    this.cert = new X509CertWithDbId(dbEntry.getCert());
}
Also used : X509CertWithDbId(org.xipki.ca.api.X509CertWithDbId)

Example 2 with X509CertWithDbId

use of org.xipki.ca.api.X509CertWithDbId in project xipki by xipki.

the class X509Ca method unrevokeCertificate0.

// method revokeSuspendedCert0
private X509CertWithDbId unrevokeCertificate0(BigInteger serialNumber, boolean force, AuditEvent event) throws OperationException {
    String hexSerial = LogUtil.formatCsn(serialNumber);
    event.addEventData(CaAuditConstants.NAME_serial, hexSerial);
    LOG.info("     START unrevokeCertificate: ca={}, serialNumber={}", caIdent, hexSerial);
    X509CertWithDbId unrevokedCert = certstore.unrevokeCertificate(caIdent, serialNumber, force, shouldPublishToDeltaCrlCache(), caIdNameMap);
    if (unrevokedCert == null) {
        return null;
    }
    for (IdentifiedX509CertPublisher publisher : publishers()) {
        if (!publisher.isAsyn()) {
            boolean successful;
            try {
                successful = publisher.certificateUnrevoked(caCert, unrevokedCert);
            } catch (RuntimeException ex) {
                successful = false;
                LogUtil.error(LOG, ex, "could not publish unrevocation of certificate to the publisher " + publisher.getIdent());
            }
            if (successful) {
                continue;
            }
        }
        // end if
        Long certId = unrevokedCert.getCertId();
        try {
            certstore.addToPublishQueue(publisher.getIdent(), certId.longValue(), caIdent);
        } catch (Throwable th) {
            LogUtil.error(LOG, th, "could not add entry to PublishQueue");
        }
    }
    // end for
    LOG.info("SUCCESSFUL unrevokeCertificate: ca={}, serialNumber={}, revocationResult=UNREVOKED", caIdent, hexSerial);
    return unrevokedCert;
}
Also used : X509CertWithDbId(org.xipki.ca.api.X509CertWithDbId) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String)

Example 3 with X509CertWithDbId

use of org.xipki.ca.api.X509CertWithDbId in project xipki by xipki.

the class X509Ca method generateCertificates.

private List<X509CertificateInfo> generateCertificates(List<CertTemplateData> certTemplates, RequestorInfo requestor, boolean keyUpdate, RequestType reqType, byte[] transactionId, String msgId) throws OperationExceptionWithIndex {
    ParamUtil.requireNonEmpty("certTemplates", certTemplates);
    final int n = certTemplates.size();
    List<GrantedCertTemplate> gcts = new ArrayList<>(n);
    for (int i = 0; i < n; i++) {
        CertTemplateData certTemplate = certTemplates.get(i);
        try {
            GrantedCertTemplate gct = createGrantedCertTemplate(certTemplate, requestor, keyUpdate);
            gcts.add(gct);
        } catch (OperationException ex) {
            throw new OperationExceptionWithIndex(i, ex);
        }
    }
    List<X509CertificateInfo> certInfos = new ArrayList<>(n);
    OperationExceptionWithIndex exception = null;
    for (int i = 0; i < n; i++) {
        if (exception != null) {
            break;
        }
        GrantedCertTemplate gct = gcts.get(i);
        final NameId certprofilIdent = gct.certprofile.getIdent();
        final String subjectText = gct.grantedSubjectText;
        LOG.info("     START generateCertificate: CA={}, profile={}, subject='{}'", caIdent, certprofilIdent, subjectText);
        boolean successful = false;
        try {
            X509CertificateInfo certInfo = generateCertificate(gct, requestor, false, reqType, transactionId, msgId);
            successful = true;
            certInfos.add(certInfo);
            if (LOG.isInfoEnabled()) {
                String prefix = certInfo.isAlreadyIssued() ? "RETURN_OLD_CERT" : "SUCCESSFUL";
                X509CertWithDbId cert = certInfo.getCert();
                LOG.info("{} generateCertificate: CA={}, profile={}, subject='{}', serialNumber={}", prefix, caIdent, certprofilIdent, cert.getSubject(), LogUtil.formatCsn(cert.getCert().getSerialNumber()));
            }
        } catch (OperationException ex) {
            exception = new OperationExceptionWithIndex(i, ex);
        } catch (Throwable th) {
            exception = new OperationExceptionWithIndex(i, new OperationException(ErrorCode.SYSTEM_FAILURE, th));
        } finally {
            if (!successful) {
                LOG.warn("    FAILED generateCertificate: CA={}, profile={}, subject='{}'", caIdent, certprofilIdent, subjectText);
            }
        }
    }
    if (exception != null) {
        LOG.error("could not generate certificate for request[{}], reverted all generated" + " certificates", exception.getIndex());
        // delete generated certificates
        for (X509CertificateInfo m : certInfos) {
            BigInteger serial = m.getCert().getCert().getSerialNumber();
            try {
                removeCertificate(serial, msgId);
            } catch (Throwable thr) {
                LogUtil.error(LOG, thr, "could not delete certificate serial=" + serial);
            }
        }
        LogUtil.warn(LOG, exception);
        throw exception;
    }
    return certInfos;
}
Also used : NameId(org.xipki.ca.api.NameId) ArrayList(java.util.ArrayList) X509CertificateInfo(org.xipki.ca.api.publisher.x509.X509CertificateInfo) X509CertWithDbId(org.xipki.ca.api.X509CertWithDbId) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) BigInteger(java.math.BigInteger) OperationException(org.xipki.ca.api.OperationException)

Example 4 with X509CertWithDbId

use of org.xipki.ca.api.X509CertWithDbId in project xipki by xipki.

the class X509Ca method removeCertificate0.

// method removeCertificate
private X509CertWithDbId removeCertificate0(BigInteger serialNumber, AuditEvent event) throws OperationException {
    event.addEventData(CaAuditConstants.NAME_serial, LogUtil.formatCsn(serialNumber));
    X509CertWithRevocationInfo certWithRevInfo = certstore.getCertWithRevocationInfo(caIdent, serialNumber, caIdNameMap);
    if (certWithRevInfo == null) {
        return null;
    }
    boolean successful = true;
    X509CertWithDbId certToRemove = certWithRevInfo.getCert();
    for (IdentifiedX509CertPublisher publisher : publishers()) {
        boolean singleSuccessful;
        try {
            singleSuccessful = publisher.certificateRemoved(caCert, certToRemove);
        } catch (RuntimeException ex) {
            singleSuccessful = false;
            LogUtil.warn(LOG, ex, "could not remove certificate to the publisher " + publisher.getIdent());
        }
        if (singleSuccessful) {
            continue;
        }
        successful = false;
        X509Certificate cert = certToRemove.getCert();
        if (LOG.isErrorEnabled()) {
            LOG.error("removing certificate issuer='{}', serial={}, subject='{}' from publisher" + " {} failed.", X509Util.getRfc4519Name(cert.getIssuerX500Principal()), LogUtil.formatCsn(cert.getSerialNumber()), X509Util.getRfc4519Name(cert.getSubjectX500Principal()), publisher.getIdent());
        }
    }
    if (!successful) {
        return null;
    }
    certstore.removeCertificate(caIdent, serialNumber);
    return certToRemove;
}
Also used : X509CertWithDbId(org.xipki.ca.api.X509CertWithDbId) X509CertWithRevocationInfo(org.xipki.ca.server.impl.store.X509CertWithRevocationInfo) X509Certificate(java.security.cert.X509Certificate)

Example 5 with X509CertWithDbId

use of org.xipki.ca.api.X509CertWithDbId in project xipki by xipki.

the class X509Ca method unrevokeCertificate.

// method revokeCertificate
public X509CertWithDbId unrevokeCertificate(BigInteger serialNumber, String msgId) throws OperationException {
    if (caInfo.isSelfSigned() && caInfo.getSerialNumber().equals(serialNumber)) {
        throw new OperationException(ErrorCode.NOT_PERMITTED, "insufficient permission unrevoke CA certificate");
    }
    AuditEvent event = newPerfAuditEvent(CaAuditConstants.TYPE_unrevoke_cert, msgId);
    boolean successful = true;
    try {
        X509CertWithDbId ret = unrevokeCertificate0(serialNumber, false, event);
        successful = true;
        return ret;
    } finally {
        finish(event, successful);
    }
}
Also used : AuditEvent(org.xipki.audit.AuditEvent) X509CertWithDbId(org.xipki.ca.api.X509CertWithDbId) OperationException(org.xipki.ca.api.OperationException)

Aggregations

X509CertWithDbId (org.xipki.ca.api.X509CertWithDbId)15 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)8 OperationException (org.xipki.ca.api.OperationException)8 X509Certificate (java.security.cert.X509Certificate)7 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 DEROctetString (org.bouncycastle.asn1.DEROctetString)5 Date (java.util.Date)4 X509CertificateInfo (org.xipki.ca.api.publisher.x509.X509CertificateInfo)4 CertificateException (java.security.cert.CertificateException)3 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)3 AuditEvent (org.xipki.audit.AuditEvent)3 CertRevocationInfo (org.xipki.security.CertRevocationInfo)3 ArrayList (java.util.ArrayList)2 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)2 IssuingDistributionPoint (org.bouncycastle.asn1.x509.IssuingDistributionPoint)2 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1