Fix issue with incorrectly saving signalingKey

Fixes #442, #447
This commit is contained in:
AsamK 2021-01-19 16:54:44 +01:00
parent c3c1802b4d
commit eae516a9a7
4 changed files with 34 additions and 33 deletions

View file

@ -244,50 +244,50 @@ public class SignalAccount implements Closeable {
rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
}
JsonNode uuidNode = rootNode.get("uuid");
if (uuidNode != null && !uuidNode.isNull()) {
if (rootNode.hasNonNull("uuid")) {
try {
uuid = UUID.fromString(uuidNode.asText());
uuid = UUID.fromString(rootNode.get("uuid").asText());
} catch (IllegalArgumentException e) {
throw new IOException("Config file contains an invalid uuid, needs to be a valid UUID", e);
}
}
JsonNode node = rootNode.get("deviceId");
if (node != null) {
deviceId = node.asInt();
if (rootNode.hasNonNull("deviceId")) {
deviceId = rootNode.get("deviceId").asInt();
}
if (rootNode.has("isMultiDevice")) {
isMultiDevice = Utils.getNotNullNode(rootNode, "isMultiDevice").asBoolean();
if (rootNode.hasNonNull("isMultiDevice")) {
isMultiDevice = rootNode.get("isMultiDevice").asBoolean();
}
username = Utils.getNotNullNode(rootNode, "username").asText();
password = Utils.getNotNullNode(rootNode, "password").asText();
JsonNode pinNode = rootNode.get("registrationLockPin");
registrationLockPin = pinNode == null || pinNode.isNull() ? null : pinNode.asText();
JsonNode pinMasterKeyNode = rootNode.get("pinMasterKey");
pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull()
? null
: new MasterKey(Base64.getDecoder().decode(pinMasterKeyNode.asText()));
JsonNode storageKeyNode = rootNode.get("storageKey");
storageKey = storageKeyNode == null || storageKeyNode.isNull()
? null
: new StorageKey(Base64.getDecoder().decode(storageKeyNode.asText()));
if (rootNode.has("signalingKey")) {
signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText();
if (rootNode.hasNonNull("registrationLockPin")) {
registrationLockPin = rootNode.get("registrationLockPin").asText();
}
if (rootNode.has("preKeyIdOffset")) {
preKeyIdOffset = Utils.getNotNullNode(rootNode, "preKeyIdOffset").asInt(0);
if (rootNode.hasNonNull("pinMasterKey")) {
pinMasterKey = new MasterKey(Base64.getDecoder().decode(rootNode.get("pinMasterKey").asText()));
}
if (rootNode.hasNonNull("storageKey")) {
storageKey = new StorageKey(Base64.getDecoder().decode(rootNode.get("storageKey").asText()));
}
if (rootNode.hasNonNull("signalingKey")) {
signalingKey = rootNode.get("signalingKey").asText();
if (signalingKey.equals("null")) {
// Workaround for load bug in older versions
signalingKey = null;
}
}
if (rootNode.hasNonNull("preKeyIdOffset")) {
preKeyIdOffset = rootNode.get("preKeyIdOffset").asInt(0);
} else {
preKeyIdOffset = 0;
}
if (rootNode.has("nextSignedPreKeyId")) {
nextSignedPreKeyId = Utils.getNotNullNode(rootNode, "nextSignedPreKeyId").asInt();
if (rootNode.hasNonNull("nextSignedPreKeyId")) {
nextSignedPreKeyId = rootNode.get("nextSignedPreKeyId").asInt();
} else {
nextSignedPreKeyId = 0;
}
if (rootNode.has("profileKey")) {
if (rootNode.hasNonNull("profileKey")) {
try {
profileKey = new ProfileKey(Base64.getDecoder()
.decode(Utils.getNotNullNode(rootNode, "profileKey").asText()));
profileKey = new ProfileKey(Base64.getDecoder().decode(rootNode.get("profileKey").asText()));
} catch (InvalidInputException e) {
throw new IOException(
"Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",

View file

@ -183,7 +183,7 @@ public class JsonGroupStore {
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
for (JsonNode n : node) {
GroupInfo g;
if (n.has("masterKey")) {
if (n.hasNonNull("masterKey")) {
// a v2 group
GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
try {

View file

@ -219,10 +219,11 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
try {
IdentityKey id = new IdentityKey(Base64.getDecoder()
.decode(trustedKey.get("identityKey").asText()), 0);
TrustLevel trustLevel = trustedKey.has("trustLevel") ? TrustLevel.fromInt(trustedKey.get(
"trustLevel").asInt()) : TrustLevel.TRUSTED_UNVERIFIED;
Date added = trustedKey.has("addedTimestamp") ? new Date(trustedKey.get("addedTimestamp")
.asLong()) : new Date();
TrustLevel trustLevel = trustedKey.hasNonNull("trustLevel")
? TrustLevel.fromInt(trustedKey.get("trustLevel").asInt())
: TrustLevel.TRUSTED_UNVERIFIED;
Date added = trustedKey.hasNonNull("addedTimestamp") ? new Date(trustedKey.get(
"addedTimestamp").asLong()) : new Date();
keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
} catch (InvalidKeyException e) {
logger.warn("Error while decoding key for {}: {}", trustedKeyName, e.getMessage());

View file

@ -84,7 +84,7 @@ public class Utils {
public static JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
JsonNode node = parent.get(name);
if (node == null) {
if (node == null || node.isNull()) {
throw new InvalidObjectException(String.format("Incorrect file format: expected parameter %s not found ",
name));
}