mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
parent
c3c1802b4d
commit
eae516a9a7
4 changed files with 34 additions and 33 deletions
|
@ -244,50 +244,50 @@ public class SignalAccount implements Closeable {
|
||||||
rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
|
rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode uuidNode = rootNode.get("uuid");
|
if (rootNode.hasNonNull("uuid")) {
|
||||||
if (uuidNode != null && !uuidNode.isNull()) {
|
|
||||||
try {
|
try {
|
||||||
uuid = UUID.fromString(uuidNode.asText());
|
uuid = UUID.fromString(rootNode.get("uuid").asText());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IOException("Config file contains an invalid uuid, needs to be a valid UUID", e);
|
throw new IOException("Config file contains an invalid uuid, needs to be a valid UUID", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JsonNode node = rootNode.get("deviceId");
|
if (rootNode.hasNonNull("deviceId")) {
|
||||||
if (node != null) {
|
deviceId = rootNode.get("deviceId").asInt();
|
||||||
deviceId = node.asInt();
|
|
||||||
}
|
}
|
||||||
if (rootNode.has("isMultiDevice")) {
|
if (rootNode.hasNonNull("isMultiDevice")) {
|
||||||
isMultiDevice = Utils.getNotNullNode(rootNode, "isMultiDevice").asBoolean();
|
isMultiDevice = rootNode.get("isMultiDevice").asBoolean();
|
||||||
}
|
}
|
||||||
username = Utils.getNotNullNode(rootNode, "username").asText();
|
username = Utils.getNotNullNode(rootNode, "username").asText();
|
||||||
password = Utils.getNotNullNode(rootNode, "password").asText();
|
password = Utils.getNotNullNode(rootNode, "password").asText();
|
||||||
JsonNode pinNode = rootNode.get("registrationLockPin");
|
if (rootNode.hasNonNull("registrationLockPin")) {
|
||||||
registrationLockPin = pinNode == null || pinNode.isNull() ? null : pinNode.asText();
|
registrationLockPin = rootNode.get("registrationLockPin").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.has("preKeyIdOffset")) {
|
if (rootNode.hasNonNull("pinMasterKey")) {
|
||||||
preKeyIdOffset = Utils.getNotNullNode(rootNode, "preKeyIdOffset").asInt(0);
|
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 {
|
} else {
|
||||||
preKeyIdOffset = 0;
|
preKeyIdOffset = 0;
|
||||||
}
|
}
|
||||||
if (rootNode.has("nextSignedPreKeyId")) {
|
if (rootNode.hasNonNull("nextSignedPreKeyId")) {
|
||||||
nextSignedPreKeyId = Utils.getNotNullNode(rootNode, "nextSignedPreKeyId").asInt();
|
nextSignedPreKeyId = rootNode.get("nextSignedPreKeyId").asInt();
|
||||||
} else {
|
} else {
|
||||||
nextSignedPreKeyId = 0;
|
nextSignedPreKeyId = 0;
|
||||||
}
|
}
|
||||||
if (rootNode.has("profileKey")) {
|
if (rootNode.hasNonNull("profileKey")) {
|
||||||
try {
|
try {
|
||||||
profileKey = new ProfileKey(Base64.getDecoder()
|
profileKey = new ProfileKey(Base64.getDecoder().decode(rootNode.get("profileKey").asText()));
|
||||||
.decode(Utils.getNotNullNode(rootNode, "profileKey").asText()));
|
|
||||||
} catch (InvalidInputException e) {
|
} catch (InvalidInputException e) {
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",
|
"Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class JsonGroupStore {
|
||||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||||
for (JsonNode n : node) {
|
for (JsonNode n : node) {
|
||||||
GroupInfo g;
|
GroupInfo g;
|
||||||
if (n.has("masterKey")) {
|
if (n.hasNonNull("masterKey")) {
|
||||||
// a v2 group
|
// a v2 group
|
||||||
GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
|
GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -219,10 +219,11 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
try {
|
try {
|
||||||
IdentityKey id = new IdentityKey(Base64.getDecoder()
|
IdentityKey id = new IdentityKey(Base64.getDecoder()
|
||||||
.decode(trustedKey.get("identityKey").asText()), 0);
|
.decode(trustedKey.get("identityKey").asText()), 0);
|
||||||
TrustLevel trustLevel = trustedKey.has("trustLevel") ? TrustLevel.fromInt(trustedKey.get(
|
TrustLevel trustLevel = trustedKey.hasNonNull("trustLevel")
|
||||||
"trustLevel").asInt()) : TrustLevel.TRUSTED_UNVERIFIED;
|
? TrustLevel.fromInt(trustedKey.get("trustLevel").asInt())
|
||||||
Date added = trustedKey.has("addedTimestamp") ? new Date(trustedKey.get("addedTimestamp")
|
: TrustLevel.TRUSTED_UNVERIFIED;
|
||||||
.asLong()) : new Date();
|
Date added = trustedKey.hasNonNull("addedTimestamp") ? new Date(trustedKey.get(
|
||||||
|
"addedTimestamp").asLong()) : new Date();
|
||||||
keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
|
keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
|
||||||
} catch (InvalidKeyException e) {
|
} catch (InvalidKeyException e) {
|
||||||
logger.warn("Error while decoding key for {}: {}", trustedKeyName, e.getMessage());
|
logger.warn("Error while decoding key for {}: {}", trustedKeyName, e.getMessage());
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class Utils {
|
||||||
|
|
||||||
public static JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
|
public static JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
|
||||||
JsonNode node = parent.get(name);
|
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 ",
|
throw new InvalidObjectException(String.format("Incorrect file format: expected parameter %s not found ",
|
||||||
name));
|
name));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue