SslContextFactory Class — spring-boot Architecture
Architecture documentation for the SslContextFactory class in SslContextFactory.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ssl/SslContextFactory.java lines 39–97
public class SslContextFactory {
private static final char[] NO_PASSWORD = {};
private static final String KEY_STORE_ALIAS = "spring-boot-docker";
public SslContextFactory() {
}
/**
* Create an {@link SSLContext} from files in the specified directory. The directory
* must contain files with the names 'key.pem', 'cert.pem', and 'ca.pem'.
* @param directory the path to a directory containing certificate and key files
* @return the {@code SSLContext}
*/
public SSLContext forDirectory(String directory) {
try {
Path keyPath = Paths.get(directory, "key.pem");
Path certPath = Paths.get(directory, "cert.pem");
Path caPath = Paths.get(directory, "ca.pem");
Path caKeyPath = Paths.get(directory, "ca-key.pem");
verifyCertificateFiles(keyPath, certPath, caPath);
KeyManagerFactory keyManagerFactory = getKeyManagerFactory(keyPath, certPath);
TrustManagerFactory trustManagerFactory = getTrustManagerFactory(caPath, caKeyPath);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
return sslContext;
}
catch (RuntimeException ex) {
throw ex;
}
catch (Exception ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
private KeyManagerFactory getKeyManagerFactory(Path keyPath, Path certPath) throws Exception {
KeyStore store = KeyStoreFactory.create(certPath, keyPath, KEY_STORE_ALIAS);
KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
factory.init(store, NO_PASSWORD);
return factory;
}
private TrustManagerFactory getTrustManagerFactory(Path caPath, Path caKeyPath)
throws NoSuchAlgorithmException, KeyStoreException {
KeyStore store = KeyStoreFactory.create(caPath, caKeyPath, KEY_STORE_ALIAS);
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init(store);
return factory;
}
private static void verifyCertificateFiles(Path... paths) {
for (Path path : paths) {
Assert.state(Files.exists(path) && Files.isRegularFile(path),
"Certificate path must contain the files 'ca.pem', 'cert.pem', and 'key.pem' files");
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free