|
|
|
@ -16,31 +16,16 @@
@@ -16,31 +16,16 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.cloud.gateway.config; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.security.KeyStore; |
|
|
|
|
import java.security.KeyStoreException; |
|
|
|
|
import java.security.NoSuchProviderException; |
|
|
|
|
import java.security.cert.Certificate; |
|
|
|
|
import java.security.cert.CertificateException; |
|
|
|
|
import java.security.cert.CertificateFactory; |
|
|
|
|
import java.security.cert.X509Certificate; |
|
|
|
|
import java.time.Duration; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import javax.net.ssl.KeyManagerFactory; |
|
|
|
|
|
|
|
|
|
import jakarta.validation.constraints.Max; |
|
|
|
|
import reactor.netty.resources.ConnectionProvider; |
|
|
|
|
import reactor.netty.tcp.SslProvider; |
|
|
|
|
import reactor.netty.transport.ProxyProvider; |
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
|
|
|
|
import org.springframework.boot.web.server.WebServerException; |
|
|
|
|
import org.springframework.core.style.ToStringCreator; |
|
|
|
|
import org.springframework.util.ResourceUtils; |
|
|
|
|
import org.springframework.util.unit.DataSize; |
|
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
|
@ -416,10 +401,6 @@ public class HttpClientProperties {
@@ -416,10 +401,6 @@ public class HttpClientProperties {
|
|
|
|
|
/** SSL close_notify read timeout. Default to 0 ms. */ |
|
|
|
|
private Duration closeNotifyReadTimeout = Duration.ZERO; |
|
|
|
|
|
|
|
|
|
/** The default ssl configuration type. Defaults to TCP. */ |
|
|
|
|
@Deprecated |
|
|
|
|
private SslProvider.DefaultConfigurationType defaultConfigurationType = SslProvider.DefaultConfigurationType.TCP; |
|
|
|
|
|
|
|
|
|
/** Keystore path for Netty HttpClient. */ |
|
|
|
|
private String keyStore; |
|
|
|
|
|
|
|
|
@ -483,77 +464,6 @@ public class HttpClientProperties {
@@ -483,77 +464,6 @@ public class HttpClientProperties {
|
|
|
|
|
this.trustedX509Certificates = trustedX509; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
public X509Certificate[] getTrustedX509CertificatesForTrustManager() { |
|
|
|
|
try { |
|
|
|
|
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); |
|
|
|
|
ArrayList<Certificate> allCerts = new ArrayList<>(); |
|
|
|
|
for (String trustedCert : getTrustedX509Certificates()) { |
|
|
|
|
try { |
|
|
|
|
URL url = ResourceUtils.getURL(trustedCert); |
|
|
|
|
Collection<? extends Certificate> certs = certificateFactory |
|
|
|
|
.generateCertificates(url.openStream()); |
|
|
|
|
allCerts.addAll(certs); |
|
|
|
|
} |
|
|
|
|
catch (IOException e) { |
|
|
|
|
throw new WebServerException("Could not load certificate '" + trustedCert + "'", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return allCerts.toArray(new X509Certificate[allCerts.size()]); |
|
|
|
|
} |
|
|
|
|
catch (CertificateException e1) { |
|
|
|
|
throw new WebServerException("Could not load CertificateFactory X.509", e1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
public KeyManagerFactory getKeyManagerFactory() { |
|
|
|
|
try { |
|
|
|
|
if (getKeyStore() != null && getKeyStore().length() > 0) { |
|
|
|
|
KeyManagerFactory keyManagerFactory = KeyManagerFactory |
|
|
|
|
.getInstance(KeyManagerFactory.getDefaultAlgorithm()); |
|
|
|
|
char[] keyPassword = getKeyPassword() != null ? getKeyPassword().toCharArray() : null; |
|
|
|
|
|
|
|
|
|
if (keyPassword == null && getKeyStorePassword() != null) { |
|
|
|
|
keyPassword = getKeyStorePassword().toCharArray(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
keyManagerFactory.init(this.createKeyStore(), keyPassword); |
|
|
|
|
|
|
|
|
|
return keyManagerFactory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
catch (Exception e) { |
|
|
|
|
throw new IllegalStateException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
public KeyStore createKeyStore() { |
|
|
|
|
try { |
|
|
|
|
KeyStore store = getKeyStoreProvider() != null |
|
|
|
|
? KeyStore.getInstance(getKeyStoreType(), getKeyStoreProvider()) |
|
|
|
|
: KeyStore.getInstance(getKeyStoreType()); |
|
|
|
|
try { |
|
|
|
|
URL url = ResourceUtils.getURL(getKeyStore()); |
|
|
|
|
store.load(url.openStream(), |
|
|
|
|
getKeyStorePassword() != null ? getKeyStorePassword().toCharArray() : null); |
|
|
|
|
} |
|
|
|
|
catch (Exception e) { |
|
|
|
|
throw new WebServerException("Could not load key store ' " + getKeyStore() + "'", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return store; |
|
|
|
|
} |
|
|
|
|
catch (KeyStoreException | NoSuchProviderException e) { |
|
|
|
|
throw new WebServerException("Could not load KeyStore for given type and provider", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: support configuration of other trust manager factories
|
|
|
|
|
|
|
|
|
|
public boolean isUseInsecureTrustManager() { |
|
|
|
|
return useInsecureTrustManager; |
|
|
|
|
} |
|
|
|
@ -586,24 +496,13 @@ public class HttpClientProperties {
@@ -586,24 +496,13 @@ public class HttpClientProperties {
|
|
|
|
|
this.closeNotifyReadTimeout = closeNotifyReadTimeout; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
public SslProvider.DefaultConfigurationType getDefaultConfigurationType() { |
|
|
|
|
return defaultConfigurationType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
public void setDefaultConfigurationType(SslProvider.DefaultConfigurationType defaultConfigurationType) { |
|
|
|
|
this.defaultConfigurationType = defaultConfigurationType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String toString() { |
|
|
|
|
return new ToStringCreator(this).append("useInsecureTrustManager", useInsecureTrustManager) |
|
|
|
|
.append("trustedX509Certificates", trustedX509Certificates) |
|
|
|
|
.append("handshakeTimeout", handshakeTimeout) |
|
|
|
|
.append("closeNotifyFlushTimeout", closeNotifyFlushTimeout) |
|
|
|
|
.append("closeNotifyReadTimeout", closeNotifyReadTimeout) |
|
|
|
|
.append("defaultConfigurationType", defaultConfigurationType).toString(); |
|
|
|
|
.append("closeNotifyReadTimeout", closeNotifyReadTimeout).toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|