Search in sources :

Example 1 with ProfileType

use of org.xipki.ca.dbtool.jaxb.ca.ProfileType in project xipki by xipki.

the class CaConfigurationDbImporter method importProfile.

// method importPublisher
private void importProfile(Profiles profiles) throws DataAccessException, IOException {
    System.out.println("importing table PROFILE");
    final String sql = "INSERT INTO PROFILE (ID,NAME,ART,TYPE,CONF) VALUES (?,?,?,?,?)";
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        for (ProfileType certprofile : profiles.getProfile()) {
            try {
                int idx = 1;
                ps.setInt(idx++, certprofile.getId());
                ps.setString(idx++, certprofile.getName());
                int art = (certprofile.getArt() == null) ? 1 : certprofile.getArt();
                ps.setInt(idx++, art);
                ps.setString(idx++, certprofile.getType());
                String conf = value(certprofile.getConf());
                ps.setString(idx++, conf);
                ps.executeUpdate();
            } catch (SQLException ex) {
                System.err.println("could not import PROFILE with NAME=" + certprofile.getName());
                throw translate(sql, ex);
            } catch (IOException ex) {
                System.err.println("could not import PROFILE with NAME=" + certprofile.getName());
                throw ex;
            }
        }
    } finally {
        releaseResources(ps, null);
    }
    System.out.println(" imported table PROFILE");
}
Also used : ProfileType(org.xipki.ca.dbtool.jaxb.ca.ProfileType) CaHasProfileType(org.xipki.ca.dbtool.jaxb.ca.CaHasProfileType) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 2 with ProfileType

use of org.xipki.ca.dbtool.jaxb.ca.ProfileType in project xipki by xipki.

the class CaConfigurationDbExporter method exportProfile.

// method exportPublisher
private void exportProfile(CAConfigurationType caconf) throws DataAccessException, IOException {
    System.out.println("exporting table PROFILE");
    Profiles profiles = new Profiles();
    final String sql = "SELECT ID,NAME,ART,TYPE,CONF FROM PROFILE";
    Statement stmt = null;
    ResultSet rs = null;
    try {
        stmt = createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            String name = rs.getString("NAME");
            ProfileType profile = new ProfileType();
            profile.setId(rs.getInt("ID"));
            profile.setName(name);
            profile.setArt(rs.getInt("ART"));
            profile.setType(rs.getString("TYPE"));
            profile.setConf(buildFileOrValue(rs.getString("CONF"), "ca-conf/certprofile-" + name));
            profiles.getProfile().add(profile);
        }
    } catch (SQLException ex) {
        throw translate(sql, ex);
    } finally {
        releaseResources(stmt, rs);
    }
    caconf.setProfiles(profiles);
    System.out.println(" exported table PROFILE");
}
Also used : ProfileType(org.xipki.ca.dbtool.jaxb.ca.ProfileType) CaHasProfileType(org.xipki.ca.dbtool.jaxb.ca.CaHasProfileType) SQLException(java.sql.SQLException) Statement(java.sql.Statement) CaHasProfiles(org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType.CaHasProfiles) Profiles(org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType.Profiles) ResultSet(java.sql.ResultSet)

Example 3 with ProfileType

use of org.xipki.ca.dbtool.jaxb.ca.ProfileType in project xipki by xipki.

the class OcspCertStoreFromCaDbImporter method importToDb.

