Search in sources :

Example 31 with NameId

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

the class CaManagerQueryExecutor method addRequestorToCa.

void addRequestorToCa(CaHasRequestorEntry requestor, NameId ca) throws CaMgmtException {
    ParamUtil.requireNonNull("requestor", requestor);
    ParamUtil.requireNonNull("ca", ca);
    final NameId requestorIdent = requestor.getRequestorIdent();
    PreparedStatement ps = null;
    final String sql = "INSERT INTO CA_HAS_REQUESTOR (CA_ID,REQUESTOR_ID,RA, PERMISSION,PROFILES)" + " VALUES (?,?,?,?,?)";
    try {
        ps = prepareStatement(sql);
        int idx = 1;
        ps.setInt(idx++, ca.getId());
        ps.setInt(idx++, requestorIdent.getId());
        boolean ra = requestor.isRa();
        setBoolean(ps, idx++, ra);
        int permission = requestor.getPermission();
        ps.setInt(idx++, permission);
        String profilesText = StringUtil.collectionAsStringByComma(requestor.getProfiles());
        ps.setString(idx++, profilesText);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not add requestor " + requestorIdent + " to CA " + ca);
        }
        LOG.info("added requestor '{}' to CA '{}': ra: {}; permission: {}; profile: {}", requestorIdent, ca, ra, permission, profilesText);
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(ps, null);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 32 with NameId

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

the class X509Ca method republishCertificates.

// method publishCertificate0
public boolean republishCertificates(List<String> publisherNames, int numThreads) {
    List<IdentifiedX509CertPublisher> publishers;
    if (publisherNames == null) {
        publishers = publishers();
    } else {
        publishers = new ArrayList<>(publisherNames.size());
        for (String publisherName : publisherNames) {
            IdentifiedX509CertPublisher publisher = null;
            for (IdentifiedX509CertPublisher p : publishers()) {
                if (p.getIdent().getName().equals(publisherName)) {
                    publisher = p;
                    break;
                }
            }
            if (publisher == null) {
                throw new IllegalArgumentException("could not find publisher " + publisherName + " for CA " + caIdent);
            }
            publishers.add(publisher);
        }
    }
    if (CollectionUtil.isEmpty(publishers)) {
        return true;
    }
    CaStatus status = caInfo.getStatus();
    caInfo.setStatus(CaStatus.INACTIVE);
    boolean onlyRevokedCerts = true;
    for (IdentifiedX509CertPublisher publisher : publishers) {
        if (publisher.publishsGoodCert()) {
            onlyRevokedCerts = false;
        }
        NameId publisherIdent = publisher.getIdent();
        try {
            LOG.info("clearing PublishQueue for publisher {}", publisherIdent);
            certstore.clearPublishQueue(caIdent, publisherIdent);
            LOG.info(" cleared PublishQueue for publisher {}", publisherIdent);
        } catch (OperationException ex) {
            LogUtil.error(LOG, ex, "could not clear PublishQueue for publisher");
        }
    }
    try {
        for (IdentifiedX509CertPublisher publisher : publishers) {
            boolean successful = publisher.caAdded(caCert);
            if (!successful) {
                LOG.error("republish CA certificate {} to publisher {} failed", caIdent, publisher.getIdent());
                return false;
            }
        }
        if (caInfo.getRevocationInfo() != null) {
            for (IdentifiedX509CertPublisher publisher : publishers) {
                boolean successful = publisher.caRevoked(caCert, caInfo.getRevocationInfo());
                if (!successful) {
                    LOG.error("republishing CA revocation to publisher {} failed", publisher.getIdent());
                    return false;
                }
            }
        }
        // end if
        CertRepublisher republisher = new CertRepublisher(caIdent, caCert, caIdNameMap, certstore, publishers, onlyRevokedCerts, numThreads);
        return republisher.republish();
    } finally {
        caInfo.setStatus(status);
    }
}
Also used : NameId(org.xipki.ca.api.NameId) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) CaStatus(org.xipki.ca.server.mgmt.api.CaStatus) OperationException(org.xipki.ca.api.OperationException)

Example 33 with NameId

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

the class X509Ca method revokeCa.

