Search in sources :

Example 1 with PDConfiguredTrustStore

use of com.helger.pd.indexer.settings.PDConfiguredTrustStore in project phoss-directory by phax.

the class ClientCertificateValidator method _initCerts.

private static void _initCerts() {
    LOGGER.info("Initializing all trusted root certificates");
    final ICommonsList<PDConfiguredTrustStore> aAllTrustStores = PDServerConfiguration.getAllTrustStores();
    LOGGER.info("Scanning " + aAllTrustStores.size() + " trust stores");
    // Get data from config file
    for (final PDConfiguredTrustStore aTS : aAllTrustStores) {
        X509Certificate aCert;
        try {
            final KeyStore aKS = KeyStoreHelper.loadKeyStoreDirect(aTS.getType(), aTS.getPath(), aTS.getPassword());
            aCert = (X509Certificate) aKS.getCertificate(aTS.getAlias());
        } catch (final Exception ex) {
            final String sMsg = "Failed to read trust store from '" + aTS.getPath() + "'";
            LOGGER.error(sMsg);
            throw new InitializationException(sMsg, ex);
        }
        // Check if both root certificates could be loaded
        if (aCert == null) {
            final String sMsg = "Failed to resolve alias '" + aTS.getAlias() + "' in trust store '" + aTS.getPath() + "'!";
            LOGGER.error(sMsg);
            throw new InitializationException(sMsg);
        }
        ALLOWED_ROOT_CERTS.add(aCert);
        LOGGER.info("Root certificate loaded successfully from trust store '" + aTS.getPath() + "' with alias '" + aTS.getAlias() + "'; root certificate serial=" + aCert.getSerialNumber().toString(16) + "; root certficate issuer=" + aCert.getIssuerX500Principal().getName());
    }
    if (ALLOWED_ROOT_CERTS.isEmpty()) {
        final String sMsg = "Server configuration contains no trusted root certificate configuration.";
        if (_isCheckDisabled())
            LOGGER.warn(sMsg + " Continuing anyway.");
        else {
            LOGGER.error(sMsg);
            throw new InitializationException(sMsg);
        }
    }
}
Also used : InitializationException(com.helger.commons.exception.InitializationException) KeyStore(java.security.KeyStore) PDConfiguredTrustStore(com.helger.pd.indexer.settings.PDConfiguredTrustStore) X509Certificate(java.security.cert.X509Certificate) InitializationException(com.helger.commons.exception.InitializationException)

Aggregations

InitializationException (com.helger.commons.exception.InitializationException)1 PDConfiguredTrustStore (com.helger.pd.indexer.settings.PDConfiguredTrustStore)1 KeyStore (java.security.KeyStore)1 X509Certificate (java.security.cert.X509Certificate)1