Skip to content

Add keyStoreAlgorithm and trustStoreAlgorithm configuration option to configure RabbitConnectionFactory #24076

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -140,9 +140,11 @@ private RabbitConnectionFactoryBean getRabbitConnectionFactoryBean(RabbitPropert
map.from(ssl::getKeyStoreType).to(factory::setKeyStoreType);
map.from(ssl::getKeyStore).to(factory::setKeyStore);
map.from(ssl::getKeyStorePassword).to(factory::setKeyStorePassphrase);
map.from(ssl::getKeyStoreAlgorithm).whenNonNull().to(factory::setKeyStoreAlgorithm);
map.from(ssl::getTrustStoreType).to(factory::setTrustStoreType);
map.from(ssl::getTrustStore).to(factory::setTrustStore);
map.from(ssl::getTrustStorePassword).to(factory::setTrustStorePassphrase);
map.from(ssl::getTrustStoreAlgorithm).whenNonNull().to(factory::setTrustStoreAlgorithm);
map.from(ssl::isValidateServerCertificate)
.to((validate) -> factory.setSkipServerCertificateValidation(!validate));
map.from(ssl::getVerifyHostname).to(factory::setEnableHostnameVerification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ public Template getTemplate() {

public class Ssl {

private static final String SUN_X509 = "SunX509";

/**
* Whether to enable SSL support. Determined automatically if an address is
* provided with the protocol (amqp:// vs. amqps://).
Expand All @@ -384,6 +386,11 @@ public class Ssl {
*/
private String keyStorePassword;

/**
* Key store algorithm.
*/
private String keyStoreAlgorithm = SUN_X509;

/**
* Trust store that holds SSL certificates.
*/
Expand All @@ -399,6 +406,11 @@ public class Ssl {
*/
private String trustStorePassword;

/**
* Trust store algorithm.
*/
private String trustStoreAlgorithm = SUN_X509;

/**
* SSL algorithm to use. By default, configured by the Rabbit client library.
*/
Expand Down Expand Up @@ -462,6 +474,14 @@ public void setKeyStorePassword(String keyStorePassword) {
this.keyStorePassword = keyStorePassword;
}

public String getKeyStoreAlgorithm() {
return this.keyStoreAlgorithm;
}

public void setKeyStoreAlgorithm(String keyStoreAlgorithm) {
this.keyStoreAlgorithm = keyStoreAlgorithm;
}

public String getTrustStore() {
return this.trustStore;
}
Expand All @@ -486,6 +506,14 @@ public void setTrustStorePassword(String trustStorePassword) {
this.trustStorePassword = trustStorePassword;
}

public String getTrustStoreAlgorithm() {
return this.trustStoreAlgorithm;
}

public void setTrustStoreAlgorithm(String trustStoreAlgorithm) {
this.trustStoreAlgorithm = trustStoreAlgorithm;
}

public String getAlgorithm() {
return this.algorithm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,36 @@ void enableSslWithValidateServerCertificateDefault() throws Exception {
});
}

@Test
void enableSslWithValidStoreAlgorithmShouldWork() throws Exception {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.rabbitmq.ssl.enabled:true",
"spring.rabbitmq.ssl.keyStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
"spring.rabbitmq.ssl.keyStoreType=jks", "spring.rabbitmq.ssl.keyStorePassword=secret",
"spring.rabbitmq.ssl.keyStoreAlgorithm=PKIX",
"spring.rabbitmq.ssl.trustStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
"spring.rabbitmq.ssl.trustStoreType=jks", "spring.rabbitmq.ssl.trustStorePassword=secret",
"spring.rabbitmq.ssl.trustStoreAlgorithm=PKIX")
.run((context) -> assertThat(context).hasNotFailed());
}

@Test
void enableSslWithInvalidStoreAlgorithmShouldFail() throws Exception {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.rabbitmq.ssl.enabled:true",
"spring.rabbitmq.ssl.keyStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
"spring.rabbitmq.ssl.keyStoreType=jks", "spring.rabbitmq.ssl.keyStorePassword=secret",
"spring.rabbitmq.ssl.keyStoreAlgorithm=foo",
"spring.rabbitmq.ssl.trustStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
"spring.rabbitmq.ssl.trustStoreType=jks", "spring.rabbitmq.ssl.trustStorePassword=secret",
"spring.rabbitmq.ssl.trustStoreAlgorithm=foo")
.run((context) -> {
assertThat(context).hasFailed();
assertThat(context).getFailure().hasMessageContaining("foo");
assertThat(context).getFailure().hasRootCauseInstanceOf(NoSuchAlgorithmException.class);
});
}

@Test
void whenACredentialsProviderIsAvailableThenConnectionFactoryIsConfiguredToUseIt() throws Exception {
this.contextRunner.withUserConfiguration(CredentialsProviderConfiguration.class)
Expand Down