]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt] Fix certificate pinning (#16857)
authorJ-N-K <github@klug.nrw>
Sat, 8 Jun 2024 21:22:24 +0000 (23:22 +0200)
committerGitHub <noreply@github.com>
Sat, 8 Jun 2024 21:22:24 +0000 (23:22 +0200)
Signed-off-by: Jan N. Klug <github@klug.nrw>
bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/BrokerHandler.java
bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/internal/ssl/Pin.java

index e5f29522e669d0282b60853b453459d69d615332..16dd1853ab524c5942e09fce69e37abff4d65a44 100644 (file)
@@ -83,6 +83,12 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba
             logger.error("Received pins hash is empty!");
             return;
         }
+        PinMessageDigest hashDigest = pin.getHashDigest();
+        if (hashDigest == null) {
+            logger.error("Received pins message digest is not set!");
+            return;
+        }
+
         String configKey = null;
         try {
             switch (pin.getType()) {
@@ -99,7 +105,7 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba
         }
 
         Configuration thingConfig = editConfiguration();
-        thingConfig.put(configKey, HexUtils.bytesToHex(hash));
+        thingConfig.put(configKey, hashDigest.getMethod() + ":" + HexUtils.bytesToHex(hash));
         updateConfiguration(thingConfig);
     }
 
index 9009b18d006475f2325b617983eebe944553eb9a..134f53408a3a484d8e5060d1db61d82eaf88dc0c 100644 (file)
@@ -54,6 +54,10 @@ public class Pin {
         return pinData;
     }
 
+    public @Nullable PinMessageDigest getHashDigest() {
+        return hashDigest;
+    }
+
     public void setLearningMode() {
         this.learning = true;
         this.pinData = null;