Prevent sending invalid locale to server

This commit is contained in:
AsamK 2021-05-21 15:38:11 +02:00
parent b8a0901fbd
commit bfd6b605e9

View file

@ -22,6 +22,8 @@ import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.helper.PinHelper;
import org.asamk.signal.manager.storage.SignalAccount;
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.guava.Optional;
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
@ -45,6 +47,8 @@ import java.util.Locale;
public class RegistrationManager implements Closeable {
private final static Logger logger = LoggerFactory.getLogger(RegistrationManager.class);
private SignalAccount account;
private final PathConfig pathConfig;
private final ServiceEnvironmentConfig serviceEnvironmentConfig;
@ -114,7 +118,7 @@ public class RegistrationManager implements Closeable {
public void register(boolean voiceVerification, String captcha) throws IOException {
if (voiceVerification) {
accountManager.requestVoiceVerificationCode(Locale.getDefault(),
accountManager.requestVoiceVerificationCode(getDefaultLocale(),
Optional.fromNullable(captcha),
Optional.absent());
} 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(
String verificationCode, String pin
) throws IOException, LockedException, KeyBackupSystemNoDataException, KeyBackupServicePinException {