mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Update dependencies
This commit is contained in:
parent
9afd4e4328
commit
47e6fc1769
9 changed files with 138 additions and 50 deletions
|
@ -168,12 +168,13 @@ public class AccountHelper {
|
|||
String newNumber, boolean voiceVerification, String captcha
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethodNotAvailableException {
|
||||
final var accountManager = dependencies.createUnauthenticatedAccountManager(newNumber, account.getPassword());
|
||||
String sessionId = NumberVerificationUtils.handleVerificationSession(accountManager,
|
||||
final var registrationApi = accountManager.getRegistrationApi();
|
||||
String sessionId = NumberVerificationUtils.handleVerificationSession(registrationApi,
|
||||
account.getSessionId(newNumber),
|
||||
id -> account.setSessionId(newNumber, id),
|
||||
voiceVerification,
|
||||
captcha);
|
||||
NumberVerificationUtils.requestVerificationCode(accountManager, sessionId, voiceVerification);
|
||||
NumberVerificationUtils.requestVerificationCode(registrationApi, sessionId, voiceVerification);
|
||||
}
|
||||
|
||||
public void finishChangeNumber(
|
||||
|
@ -280,13 +281,13 @@ public class AccountHelper {
|
|||
pin,
|
||||
context.getPinHelper(),
|
||||
(sessionId1, verificationCode1, registrationLock) -> {
|
||||
final var accountManager = dependencies.getAccountManager();
|
||||
final var registrationApi = dependencies.getRegistrationApi();
|
||||
try {
|
||||
Utils.handleResponseException(accountManager.verifyAccount(verificationCode1, sessionId1));
|
||||
Utils.handleResponseException(registrationApi.verifyAccount(verificationCode1, sessionId1));
|
||||
} catch (AlreadyVerifiedException e) {
|
||||
// Already verified so can continue changing number
|
||||
}
|
||||
return Utils.handleResponseException(accountManager.changeNumber(new ChangePhoneNumberRequest(
|
||||
return Utils.handleResponseException(registrationApi.changeNumber(new ChangePhoneNumberRequest(
|
||||
sessionId1,
|
||||
null,
|
||||
newNumber,
|
||||
|
|
|
@ -129,14 +129,13 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
return;
|
||||
}
|
||||
|
||||
String sessionId = NumberVerificationUtils.handleVerificationSession(unauthenticatedAccountManager,
|
||||
final var registrationApi = unauthenticatedAccountManager.getRegistrationApi();
|
||||
String sessionId = NumberVerificationUtils.handleVerificationSession(registrationApi,
|
||||
account.getSessionId(account.getNumber()),
|
||||
id -> account.setSessionId(account.getNumber(), id),
|
||||
voiceVerification,
|
||||
captcha);
|
||||
NumberVerificationUtils.requestVerificationCode(unauthenticatedAccountManager,
|
||||
sessionId,
|
||||
voiceVerification);
|
||||
NumberVerificationUtils.requestVerificationCode(registrationApi, sessionId, voiceVerification);
|
||||
account.setRegistered(false);
|
||||
} catch (DeprecatedVersionException e) {
|
||||
logger.debug("Signal-Server returned deprecated version exception", e);
|
||||
|
@ -196,7 +195,8 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
|
||||
final var aciPreKeys = generatePreKeysForType(account.getAccountData(ServiceIdType.ACI));
|
||||
final var pniPreKeys = generatePreKeysForType(account.getAccountData(ServiceIdType.PNI));
|
||||
final var response = Utils.handleResponseException(unauthenticatedAccountManager.registerAccount(null,
|
||||
final var registrationApi = unauthenticatedAccountManager.getRegistrationApi();
|
||||
final var response = Utils.handleResponseException(registrationApi.registerAccount(null,
|
||||
recoveryPassword,
|
||||
account.getAccountAttributes(null),
|
||||
aciPreKeys,
|
||||
|
@ -256,12 +256,13 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
final PreKeyCollection aciPreKeys,
|
||||
final PreKeyCollection pniPreKeys
|
||||
) throws IOException {
|
||||
final var registrationApi = unauthenticatedAccountManager.getRegistrationApi();
|
||||
try {
|
||||
Utils.handleResponseException(unauthenticatedAccountManager.verifyAccount(verificationCode, sessionId));
|
||||
Utils.handleResponseException(registrationApi.verifyAccount(verificationCode, sessionId));
|
||||
} catch (AlreadyVerifiedException e) {
|
||||
// Already verified so can continue registering
|
||||
}
|
||||
return Utils.handleResponseException(unauthenticatedAccountManager.registerAccount(sessionId,
|
||||
return Utils.handleResponseException(registrationApi.registerAccount(sessionId,
|
||||
null,
|
||||
account.getAccountAttributes(registrationLock),
|
||||
aciPreKeys,
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.whispersystems.signalservice.api.groupsv2.GroupsV2Api;
|
|||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
||||
import org.whispersystems.signalservice.api.push.ServiceIdType;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.registration.RegistrationApi;
|
||||
import org.whispersystems.signalservice.api.services.ProfileService;
|
||||
import org.whispersystems.signalservice.api.svr.SecureValueRecovery;
|
||||
import org.whispersystems.signalservice.api.util.CredentialsProvider;
|
||||
|
@ -47,6 +48,7 @@ public class SignalDependencies {
|
|||
|
||||
private SignalServiceAccountManager accountManager;
|
||||
private GroupsV2Api groupsV2Api;
|
||||
private RegistrationApi registrationApi;
|
||||
private GroupsV2Operations groupsV2Operations;
|
||||
private ClientZkOperations clientZkOperations;
|
||||
|
||||
|
@ -80,8 +82,14 @@ public class SignalDependencies {
|
|||
if (this.pushServiceSocket != null) {
|
||||
this.pushServiceSocket.close();
|
||||
this.pushServiceSocket = null;
|
||||
this.accountManager = null;
|
||||
this.messageReceiver = null;
|
||||
this.messageSender = null;
|
||||
this.profileService = null;
|
||||
this.groupsV2Api = null;
|
||||
this.registrationApi = null;
|
||||
this.secureValueRecovery = null;
|
||||
}
|
||||
this.messageSender = null;
|
||||
getSignalWebSocket().forceNewWebSockets();
|
||||
}
|
||||
|
||||
|
@ -143,6 +151,10 @@ public class SignalDependencies {
|
|||
return getOrCreate(() -> groupsV2Api, () -> groupsV2Api = getAccountManager().getGroupsV2Api());
|
||||
}
|
||||
|
||||
public RegistrationApi getRegistrationApi() {
|
||||
return getOrCreate(() -> registrationApi, () -> registrationApi = getAccountManager().getRegistrationApi());
|
||||
}
|
||||
|
||||
public GroupsV2Operations getGroupsV2Operations() {
|
||||
return getOrCreate(() -> groupsV2Operations,
|
||||
() -> groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
|
||||
|
|
|
@ -10,14 +10,15 @@ import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
|
|||
import org.asamk.signal.manager.helper.PinHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||
import org.whispersystems.signalservice.api.NetworkResult;
|
||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NoSuchSessionException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.PushChallengeRequiredException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.TokenNotAcceptedException;
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse;
|
||||
import org.whispersystems.signalservice.api.registration.RegistrationApi;
|
||||
import org.whispersystems.signalservice.internal.push.LockedException;
|
||||
import org.whispersystems.signalservice.internal.push.PushServiceSocket.VerificationCodeTransport;
|
||||
import org.whispersystems.signalservice.internal.push.RegistrationSessionMetadataResponse;
|
||||
import org.whispersystems.signalservice.internal.push.VerifyAccountResponse;
|
||||
|
||||
|
@ -30,7 +31,7 @@ public class NumberVerificationUtils {
|
|||
private static final Logger logger = LoggerFactory.getLogger(NumberVerificationUtils.class);
|
||||
|
||||
public static String handleVerificationSession(
|
||||
SignalServiceAccountManager accountManager,
|
||||
RegistrationApi registrationApi,
|
||||
String sessionId,
|
||||
Consumer<String> sessionIdSaver,
|
||||
boolean voiceVerification,
|
||||
|
@ -38,11 +39,11 @@ public class NumberVerificationUtils {
|
|||
) throws CaptchaRequiredException, IOException, RateLimitException, VerificationMethodNotAvailableException {
|
||||
RegistrationSessionMetadataResponse sessionResponse;
|
||||
try {
|
||||
sessionResponse = getValidSession(accountManager, sessionId);
|
||||
sessionResponse = getValidSession(registrationApi, sessionId);
|
||||
} catch (PushChallengeRequiredException |
|
||||
org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException e) {
|
||||
if (captcha != null) {
|
||||
sessionResponse = submitCaptcha(accountManager, sessionId, captcha);
|
||||
sessionResponse = submitCaptcha(registrationApi, sessionId, captcha);
|
||||
} else {
|
||||
throw new CaptchaRequiredException("Captcha Required");
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ public class NumberVerificationUtils {
|
|||
|
||||
if (sessionResponse.getBody().getRequestedInformation().contains("captcha")) {
|
||||
if (captcha != null) {
|
||||
sessionResponse = submitCaptcha(accountManager, sessionId, captcha);
|
||||
sessionResponse = submitCaptcha(registrationApi, sessionId, captcha);
|
||||
}
|
||||
if (!sessionResponse.getBody().getAllowedToRequestCode()) {
|
||||
throw new CaptchaRequiredException("Captcha Required");
|
||||
|
@ -88,14 +89,20 @@ public class NumberVerificationUtils {
|
|||
}
|
||||
|
||||
public static void requestVerificationCode(
|
||||
SignalServiceAccountManager accountManager, String sessionId, boolean voiceVerification
|
||||
RegistrationApi registrationApi, String sessionId, boolean voiceVerification
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException {
|
||||
final ServiceResponse<RegistrationSessionMetadataResponse> response;
|
||||
final NetworkResult<RegistrationSessionMetadataResponse> response;
|
||||
final var locale = Utils.getDefaultLocale(Locale.US);
|
||||
if (voiceVerification) {
|
||||
response = accountManager.requestVoiceVerificationCode(sessionId, locale, false);
|
||||
response = registrationApi.requestSmsVerificationCode(sessionId,
|
||||
locale,
|
||||
false,
|
||||
VerificationCodeTransport.VOICE);
|
||||
} else {
|
||||
response = accountManager.requestSmsVerificationCode(sessionId, locale, false);
|
||||
response = registrationApi.requestSmsVerificationCode(sessionId,
|
||||
locale,
|
||||
false,
|
||||
VerificationCodeTransport.SMS);
|
||||
}
|
||||
try {
|
||||
Utils.handleResponseException(response);
|
||||
|
@ -140,37 +147,37 @@ public class NumberVerificationUtils {
|
|||
}
|
||||
|
||||
private static RegistrationSessionMetadataResponse validateSession(
|
||||
final SignalServiceAccountManager accountManager, final String sessionId
|
||||
final RegistrationApi registrationApi, final String sessionId
|
||||
) throws IOException {
|
||||
if (sessionId == null || sessionId.isEmpty()) {
|
||||
throw new NoSuchSessionException();
|
||||
}
|
||||
return Utils.handleResponseException(accountManager.getRegistrationSession(sessionId));
|
||||
return Utils.handleResponseException(registrationApi.getRegistrationSessionStatus(sessionId));
|
||||
}
|
||||
|
||||
private static RegistrationSessionMetadataResponse requestValidSession(
|
||||
final SignalServiceAccountManager accountManager
|
||||
final RegistrationApi registrationApi
|
||||
) throws IOException {
|
||||
return Utils.handleResponseException(accountManager.createRegistrationSession(null, "", ""));
|
||||
return Utils.handleResponseException(registrationApi.createRegistrationSession(null, "", ""));
|
||||
}
|
||||
|
||||
private static RegistrationSessionMetadataResponse getValidSession(
|
||||
final SignalServiceAccountManager accountManager, final String sessionId
|
||||
final RegistrationApi registrationApi, final String sessionId
|
||||
) throws IOException {
|
||||
try {
|
||||
return validateSession(accountManager, sessionId);
|
||||
return validateSession(registrationApi, sessionId);
|
||||
} catch (NoSuchSessionException e) {
|
||||
logger.debug("No registration session, creating new one.");
|
||||
return requestValidSession(accountManager);
|
||||
return requestValidSession(registrationApi);
|
||||
}
|
||||
}
|
||||
|
||||
private static RegistrationSessionMetadataResponse submitCaptcha(
|
||||
SignalServiceAccountManager accountManager, String sessionId, String captcha
|
||||
RegistrationApi registrationApi, String sessionId, String captcha
|
||||
) throws IOException, CaptchaRequiredException {
|
||||
captcha = captcha == null ? null : captcha.replace("signalcaptcha://", "");
|
||||
try {
|
||||
return Utils.handleResponseException(accountManager.submitCaptchaToken(sessionId, captcha));
|
||||
return Utils.handleResponseException(registrationApi.submitCaptchaToken(sessionId, captcha));
|
||||
} catch (PushChallengeRequiredException |
|
||||
org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException |
|
||||
TokenNotAcceptedException _e) {
|
||||
|
|
|
@ -6,9 +6,9 @@ import org.signal.libsignal.protocol.fingerprint.Fingerprint;
|
|||
import org.signal.libsignal.protocol.fingerprint.NumericFingerprintGenerator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.NetworkResult;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
|
@ -140,15 +140,15 @@ public class Utils {
|
|||
return map;
|
||||
}
|
||||
|
||||
public static <T> T handleResponseException(final ServiceResponse<T> response) throws IOException {
|
||||
final var throwableOptional = response.getExecutionError().or(response::getApplicationError);
|
||||
if (throwableOptional.isPresent()) {
|
||||
if (throwableOptional.get() instanceof IOException) {
|
||||
throw (IOException) throwableOptional.get();
|
||||
public static <T> T handleResponseException(final NetworkResult<T> response) throws IOException {
|
||||
final var throwableOptional = response.getCause();
|
||||
if (throwableOptional != null) {
|
||||
if (throwableOptional instanceof IOException ioException) {
|
||||
throw ioException;
|
||||
} else {
|
||||
throw new IOException(throwableOptional.get());
|
||||
throw new IOException(throwableOptional);
|
||||
}
|
||||
}
|
||||
return response.getResult().orElse(null);
|
||||
return response.successOrThrow();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue