use of org.xipki.ca.api.NameId in project xipki by xipki.
the class CaManagerImpl method addCa.
@Override
public void addCa(CaEntry caEntry) throws CaMgmtException {
ParamUtil.requireNonNull("caEntry", caEntry);
asssertMasterMode();
NameId ident = caEntry.getIdent();
String name = ident.getName();
if (caInfos.containsKey(name)) {
throw new CaMgmtException(concat("CA named ", name, " exists"));
}
String origSignerConf = caEntry.getSignerConf();
String newSignerConf = canonicalizeSignerConf(caEntry.getSignerType(), origSignerConf, null, securityFactory);
if (!origSignerConf.equals(newSignerConf)) {
caEntry.setSignerConf(newSignerConf);
}
if (caEntry instanceof X509CaEntry) {
try {
X509CaEntry tmpCaEntry = (X509CaEntry) caEntry;
List<String[]> signerConfs = CaEntry.splitCaSignerConfs(tmpCaEntry.getSignerConf());
ConcurrentContentSigner signer;
for (String[] m : signerConfs) {
SignerConf signerConf = new SignerConf(m[1]);
signer = securityFactory.createSigner(tmpCaEntry.getSignerType(), signerConf, tmpCaEntry.getCert());
if (tmpCaEntry.getCert() == null) {
if (signer.getCertificate() == null) {
throw new CaMgmtException("CA signer without certificate is not allowed");
}
tmpCaEntry.setCert(signer.getCertificate());
}
}
} catch (XiSecurityException | ObjectCreationException ex) {
throw new CaMgmtException(concat("could not create signer for new CA ", name, ": ", ex.getMessage()), ex);
}
}
queryExecutor.addCa(caEntry);
if (!createCa(name)) {
LOG.error("could not create CA {}", name);
} else {
if (startCa(name)) {
LOG.info("started CA {}", name);
} else {
LOG.error("could not start CA {}", name);
}
}
}
use of org.xipki.ca.api.NameId in project xipki by xipki.
the class CaManagerImpl method getAliasesForCa.
@Override
public Set<String> getAliasesForCa(String caName) {
caName = ParamUtil.requireNonBlank("caName", caName).toLowerCase();
Set<String> aliases = new HashSet<>();
X509Ca ca = x509cas.get(caName);
if (ca == null) {
return aliases;
}
NameId caIdent = ca.getCaIdent();
for (String alias : caAliases.keySet()) {
Integer thisCaId = caAliases.get(alias);
if (caIdent.getId().equals(thisCaId)) {
aliases.add(alias);
}
}
return aliases;
}
use of org.xipki.ca.api.NameId in project xipki by xipki.
the class CaManagerImpl method addPublisherToCa.
// method removePublisherFromCa
@Override
public void addPublisherToCa(String publisherName, String caName) throws CaMgmtException {
publisherName = ParamUtil.requireNonBlank("publisherName", publisherName).toLowerCase();
caName = ParamUtil.requireNonBlank("caName", caName).toLowerCase();
asssertMasterMode();
NameId ident = idNameMap.getPublisher(publisherName);
if (ident == null) {
String msg = concat("unknown publisher ", publisherName);
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<String> publisherNames = caHasPublishers.get(caName);
if (publisherNames == null) {
publisherNames = new HashSet<>();
caHasPublishers.put(caName, publisherNames);
} else {
if (publisherNames.contains(publisherName)) {
String msg = concat("publisher ", publisherName, " already associated with CA ", caName);
LOG.warn(msg);
throw new CaMgmtException(msg);
}
}
IdentifiedX509CertPublisher publisher = publishers.get(publisherName);
if (publisher == null) {
throw new CaMgmtException(concat("publisher '", publisherName, "' is faulty"));
}
queryExecutor.addPublisherToCa(idNameMap.getPublisher(publisherName), caIdent);
publisherNames.add(publisherName);
caHasPublishers.get(caName).add(publisherName);
publisher.caAdded(caInfos.get(caName).getCert());
}
use of org.xipki.ca.api.NameId in project xipki by xipki.
the class CaManagerImpl method changeScep.
// method removeScep
public void changeScep(ChangeScepEntry scepEntry) throws CaMgmtException {
ParamUtil.requireNonNull("scepEntry", scepEntry);
asssertMasterMode();
String name = scepEntry.getName();
NameId caId = scepEntry.getCaIdent();
Boolean active = scepEntry.getActive();
String responderName = scepEntry.getResponderName();
String control = scepEntry.getControl();
if (caId == null && responderName == null && control == null) {
throw new IllegalArgumentException("nothing to change or SCEP " + name);
}
if (caId != null && caId.getId() == null) {
String caName = caId.getName();
caId = idNameMap.getCa(caName);
if (caId == null) {
throw new CaMgmtException(concat("Unknown CA ", caName));
}
}
ScepImpl scep = queryExecutor.changeScep(name, caId, active, responderName, scepEntry.getCertProfiles(), control, this, securityFactory);
if (scep == null) {
throw new CaMgmtException("could not chagne SCEP " + name);
}
sceps.remove(name);
scepDbEntries.remove(name);
scepDbEntries.put(name, scep.getDbEntry());
sceps.put(name, scep);
}
use of org.xipki.ca.api.NameId in project xipki by xipki.
the class CaManagerQueryExecutor method createCaInfo.
// method createResponder
X509CaInfo createCaInfo(String name, boolean masterMode, CertificateStore certstore) throws CaMgmtException {
final String sql = sqls.sqlSelectCa;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = prepareStatement(sql);
stmt.setString(1, name);
rs = stmt.executeQuery();
if (!rs.next()) {
throw new CaMgmtException("uknown CA " + name);
}
int artCode = rs.getInt("ART");
if (artCode != CertArt.X509PKC.getCode()) {
throw new CaMgmtException("CA " + name + " is not X509CA, and is not supported");
}
String crlUris = rs.getString("CRL_URIS");
String deltaCrlUris = rs.getString("DELTACRL_URIS");
CertRevocationInfo revocationInfo = null;
boolean revoked = rs.getBoolean("REV");
if (revoked) {
int revReason = rs.getInt("RR");
long revTime = rs.getInt("RT");
long revInvalidityTime = rs.getInt("RIT");
Date revInvTime = (revInvalidityTime == 0) ? null : new Date(revInvalidityTime * 1000);
revocationInfo = new CertRevocationInfo(revReason, new Date(revTime * 1000), revInvTime);
}
List<String> tmpCrlUris = null;
if (StringUtil.isNotBlank(crlUris)) {
tmpCrlUris = StringUtil.splitByComma(crlUris);
}
List<String> tmpDeltaCrlUris = null;
if (StringUtil.isNotBlank(deltaCrlUris)) {
tmpDeltaCrlUris = StringUtil.splitByComma(deltaCrlUris);
}
String ocspUris = rs.getString("OCSP_URIS");
List<String> tmpOcspUris = null;
if (StringUtil.isNotBlank(ocspUris)) {
tmpOcspUris = StringUtil.splitByComma(ocspUris);
}
String caCertUris = rs.getString("CACERT_URIS");
List<String> tmpCaCertUris = null;
if (StringUtil.isNotBlank(caCertUris)) {
tmpCaCertUris = StringUtil.splitByComma(caCertUris);
}
X509CaUris caUris = new X509CaUris(tmpCaCertUris, tmpOcspUris, tmpCrlUris, tmpDeltaCrlUris);
int id = rs.getInt("ID");
int serialNoSize = rs.getInt("SN_SIZE");
long nextCrlNo = rs.getLong("NEXT_CRLNO");
String signerType = rs.getString("SIGNER_TYPE");
String signerConf = rs.getString("SIGNER_CONF");
int numCrls = rs.getInt("NUM_CRLS");
int expirationPeriod = rs.getInt("EXPIRATION_PERIOD");
X509CaEntry entry = new X509CaEntry(new NameId(id, name), serialNoSize, nextCrlNo, signerType, signerConf, caUris, numCrls, expirationPeriod);
String b64cert = rs.getString("CERT");
X509Certificate cert = generateCert(b64cert);
entry.setCert(cert);
String status = rs.getString("STATUS");
CaStatus caStatus = CaStatus.forName(status);
entry.setStatus(caStatus);
String maxValidityS = rs.getString("MAX_VALIDITY");
CertValidity maxValidity = CertValidity.getInstance(maxValidityS);
entry.setMaxValidity(maxValidity);
int keepExpiredCertDays = rs.getInt("KEEP_EXPIRED_CERT_DAYS");
entry.setKeepExpiredCertInDays(keepExpiredCertDays);
String crlsignerName = rs.getString("CRLSIGNER_NAME");
if (StringUtil.isNotBlank(crlsignerName)) {
entry.setCrlSignerName(crlsignerName);
}
String responderName = rs.getString("RESPONDER_NAME");
if (StringUtil.isNotBlank(responderName)) {
entry.setResponderName(responderName);
}
String extraControl = rs.getString("EXTRA_CONTROL");
if (StringUtil.isNotBlank(extraControl)) {
entry.setExtraControl(new ConfPairs(extraControl).unmodifiable());
}
String cmpcontrolName = rs.getString("CMPCONTROL_NAME");
if (StringUtil.isNotBlank(cmpcontrolName)) {
entry.setCmpControlName(cmpcontrolName);
}
boolean duplicateKeyPermitted = (rs.getInt("DUPLICATE_KEY") != 0);
entry.setDuplicateKeyPermitted(duplicateKeyPermitted);
boolean duplicateSubjectPermitted = (rs.getInt("DUPLICATE_SUBJECT") != 0);
entry.setDuplicateSubjectPermitted(duplicateSubjectPermitted);
boolean saveReq = (rs.getInt("SAVE_REQ") != 0);
entry.setSaveRequest(saveReq);
int permission = rs.getInt("PERMISSION");
entry.setPermission(permission);
entry.setRevocationInfo(revocationInfo);
String validityModeS = rs.getString("VALIDITY_MODE");
ValidityMode validityMode = null;
if (validityModeS != null) {
validityMode = ValidityMode.forName(validityModeS);
}
if (validityMode == null) {
validityMode = ValidityMode.STRICT;
}
entry.setValidityMode(validityMode);
try {
return new X509CaInfo(entry, certstore);
} catch (OperationException ex) {
throw new CaMgmtException(ex);
}
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(stmt, rs);
}
}
Aggregations