Search in sources :

Example 1 with CaMgmtException

use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.

the class CaManagerImpl method createX509CrlSigner.

// method createCmpResponder
X509CrlSignerEntryWrapper createX509CrlSigner(X509CrlSignerEntry dbEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("dbEntry", dbEntry);
    X509CrlSignerEntryWrapper signer = new X509CrlSignerEntryWrapper();
    try {
        signer.setDbEntry(dbEntry);
    } catch (InvalidConfException ex) {
        throw new CaMgmtException(concat("InvalidConfException: ", ex.getMessage()));
    }
    try {
        signer.initSigner(securityFactory);
    } catch (XiSecurityException | OperationException | InvalidConfException ex) {
        String message = "could not create CRL signer " + dbEntry.getName();
        LogUtil.error(LOG, ex, message);
        if (ex instanceof OperationException) {
            throw new CaMgmtException(message + ": " + ((OperationException) ex).getErrorCode() + ", " + ex.getMessage());
        } else {
            throw new CaMgmtException(concat(message, ": ", ex.getMessage()));
        }
    }
    return signer;
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) XiSecurityException(org.xipki.security.exception.XiSecurityException) InvalidConfException(org.xipki.common.InvalidConfException) OperationException(org.xipki.ca.api.OperationException)

Example 2 with CaMgmtException

use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.

the class CaManagerImpl method initSceps.

// method initCmpControls
private void initSceps() throws CaMgmtException {
    if (scepsInitialized) {
        return;
    }
    sceps.clear();
    scepDbEntries.clear();
    List<String> names = queryExecutor.namesFromTable("SCEP");
    for (String name : names) {
        ScepEntry scepDb = queryExecutor.getScep(name, idNameMap);
        if (scepDb == null) {
            continue;
        }
        scepDbEntries.put(name, scepDb);
        try {
            ScepImpl scep = new ScepImpl(scepDb, this);
            sceps.put(name, scep);
        } catch (CaMgmtException ex) {
            LogUtil.error(LOG, ex, concat("could not initialize SCEP entry ", name, ", ignore it"));
        }
    }
    scepsInitialized = true;
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) ScepImpl(org.xipki.ca.server.impl.scep.ScepImpl) ChangeScepEntry(org.xipki.ca.server.mgmt.api.x509.ChangeScepEntry) ScepEntry(org.xipki.ca.server.mgmt.api.x509.ScepEntry)

Example 3 with CaMgmtException

use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.

the class CaManagerImpl method addScep.

// method getCurrentCrl
@Override
public void addScep(ScepEntry dbEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("dbEntry", dbEntry);
    asssertMasterMode();
    final String name = dbEntry.getName();
    if (scepDbEntries.containsKey(name)) {
        throw new CaMgmtException(concat("SCEP named ", name, " exists"));
    }
    String caName = dbEntry.getCaIdent().getName();
    NameId caIdent = idNameMap.getCa(caName);
    if (caIdent == null) {
        String msg = concat("unknown CA ", caName);
        LOG.warn(msg);
        throw new CaMgmtException(msg);
    }
    dbEntry.getCaIdent().setId(caIdent.getId());
    ScepImpl scep = new ScepImpl(dbEntry, this);
    queryExecutor.addScep(dbEntry);
    scepDbEntries.put(name, dbEntry);
    sceps.put(name, scep);
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId) ScepImpl(org.xipki.ca.server.impl.scep.ScepImpl)

Example 4 with CaMgmtException

use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.

the class CaManagerImpl method lockCa.

private void lockCa(boolean forceRelock) throws CaMgmtException {
    SystemEvent lockInfo = queryExecutor.getSystemEvent(EVENT_LOCK);
    if (lockInfo != null) {
        String lockedBy = lockInfo.getOwner();
        Date lockedAt = new Date(lockInfo.getEventTime() * 1000L);
        if (!this.lockInstanceId.equals(lockedBy)) {
            String msg = concat("could not lock CA, it has been locked by ", lockedBy, " since ", lockedAt.toString(), ". In general this indicates that another" + " CA software in active mode is accessing the database or the last shutdown of CA" + " software in active mode is abnormal.");
            LOG.error(msg);
            throw new CaMgmtException(msg);
        }
        if (forceRelock) {
            LOG.info("CA has been locked by me since {}, re-lock it", lockedAt);
        }
    }
    SystemEvent newLockInfo = new SystemEvent(EVENT_LOCK, lockInstanceId, System.currentTimeMillis() / 1000L);
    queryExecutor.changeSystemEvent(newLockInfo);
    caLockedByMe = true;
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) Date(java.util.Date)

Example 5 with CaMgmtException

use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.

the class CaManagerImpl method getCrl.

// method generateCrlOnDemand
@Override
public X509CRL getCrl(String caName, BigInteger crlNumber) throws CaMgmtException {
    caName = ParamUtil.requireNonBlank("caName", caName).toLowerCase();
    ParamUtil.requireNonNull("crlNumber", crlNumber);
    X509Ca ca = getX509Ca(caName);
    try {
        X509CRL crl = ca.getCrl(crlNumber);
        if (crl == null) {
            LOG.warn("found no CRL for CA {} and crlNumber {}", caName, crlNumber);
        }
        return crl;
    } catch (OperationException ex) {
        throw new CaMgmtException(ex.getMessage(), ex);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) X509CRL(java.security.cert.X509CRL) OperationException(org.xipki.ca.api.OperationException)

Aggregations

CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)157 PreparedStatement (java.sql.PreparedStatement)63 SQLException (java.sql.SQLException)63 CmdFailure (org.xipki.console.karaf.CmdFailure)52 NameId (org.xipki.ca.api.NameId)31 ResultSet (java.sql.ResultSet)24 OperationException (org.xipki.ca.api.OperationException)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 InvalidConfException (org.xipki.common.InvalidConfException)11 DataAccessException (org.xipki.datasource.DataAccessException)11 CertificateEncodingException (java.security.cert.CertificateEncodingException)9 CaHasRequestorEntry (org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)9 CertificateException (java.security.cert.CertificateException)8 ObjectCreationException (org.xipki.common.ObjectCreationException)8 X509Certificate (java.security.cert.X509Certificate)7 Date (java.util.Date)7 X509CaEntry (org.xipki.ca.server.mgmt.api.x509.X509CaEntry)7 IOException (java.io.IOException)6 Statement (java.sql.Statement)6 CaHasUserEntry (org.xipki.ca.server.mgmt.api.CaHasUserEntry)6