Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

the TrustManagerFactory for some reason does not contain any trustAnchors, when it should contain the default cert-chain of the JVM. (#1461)

Panos Kalogeropoulosb1f4a6da6a41
diff --git a/agent/src/main/java/org/openremote/agent/protocol/mqtt/MQTTProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/mqtt/MQTTProtocol.java
index fe3c563a8..0f88486cc 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/mqtt/MQTTProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/mqtt/MQTTProtocol.java
@@ -120,11 +120,9 @@ public class MQTTProtocol extends AbstractMQTTClientProtocol<MQTTProtocol, MQTTA
//It's fine if they're null, they're not going to be used when creating the client
TrustManagerFactory trustManagerFactory = null;
KeyManagerFactory keyManagerFactory = null;
- if(agent.isSecureMode().orElse(false)){
+ if(agent.isSecureMode().orElse(false) && agent.getCertificateAlias().isPresent()){
trustManagerFactory = keyStoreService.getTrustManagerFactory();
- if(agent.getCertificateAlias().isPresent()){
- keyManagerFactory = keyStoreService.getKeyManagerFactory(agent.getRealm()+"."+agent.getCertificateAlias().orElseThrow());
- }
+ keyManagerFactory = keyStoreService.getKeyManagerFactory(agent.getRealm()+"."+agent.getCertificateAlias().orElseThrow());
}
return new MQTT_IOClient(agent.getClientId().orElseGet(UniqueIdentifierGenerator::generateId), host, port, agent.isSecureMode().orElse(false), !agent.isResumeSession().orElse(false), agent.getUsernamePassword().orElse(null), websocketURI, lastWill, keyManagerFactory, trustManagerFactory);