Initializes this factory with a source of certificate authorities and
related trust material.

@param keyStore
The key store or null
@throws KeyStoreException
if the initialization fails.
5076
@Override
	protected void engineInit(KeyStore keyStore) throws KeyStoreException {
		try {
			this
					.engineInit(new CertPathTrustManagerParameters(
							new X509ProxyCertPathParameters(keyStore, null,
									null, false)));
		} catch (InvalidAlgorithmParameterException e) {
			throw new KeyStoreException(e);
		}
	}
458351
private void readTrustStore(Configuration conf) throws IOException, FormatNotUnderstoodException {
	if (((this.hocr.getSigTruststoreFile()!=null) && (!"".equals(this.hocr.getSigTruststoreFile())))) {
		LOG.info("Reading truststore to validate certificate chain for signatures");
		HadoopKeyStoreManager hksm = new HadoopKeyStoreManager(conf);
		try {
			hksm.openKeyStore(new Path(this.hocr.getSigTruststoreFile()), this.hocr.getSigTruststoreType(), this.hocr.getSigTruststorePassword());
			this.hocr.setX509CertificateChain(hksm.getAllX509Certificates());
		} catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IllegalArgumentException e) {
			LOG.error("Cannopt read truststore. Exception: ",e);
			throw new FormatNotUnderstoodException("Cannot read truststore to establish certificate chain for signature validation "+e);
		}
		
	}
}
72185
public static void loadX509Cert( File certFile, KeyStore keyStore ) throws GeneralSecurityException, IOException
    {
        try ( BufferedInputStream inputStream = new BufferedInputStream( new FileInputStream( certFile ) ) )
        {
            CertificateFactory certFactory = CertificateFactory.getInstance( "X.509" );

            int certCount = 0; // The file might contain multiple certs
            while ( inputStream.available() > 0 )
            {
                try
                {
                    Certificate cert = certFactory.generateCertificate( inputStream );
                    certCount++;
                    loadX509Cert( cert, "neo4j.javadriver.trustedcert." + certCount, keyStore );
                }
                catch ( CertificateException e )
                {
                    if ( e.getCause() != null && e.getCause().getMessage().equals( "Empty input" ) )
                    {
                        // This happens if there is whitespace at the end of the certificate - we load one cert, and then try and load a
                        // second cert, at which point we fail
                        return;
                    }
                    throw new IOException( "Failed to load certificate from `" + certFile.getAbsolutePath() + "`: " + certCount + " : " + e.getMessage(), e );
                }
            }
        }
    }
272252
public static KeyStore createTrustStore(final Reader certReader) throws IOException, CertificateException,
            KeyStoreException, NoSuchAlgorithmException {
        try (PEMParser pemParser = new PEMParser(certReader)) {

            KeyStore trustStore = KeyStore.getInstance("JKS");
            trustStore.load(null);

            int index = 1;
            Object pemCert;

            while ((pemCert = pemParser.readObject()) != null) {
                Certificate caCertificate = new JcaX509CertificateConverter()
                        .setProvider(BouncyCastleProvider.PROVIDER_NAME)
                        .getCertificate((X509CertificateHolder) pemCert);
                trustStore.setCertificateEntry("ca-" + index, caCertificate);
                index++;
            }

            return trustStore;
        }
    }
297142
public static KeyStore loadKeyStore(String keystoreType, @Nullable String keystorePassword, InputStream is)
            throws KeyStoreException {
        try {
            KeyStore keystore = KeyStore.getInstance(keystoreType);
            keystore.load(is, keystorePassword != null ? keystorePassword.toCharArray() : null);
            return keystore;
        } catch (IOException x) {
            throw new KeyStoreException(x);
        } catch (GeneralSecurityException x) {
            throw new KeyStoreException(x);
        } finally {
            try {
                is.close();
            } catch (IOException x) {
                // Ignored.
            }
        }
    }
1077956
public void validate( KeyStore keyStore ) throws CertificateException
{
    try
    {
        Enumeration<String> aliases = keyStore.aliases();
        
        for ( ; aliases.hasMoreElements(); )
        {
            String alias = aliases.nextElement();
            
            validate(keyStore,alias);
        }
        
    }
    catch ( KeyStoreException kse )
    {
        throw new CertificateException("Unable to retrieve aliases from keystore", kse);
    }
}
1114719
public void setCertificateAuthorities(java.util.Collection<CertificateAuthority> certificateAuthorities) {
        if (certificateAuthorities == null) {
            this.certificateAuthorities = null;
            return;
        }

        this.certificateAuthorities = new java.util.ArrayList<CertificateAuthority>(certificateAuthorities);
    }