public void importToDb() throws Exception {
    CertStoreType certstore;
    try {
        @SuppressWarnings("unchecked") JAXBElement<CertStoreType> root = (JAXBElement<CertStoreType>) unmarshaller.unmarshal(new File(baseDir, FILENAME_CA_CERTSTORE));
        certstore = root.getValue();
    } catch (JAXBException ex) {
        throw XmlUtil.convert(ex);
    }
    if (certstore.getVersion() > VERSION) {
        throw new InvalidInputException("could not import CertStore greater than " + VERSION + ": " + certstore.getVersion());
    }
    CAConfigurationType caConf;
    try {
        File file = new File(baseDir + File.separator + FILENAME_CA_CONFIGURATION);
        @SuppressWarnings("unchecked") JAXBElement<CAConfigurationType> rootCaConf = (JAXBElement<CAConfigurationType>) unmarshaller.unmarshal(file);
        caConf = rootCaConf.getValue();
    } catch (JAXBException ex) {
        throw XmlUtil.convert(ex);
    }
    if (caConf.getVersion() > VERSION) {
        throw new InvalidInputException("could not import CA Configuration greater than " + VERSION + ": " + certstore.getVersion());
    }
    System.out.println("importing CA certstore to OCSP database");
    try {
        if (!resume) {
            dropIndexes();
        }
        PublisherType publisherType = null;
        for (PublisherType type : caConf.getPublishers().getPublisher()) {
            if (publisherName.equals(type.getName())) {
                publisherType = type;
                break;
            }
        }
        if (publisherType == null) {
            throw new InvalidInputException("unknown publisher " + publisherName);
        }
        String type = publisherType.getType();
        if (!"ocsp".equalsIgnoreCase(type)) {
            throw new InvalidInputException("Unkwown publisher type " + type);
        }
        ConfPairs confPairs = new ConfPairs(value(publisherType.getConf()));
        String str = confPairs.value("publish.goodcerts");
        boolean revokedOnly = false;
        if (str != null) {
            revokedOnly = !Boolean.parseBoolean(str);
        }
        Set<Integer> relatedCaIds = new HashSet<>();
        for (CaHasPublisherType ctype : caConf.getCaHasPublishers().getCaHasPublisher()) {
            if (ctype.getPublisherId() == publisherType.getId()) {
                relatedCaIds.add(ctype.getCaId());
            }
        }
        List<CaType> relatedCas = new LinkedList<>();
        for (CaType m : caConf.getCas().getCa()) {
            if (relatedCaIds.contains(m.getId())) {
                relatedCas.add(m);
            }
        }
        if (relatedCas.isEmpty()) {
            System.out.println("No CA has publisher " + publisherName);
            return;
        }
        Map<Integer, String> profileMap = new HashMap<Integer, String>();
        for (ProfileType ni : caConf.getProfiles().getProfile()) {
            profileMap.put(ni.getId(), ni.getName());
        }
        List<Integer> relatedCertStoreCaIds = resume ? getIssuerIds(relatedCas) : importIssuer(relatedCas);
        File processLogFile = new File(baseDir, DbPorter.IMPORT_TO_OCSP_PROCESS_LOG_FILENAME);
        importCert(certstore, profileMap, revokedOnly, relatedCertStoreCaIds, processLogFile);
        recoverIndexes();
        processLogFile.delete();
    } catch (Exception ex) {
        System.err.println("could not import OCSP certstore to database");
        throw ex;
    }
    System.out.println(" imported OCSP certstore to database");
}
Also used : CaHasPublisherType(org.xipki.ca.dbtool.jaxb.ca.CaHasPublisherType) PublisherType(org.xipki.ca.dbtool.jaxb.ca.PublisherType) HashMap(java.util.HashMap) CaType(org.xipki.ca.dbtool.jaxb.ca.CaType) CertStoreType(org.xipki.ca.dbtool.jaxb.ca.CertStoreType) HashSet(java.util.HashSet) CAConfigurationType(org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType) InvalidInputException(org.xipki.dbtool.InvalidInputException) ProfileType(org.xipki.ca.dbtool.jaxb.ca.ProfileType) JAXBException(javax.xml.bind.JAXBException) ConfPairs(org.xipki.common.ConfPairs) JAXBElement(javax.xml.bind.JAXBElement) LinkedList(java.util.LinkedList) InvalidInputException(org.xipki.dbtool.InvalidInputException) SQLException(java.sql.SQLException) DataAccessException(org.xipki.datasource.DataAccessException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) JAXBException(javax.xml.bind.JAXBException) CaHasPublisherType(org.xipki.ca.dbtool.jaxb.ca.CaHasPublisherType) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

SQLException (java.sql.SQLException)3 ProfileType (org.xipki.ca.dbtool.jaxb.ca.ProfileType)3 IOException (java.io.IOException)2 CaHasProfileType (org.xipki.ca.dbtool.jaxb.ca.CaHasProfileType)2 File (java.io.File)1 CertificateException (java.security.cert.CertificateException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 ZipFile (java.util.zip.ZipFile)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 CAConfigurationType (org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType)1 CaHasProfiles (org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType.CaHasProfiles)1 Profiles (org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType.Profiles)1 CaHasPublisherType (org.xipki.ca.dbtool.jaxb.ca.CaHasPublisherType)1 CaType (org.xipki.ca.dbtool.jaxb.ca.CaType)1