mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Merge branch 'master' of https://github.com/scottslewis/signal-cli.git
This commit is contained in:
commit
19e7e1a493
17 changed files with 126 additions and 35 deletions
|
@ -210,12 +210,6 @@ public class StorageHelper {
|
|||
remoteOnlyRecords.size());
|
||||
}
|
||||
|
||||
final var unknownInserts = processKnownRecords(connection, remoteOnlyRecords);
|
||||
final var unknownDeletes = idDifference.localOnlyIds()
|
||||
.stream()
|
||||
.filter(id -> !KNOWN_TYPES.contains(id.getType()))
|
||||
.toList();
|
||||
|
||||
if (!idDifference.localOnlyIds().isEmpty()) {
|
||||
final var updated = account.getRecipientStore()
|
||||
.removeStorageIdsFromLocalOnlyUnregisteredRecipients(connection,
|
||||
|
@ -228,6 +222,12 @@ public class StorageHelper {
|
|||
}
|
||||
}
|
||||
|
||||
final var unknownInserts = processKnownRecords(connection, remoteOnlyRecords);
|
||||
final var unknownDeletes = idDifference.localOnlyIds()
|
||||
.stream()
|
||||
.filter(id -> !KNOWN_TYPES.contains(id.getType()))
|
||||
.toList();
|
||||
|
||||
logger.debug("Storage ids with unknown type: {} inserts, {} deletes",
|
||||
unknownInserts.size(),
|
||||
unknownDeletes.size());
|
||||
|
@ -279,10 +279,22 @@ public class StorageHelper {
|
|||
try (final var connection = account.getAccountDatabase().getConnection()) {
|
||||
connection.setAutoCommit(false);
|
||||
|
||||
final var localStorageIds = getAllLocalStorageIds(connection);
|
||||
final var idDifference = findIdDifference(remoteManifest.storageIds, localStorageIds);
|
||||
var localStorageIds = getAllLocalStorageIds(connection);
|
||||
var idDifference = findIdDifference(remoteManifest.storageIds, localStorageIds);
|
||||
logger.debug("ID Difference :: {}", idDifference);
|
||||
|
||||
final var unknownOnlyLocal = idDifference.localOnlyIds()
|
||||
.stream()
|
||||
.filter(id -> !KNOWN_TYPES.contains(id.getType()))
|
||||
.toList();
|
||||
|
||||
if (!unknownOnlyLocal.isEmpty()) {
|
||||
logger.debug("Storage ids with unknown type: {} to delete", unknownOnlyLocal.size());
|
||||
account.getUnknownStorageIdStore().deleteUnknownStorageIds(connection, unknownOnlyLocal);
|
||||
localStorageIds = getAllLocalStorageIds(connection);
|
||||
idDifference = findIdDifference(remoteManifest.storageIds, localStorageIds);
|
||||
}
|
||||
|
||||
final var remoteDeletes = idDifference.remoteOnlyIds().stream().map(StorageId::getRaw).toList();
|
||||
final var remoteInserts = buildLocalStorageRecords(connection, idDifference.localOnlyIds());
|
||||
// TODO check if local storage record proto matches remote, then reset to remote storage_id
|
||||
|
@ -595,7 +607,7 @@ public class StorageHelper {
|
|||
final var remote = remoteByRawId.get(rawId);
|
||||
final var local = localByRawId.get(rawId);
|
||||
|
||||
if (remote.getType() != local.getType() && local.getType() != 0) {
|
||||
if (remote.getType() != local.getType() && KNOWN_TYPES.contains(local.getType())) {
|
||||
remoteOnlyRawIds.remove(rawId);
|
||||
localOnlyRawIds.remove(rawId);
|
||||
hasTypeMismatch = true;
|
||||
|
|
|
@ -2,9 +2,12 @@ package org.asamk.signal.manager.internal;
|
|||
|
||||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||
import org.asamk.signal.manager.util.Utils;
|
||||
import org.signal.libsignal.metadata.certificate.CertificateValidator;
|
||||
import org.signal.libsignal.net.Network;
|
||||
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||
import org.whispersystems.signalservice.api.SignalServiceDataStore;
|
||||
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
||||
|
@ -31,6 +34,9 @@ import org.whispersystems.signalservice.internal.push.PushServiceSocket;
|
|||
import org.whispersystems.signalservice.internal.websocket.OkHttpWebSocketConnection;
|
||||
import org.whispersystems.signalservice.internal.websocket.WebSocketConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -38,6 +44,8 @@ import java.util.function.Supplier;
|
|||
|
||||
public class SignalDependencies {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SignalDependencies.class);
|
||||
|
||||
private final Object LOCK = new Object();
|
||||
|
||||
private final ServiceEnvironmentConfig serviceEnvironmentConfig;
|
||||
|
@ -129,8 +137,34 @@ public class SignalDependencies {
|
|||
}
|
||||
|
||||
public Network getLibSignalNetwork() {
|
||||
return getOrCreate(() -> libSignalNetwork,
|
||||
() -> libSignalNetwork = new Network(serviceEnvironmentConfig.netEnvironment(), userAgent));
|
||||
return getOrCreate(() -> libSignalNetwork, () -> {
|
||||
libSignalNetwork = new Network(serviceEnvironmentConfig.netEnvironment(), userAgent);
|
||||
setSignalNetworkProxy(libSignalNetwork);
|
||||
});
|
||||
}
|
||||
|
||||
private void setSignalNetworkProxy(Network libSignalNetwork) {
|
||||
final var proxy = Utils.getHttpsProxy();
|
||||
if (proxy.address() instanceof InetSocketAddress addr) {
|
||||
switch (proxy.type()) {
|
||||
case Proxy.Type.DIRECT -> {
|
||||
}
|
||||
case Proxy.Type.HTTP -> {
|
||||
try {
|
||||
libSignalNetwork.setProxy("http", addr.getHostName(), addr.getPort(), null, null);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to set http proxy", e);
|
||||
}
|
||||
}
|
||||
case Proxy.Type.SOCKS -> {
|
||||
try {
|
||||
libSignalNetwork.setProxy("socks", addr.getHostName(), addr.getPort(), null, null);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to set socks proxy", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SignalServiceAccountManager getAccountManager() {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class KeyValueStore {
|
|||
try (final var connection = database.getConnection()) {
|
||||
return getEntry(connection, key);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Failed read from pre_key store", e);
|
||||
throw new RuntimeException("Failed read from key_value store", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,38 +47,38 @@ public class NumberVerificationUtils {
|
|||
}
|
||||
}
|
||||
|
||||
sessionId = sessionResponse.getBody().getId();
|
||||
sessionId = sessionResponse.getMetadata().getId();
|
||||
sessionIdSaver.accept(sessionId);
|
||||
|
||||
if (sessionResponse.getBody().getVerified()) {
|
||||
if (sessionResponse.getMetadata().getVerified()) {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
if (sessionResponse.getBody().getAllowedToRequestCode()) {
|
||||
if (sessionResponse.getMetadata().getAllowedToRequestCode()) {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
final var nextAttempt = voiceVerification
|
||||
? sessionResponse.getBody().getNextCall()
|
||||
: sessionResponse.getBody().getNextSms();
|
||||
? sessionResponse.getMetadata().getNextCall()
|
||||
: sessionResponse.getMetadata().getNextSms();
|
||||
if (nextAttempt == null) {
|
||||
throw new VerificationMethodNotAvailableException();
|
||||
} else if (nextAttempt > 0) {
|
||||
final var timestamp = sessionResponse.getHeaders().getTimestamp() + nextAttempt * 1000;
|
||||
final var timestamp = sessionResponse.getClientReceivedAtMilliseconds() + nextAttempt * 1000;
|
||||
throw new RateLimitException(timestamp);
|
||||
}
|
||||
|
||||
final var nextVerificationAttempt = sessionResponse.getBody().getNextVerificationAttempt();
|
||||
final var nextVerificationAttempt = sessionResponse.getMetadata().getNextVerificationAttempt();
|
||||
if (nextVerificationAttempt != null && nextVerificationAttempt > 0) {
|
||||
final var timestamp = sessionResponse.getHeaders().getTimestamp() + nextVerificationAttempt * 1000;
|
||||
final var timestamp = sessionResponse.getClientReceivedAtMilliseconds() + nextVerificationAttempt * 1000;
|
||||
throw new CaptchaRequiredException(timestamp);
|
||||
}
|
||||
|
||||
if (sessionResponse.getBody().getRequestedInformation().contains("captcha")) {
|
||||
if (sessionResponse.getMetadata().getRequestedInformation().contains("captcha")) {
|
||||
if (captcha != null) {
|
||||
sessionResponse = submitCaptcha(registrationApi, sessionId, captcha);
|
||||
}
|
||||
if (!sessionResponse.getBody().getAllowedToRequestCode()) {
|
||||
if (!sessionResponse.getMetadata().getAllowedToRequestCode()) {
|
||||
throw new CaptchaRequiredException("Captcha Required");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
|
@ -202,4 +206,19 @@ public class Utils {
|
|||
public static String nullIfEmpty(String string) {
|
||||
return string == null || string.isEmpty() ? null : string;
|
||||
}
|
||||
|
||||
public static Proxy getHttpsProxy() {
|
||||
final URI uri;
|
||||
try {
|
||||
uri = new URI("https://example");
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final var proxies = ProxySelector.getDefault().select(uri);
|
||||
if (proxies.isEmpty()) {
|
||||
return Proxy.NO_PROXY;
|
||||
} else {
|
||||
return proxies.getFirst();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue