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.VerificationMethodNotAvailableException;
import org.asamk.signal.manager.helper.PinHelper;
-import org.whispersystems.signalservice.api.KbsPinData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.kbs.MasterKey;
import org.whispersystems.signalservice.api.push.exceptions.NoSuchSessionException;
public class NumberVerificationUtils {
+ private static final Logger logger = LoggerFactory.getLogger(NumberVerificationUtils.class);
+
public static String handleVerificationSession(
SignalServiceAccountManager accountManager,
String sessionId,
Consumer<String> sessionIdSaver,
boolean voiceVerification,
String captcha
- ) throws CaptchaRequiredException, IOException, RateLimitException {
+ ) throws CaptchaRequiredException, IOException, RateLimitException, VerificationMethodNotAvailableException {
RegistrationSessionMetadataResponse sessionResponse;
try {
sessionResponse = getValidSession(accountManager, sessionId);
final var nextAttempt = voiceVerification
? sessionResponse.getBody().getNextCall()
: sessionResponse.getBody().getNextSms();
- if (nextAttempt != null && nextAttempt > 0) {
+ if (nextAttempt == null) {
+ throw new VerificationMethodNotAvailableException();
+ } else if (nextAttempt > 0) {
final var timestamp = sessionResponse.getHeaders().getTimestamp() + nextAttempt * 1000;
throw new RateLimitException(timestamp);
}
throw new PinLockedException(e.getTimeRemaining());
}
- KbsPinData registrationLockData;
- registrationLockData = pinHelper.getRegistrationLockData(pin, e);
+ final var registrationLockData = pinHelper.getRegistrationLockData(pin, e);
if (registrationLockData == null) {
throw e;
}
private static RegistrationSessionMetadataResponse requestValidSession(
final SignalServiceAccountManager accountManager
- ) throws NoSuchSessionException, IOException {
+ ) throws IOException {
return Utils.handleResponseException(accountManager.createRegistrationSession(null, "", ""));
}
try {
return validateSession(accountManager, sessionId);
} catch (NoSuchSessionException e) {
+ logger.debug("No registration session, creating new one.");
return requestValidSession(accountManager);
}
}