Search in sources :

Example 6 with CaType

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");
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) CertificateException(java.security.cert.CertificateException) CaType(org.xipki.ca.dbtool.jaxb.ca.CaType) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

CaType (org.xipki.ca.dbtool.jaxb.ca.CaType)6 SQLException (java.sql.SQLException)4 CertificateException (java.security.cert.CertificateException)3 LinkedList (java.util.LinkedList)3 IOException (java.io.IOException)2 PreparedStatement (java.sql.PreparedStatement)2 File (java.io.File)1 X509Certificate (java.security.cert.X509Certificate)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ZipFile (java.util.zip.ZipFile)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Certificate (org.bouncycastle.asn1.x509.Certificate)1 TBSCertificate (org.bouncycastle.asn1.x509.TBSCertificate)1 CAConfigurationType (org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType)1 Cas (org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType.Cas)1 CaHasPublisherType (org.xipki.ca.dbtool.jaxb.ca.CaHasPublisherType)1