]> nmode's Git Repositories - signal-cli/commitdiff
Add additional logging
authorAsamK <asamk@gmx.de>
Wed, 29 Dec 2021 08:45:59 +0000 (09:45 +0100)
committerAsamK <asamk@gmx.de>
Thu, 30 Dec 2021 10:53:22 +0000 (11:53 +0100)
graalvm-config-dir/reflect-config.json
lib/src/main/java/org/asamk/signal/manager/storage/SignalAccount.java
lib/src/main/java/org/asamk/signal/manager/storage/identities/IdentityKeyStore.java
src/main/java/org/asamk/signal/App.java

index a3edb9677ba150064b66b5676cf881df89b64092..dd5b4156857c7ef7def178c61d7e8f779e2bbfd3 100644 (file)
   "name":"java.lang.String",
   "allPublicMethods":true}
 ,
+{
+  "name":"java.lang.Throwable",
+  "queryAllPublicMethods":true,
+  "methods":[{"name":"addSuppressed","parameterTypes":["java.lang.Throwable"] }]}
+,
 {
   "name":"java.lang.reflect.Method",
   "methods":[{"name":"isDefault","parameterTypes":[] }]}
index 67fc252958208b1a9a5558a7beb156347b592b8a..8a8fdd3e44262e51bcf459739aee1ad2d1d7e44f 100644 (file)
@@ -122,11 +122,14 @@ public class SignalAccount implements Closeable {
     public static SignalAccount load(
             File dataPath, String account, boolean waitForLock, final TrustNewIdentity trustNewIdentity
     ) throws IOException {
+        logger.trace("Opening account file");
         final var fileName = getFileName(dataPath, account);
         final var pair = openFileChannel(fileName, waitForLock);
         try {
             var signalAccount = new SignalAccount(pair.first(), pair.second());
+            logger.trace("Loading account file");
             signalAccount.load(dataPath, trustNewIdentity);
+            logger.trace("Migrating legacy parts of account file");
             signalAccount.migrateLegacyConfigs();
 
             if (!account.equals(signalAccount.getAccount())) {
index 5a651eddb14f501d44165b0b9a8f45de876f12ff..bb4627a2902be75b140111b62af58b2168d54437 100644 (file)
@@ -84,6 +84,7 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
             final var identityInfo = loadIdentityLocked(recipientId);
             if (identityInfo != null && identityInfo.getIdentityKey().equals(identityKey)) {
                 // Identity already exists, not updating the trust level
+                logger.trace("Not storing new identity for recipient {}, identity already stored", recipientId);
                 return false;
             }
 
@@ -101,18 +102,23 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
         isRetryingDecryption = retryingDecryption;
     }
 
-    public boolean setIdentityTrustLevel(
-            RecipientId recipientId, IdentityKey identityKey, TrustLevel trustLevel
-    ) {
+    public boolean setIdentityTrustLevel(RecipientId recipientId, IdentityKey identityKey, TrustLevel trustLevel) {
         synchronized (cachedIdentities) {
             final var identityInfo = loadIdentityLocked(recipientId);
-            if (identityInfo == null
-                    || !identityInfo.getIdentityKey().equals(identityKey)
-                    || identityInfo.getTrustLevel() == trustLevel) {
-                // Identity not found or trust not changed, not updating the trust level
+            if (identityInfo == null) {
+                logger.debug("Not updating trust level for recipient {}, identity not found", recipientId);
+                return false;
+            }
+            if (!identityInfo.getIdentityKey().equals(identityKey)) {
+                logger.debug("Not updating trust level for recipient {}, different identity found", recipientId);
+                return false;
+            }
+            if (identityInfo.getTrustLevel() == trustLevel) {
+                logger.debug("Not updating trust level for recipient {}, trust level already matches", recipientId);
                 return false;
             }
 
+            logger.debug("Updating trust level for recipient {} with trust {}", recipientId, trustLevel);
             final var newIdentityInfo = new IdentityInfo(recipientId,
                     identityKey,
                     trustLevel,
@@ -134,20 +140,24 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
             // TODO implement possibility for different handling of incoming/outgoing trust decisions
             var identityInfo = loadIdentityLocked(recipientId);
             if (identityInfo == null) {
-                // Identity not found
+                logger.debug("Initial identity found for {}, saving.", recipientId);
                 saveIdentity(address, identityKey);
-                return trustNewIdentity == TrustNewIdentity.ON_FIRST_USE;
-            }
-
-            if (!identityInfo.getIdentityKey().equals(identityKey)) {
+                identityInfo = loadIdentityLocked(recipientId);
+            } else if (!identityInfo.getIdentityKey().equals(identityKey)) {
                 // Identity found, but different
                 if (direction == Direction.SENDING) {
+                    logger.debug("Changed identity found for {}, saving.", recipientId);
                     saveIdentity(address, identityKey);
                     identityInfo = loadIdentityLocked(recipientId);
+                } else {
+                    logger.trace("Trusting identity for {} for {}: {}", recipientId, direction, false);
+                    return false;
                 }
             }
 
-            return identityInfo.isTrusted();
+            final var isTrusted = identityInfo != null && identityInfo.isTrusted();
+            logger.trace("Trusting identity for {} for {}: {}", recipientId, direction, isTrusted);
+            return isTrusted;
         }
     }
 
@@ -239,6 +249,10 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
     }
 
     private void storeIdentityLocked(final RecipientId recipientId, final IdentityInfo identityInfo) {
+        logger.trace("Storing identity info for {}, trust: {}, added: {}",
+                recipientId,
+                identityInfo.getTrustLevel(),
+                identityInfo.getDateAdded());
         cachedIdentities.put(recipientId, identityInfo);
 
         var storage = new IdentityStorage(Base64.getEncoder().encodeToString(identityInfo.getIdentityKey().serialize()),
index f807e8fdfb5dfa6ef7622b4bad4e003be733ecec..a20b14e39efb231f429949a6212dd7063a98d709 100644 (file)
@@ -290,6 +290,7 @@ public class App {
             final TrustNewIdentity trustNewIdentity
     ) throws CommandException {
         Manager manager;
+        logger.trace("Loading account file for {}", account);
         try {
             manager = Manager.init(account, dataPath, serviceEnvironment, BaseConfig.USER_AGENT, trustNewIdentity);
         } catch (NotRegisteredException e) {
@@ -304,6 +305,7 @@ public class App {
                     + ")", e);
         }
 
+        logger.trace("Checking account state");
         try {
             manager.checkAccountState();
         } catch (IOException e) {