|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -31,6 +31,7 @@ import reactor.netty.tcp.SslProvider;
|
|
|
|
|
import org.springframework.boot.web.server.Http2;
|
|
|
|
|
import org.springframework.boot.web.server.Ssl;
|
|
|
|
|
import org.springframework.boot.web.server.SslStoreProvider;
|
|
|
|
|
import org.springframework.boot.web.server.WebServerException;
|
|
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -38,6 +39,7 @@ import org.springframework.util.ResourceUtils;
|
|
|
|
|
* instance.
|
|
|
|
|
*
|
|
|
|
|
* @author Brian Clozel
|
|
|
|
|
* @author Raheela Aslam
|
|
|
|
|
*/
|
|
|
|
|
public class SslServerCustomizer implements NettyServerCustomizer {
|
|
|
|
|
|
|
|
|
@ -135,21 +137,42 @@ public class SslServerCustomizer implements NettyServerCustomizer {
|
|
|
|
|
if (sslStoreProvider != null) {
|
|
|
|
|
return sslStoreProvider.getTrustStore();
|
|
|
|
|
}
|
|
|
|
|
return loadKeyStore(ssl.getTrustStoreType(), ssl.getTrustStoreProvider(),
|
|
|
|
|
return loadTrustStore(ssl.getTrustStoreType(), ssl.getTrustStoreProvider(),
|
|
|
|
|
ssl.getTrustStore(), ssl.getTrustStorePassword());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private KeyStore loadKeyStore(String type, String provider, String resource,
|
|
|
|
|
String password) throws Exception {
|
|
|
|
|
type = (type != null) ? type : "JKS";
|
|
|
|
|
|
|
|
|
|
return loadStore(type, provider, resource, password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private KeyStore loadTrustStore(String type, String provider, String resource,
|
|
|
|
|
String password) throws Exception {
|
|
|
|
|
if (resource == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return loadStore(type, provider, resource, password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private KeyStore loadStore(String type, String provider, String resource,
|
|
|
|
|
String password) throws Exception {
|
|
|
|
|
type = (type != null) ? type : "JKS";
|
|
|
|
|
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider)
|
|
|
|
|
: KeyStore.getInstance(type);
|
|
|
|
|
try {
|
|
|
|
|
URL url = ResourceUtils.getURL(resource);
|
|
|
|
|
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
|
|
|
|
|
store.load(url.openStream(),
|
|
|
|
|
(password != null) ? password.toCharArray() : null);
|
|
|
|
|
return store;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
throw new WebServerException("Could not load key store '" + resource + "'",
|
|
|
|
|
ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|