use of org.xipki.ca.dbtool.jaxb.ca.CaType in project xipki by xipki.
the class CaConfigurationDbImporter method importCa.
// method importProfile
private void importCa(Cas cas) throws DataAccessException, CertificateException, IOException {
System.out.println("importing table CA");
String sql = "INSERT INTO CA (ID,NAME,ART,SUBJECT,SN_SIZE,NEXT_CRLNO,STATUS,CRL_URIS," + "DELTACRL_URIS,OCSP_URIS,CACERT_URIS,MAX_VALIDITY,CERT,SIGNER_TYPE,CRLSIGNER_NAME," + "RESPONDER_NAME,CMPCONTROL_NAME,DUPLICATE_KEY,DUPLICATE_SUBJECT,SAVE_REQ," + "PERMISSION,NUM_CRLS,EXPIRATION_PERIOD,KEEP_EXPIRED_CERT_DAYS," + "REV,RR,RT,RIT,VALIDITY_MODE,EXTRA_CONTROL,SIGNER_CONF)" + " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
for (CaType ca : cas.getCa()) {
int art = (ca.getArt() == null) ? 1 : ca.getArt();
try {
byte[] certBytes = binary(ca.getCert());
X509Certificate cert = X509Util.parseCert(certBytes);
int idx = 1;
ps.setInt(idx++, ca.getId());
ps.setString(idx++, ca.getName().toLowerCase());
ps.setInt(idx++, art);
ps.setString(idx++, X509Util.cutX500Name(cert.getSubjectX500Principal(), maxX500nameLen));
ps.setInt(idx++, ca.getSnSize());
ps.setLong(idx++, ca.getNextCrlNo());
ps.setString(idx++, ca.getStatus());
ps.setString(idx++, ca.getCrlUris());
ps.setString(idx++, ca.getDeltacrlUris());
ps.setString(idx++, ca.getOcspUris());
ps.setString(idx++, ca.getCacertUris());
ps.setString(idx++, ca.getMaxValidity());
ps.setString(idx++, Base64.encodeToString(certBytes));
ps.setString(idx++, ca.getSignerType());
ps.setString(idx++, ca.getCrlsignerName());
ps.setString(idx++, ca.getResponderName());
ps.setString(idx++, ca.getCmpcontrolName());
ps.setInt(idx++, ca.getDuplicateKey());
ps.setInt(idx++, ca.getDuplicateSubject());
ps.setInt(idx++, ca.getSaveReq());
ps.setInt(idx++, ca.getPermission());
Integer numCrls = ca.getNumCrls();
int tmpNumCrls = (numCrls == null) ? 30 : numCrls.intValue();
ps.setInt(idx++, tmpNumCrls);
ps.setInt(idx++, ca.getExpirationPeriod());
ps.setInt(idx++, ca.getKeepExpiredCertDays());
setBoolean(ps, idx++, ca.isRevoked());
setInt(ps, idx++, ca.getRevReason());
setLong(ps, idx++, ca.getRevTime());
setLong(ps, idx++, ca.getRevInvTime());
ps.setString(idx++, ca.getValidityMode());
ps.setString(idx++, ca.getExtraControl());
ps.setString(idx++, value(ca.getSignerConf()));
ps.executeUpdate();
} catch (SQLException ex) {
System.err.println("could not import CA with NAME=" + ca.getName());
throw translate(sql, ex);
} catch (CertificateException | IOException ex) {
System.err.println("could not import CA with NAME=" + ca.getName());
throw ex;
}
}
} finally {
releaseResources(ps, null);
}
System.out.println(" imported table CA");
}
Aggregations