Skip to content

Commit 84009f2

Browse files
dimitarpDimitar Popov
andauthored
Ssl bundles not working because of wrong condition (#3641)
* Add test for ssl bundle configuration * Fix support of ssl bundles --------- Co-authored-by: Dimitar Popov <dimitar.popov@seitenbau.com>
1 parent 5aee84c commit 84009f2

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/AbstractSslConfigurer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ protected HttpClientProperties.Ssl getSslProperties() {
6767
}
6868

6969
protected SslBundle getBundle() {
70-
if (ssl.getSslBundle() == null || ssl.getSslBundle().length() > 0) {
71-
return null;
72-
}
73-
if (bundles.getBundleNames().contains(ssl.getSslBundle())) {
70+
if (ssl.getSslBundle() != null && ssl.getSslBundle().length() > 0 && bundles.getBundleNames().contains(ssl.getSslBundle())) {
7471
return bundles.getBundle(ssl.getSslBundle());
7572
}
7673
return null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.springframework.cloud.gateway.test.ssl;
2+
3+
import io.netty.handler.ssl.SslContextBuilder;
4+
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.ssl.SslBundles;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
10+
import org.springframework.test.annotation.DirtiesContext;
11+
import org.springframework.test.context.ActiveProfiles;
12+
import reactor.netty.http.client.HttpClient;
13+
14+
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
15+
16+
@SpringBootTest(webEnvironment = RANDOM_PORT)
17+
@DirtiesContext
18+
@ActiveProfiles("client-auth-ssl-bundle")
19+
public class ClientCertAuthSSLBundleTests extends SingleCertSSLTests {
20+
@Autowired
21+
private SslBundles sslBundles;
22+
23+
@BeforeEach
24+
public void setup() throws Exception {
25+
final var sslBundle = sslBundles.getBundle("scg-keystore-with-different-key-password");
26+
final var sslContext = SslContextBuilder.forClient()
27+
.trustManager(InsecureTrustManagerFactory.INSTANCE)
28+
.keyManager(sslBundle.getManagers().getKeyManagerFactory())
29+
.build();
30+
HttpClient httpClient = HttpClient.create().secure(ssl -> ssl.sslContext(sslContext));
31+
setup(new ReactorClientHttpConnector(httpClient), "https://localhost:" + port);
32+
}
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
test:
2+
uri: lb:https://testservice
3+
4+
server:
5+
ssl:
6+
enabled: true
7+
key-alias: scg
8+
key-store-password: scg1234
9+
key-password: keyscg1234
10+
key-store: classpath:scg-keystore-with-different-key-password.jks
11+
trust-store: classpath:scg-truststore.jks
12+
trust-store-password: scg1234
13+
trust-store-type: JKS
14+
key-store-type: JKS
15+
client-auth: Need
16+
spring:
17+
cloud:
18+
gateway:
19+
httpclient:
20+
ssl:
21+
ssl-bundle: scg-keystore-with-different-key-password
22+
trustedX509Certificates:
23+
- src/test/resources/single-cert-for-different-key-password.pem
24+
default-filters:
25+
- PrefixPath=/httpbin
26+
routes:
27+
- id: default_path_to_httpbin
28+
uri: ${test.uri}
29+
order: 10000
30+
predicates:
31+
- name: Path
32+
args:
33+
pattern: /**
34+
ssl:
35+
bundle:
36+
jks:
37+
scg-keystore-with-different-key-password:
38+
key:
39+
password: keyscg1234
40+
keystore:
41+
type: JKS
42+
location: classpath:scg-keystore-with-different-key-password.jks
43+
password: scg1234

0 commit comments

Comments
 (0)