Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use empty keystore for outbound calls #3273

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public BeanPostProcessor routingFilterHandler(HttpClient httpClient, ObjectProvi
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if ("routingFilter".equals(beanName)) {
log.debug("Updating routing bean {}", NettyRoutingFilterApiml.class);
// once is creating original bean by autoconfiguration replace it with custom implementation
return new NettyRoutingFilterApiml(httpClient, headersFiltersProvider, properties, justTruststore, withKeystore);
}
Expand All @@ -212,11 +213,16 @@ SslContext sslContext(boolean setKeystore) {
trustManagerFactory.init(trustStore);
builder.trustManager(trustManagerFactory);

KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
if (setKeystore) {
KeyStore keyStore = SecurityUtils.loadKeyStore(keyStoreType, keyStorePath, keyStorePassword);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStorePassword);
builder.keyManager(keyManagerFactory);
} else {
KeyStore emptyKeystore = KeyStore.getInstance(KeyStore.getDefaultType());
emptyKeystore.load(null, null);
keyManagerFactory.init(emptyKeystore, null);
builder.keyManager(keyManagerFactory);
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import io.netty.channel.ChannelOption;
import io.netty.handler.ssl.SslContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.gateway.config.HttpClientProperties;
import org.springframework.cloud.gateway.filter.NettyRoutingFilter;
Expand All @@ -26,6 +27,7 @@
import static org.springframework.cloud.gateway.support.RouteMetadataUtils.CONNECT_TIMEOUT_ATTR;
import static org.zowe.apiml.constants.ApimlConstants.HTTP_CLIENT_USE_CLIENT_CERTIFICATE;

@Slf4j
public class NettyRoutingFilterApiml extends NettyRoutingFilter {

private final HttpClient httpClientNoCert;
Expand All @@ -49,8 +51,7 @@ static Integer getInteger(Object connectTimeoutAttr) {
Integer connectTimeout;
if (connectTimeoutAttr instanceof Integer) {
connectTimeout = (Integer) connectTimeoutAttr;
}
else {
} else {
connectTimeout = Integer.parseInt(connectTimeoutAttr.toString());
}
return connectTimeout;
Expand All @@ -62,6 +63,7 @@ protected HttpClient getHttpClient(Route route, ServerWebExchange exchange) {
boolean useClientCert = Optional.ofNullable((Boolean) exchange.getAttribute(HTTP_CLIENT_USE_CLIENT_CERTIFICATE)).orElse(Boolean.FALSE);
HttpClient httpClient = useClientCert ? httpClientClientCert : httpClientNoCert;

log.debug("Using client with keystore {}", useClientCert);
Object connectTimeoutAttr = route.getMetadata().get(CONNECT_TIMEOUT_ATTR);
if (connectTimeoutAttr != null) {
// if there is configured timeout, respect it
Expand Down
Loading