From dba087e949ec04085339710e4fbf253605c450c8 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Tue, 28 Sep 2021 16:48:34 +0300 Subject: [PATCH] Lwm2m credentials base64 fix bug PSK (hexDec) --- .../lwm2m/AbstractLwM2MClientCredentialsWithKey.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/device/credentials/lwm2m/AbstractLwM2MClientCredentialsWithKey.java b/common/data/src/main/java/org/thingsboard/server/common/data/device/credentials/lwm2m/AbstractLwM2MClientCredentialsWithKey.java index 4279694909..26cc55faa6 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/device/credentials/lwm2m/AbstractLwM2MClientCredentialsWithKey.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/device/credentials/lwm2m/AbstractLwM2MClientCredentialsWithKey.java @@ -20,6 +20,7 @@ import lombok.Getter; import lombok.Setter; import lombok.SneakyThrows; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.Hex; public abstract class AbstractLwM2MClientCredentialsWithKey extends AbstractLwM2MClientCredentials { @Getter @@ -32,7 +33,12 @@ public abstract class AbstractLwM2MClientCredentialsWithKey extends AbstractLwM2 @JsonIgnore public byte[] getDecodedKey() throws IllegalArgumentException { if (keyInBytes == null) { - keyInBytes = Base64.decodeBase64(key.getBytes()); + if (this.getSecurityConfigClientMode() == LwM2MSecurityMode.PSK) { + keyInBytes = Hex.decodeHex(key.toLowerCase().toCharArray()); + } + else { + keyInBytes = Base64.decodeBase64(key.getBytes()); + } } return keyInBytes; }