// method shouldPublishToDeltaCrlCache
public void revokeCa(CertRevocationInfo revocationInfo, String msgId) throws OperationException {
    ParamUtil.requireNonNull("revocationInfo", revocationInfo);
    caInfo.setRevocationInfo(revocationInfo);
    if (caInfo.isSelfSigned()) {
        AuditEvent event = newPerfAuditEvent(CaAuditConstants.TYPE_revoke_cert, msgId);
        boolean successful = true;
        try {
            X509CertWithRevocationInfo ret = revokeCertificate0(caInfo.getSerialNumber(), revocationInfo.getReason(), revocationInfo.getInvalidityTime(), true, event);
            successful = (ret != null);
        } finally {
            finish(event, successful);
        }
    }
    boolean failed = false;
    for (IdentifiedX509CertPublisher publisher : publishers()) {
        NameId ident = publisher.getIdent();
        boolean successful = publisher.caRevoked(caCert, revocationInfo);
        if (successful) {
            LOG.info("published event caRevoked of CA {} to publisher {}", caIdent, ident);
        } else {
            failed = true;
            LOG.error("could not publish event caRevoked of CA {} to publisher {}", caIdent, ident);
        }
    }
    if (failed) {
        final String message = "could not event caRevoked of CA " + caIdent + " to at least one publisher";
        throw new OperationException(ErrorCode.SYSTEM_FAILURE, message);
    }
}
Also used : NameId(org.xipki.ca.api.NameId) AuditEvent(org.xipki.audit.AuditEvent) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) X509CertWithRevocationInfo(org.xipki.ca.server.impl.store.X509CertWithRevocationInfo) OperationException(org.xipki.ca.api.OperationException)

Example 34 with NameId

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

the class CaManagerImpl method changeCa.

@Override
public void changeCa(ChangeCaEntry entry) throws CaMgmtException {
    ParamUtil.requireNonNull("entry", entry);
    asssertMasterMode();
    String name = entry.getIdent().getName();
    NameId ident = idNameMap.getCa(name);
    if (ident == null) {
        throw new CaMgmtException("Unknown CA " + name);
    }
    entry.getIdent().setId(ident.getId());
    queryExecutor.changeCa(entry, securityFactory);
    if (!createCa(name)) {
        LOG.error("could not create CA {}", name);
    } else {
        X509CaInfo caInfo = caInfos.get(name);
        if (CaStatus.ACTIVE != caInfo.getCaEntry().getStatus()) {
            return;
        }
        if (startCa(name)) {
            LOG.info("started CA {}", name);
        } else {
            LOG.error("could not start CA {}", name);
        }
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId)

Example 35 with NameId

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

the class CaManagerImpl method addRequestorToCa.

// method removeRequestorFromCa
@Override
public void addRequestorToCa(CaHasRequestorEntry requestor, String caName) throws CaMgmtException {
    ParamUtil.requireNonNull("requestor", requestor);
    caName = ParamUtil.requireNonBlank("caName", caName).toLowerCase();
    asssertMasterMode();
    NameId requestorIdent = requestor.getRequestorIdent();
    NameId ident = idNameMap.getRequestor(requestorIdent.getName());
    if (ident == null) {
        String msg = concat("unknown requestor ", requestorIdent.getName());
        LOG.warn(msg);
        throw new CaMgmtException(msg);
    }
    NameId caIdent = idNameMap.getCa(caName);
    if (caIdent == null) {
        String msg = concat("unknown CA ", caName);
        LOG.warn(msg);
        throw new CaMgmtException(msg);
    }
    // Set the ID of requestor
    requestorIdent.setId(ident.getId());
    Set<CaHasRequestorEntry> cmpRequestors = caHasRequestors.get(caName);
    if (cmpRequestors == null) {
        cmpRequestors = new HashSet<>();
        caHasRequestors.put(caName, cmpRequestors);
    } else {
        for (CaHasRequestorEntry entry : cmpRequestors) {
            String requestorName = requestorIdent.getName();
            if (entry.getRequestorIdent().getName().equals(requestorName)) {
                String msg = concat("Requestor ", requestorName, " already associated with CA ", caName);
                LOG.warn(msg);
                throw new CaMgmtException(msg);
            }
        }
    }
    cmpRequestors.add(requestor);
    queryExecutor.addRequestorToCa(requestor, caIdent);
    caHasRequestors.get(caName).add(requestor);
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId) CaHasRequestorEntry(org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)

Aggregations

NameId (org.xipki.ca.api.NameId)43 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)31 PreparedStatement (java.sql.PreparedStatement)12 SQLException (java.sql.SQLException)12 ResultSet (java.sql.ResultSet)9 OperationException (org.xipki.ca.api.OperationException)9 CmdFailure (org.xipki.console.karaf.CmdFailure)9 BigInteger (java.math.BigInteger)8 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)6 CaHasRequestorEntry (org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)6 X509Certificate (java.security.cert.X509Certificate)5 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)5 CaHasUserEntry (org.xipki.ca.server.mgmt.api.CaHasUserEntry)5 X509CaEntry (org.xipki.ca.server.mgmt.api.x509.X509CaEntry)5 Date (java.util.Date)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CaStatus (org.xipki.ca.server.mgmt.api.CaStatus)4 X509CaUris (org.xipki.ca.server.mgmt.api.x509.X509CaUris)4 ConfPairs (org.xipki.common.ConfPairs)4 IllegalCmdParamException (org.xipki.console.karaf.IllegalCmdParamException)4