Browse Source

Lwm2m credentials base64 fix bug PSK (hexDec)

pull/5299/head
nickAS21 5 years ago
parent
commit
dba087e949
  1. 8
      common/data/src/main/java/org/thingsboard/server/common/data/device/credentials/lwm2m/AbstractLwM2MClientCredentialsWithKey.java

8
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;
}

Loading…
Cancel
Save