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: Fixed SSLManager service truststore unset method (#4118) [backport release-5.2.0] #4119

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 @@ -137,7 +137,7 @@ public void setTruststoreKeystoreService(KeystoreService keystoreService, final
}

public void unsetTruststoreKeystoreService(KeystoreService keystoreService) {
if (this.keystoreService == truststoreKeystoreService) {
if (this.truststoreKeystoreService == keystoreService) {

this.truststoreKeystoreService = null;
this.truststoreKeystoreServicePid = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,52 @@ public void shouldConnectOverMqttsWithClientSideAuthWithSeparateTruststore() thr
}
}

@Test
public void connectionShouldFailIfSeparateTruststoreIsUnset() throws Exception {
try (final Fixture fixture = new Fixture()) {

fixture.createFactoryConfiguration(ConfigurableComponent.class, TEST_TRUSTSTORE_PID,
KEYSTORE_SERVICE_FACTORY_PID, KeystoreServiceOptions.defaultConfiguration()
.withKeystorePath(mqttTrustStore.getAbsolutePath()).toProperties())
.get(30, TimeUnit.SECONDS);

fixture.createFactoryConfiguration(ConfigurableComponent.class, TEST_KEYSTORE_PID,
KEYSTORE_SERVICE_FACTORY_PID,
KeystoreServiceOptions.defaultConfiguration()
.withKeystorePath(mqttKeyStoreKeyOnly.getAbsolutePath()).toProperties())
.get(30, TimeUnit.SECONDS);

fixture.createFactoryConfiguration(ConfigurableComponent.class, TEST_SSL_MANAGER_SERVICE_PID,
SSL_MANAGER_SERVICE_FACTORY_PID,
SslManagerServiceOptions.defaultConfiguration().withKeystoreTargetFilter(TEST_KEYSTORE_FILTER)
.withTruststoreTargetFilter(TEST_TRUSTSTORE_FILTER).withHostnameVerification(false)
.toProperties())
.get(30, TimeUnit.SECONDS);

final DataTransportService test = fixture
.createFactoryConfiguration(DataTransportService.class, TEST_MQTT_DATA_TRANSPORT_PID,
MQTT_DATA_TRANSPORT_FACTORY_PID,
MqttDataTransportOptions.defaultConfiguration().withBrokerUrl("mqtts://localhost:8889")
.withSslManagerTargetFilter(TEST_SSL_MANAGER_SERVICE_FILTER).toProperties())
.get(30, TimeUnit.SECONDS);

WireTestUtil
.updateComponentConfiguration(configurationService, TEST_SSL_MANAGER_SERVICE_PID,
SslManagerServiceOptions.defaultConfiguration()
.withTruststoreTargetFilter("(kura.service.pid=changeit)").toProperties())
.get(30, TimeUnit.SECONDS);

assertNotNull(test);
try {
test.connect();
} catch (final KuraConnectException e) {
return;
}

fail("connection should have failed");
}
}

@Test
public void shouldNotConnectOverMqttsWithClientSideAuthWithWrongTruststore() throws Exception {
try (final Fixture fixture = new Fixture()) {
Expand Down