mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Prevent sending invalid locale to server
This commit is contained in:
parent
b8a0901fbd
commit
bfd6b605e9
1 changed files with 17 additions and 1 deletions
|
@ -22,6 +22,8 @@ import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||||
import org.asamk.signal.manager.helper.PinHelper;
|
import org.asamk.signal.manager.helper.PinHelper;
|
||||||
import org.asamk.signal.manager.storage.SignalAccount;
|
import org.asamk.signal.manager.storage.SignalAccount;
|
||||||
import org.asamk.signal.manager.util.KeyUtils;
|
import org.asamk.signal.manager.util.KeyUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.libsignal.util.KeyHelper;
|
import org.whispersystems.libsignal.util.KeyHelper;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
|
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
|
||||||
|
@ -45,6 +47,8 @@ import java.util.Locale;
|
||||||
|
|
||||||
public class RegistrationManager implements Closeable {
|
public class RegistrationManager implements Closeable {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(RegistrationManager.class);
|
||||||
|
|
||||||
private SignalAccount account;
|
private SignalAccount account;
|
||||||
private final PathConfig pathConfig;
|
private final PathConfig pathConfig;
|
||||||
private final ServiceEnvironmentConfig serviceEnvironmentConfig;
|
private final ServiceEnvironmentConfig serviceEnvironmentConfig;
|
||||||
|
@ -114,7 +118,7 @@ public class RegistrationManager implements Closeable {
|
||||||
|
|
||||||
public void register(boolean voiceVerification, String captcha) throws IOException {
|
public void register(boolean voiceVerification, String captcha) throws IOException {
|
||||||
if (voiceVerification) {
|
if (voiceVerification) {
|
||||||
accountManager.requestVoiceVerificationCode(Locale.getDefault(),
|
accountManager.requestVoiceVerificationCode(getDefaultLocale(),
|
||||||
Optional.fromNullable(captcha),
|
Optional.fromNullable(captcha),
|
||||||
Optional.absent());
|
Optional.absent());
|
||||||
} else {
|
} else {
|
||||||
|
@ -122,6 +126,18 @@ public class RegistrationManager implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Locale getDefaultLocale() {
|
||||||
|
final var locale = Locale.getDefault();
|
||||||
|
try {
|
||||||
|
Locale.LanguageRange.parse(locale.getLanguage() + "-" + locale.getCountry());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.debug("Invalid locale, ignoring: {}", locale);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
|
||||||
public Manager verifyAccount(
|
public Manager verifyAccount(
|
||||||
String verificationCode, String pin
|
String verificationCode, String pin
|
||||||
) throws IOException, LockedException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
|
) throws IOException, LockedException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue