Print more detailed error message when registering with non-normalized number

Fixes #958
This commit is contained in:
AsamK 2022-05-22 22:01:11 +02:00
parent cf07512d24
commit 995eaa6e7c
7 changed files with 35 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package org.asamk.signal.manager;
import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.IncorrectPinException; import org.asamk.signal.manager.api.IncorrectPinException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException; import org.asamk.signal.manager.api.PinLockedException;
import java.io.Closeable; import java.io.Closeable;
@ -9,7 +10,9 @@ import java.io.IOException;
public interface RegistrationManager extends Closeable { public interface RegistrationManager extends Closeable {
void register(boolean voiceVerification, String captcha) throws IOException, CaptchaRequiredException; void register(
boolean voiceVerification, String captcha
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException;
void verifyAccount( void verifyAccount(
String verificationCode, String pin String verificationCode, String pin

View file

@ -18,6 +18,7 @@ package org.asamk.signal.manager;
import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.IncorrectPinException; import org.asamk.signal.manager.api.IncorrectPinException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException; import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.UpdateProfile; import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.config.ServiceConfig; import org.asamk.signal.manager.config.ServiceConfig;
@ -95,7 +96,9 @@ class RegistrationManagerImpl implements RegistrationManager {
} }
@Override @Override
public void register(boolean voiceVerification, String captcha) throws IOException, CaptchaRequiredException { public void register(
boolean voiceVerification, String captcha
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
if (account.isRegistered() if (account.isRegistered()
&& account.getServiceEnvironment() != null && account.getServiceEnvironment() != null
&& account.getServiceEnvironment() != serviceEnvironmentConfig.getType()) { && account.getServiceEnvironment() != serviceEnvironmentConfig.getType()) {

View file

@ -0,0 +1,12 @@
package org.asamk.signal.manager.api;
public class NonNormalizedPhoneNumberException extends Exception {
public NonNormalizedPhoneNumberException(final String message) {
super(message);
}
public NonNormalizedPhoneNumberException(final String message, final Throwable cause) {
super(message, cause);
}
}

View file

@ -5,6 +5,7 @@ import org.asamk.signal.manager.SignalDependencies;
import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.IncorrectPinException; import org.asamk.signal.manager.api.IncorrectPinException;
import org.asamk.signal.manager.api.InvalidDeviceLinkException; import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException; import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.config.ServiceConfig; import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.storage.SignalAccount; import org.asamk.signal.manager.storage.SignalAccount;
@ -95,7 +96,7 @@ public class AccountHelper {
public void startChangeNumber( public void startChangeNumber(
String newNumber, String captcha, boolean voiceVerification String newNumber, String captcha, boolean voiceVerification
) throws IOException, CaptchaRequiredException { ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
final var accountManager = dependencies.createUnauthenticatedAccountManager(newNumber, account.getPassword()); final var accountManager = dependencies.createUnauthenticatedAccountManager(newNumber, account.getPassword());
NumberVerificationUtils.requestVerificationCode(accountManager, captcha, voiceVerification); NumberVerificationUtils.requestVerificationCode(accountManager, captcha, voiceVerification);
} }

View file

@ -2,6 +2,7 @@ package org.asamk.signal.manager.util;
import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.IncorrectPinException; import org.asamk.signal.manager.api.IncorrectPinException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.Pair; import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.PinLockedException; import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.helper.PinHelper; import org.asamk.signal.manager.helper.PinHelper;
@ -20,7 +21,7 @@ public class NumberVerificationUtils {
public static void requestVerificationCode( public static void requestVerificationCode(
SignalServiceAccountManager accountManager, String captcha, boolean voiceVerification SignalServiceAccountManager accountManager, String captcha, boolean voiceVerification
) throws IOException, CaptchaRequiredException { ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
captcha = captcha == null ? null : captcha.replace("signalcaptcha://", ""); captcha = captcha == null ? null : captcha.replace("signalcaptcha://", "");
final ServiceResponse<RequestVerificationCodeResponse> response; final ServiceResponse<RequestVerificationCodeResponse> response;
@ -39,6 +40,11 @@ public class NumberVerificationUtils {
handleResponseException(response); handleResponseException(response);
} catch (org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException e) { } catch (org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException e) {
throw new CaptchaRequiredException(e.getMessage(), e); throw new CaptchaRequiredException(e.getMessage(), e);
} catch (org.whispersystems.signalservice.api.push.exceptions.NonNormalizedPhoneNumberException e) {
throw new NonNormalizedPhoneNumberException("Phone number is not normalized ("
+ e.getMessage()
+ "). Expected normalized: "
+ e.getNormalizedNumber(), e);
} }
} }

View file

@ -12,6 +12,7 @@ import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.RegistrationManager; import org.asamk.signal.manager.RegistrationManager;
import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.output.JsonWriter; import org.asamk.signal.output.JsonWriter;
import java.io.IOException; import java.io.IOException;
@ -76,6 +77,8 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
message = "Invalid captcha given."; message = "Invalid captcha given.";
} }
throw new UserErrorException(message); throw new UserErrorException(message);
} catch (NonNormalizedPhoneNumberException e) {
throw new UserErrorException("Failed to register: " + e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("Request verify error: " + e.getMessage(), e); throw new IOErrorException("Request verify error: " + e.getMessage(), e);
} }

View file

@ -9,6 +9,7 @@ import org.asamk.signal.manager.ProvisioningManager;
import org.asamk.signal.manager.RegistrationManager; import org.asamk.signal.manager.RegistrationManager;
import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.IncorrectPinException; import org.asamk.signal.manager.api.IncorrectPinException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException; import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.UserAlreadyExistsException; import org.asamk.signal.manager.api.UserAlreadyExistsException;
import org.freedesktop.dbus.DBusPath; import org.freedesktop.dbus.DBusPath;
@ -61,6 +62,8 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
} catch (CaptchaRequiredException e) { } catch (CaptchaRequiredException e) {
String message = captcha == null ? "Captcha required for verification." : "Invalid captcha given."; String message = captcha == null ? "Captcha required for verification." : "Invalid captcha given.";
throw new SignalControl.Error.RequiresCaptcha(message); throw new SignalControl.Error.RequiresCaptcha(message);
} catch (NonNormalizedPhoneNumberException e) {
throw new Error.InvalidNumber(e.getMessage());
} catch (OverlappingFileLockException e) { } catch (OverlappingFileLockException e) {
throw new SignalControl.Error.Failure("Account is already in use"); throw new SignalControl.Error.Failure("Account is already in use");
} catch (IOException e) { } catch (IOException e) {