]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/Main.java
Retry decrypting of messages from previously untrusted keys
[signal-cli] / src / main / java / org / asamk / signal / Main.java
index 25807a6b5e58840bdc16aed3e7ffd81a720e2aed..40e28d25673213216af1b5bf186653c4e6f23253 100644 (file)
@@ -310,6 +310,9 @@ public class Main {
                         } catch (GroupNotFoundException e) {
                             handleGroupNotFoundException(e);
                             return 1;
+                        } catch (NotAGroupMemberException e) {
+                            handleNotAGroupMemberException(e);
+                            return 1;
                         } catch (AttachmentInvalidException e) {
                             System.err.println("Failed to add attachment: " + e.getMessage());
                             System.err.println("Aborting sending.");
@@ -401,6 +404,9 @@ public class Main {
                     } catch (GroupNotFoundException e) {
                         handleGroupNotFoundException(e);
                         return 1;
+                    } catch (NotAGroupMemberException e) {
+                        handleNotAGroupMemberException(e);
+                        return 1;
                     }
 
                     break;
@@ -433,6 +439,9 @@ public class Main {
                     } catch (GroupNotFoundException e) {
                         handleGroupNotFoundException(e);
                         return 1;
+                    } catch (NotAGroupMemberException e) {
+                        handleNotAGroupMemberException(e);
+                        return 1;
                     } catch (EncapsulatedExceptions e) {
                         handleEncapsulatedExceptions(e);
                         return 3;
@@ -553,6 +562,13 @@ public class Main {
         System.err.println("Aborting sending.");
     }
 
+    private static void handleNotAGroupMemberException(NotAGroupMemberException e) {
+        System.err.println("Failed to send to group: " + e.getMessage());
+        System.err.println("Update the group on another device to readd the user to this group.");
+        System.err.println("Aborting sending.");
+    }
+
+
     private static void handleDBusExecutionException(DBusExecutionException e) {
         System.err.println("Cannot connect to dbus: " + e.getMessage());
         System.err.println("Aborting.");
@@ -752,7 +768,7 @@ public class Main {
         }
 
         @Override
-        public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content) {
+        public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
             SignalServiceAddress source = envelope.getSourceAddress();
             ContactInfo sourceContact = m.getContact(source.getNumber());
             System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "“" + sourceContact.name + "” ") + source.getNumber(), envelope.getSourceDevice()));
@@ -764,6 +780,16 @@ public class Main {
             if (envelope.isReceipt()) {
                 System.out.println("Got receipt.");
             } else if (envelope.isSignalMessage() | envelope.isPreKeySignalMessage()) {
+                if (exception != null) {
+                    if (exception instanceof org.whispersystems.libsignal.UntrustedIdentityException) {
+                        org.whispersystems.libsignal.UntrustedIdentityException e = (org.whispersystems.libsignal.UntrustedIdentityException) exception;
+                        System.out.println("The user’s key is untrusted, either the user has reinstalled Signal or a third party sent this message.");
+                        System.out.println("Use 'signal-cli -u " + m.getUsername() + " listIdentities -n " + e.getName() + "', verify the key and run 'signal-cli -u " + m.getUsername() + " trust -v \"FINGER_PRINT\" " + e.getName() + "' to mark it as trusted");
+                        System.out.println("If you don't care about security, use 'signal-cli -u " + m.getUsername() + " trust -a " + e.getName() + "' to trust it without verification");
+                    } else {
+                        System.out.println("Exception: " + exception.getMessage() + " (" + exception.getClass().getSimpleName() + ")");
+                    }
+                }
                 if (content == null) {
                     System.out.println("Failed to decrypt message.");
                 } else {
@@ -888,8 +914,8 @@ public class Main {
         }
 
         @Override
-        public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content) {
-            super.handleMessage(envelope, content);
+        public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
+            super.handleMessage(envelope, content, exception);
 
             if (!envelope.isReceipt() && content != null && content.getDataMessage().isPresent()) {
                 SignalServiceDataMessage message = content.getDataMessage().get();