...
 
Commits (2)
......@@ -55,10 +55,9 @@ public class Main implements Runnable {
@Option(names={"-d", "--data"}, description="Data storage location")
private String data_path = System.getProperty("user.home") + "/.config/signald";
private static final Logger logger = LogManager.getLogger("signald");
private static final Logger logger = LogManager.getLogger();
public void run() {
Logger logger = LogManager.getLogger("signald");
if(verbose) {
Configurator.setLevel(System.getProperty("log4j.logger"), Level.DEBUG);
}
......
......@@ -23,7 +23,7 @@ import org.apache.logging.log4j.Logger;
import org.whispersystems.libsignal.logging.SignalProtocolLogger;
class ProtocolLogger implements SignalProtocolLogger {
private static final Logger logger = LogManager.getLogger("signal-protocol");
private static final Logger logger = LogManager.getLogger();
public void log(int priority, String tag, String message) {
logger.debug("[" + tag + "] " + message);
......
......@@ -19,11 +19,16 @@ package io.finn.signald.clientprotocol.v1;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.finn.signald.Util;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.util.UUID;
public class JsonAddress {
private static final Logger logger = LogManager.getLogger();
public String number;
public String uuid;
......@@ -32,8 +37,13 @@ public class JsonAddress {
public JsonAddress() {};
public JsonAddress(String number, UUID uuid) {
this.number = number;
public JsonAddress(String n, UUID uuid) {
if(!n.startsWith("+") && UuidUtil.isUuid(n)) {
logger.warn("Number field has a valid UUID in it! Converting to UUID field (this is to fix a data migration issue in signald, do not rely on this behavior when using the socket API)");
uuid = UUID.fromString(n);
} else {
number = n;
}
if(uuid != null) {
this.uuid = uuid.toString();
}
......@@ -53,7 +63,13 @@ public class JsonAddress {
public JsonAddress(SignalServiceAddress address) {
if(address.getNumber().isPresent()) {
number = address.getNumber().get();
String n = address.getNumber().get();
if(!n.startsWith("+") && UuidUtil.isUuid(n)) {
logger.warn("Number field has a valid UUID in it! Converting to UUID field (this is to fix a data migration issue in signald, do not rely on this behavior when using the socket API)");
uuid = n;
} else {
number = n;
}
}
if(address.getUuid().isPresent()) {
......
......@@ -65,7 +65,7 @@ public class AccountData {
public List<JsonAddress> recipientStore = new ArrayList<>();
private static String dataPath;
private static Logger logger = LogManager.getLogger("AccountData");
private static final Logger logger = LogManager.getLogger();
public static AccountData load(File storageFile) throws IOException {
logger.debug("Loading account from disk.");
......@@ -113,6 +113,8 @@ public class AccountData {
if(address == null) {
address = new JsonAddress(username);
}
axolotlStore.sessionStore.resolveAll();
axolotlStore.identityKeyStore.dedup();
}
public void save() throws IOException {
......
......@@ -35,7 +35,8 @@ import java.util.Map;
@JsonSerialize(using=GroupStore.GroupStoreSerializer.class)
@JsonDeserialize(using=GroupStore.GroupStoreDeserializer.class)
public class GroupStore {
static final Logger logger = LogManager.getLogger(GroupStore.class);
static final Logger logger = LogManager.getLogger();
private static final ObjectMapper jsonProcessor = new ObjectMapper();
private Map<String, GroupInfo> groups = new HashMap<>();
......
......@@ -38,7 +38,8 @@ import java.util.Date;
import java.util.List;
public class IdentityKeyStore implements org.whispersystems.libsignal.state.IdentityKeyStore {
private static Logger log = LogManager.getLogger(IdentityKeyStore.class.getName());
private static final Logger logger = LogManager.getLogger();
private AddressResolver resolver;
public List<IdentityKeyStore.Identity> trustedKeys = new ArrayList<>();
......@@ -93,7 +94,7 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
List<Identity> matches = new ArrayList<>();
for(Identity key : trustedKeys) {
if(key.address == null) {
log.warn("Key has no address! This may indicate a corrupt data file.");
logger.warn("Key has no address! This may indicate a corrupt data file.");
continue;
}
if(key.address.matches(other)) {
......@@ -172,6 +173,30 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
return maxIdentity.getKey();
}
public void dedup() {
List<Identity> duplicates = new ArrayList<>();
// this is a hell of a lot of nested loops...
for(Identity i : trustedKeys) {
for(Identity j : trustedKeys) {
if(i.identityKey.equals(j.identityKey)) {
for(Identity dup : duplicates) {
if(dup.address.matches(i.address)) {
i.address.update(dup.address.getSignalServiceAddress());
continue;
}
}
duplicates.add(i);
}
}
}
for(Identity dup : duplicates) {
logger.warn("Found duplicate identity key with address " + dup.address.toRedactedString());
trustedKeys.remove(dup);
}
}
@JsonIgnore
public List<Identity> getIdentities() {
return trustedKeys;
......
......@@ -142,6 +142,12 @@ public class SessionStore implements org.whispersystems.libsignal.state.SessionS
sessions.removeIf(info -> info.address.matches(serviceAddress));
}
public void resolveAll() {
for(SessionInfo s : sessions) {
s.address = resolver.resolve(s.address);
}
}
public static class SessionStoreDeserializer extends JsonDeserializer<SessionStore> {
@Override
......
......@@ -18,10 +18,14 @@
package io.finn.signald.util;
import io.finn.signald.clientprotocol.v1.JsonAddress;
import io.finn.signald.storage.AddressResolver;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.UuidUtil;
public class AddressUtil {
import java.util.ArrayList;
import java.util.Collection;
public class AddressUtil implements AddressResolver {
public static SignalServiceAddress fromIdentifier(String identifier) {
if(UuidUtil.isUuid(identifier)) {
return new SignalServiceAddress(UuidUtil.parseOrNull(identifier), null);
......@@ -41,4 +45,24 @@ public class AddressUtil {
}
return old;
}
@Override
public SignalServiceAddress resolve(String identifier) {
return fromIdentifier(identifier);
}
@Override
public SignalServiceAddress resolve(SignalServiceAddress partial) {
return partial;
}
@Override
public Collection<SignalServiceAddress> resolve(Collection<SignalServiceAddress> partials) {
Collection <SignalServiceAddress> full = new ArrayList<>();
for(SignalServiceAddress p : partials) {
full.add(resolve(p));
}
return full;
}
}