Skip to content

Commit

Permalink
Show information when requesting voice verification without SMS verif…
Browse files Browse the repository at this point in the history
…ication

Fixes #1373
  • Loading branch information
AsamK committed Feb 20, 2024
1 parent f1e3b5c commit 59c1f4e
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/src/main/java/org/asamk/signal/manager/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.api.UsernameLinkUrl;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
Expand Down Expand Up @@ -125,7 +126,7 @@ void updateAccountAttributes(

void startChangeNumber(
String newNumber, boolean voiceVerification, String captcha
) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException;
) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException, VerificationMethoNotAvailableException;

void finishChangeNumber(
String newNumber, String verificationCode, String pin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;

import java.io.Closeable;
import java.io.IOException;
Expand All @@ -13,7 +14,7 @@ public interface RegistrationManager extends Closeable {

void register(
boolean voiceVerification, String captcha
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException;
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException;

void verifyAccount(
String verificationCode, String pin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.asamk.signal.manager.api;

public class VerificationMethoNotAvailableException extends Exception {

public VerificationMethoNotAvailableException() {
super("Invalid verification method");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException;
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.jobs.SyncStorageJob;
import org.asamk.signal.manager.storage.SignalAccount;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void setPni(

public void startChangeNumber(
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());
String sessionId = NumberVerificationUtils.handleVerificationSession(accountManager,
account.getSessionId(newNumber),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.api.UserStatus;
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.helper.AccountFileUpdater;
import org.asamk.signal.manager.helper.Context;
Expand Down Expand Up @@ -374,7 +375,7 @@ public void deleteUsername() throws IOException {
@Override
public void startChangeNumber(
String newNumber, boolean voiceVerification, String captcha
) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException {
) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException, VerificationMethoNotAvailableException {
if (!account.isPrimaryDevice()) {
throw new NotPrimaryDeviceException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.RateLimitException;
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.ServiceEnvironmentConfig;
import org.asamk.signal.manager.helper.AccountFileUpdater;
Expand Down Expand Up @@ -104,7 +105,7 @@ public RegistrationManagerImpl(
@Override
public void register(
boolean voiceVerification, String captcha
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException {
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException {
if (account.isRegistered()
&& account.getServiceEnvironment() != null
&& account.getServiceEnvironment() != serviceEnvironmentConfig.type()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.manager.helper.PinHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -34,7 +35,7 @@ public static String handleVerificationSession(
Consumer<String> sessionIdSaver,
boolean voiceVerification,
String captcha
) throws CaptchaRequiredException, IOException, RateLimitException {
) throws CaptchaRequiredException, IOException, RateLimitException, VerificationMethoNotAvailableException {
RegistrationSessionMetadataResponse sessionResponse;
try {
sessionResponse = getValidSession(accountManager, sessionId);
Expand All @@ -61,7 +62,9 @@ public static String handleVerificationSession(
final var nextAttempt = voiceVerification
? sessionResponse.getBody().getNextCall()
: 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;
throw new RateLimitException(timestamp);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/asamk/signal/commands/RegisterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.asamk.signal.manager.api.CaptchaRequiredException;
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.output.JsonWriter;
import org.asamk.signal.util.CommandUtil;

Expand Down Expand Up @@ -79,6 +80,12 @@ private void register(
} catch (IOException e) {
throw new IOErrorException("Failed to register: %s (%s)".formatted(e.getMessage(),
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;

Expand Down Expand Up @@ -59,6 +60,12 @@ public void handleCommand(
} catch (IOException e) {
throw new IOErrorException("Failed to change number: %s (%s)".formatted(e.getMessage(),
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.UserAlreadyExistsException;
import org.asamk.signal.manager.api.VerificationMethoNotAvailableException;
import org.freedesktop.dbus.DBusPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void registerWithCaptcha(
throw new Error.InvalidNumber(e.getMessage());
} catch (OverlappingFileLockException e) {
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());
}
}
Expand Down

1 comment on commit 59c1f4e

@szepeviktor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AsamK A "d" is missing from VerificationMethoNotAvailableException

Please sign in to comment.