791864
private TrustManager[] createTrustManagers() throws ClientSslSocketFactoryException {

    	final TrustManagerFactory factory;

    	try {
    		factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    		factory.init(this.trustStore);
    	} catch (NoSuchAlgorithmException e) {
    		throw new ClientSslSocketFactoryException(String.format("Failed to create the trust store because the algorithm %s is not supported. ",
    				KeyManagerFactory.getDefaultAlgorithm()), e);
    	} catch (KeyStoreException e) {
    		throw new ClientSslSocketFactoryException("KeyStore exception initializing trust manager factory; this is probably fatal", e);
    	}

    	final TrustManager[] managers = factory.getTrustManagers();

    	LOGGER.debug("TrustManagers are initialized. Total {} managers: ", managers.length);

    	return managers;

    }
771579
public void store(Path path, String keyStorePassword) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
		OutputStream os = this.fs.create(path, true);
		this.keystore.store(os,keyStorePassword.toCharArray());
		if (os!=null) {
			os.close();
		}
	}
631845
public String validate(KeyStore keyStore, String keyAlias) throws CertificateException {
        String result = null;
        if (keyAlias != null) {
            try {
                validate(keyStore, keyStore.getCertificate(keyAlias));
            } catch (KeyStoreException kse) {
                logger.debug("", kse);
                throw new CertificateException("Unable to validate certificate" +
                        " for alias [" + keyAlias + "]: " + kse.getMessage(), kse);
            }
            result = keyAlias;
        }
	return result;
    }
709042
public static KeyStore load(InputStream in, char[] password) {

        try {
            KeyStore myTrustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            myTrustStore.load(in, password);
            return myTrustStore;
        } catch (CertificateException | NoSuchAlgorithmException | KeyStoreException | IOException e) {
            throw new TrustManagerLoadFailedException(e);
        } finally {
            Closeables.closeQuietly(in);
        }
    }
65174
public void setCertificates(java.util.Collection<Certificate> certificates) {
        if (certificates == null) {
            this.certificates = null;
            return;
        }

        this.certificates = new com.amazonaws.internal.SdkInternalList<Certificate>(certificates);
    }
324940
public static TrustManager[] getTrustManagers() throws InitializationException {
		String file = System.getProperty("javax.net.ssl.trustStore");
		String pass = System.getProperty("javax.net.ssl.trustStorePassword");

		if (file == null || pass == null) {
			throw new InitializationException("javax.net.ssl.trustStore / "
					+ "javax.net.ssl.trustStorePassword not set");
		}

		return getTrustManagers(file, pass);
	}
292248
static KeyStore buildKeyStore(X509Certificate[] certChain, PrivateKey key, char[] keyPasswordChars)
            throws KeyStoreException, NoSuchAlgorithmException,
                   CertificateException, IOException {
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(null, null);
        ks.setKeyEntry(ALIAS, key, keyPasswordChars, certChain);
        return ks;
    }
488861
@Override
	public void engineSetKeyEntry(String s, Key key, char[] chars,
			Certificate[] certificates) throws KeyStoreException {

		if (!(key instanceof PrivateKey)) {
			throw new KeyStoreException("PrivateKey expected");
		}

		if (!(certificates instanceof X509Certificate[])) {
			throw new KeyStoreException(
					"Certificate chain of X509Certificate expected");
		}
		CredentialWrapper wrapper;
		X509Credential credential = new X509Credential((PrivateKey) key,
				(X509Certificate[]) certificates);
		if (credential.isEncryptedKey()) {
			wrapper = createCertKeyCredential(s, credential);
		} else {
			wrapper = createProxyCredential(s, credential);
		}
		storeWrapper(wrapper);
		this.aliasObjectMap.put(wrapper.getAlias(), wrapper);
	}
33797
public void setCertificateStatuses(java.util.Collection<String> certificateStatuses) {
        if (certificateStatuses == null) {
            this.certificateStatuses = null;
            return;
        }

        this.certificateStatuses = new java.util.ArrayList<String>(certificateStatuses);
    }
243507
@Override
    public void start(StartContext context) throws StartException {
        try {
            theTrustManagers = createTrustManagers();
        } catch (NoSuchAlgorithmException e) {
            throw DomainManagementLogger.ROOT_LOGGER.unableToStart(e);
        } catch (KeyStoreException e) {
            throw DomainManagementLogger.ROOT_LOGGER.unableToStart(e);
        }
    }