mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-04 05:00:39 +00:00
Merge branch 'AsamK:master' into master
This commit is contained in:
commit
c40a70b63b
6 changed files with 79 additions and 11 deletions
|
@ -405,6 +405,10 @@ public class Manager implements Closeable {
|
||||||
account.setRegistered(false);
|
account.setRegistered(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException {
|
||||||
|
dependencies.getAccountManager().submitRateLimitRecaptchaChallenge(challenge, captcha);
|
||||||
|
}
|
||||||
|
|
||||||
public List<Device> getLinkedDevices() throws IOException {
|
public List<Device> getLinkedDevices() throws IOException {
|
||||||
var devices = dependencies.getAccountManager().getDevices();
|
var devices = dependencies.getAccountManager().getDevices();
|
||||||
account.setMultiDevice(devices.size() > 1);
|
account.setMultiDevice(devices.size() > 1);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.asamk.signal.manager;
|
||||||
import org.asamk.signal.manager.config.ServiceConfig;
|
import org.asamk.signal.manager.config.ServiceConfig;
|
||||||
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||||
import org.signal.libsignal.metadata.certificate.CertificateValidator;
|
import org.signal.libsignal.metadata.certificate.CertificateValidator;
|
||||||
|
import org.signal.zkgroup.profiles.ClientZkProfileOperations;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.KeyBackupService;
|
import org.whispersystems.signalservice.api.KeyBackupService;
|
||||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||||
|
@ -93,6 +94,11 @@ public class SignalDependencies {
|
||||||
: null);
|
: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ClientZkProfileOperations getClientZkProfileOperations() {
|
||||||
|
final var clientZkOperations = getClientZkOperations();
|
||||||
|
return clientZkOperations == null ? null : clientZkOperations.getProfileOperations();
|
||||||
|
}
|
||||||
|
|
||||||
public SignalWebSocket getSignalWebSocket() {
|
public SignalWebSocket getSignalWebSocket() {
|
||||||
return getOrCreate(() -> signalWebSocket, () -> {
|
return getOrCreate(() -> signalWebSocket, () -> {
|
||||||
final var timer = new UptimeSleepTimer();
|
final var timer = new UptimeSleepTimer();
|
||||||
|
@ -126,7 +132,7 @@ public class SignalDependencies {
|
||||||
() -> messageReceiver = new SignalServiceMessageReceiver(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
() -> messageReceiver = new SignalServiceMessageReceiver(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||||
credentialsProvider,
|
credentialsProvider,
|
||||||
userAgent,
|
userAgent,
|
||||||
getClientZkOperations().getProfileOperations(),
|
getClientZkProfileOperations(),
|
||||||
ServiceConfig.AUTOMATIC_NETWORK_RETRY));
|
ServiceConfig.AUTOMATIC_NETWORK_RETRY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +145,7 @@ public class SignalDependencies {
|
||||||
userAgent,
|
userAgent,
|
||||||
getSignalWebSocket(),
|
getSignalWebSocket(),
|
||||||
Optional.absent(),
|
Optional.absent(),
|
||||||
getClientZkOperations().getProfileOperations(),
|
getClientZkProfileOperations(),
|
||||||
executor,
|
executor,
|
||||||
ServiceConfig.MAX_ENVELOPE_SIZE,
|
ServiceConfig.MAX_ENVELOPE_SIZE,
|
||||||
ServiceConfig.AUTOMATIC_NETWORK_RETRY));
|
ServiceConfig.AUTOMATIC_NETWORK_RETRY));
|
||||||
|
@ -156,7 +162,7 @@ public class SignalDependencies {
|
||||||
|
|
||||||
public ProfileService getProfileService() {
|
public ProfileService getProfileService() {
|
||||||
return getOrCreate(() -> profileService,
|
return getOrCreate(() -> profileService,
|
||||||
() -> profileService = new ProfileService(getClientZkOperations().getProfileOperations(),
|
() -> profileService = new ProfileService(getClientZkProfileOperations(),
|
||||||
getMessageReceiver(),
|
getMessageReceiver(),
|
||||||
getSignalWebSocket()));
|
getSignalWebSocket()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||||
|
import org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -282,6 +283,8 @@ public class SendHelper {
|
||||||
message,
|
message,
|
||||||
SignalServiceMessageSender.IndividualSendEvents.EMPTY);
|
SignalServiceMessageSender.IndividualSendEvents.EMPTY);
|
||||||
}
|
}
|
||||||
|
} catch (ProofRequiredException e) {
|
||||||
|
return SendMessageResult.proofRequiredFailure(address, e);
|
||||||
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
} catch (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException e) {
|
||||||
return SendMessageResult.identityFailure(address, e.getIdentityKey());
|
return SendMessageResult.identityFailure(address, e.getIdentityKey());
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class Commands {
|
||||||
addCommand(new SendSyncRequestCommand());
|
addCommand(new SendSyncRequestCommand());
|
||||||
addCommand(new SendTypingCommand());
|
addCommand(new SendTypingCommand());
|
||||||
addCommand(new SetPinCommand());
|
addCommand(new SetPinCommand());
|
||||||
|
addCommand(new SubmitRateLimitChallengeCommand());
|
||||||
addCommand(new TrustCommand());
|
addCommand(new TrustCommand());
|
||||||
addCommand(new UnblockCommand());
|
addCommand(new UnblockCommand());
|
||||||
addCommand(new UnregisterCommand());
|
addCommand(new UnregisterCommand());
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package org.asamk.signal.commands;
|
||||||
|
|
||||||
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
|
import org.asamk.signal.OutputWriter;
|
||||||
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
|
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class SubmitRateLimitChallengeCommand implements JsonRpcLocalCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "submitRateLimitChallenge";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
|
subparser.help(
|
||||||
|
"Submit a captcha challenge to lift the rate limit. This command should only be necessary when sending fails with a proof required error.");
|
||||||
|
subparser.addArgument("--challenge")
|
||||||
|
.required(true)
|
||||||
|
.help("The challenge token taken from the proof required error.");
|
||||||
|
subparser.addArgument("--captcha")
|
||||||
|
.required(true)
|
||||||
|
.help("The captcha token from the solved captcha on the signal website.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCommand(final Namespace ns, final Manager m, OutputWriter outputWriter) throws CommandException {
|
||||||
|
final var challenge = ns.getString("challenge");
|
||||||
|
final var captchaString = ns.getString("captcha");
|
||||||
|
final var captcha = captchaString == null ? null : captchaString.replace("signalcaptcha://", "");
|
||||||
|
|
||||||
|
try {
|
||||||
|
m.submitRateLimitRecaptchaChallenge(challenge, captcha);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOErrorException("Submit challenge error: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -58,16 +58,20 @@ public class ErrorUtils {
|
||||||
|
|
||||||
public static String getErrorMessageFromSendMessageResult(SendMessageResult result) {
|
public static String getErrorMessageFromSendMessageResult(SendMessageResult result) {
|
||||||
var identifier = getLegacyIdentifier(result.getAddress());
|
var identifier = getLegacyIdentifier(result.getAddress());
|
||||||
if (result.isNetworkFailure()) {
|
if (result.getProofRequiredFailure() != null) {
|
||||||
return String.format("Network failure for \"%s\"", identifier);
|
|
||||||
} else if (result.isUnregisteredFailure()) {
|
|
||||||
return String.format("Unregistered user \"%s\"", identifier);
|
|
||||||
} else if (result.getIdentityFailure() != null) {
|
|
||||||
return String.format("Untrusted Identity for \"%s\"", identifier);
|
|
||||||
} else if (result.getProofRequiredFailure() != null) {
|
|
||||||
final var failure = result.getProofRequiredFailure();
|
final var failure = result.getProofRequiredFailure();
|
||||||
return String.format(
|
return String.format(
|
||||||
"CAPTCHA proof required for sending to \"%s\", available options \"%s\" with token \"%s\", or wait \"%d\" seconds",
|
"CAPTCHA proof required for sending to \"%s\", available options \"%s\" with challenge token \"%s\", or wait \"%d\" seconds.\n"
|
||||||
|
+ (
|
||||||
|
failure.getOptions().contains(ProofRequiredException.Option.RECAPTCHA)
|
||||||
|
?
|
||||||
|
"To get the captcha token, go to https://signalcaptchas.org/registration/generate.html\n"
|
||||||
|
+ "Check the developer tools (F12) console for a failed redirect to signalcaptcha://\n"
|
||||||
|
+ "Everything after signalcaptcha:// is the captcha token.\n"
|
||||||
|
+ "Use the following command to submit the captcha token:\n"
|
||||||
|
+ "signal-cli submitRateLimitChallenge --challenge CHALLENGE_TOKEN --captcha CAPTCHA_TOKEN"
|
||||||
|
: ""
|
||||||
|
),
|
||||||
identifier,
|
identifier,
|
||||||
failure.getOptions()
|
failure.getOptions()
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -75,6 +79,12 @@ public class ErrorUtils {
|
||||||
.collect(Collectors.joining(", ")),
|
.collect(Collectors.joining(", ")),
|
||||||
failure.getToken(),
|
failure.getToken(),
|
||||||
failure.getRetryAfterSeconds());
|
failure.getRetryAfterSeconds());
|
||||||
|
} else if (result.isNetworkFailure()) {
|
||||||
|
return String.format("Network failure for \"%s\"", identifier);
|
||||||
|
} else if (result.isUnregisteredFailure()) {
|
||||||
|
return String.format("Unregistered user \"%s\"", identifier);
|
||||||
|
} else if (result.getIdentityFailure() != null) {
|
||||||
|
return String.format("Untrusted Identity for \"%s\"", identifier);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue