mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Remove libsignal-service from manager lib API
This commit is contained in:
parent
9075cc1a30
commit
2ab42ca547
31 changed files with 269 additions and 96 deletions
|
@ -32,7 +32,6 @@ import org.freedesktop.dbus.exceptions.DBusException;
|
|||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -133,7 +132,7 @@ public class App {
|
|||
dataPath = getDefaultDataPath();
|
||||
}
|
||||
|
||||
if (!ServiceConfig.getCapabilities().isGv2()) {
|
||||
if (!ServiceConfig.isZkgroupAvailable()) {
|
||||
logger.warn("WARNING: Support for new group V2 is disabled,"
|
||||
+ " because the required native library dependency is missing: libzkgroup");
|
||||
}
|
||||
|
@ -182,7 +181,7 @@ public class App {
|
|||
}
|
||||
|
||||
username = usernames.get(0);
|
||||
} else if (!PhoneNumberFormatter.isValidNumber(username, null)) {
|
||||
} else if (!Manager.isValidNumber(username, null)) {
|
||||
throw new UserErrorException("Invalid username (phone number), make sure you include the country code.");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.asamk.signal.commands.exceptions.IOErrorException;
|
|||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.LibSignalLogger;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.util.SecurityProvider;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class Main {
|
|||
System.setProperty("org.slf4j.simpleLogger.showShortLogName", "false");
|
||||
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
|
||||
System.setProperty("org.slf4j.simpleLogger.dateTimeFormat", "yyyy-MM-dd'T'HH:mm:ss.SSSXX");
|
||||
LibSignalLogger.initLogger();
|
||||
Manager.initLogger();
|
||||
} else {
|
||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
|
||||
System.setProperty("org.slf4j.simpleLogger.showThreadName", "false");
|
||||
|
|
|
@ -361,7 +361,9 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
) {
|
||||
writer.println("Id: {}", quote.id());
|
||||
writer.println("Author: {}", formatContact(quote.author()));
|
||||
writer.println("Text: {}", quote.text());
|
||||
if (quote.text().isPresent()) {
|
||||
writer.println("Text: {}", quote.text().get());
|
||||
}
|
||||
if (quote.mentions() != null && quote.mentions().size() > 0) {
|
||||
writer.println("Mentions:");
|
||||
for (var mention : quote.mentions()) {
|
||||
|
@ -371,14 +373,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
if (quote.attachments().size() > 0) {
|
||||
writer.println("Attachments:");
|
||||
for (var attachment : quote.attachments()) {
|
||||
writer.println("- Filename: {}", attachment.fileName());
|
||||
writer.indent(w -> {
|
||||
w.println("Type: {}", attachment.contentType());
|
||||
w.println("Thumbnail:");
|
||||
if (attachment.thumbnail().isPresent()) {
|
||||
printAttachment(w, attachment.thumbnail().get());
|
||||
}
|
||||
});
|
||||
writer.println("- Attachment:");
|
||||
printAttachment(writer.indentedWriter(), attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -527,6 +523,10 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
+ attachment.preview().get().length
|
||||
+ " bytes)" : "");
|
||||
}
|
||||
if (attachment.thumbnail().isPresent()) {
|
||||
writer.println("Thumbnail:");
|
||||
printAttachment(writer.indentedWriter(), attachment.thumbnail().get());
|
||||
}
|
||||
final var flags = new ArrayList<String>();
|
||||
if (attachment.isVoiceNote()) {
|
||||
flags.add("voice note");
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.asamk.signal.manager.Manager;
|
|||
import org.asamk.signal.manager.api.InactiveGroupLinkException;
|
||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
@ -70,8 +69,6 @@ public class JoinGroupCommand implements JsonRpcLocalCommand {
|
|||
}
|
||||
}
|
||||
handleSendMessageResults(results.second().results());
|
||||
} catch (GroupPatchNotAcceptedException e) {
|
||||
throw new UserErrorException("Failed to join group, maybe already a member");
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Failed to send message: "
|
||||
+ e.getMessage()
|
||||
|
|
|
@ -63,10 +63,10 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
|||
} else {
|
||||
final var writer = (JsonWriter) outputWriter;
|
||||
final var jsonIdentities = identities.stream().map(id -> {
|
||||
final var address = id.recipient().toSignalServiceAddress();
|
||||
final var address = id.recipient();
|
||||
var safetyNumber = Util.formatSafetyNumber(id.safetyNumber());
|
||||
var scannableSafetyNumber = id.scannableSafetyNumber();
|
||||
return new JsonIdentity(address.getNumber().orNull(),
|
||||
return new JsonIdentity(address.getNumber().orElse(null),
|
||||
address.getUuid().toString(),
|
||||
Hex.toString(id.getFingerprint()),
|
||||
safetyNumber,
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.asamk.signal.commands.exceptions.CommandException;
|
|||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.RegistrationManager;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -5,12 +5,10 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
|||
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.RegistrationManager;
|
||||
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
|
||||
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
|
||||
import org.whispersystems.signalservice.internal.push.LockedException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -36,15 +34,13 @@ public class VerifyCommand implements RegistrationCommand {
|
|||
try {
|
||||
final var manager = m.verifyAccount(verificationCode, pin);
|
||||
manager.close();
|
||||
} catch (LockedException e) {
|
||||
} catch (PinLockedException e) {
|
||||
throw new UserErrorException(
|
||||
"Verification failed! This number is locked with a pin. Hours remaining until reset: "
|
||||
+ (e.getTimeRemaining() / 1000 / 60 / 60)
|
||||
+ "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
|
||||
} catch (KeyBackupServicePinException e) {
|
||||
} catch (IncorrectPinException e) {
|
||||
throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
|
||||
} catch (KeyBackupSystemNoDataException e) {
|
||||
throw new UnexpectedErrorException("Verification failed! No KBS data.", e);
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Verify error: " + e.getMessage(), e);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.freedesktop.dbus.DBusPath;
|
|||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.interfaces.DBusInterface;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -84,7 +82,7 @@ public class DbusManagerImpl implements Manager {
|
|||
final var result = new HashMap<String, Pair<String, UUID>>();
|
||||
for (var i = 0; i < numbersList.size(); i++) {
|
||||
result.put(numbersList.get(i),
|
||||
new Pair<>(numbersList.get(i), registered.get(i) ? UuidUtil.UNKNOWN_UUID : null));
|
||||
new Pair<>(numbersList.get(i), registered.get(i) ? RecipientAddress.UNKNOWN_UUID : null));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -173,7 +171,7 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Profile getRecipientProfile(final RecipientIdentifier.Single recipient) throws UnregisteredUserException {
|
||||
public Profile getRecipientProfile(final RecipientIdentifier.Single recipient) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -370,7 +368,7 @@ public class DbusManagerImpl implements Manager {
|
|||
@Override
|
||||
public void setContactName(
|
||||
final RecipientIdentifier.Single recipient, final String name
|
||||
) throws NotMasterDeviceException, UnregisteredUserException {
|
||||
) throws NotMasterDeviceException {
|
||||
signal.setContactName(recipient.getIdentifier(), name);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,11 @@ import org.asamk.signal.manager.Manager;
|
|||
import org.asamk.signal.manager.ProvisioningManager;
|
||||
import org.asamk.signal.manager.RegistrationManager;
|
||||
import org.asamk.signal.manager.UserAlreadyExists;
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.freedesktop.dbus.DBusPath;
|
||||
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
|
||||
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException;
|
||||
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
@ -100,7 +99,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
|
|||
public void registerWithCaptcha(
|
||||
final String number, final boolean voiceVerification, final String captcha
|
||||
) throws Error.Failure, Error.InvalidNumber {
|
||||
if (!PhoneNumberFormatter.isValidNumber(number, null)) {
|
||||
if (!Manager.isValidNumber(number, null)) {
|
||||
throw new SignalControl.Error.InvalidNumber(
|
||||
"Invalid username (phone number), make sure you include the country code.");
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
|
|||
try (final RegistrationManager registrationManager = c.getNewRegistrationManager(number)) {
|
||||
final Manager manager = registrationManager.verifyAccount(verificationCode, pin);
|
||||
addManager(manager);
|
||||
} catch (IOException | KeyBackupSystemNoDataException | KeyBackupServicePinException e) {
|
||||
} catch (IOException | PinLockedException | IncorrectPinException e) {
|
||||
throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,11 @@ import org.asamk.signal.manager.UntrustedIdentityException;
|
|||
import org.asamk.signal.manager.api.Identity;
|
||||
import org.asamk.signal.manager.api.InactiveGroupLinkException;
|
||||
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
|
||||
import org.asamk.signal.manager.api.InvalidNumberException;
|
||||
import org.asamk.signal.manager.api.Message;
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.SendMessageResult;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
import org.asamk.signal.manager.api.UpdateGroup;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
|
@ -32,8 +34,6 @@ import org.freedesktop.dbus.connections.impl.DBusConnection;
|
|||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.freedesktop.dbus.types.Variant;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -719,7 +719,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
final var message = timestamp + "\nFailed to send message:\n" + error + '\n';
|
||||
|
||||
if (result.getIdentityFailure() != null) {
|
||||
if (result.isIdentityFailure()) {
|
||||
throw new Error.UntrustedIdentity(message);
|
||||
} else {
|
||||
throw new Error.Failure(message);
|
||||
|
|
|
@ -5,9 +5,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.UntrustedIdentityException;
|
||||
import org.asamk.signal.manager.api.InvalidNumberException;
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -2,10 +2,10 @@ package org.asamk.signal.util;
|
|||
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.api.InvalidNumberException;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
|
|
@ -2,11 +2,11 @@ package org.asamk.signal.util;
|
|||
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.manager.api.ProofRequiredException;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.SendMessageResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -14,8 +14,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
public class ErrorUtils {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ErrorUtils.class);
|
||||
|
@ -57,9 +55,9 @@ public class ErrorUtils {
|
|||
}
|
||||
|
||||
public static String getErrorMessageFromSendMessageResult(SendMessageResult result) {
|
||||
var identifier = getLegacyIdentifier(result.getAddress());
|
||||
if (result.getProofRequiredFailure() != null) {
|
||||
final var failure = result.getProofRequiredFailure();
|
||||
var identifier = result.address().getLegacyIdentifier();
|
||||
if (result.proofRequiredFailure() != null) {
|
||||
final var failure = result.proofRequiredFailure();
|
||||
return String.format(
|
||||
"CAPTCHA proof required for sending to \"%s\", available options \"%s\" with challenge token \"%s\", or wait \"%d\" seconds.\n"
|
||||
+ (
|
||||
|
@ -83,7 +81,7 @@ public class ErrorUtils {
|
|||
return String.format("Network failure for \"%s\"", identifier);
|
||||
} else if (result.isUnregisteredFailure()) {
|
||||
return String.format("Unregistered user \"%s\"", identifier);
|
||||
} else if (result.getIdentityFailure() != null) {
|
||||
} else if (result.isIdentityFailure()) {
|
||||
return String.format("Untrusted Identity for \"%s\"", identifier);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -5,8 +5,6 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -59,10 +57,6 @@ public class Util {
|
|||
return f.toString();
|
||||
}
|
||||
|
||||
public static String getLegacyIdentifier(final SignalServiceAddress address) {
|
||||
return address.getNumber().or(() -> address.getUuid().toString());
|
||||
}
|
||||
|
||||
public static ObjectMapper createJsonObjectMapper() {
|
||||
var objectMapper = new ObjectMapper();
|
||||
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue