use of org.neo4j.bolt.security.ssl.KeyStoreFactory in project neo4j by neo4j.
the class BoltKernelExtension method createKeyStore.
private KeyStoreInformation createKeyStore(Configuration config, Log log, AdvertisedSocketAddress address) throws GeneralSecurityException, IOException, OperatorCreationException {
File privateKeyPath = config.get(Settings.tls_key_file).getAbsoluteFile();
File certificatePath = config.get(Settings.tls_certificate_file).getAbsoluteFile();
if (!certificatePath.exists() && !privateKeyPath.exists()) {
log.info("No SSL certificate found, generating a self-signed certificate..");
Certificates certFactory = new Certificates();
certFactory.createSelfSignedCertificate(certificatePath, privateKeyPath, address.getHostname());
}
if (!certificatePath.exists()) {
throw new IllegalStateException(format("TLS private key found, but missing certificate at '%s'. Cannot start server without " + "certificate.", certificatePath));
}
if (!privateKeyPath.exists()) {
throw new IllegalStateException(format("TLS certificate found, but missing key at '%s'. Cannot start server without key.", privateKeyPath));
}
return new KeyStoreFactory().createKeyStore(privateKeyPath, certificatePath);
}
use of org.neo4j.bolt.security.ssl.KeyStoreFactory in project neo4j by neo4j.
the class AbstractNeoServer method createKeyStore.
protected Optional<KeyStoreInformation> createKeyStore() {
if (httpsIsEnabled()) {
File privateKeyPath = config.get(ServerSettings.tls_key_file).getAbsoluteFile();
File certificatePath = config.get(ServerSettings.tls_certificate_file).getAbsoluteFile();
try {
// If neither file is specified
if (!certificatePath.exists() && !privateKeyPath.exists()) {
//noinspection deprecation
log.info("No SSL certificate found, generating a self-signed certificate..");
Certificates certFactory = new Certificates();
certFactory.createSelfSignedCertificate(certificatePath, privateKeyPath, httpListenAddress.getHostname());
}
// Make sure both files were there, or were generated
if (!certificatePath.exists()) {
throw new ServerStartupException(String.format("TLS private key found, but missing certificate at '%s'. Cannot start server " + "without certificate.", certificatePath));
}
if (!privateKeyPath.exists()) {
throw new ServerStartupException(String.format("TLS certificate found, but missing key at '%s'. Cannot start server without key.", privateKeyPath));
}
return Optional.of(new KeyStoreFactory().createKeyStore(privateKeyPath, certificatePath));
} catch (GeneralSecurityException e) {
throw new ServerStartupException("TLS certificate error occurred, unable to start server: " + e.getMessage(), e);
} catch (IOException | OperatorCreationException e) {
throw new ServerStartupException("IO problem while loading or creating TLS certificates: " + e.getMessage(), e);
}
} else {
return Optional.empty();
}
}
Aggregations