]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/helper/PinHelper.java
Improve behavior when pin data doesn't exist on the server
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / helper / PinHelper.java
index cb9b9057eb9b1f501341adc29a4653adbe47a32f..40878647079cdae284d3cac036e104cad7b40ad3 100644 (file)
@@ -21,9 +21,7 @@ public class PinHelper {
         this.secureValueRecoveries = secureValueRecoveries;
     }
 
-    public void setRegistrationLockPin(
-            String pin, MasterKey masterKey
-    ) throws IOException {
+    public void setRegistrationLockPin(String pin, MasterKey masterKey) throws IOException {
         IOException exception = null;
         for (final var secureValueRecovery : secureValueRecoveries) {
             try {
@@ -32,11 +30,11 @@ public class PinHelper {
                     case SecureValueRecovery.BackupResponse.Success success -> {
                     }
                     case SecureValueRecovery.BackupResponse.ServerRejected serverRejected ->
-                            logger.warn("Backup svr2 failed: ServerRejected");
+                            logger.warn("Backup svr failed: ServerRejected");
                     case SecureValueRecovery.BackupResponse.EnclaveNotFound enclaveNotFound ->
-                            logger.warn("Backup svr2 failed: EnclaveNotFound");
+                            logger.warn("Backup svr failed: EnclaveNotFound");
                     case SecureValueRecovery.BackupResponse.ExposeFailure exposeFailure ->
-                            logger.warn("Backup svr2 failed: ExposeFailure");
+                            logger.warn("Backup svr failed: ExposeFailure");
                     case SecureValueRecovery.BackupResponse.ApplicationError error ->
                             throw new IOException(error.getException());
                     case SecureValueRecovery.BackupResponse.NetworkError error -> throw error.getException();
@@ -82,14 +80,19 @@ public class PinHelper {
     }
 
     public SecureValueRecovery.RestoreResponse.Success getRegistrationLockData(
-            String pin, LockedException lockedException
+            String pin,
+            LockedException lockedException
     ) throws IOException, IncorrectPinException {
         var svr2Credentials = lockedException.getSvr2Credentials();
         if (svr2Credentials != null) {
             IOException exception = null;
             for (final var secureValueRecovery : secureValueRecoveries) {
                 try {
-                    return getRegistrationLockData(secureValueRecovery, svr2Credentials, pin);
+                    final var lockData = getRegistrationLockData(secureValueRecovery, svr2Credentials, pin);
+                    if (lockData == null) {
+                        continue;
+                    }
+                    return lockData;
                 } catch (IOException e) {
                     exception = e;
                 }
@@ -103,7 +106,9 @@ public class PinHelper {
     }
 
     public SecureValueRecovery.RestoreResponse.Success getRegistrationLockData(
-            SecureValueRecovery secureValueRecovery, AuthCredentials authCredentials, String pin
+            SecureValueRecovery secureValueRecovery,
+            AuthCredentials authCredentials,
+            String pin
     ) throws IOException, IncorrectPinException {
         final var restoreResponse = secureValueRecovery.restoreDataPreRegistration(authCredentials, null, pin);