Search in sources :

Example 1 with ResponderEntry

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

the class CaManagerImpl method initResponders.

// method initRequestors
private void initResponders() throws CaMgmtException {
    if (responderInitialized) {
        return;
    }
    responderDbEntries.clear();
    responders.clear();
    List<String> names = queryExecutor.namesFromTable("RESPONDER");
    for (String name : names) {
        ResponderEntry dbEntry = queryExecutor.createResponder(name);
        if (dbEntry == null) {
            LOG.error("could not initialize Responder '{}'", name);
            continue;
        }
        dbEntry.setConfFaulty(true);
        responderDbEntries.put(name, dbEntry);
        ResponderEntryWrapper responder = createResponder(dbEntry);
        if (responder != null) {
            dbEntry.setConfFaulty(false);
            responders.put(name, responder);
        }
    }
    responderInitialized = true;
}
Also used : ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry) ResponderEntryWrapper(org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)

Example 2 with ResponderEntry

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

the class CaManagerQueryExecutor method changeResponder.

// method changeRequestor
ResponderEntryWrapper changeResponder(String name, String type, String conf, String base64Cert, CaManagerImpl caManager, SecurityFactory securityFactory) throws CaMgmtException {
    ParamUtil.requireNonBlank("name", name);
    ParamUtil.requireNonNull("caManager", caManager);
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("UPDATE RESPONDER SET ");
    AtomicInteger index = new AtomicInteger(1);
    Integer idxType = addToSqlIfNotNull(sqlBuilder, index, type, "TYPE");
    Integer idxCert = addToSqlIfNotNull(sqlBuilder, index, base64Cert, "CERT");
    Integer idxConf = addToSqlIfNotNull(sqlBuilder, index, conf, "CONF");
    sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
    sqlBuilder.append(" WHERE NAME=?");
    if (index.get() == 1) {
        throw new IllegalArgumentException("nothing to change");
    }
    ResponderEntry dbEntry = createResponder(name);
    String tmpType = (type != null) ? type : dbEntry.getType();
    String tmpConf;
    if (conf == null) {
        tmpConf = dbEntry.getConf();
    } else {
        tmpConf = CaManagerImpl.canonicalizeSignerConf(tmpType, conf, null, securityFactory);
    }
    String tmpBase64Cert;
    if (base64Cert == null) {
        tmpBase64Cert = dbEntry.getBase64Cert();
    } else {
        tmpBase64Cert = base64Cert;
    }
    ResponderEntry newDbEntry = new ResponderEntry(name, tmpType, tmpConf, tmpBase64Cert);
    ResponderEntryWrapper responder = caManager.createResponder(newDbEntry);
    final String sql = sqlBuilder.toString();
    StringBuilder sb = new StringBuilder();
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        if (idxType != null) {
            String txt = tmpType;
            ps.setString(idxType, txt);
            sb.append("type: '").append(txt).append("'; ");
        }
        if (idxConf != null) {
            String txt = getRealString(tmpConf);
            sb.append("conf: '").append(SignerConf.toString(txt, false, true));
            ps.setString(idxConf, txt);
        }
        if (idxCert != null) {
            String txt = getRealString(tmpBase64Cert);
            sb.append("cert: '");
            if (txt == null) {
                sb.append("null");
            } else {
                try {
                    String subject = canonicalizName(X509Util.parseBase64EncodedCert(txt).getSubjectX500Principal());
                    sb.append(subject);
                } catch (CertificateException ex) {
                    sb.append("ERROR");
                }
            }
            sb.append("'; ");
            ps.setString(idxCert, txt);
        }
        ps.setString(index.get(), name);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not change responder " + name);
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1).deleteCharAt(sb.length() - 1);
        }
        LOG.info("changed responder: {}", sb);
        return responder;
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(ps, null);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SQLException(java.sql.SQLException) ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry) PreparedStatement(java.sql.PreparedStatement) CertificateException(java.security.cert.CertificateException) ResponderEntryWrapper(org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)

Example 3 with ResponderEntry

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

the class CaManagerQueryExecutor method createResponder.

// method createCmpControl
ResponderEntry createResponder(String name) throws CaMgmtException {
    final String sql = sqls.sqlSelectResponder;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = prepareStatement(sql);
        stmt.setString(1, name);
        rs = stmt.executeQuery();
        if (!rs.next()) {
            throw new CaMgmtException("unknown responder " + name);
        }
        String type = rs.getString("TYPE");
        String conf = rs.getString("CONF");
        String b64Cert = rs.getString("CERT");
        return new ResponderEntry(name, type, conf, b64Cert);
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(stmt, rs);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry)

Example 4 with ResponderEntry

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

the class ResponderUpdateCmd method getSignerConf.

protected String getSignerConf() throws Exception {
    if (signerConf == null) {
        return signerConf;
    }
    String tmpSignerType = signerType;
    if (tmpSignerType == null) {
        ResponderEntry entry = caManager.getResponder(name);
        if (entry == null) {
            throw new IllegalCmdParamException("please specify the signerType");
        }
        tmpSignerType = entry.getType();
    }
    return ShellUtil.canonicalizeSignerConf(tmpSignerType, signerConf, passwordResolver, securityFactory);
}
Also used : IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry)

Example 5 with ResponderEntry

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

the class ResponderAddCmd method execute0.

@Override
protected Object execute0() throws Exception {
    String base64Cert = null;
    X509Certificate signerCert = null;
    if (certFile != null) {
        signerCert = X509Util.parseCert(certFile);
        base64Cert = IoUtil.base64Encode(signerCert.getEncoded(), false);
    }
    if ("PKCS12".equalsIgnoreCase(signerType) || "JKS".equalsIgnoreCase(signerType)) {
        signerConf = ShellUtil.canonicalizeSignerConf(signerType, signerConf, passwordResolver, securityFactory);
    }
    ResponderEntry entry = new ResponderEntry(name, signerType, signerConf, base64Cert);
    String msg = "CMP responder " + name;
    try {
        caManager.addResponder(entry);
        println("added " + msg);
        return null;
    } catch (CaMgmtException ex) {
        throw new CmdFailure("could not add " + msg + ", error: " + ex.getMessage(), ex);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) CmdFailure(org.xipki.console.karaf.CmdFailure) ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry) X509Certificate(java.security.cert.X509Certificate)

Aggregations

ResponderEntry (org.xipki.ca.server.mgmt.api.ResponderEntry)10 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)5 X509Certificate (java.security.cert.X509Certificate)3 AddUserEntry (org.xipki.ca.server.mgmt.api.AddUserEntry)3 CaHasRequestorEntry (org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)3 CaHasUserEntry (org.xipki.ca.server.mgmt.api.CaHasUserEntry)3 CertprofileEntry (org.xipki.ca.server.mgmt.api.CertprofileEntry)3 CmpControlEntry (org.xipki.ca.server.mgmt.api.CmpControlEntry)3 PublisherEntry (org.xipki.ca.server.mgmt.api.PublisherEntry)3 RequestorEntry (org.xipki.ca.server.mgmt.api.RequestorEntry)3 UserEntry (org.xipki.ca.server.mgmt.api.UserEntry)3 ScepEntry (org.xipki.ca.server.mgmt.api.x509.ScepEntry)3 X509CaEntry (org.xipki.ca.server.mgmt.api.x509.X509CaEntry)3 X509CrlSignerEntry (org.xipki.ca.server.mgmt.api.x509.X509CrlSignerEntry)3 CmdFailure (org.xipki.console.karaf.CmdFailure)3 IOException (java.io.IOException)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 CertificateException (java.security.cert.CertificateException)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2