Show information when requesting voice verification without SMS verification

Fixes #1373
This commit is contained in:
AsamK 2024-02-20 17:37:31 +01:00
parent f1e3b5c9cc
commit 59c1f4eed2
10 changed files with 39 additions and 8 deletions

View file

@ -43,6 +43,7 @@ import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.api.UpdateProfile; import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.api.UserStatus; import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.api.UsernameLinkUrl; import org.asamk.signal.manager.api.UsernameLinkUrl;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter; import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
@ -125,7 +126,7 @@ public interface Manager extends Closeable {
void startChangeNumber( void startChangeNumber(
String newNumber, boolean voiceVerification, String captcha String newNumber, boolean voiceVerification, String captcha
) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException; ) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException, VerificationMethoNotAvailableException;
void finishChangeNumber( void finishChangeNumber(
String newNumber, String verificationCode, String pin String newNumber, String verificationCode, String pin

View file

@ -5,6 +5,7 @@ import org.asamk.signal.manager.api.IncorrectPinException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException; 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.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
@ -13,7 +14,7 @@ public interface RegistrationManager extends Closeable {
void register( void register(
boolean voiceVerification, String captcha boolean voiceVerification, String captcha
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException; ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException;
void verifyAccount( void verifyAccount(
String verificationCode, String pin String verificationCode, String pin

View file

@ -0,0 +1,8 @@
package org.asamk.signal.manager.api;
public class VerificationMethoNotAvailableException extends Exception {
public VerificationMethoNotAvailableException() {
super("Invalid verification method");
}
}

View file

@ -7,6 +7,7 @@ import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException; 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.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.manager.internal.SignalDependencies; import org.asamk.signal.manager.internal.SignalDependencies;
import org.asamk.signal.manager.jobs.SyncStorageJob; import org.asamk.signal.manager.jobs.SyncStorageJob;
import org.asamk.signal.manager.storage.SignalAccount; import org.asamk.signal.manager.storage.SignalAccount;
@ -164,7 +165,7 @@ public class AccountHelper {
public void startChangeNumber( public void startChangeNumber(
String newNumber, boolean voiceVerification, String captcha String newNumber, boolean voiceVerification, String captcha
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException { ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException {
final var accountManager = dependencies.createUnauthenticatedAccountManager(newNumber, account.getPassword()); final var accountManager = dependencies.createUnauthenticatedAccountManager(newNumber, account.getPassword());
String sessionId = NumberVerificationUtils.handleVerificationSession(accountManager, String sessionId = NumberVerificationUtils.handleVerificationSession(accountManager,
account.getSessionId(newNumber), account.getSessionId(newNumber),

View file

@ -64,6 +64,7 @@ import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.api.UpdateProfile; import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.api.UserStatus; import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.api.UsernameLinkUrl; import org.asamk.signal.manager.api.UsernameLinkUrl;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig; import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.helper.AccountFileUpdater; import org.asamk.signal.manager.helper.AccountFileUpdater;
import org.asamk.signal.manager.helper.Context; import org.asamk.signal.manager.helper.Context;
@ -374,7 +375,7 @@ public class ManagerImpl implements Manager {
@Override @Override
public void startChangeNumber( public void startChangeNumber(
String newNumber, boolean voiceVerification, String captcha String newNumber, boolean voiceVerification, String captcha
) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException { ) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException, VerificationMethoNotAvailableException {
if (!account.isPrimaryDevice()) { if (!account.isPrimaryDevice()) {
throw new NotPrimaryDeviceException(); throw new NotPrimaryDeviceException();
} }

View file

@ -24,6 +24,7 @@ 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.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.UpdateProfile; import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.manager.config.ServiceConfig; import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig; import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.helper.AccountFileUpdater; import org.asamk.signal.manager.helper.AccountFileUpdater;
@ -104,7 +105,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
@Override @Override
public void register( public void register(
boolean voiceVerification, String captcha boolean voiceVerification, String captcha
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException { ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException {
if (account.isRegistered() if (account.isRegistered()
&& account.getServiceEnvironment() != null && account.getServiceEnvironment() != null
&& account.getServiceEnvironment() != serviceEnvironmentConfig.type()) { && account.getServiceEnvironment() != serviceEnvironmentConfig.type()) {

View file

@ -6,6 +6,7 @@ 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.api.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.manager.helper.PinHelper; import org.asamk.signal.manager.helper.PinHelper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -34,7 +35,7 @@ public class NumberVerificationUtils {
Consumer<String> sessionIdSaver, Consumer<String> sessionIdSaver,
boolean voiceVerification, boolean voiceVerification,
String captcha String captcha
) throws CaptchaRequiredException, IOException, RateLimitException { ) throws CaptchaRequiredException, IOException, RateLimitException, VerificationMethoNotAvailableException {
RegistrationSessionMetadataResponse sessionResponse; RegistrationSessionMetadataResponse sessionResponse;
try { try {
sessionResponse = getValidSession(accountManager, sessionId); sessionResponse = getValidSession(accountManager, sessionId);
@ -61,7 +62,9 @@ public class NumberVerificationUtils {
final var nextAttempt = voiceVerification final var nextAttempt = voiceVerification
? sessionResponse.getBody().getNextCall() ? sessionResponse.getBody().getNextCall()
: sessionResponse.getBody().getNextSms(); : sessionResponse.getBody().getNextSms();
if (nextAttempt != null && nextAttempt > 0) { if (nextAttempt == null) {
throw new VerificationMethoNotAvailableException();
} else if (nextAttempt > 0) {
final var timestamp = sessionResponse.getHeaders().getTimestamp() + nextAttempt * 1000; final var timestamp = sessionResponse.getHeaders().getTimestamp() + nextAttempt * 1000;
throw new RateLimitException(timestamp); throw new RateLimitException(timestamp);
} }

View file

@ -15,6 +15,7 @@ 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.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.output.JsonWriter; import org.asamk.signal.output.JsonWriter;
import org.asamk.signal.util.CommandUtil; import org.asamk.signal.util.CommandUtil;
@ -79,6 +80,12 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("Failed to register: %s (%s)".formatted(e.getMessage(), throw new IOErrorException("Failed to register: %s (%s)".formatted(e.getMessage(),
e.getClass().getSimpleName()), e); e.getClass().getSimpleName()), e);
} catch (VerificationMethoNotAvailableException e) {
throw new UserErrorException("Failed to register: " + e.getMessage() + (
voiceVerification
? ": Before requesting voice verification you need to request SMS verification and wait a minute."
: ""
), e);
} }
} }

View file

@ -13,6 +13,7 @@ import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException; import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.NotPrimaryDeviceException; import org.asamk.signal.manager.api.NotPrimaryDeviceException;
import org.asamk.signal.manager.api.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.output.OutputWriter; import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil; import org.asamk.signal.util.CommandUtil;
@ -59,6 +60,12 @@ public class StartChangeNumberCommand implements JsonRpcLocalCommand {
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("Failed to change number: %s (%s)".formatted(e.getMessage(), throw new IOErrorException("Failed to change number: %s (%s)".formatted(e.getMessage(),
e.getClass().getSimpleName()), e); e.getClass().getSimpleName()), e);
} catch (VerificationMethoNotAvailableException e) {
throw new UserErrorException("Failed to register: " + e.getMessage() + (
voiceVerification
? ": Before requesting voice verification you need to request SMS verification and wait a minute."
: ""
), e);
} }
} }
} }

View file

@ -13,6 +13,7 @@ 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.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.UserAlreadyExistsException; import org.asamk.signal.manager.api.UserAlreadyExistsException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.freedesktop.dbus.DBusPath; import org.freedesktop.dbus.DBusPath;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -73,7 +74,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
throw new Error.InvalidNumber(e.getMessage()); 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 | VerificationMethoNotAvailableException e) {
throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage()); throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage());
} }
} }