mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 12:30:39 +00:00
Merge remote-tracking branch 'AsamK/master'
This commit is contained in:
commit
be32bf9856
29 changed files with 1163 additions and 563 deletions
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
|
@ -17,7 +17,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Setup Java JDK
|
- name: Setup Java JDK
|
||||||
uses: actions/setup-java@v1.3.0
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 11
|
||||||
|
|
||||||
|
|
18
.idea/codeStyles/Project.xml
generated
18
.idea/codeStyles/Project.xml
generated
|
@ -28,6 +28,24 @@
|
||||||
</option>
|
</option>
|
||||||
<option name="JD_P_AT_EMPTY_LINES" value="false" />
|
<option name="JD_P_AT_EMPTY_LINES" value="false" />
|
||||||
</JavaCodeStyleSettings>
|
</JavaCodeStyleSettings>
|
||||||
|
<JetCodeStyleSettings>
|
||||||
|
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||||
|
<value>
|
||||||
|
<package name="java.util" alias="false" withSubpackages="false" />
|
||||||
|
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||||
|
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||||
|
<value>
|
||||||
|
<package name="" alias="false" withSubpackages="true" />
|
||||||
|
<package name="java" alias="false" withSubpackages="true" />
|
||||||
|
<package name="javax" alias="false" withSubpackages="true" />
|
||||||
|
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||||
|
<package name="" alias="true" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</JetCodeStyleSettings>
|
||||||
<XML>
|
<XML>
|
||||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||||
</XML>
|
</XML>
|
||||||
|
|
19
CHANGELOG.md
Normal file
19
CHANGELOG.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.6.12] - 2020-11-22
|
||||||
|
### Added
|
||||||
|
- Show additional message content (view once, remote delete, mention, …) for received messages
|
||||||
|
- `--captcha` parameter for `register` command, required for some IP ranges
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Profile keys are now stored separately from contact list
|
||||||
|
- Receipts from normal and unidentified messages now have the same format in json output
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Issue where some messages were sent with an old counter index
|
||||||
|
|
||||||
|
## Older
|
||||||
|
|
||||||
|
Look at the [release tags](https://github.com/AsamK/signal-cli/releases) for information about older releases.
|
|
@ -7,7 +7,7 @@ targetCompatibility = JavaVersion.VERSION_11
|
||||||
|
|
||||||
mainClassName = 'org.asamk.signal.Main'
|
mainClassName = 'org.asamk.signal.Main'
|
||||||
|
|
||||||
version = '0.6.11'
|
version = '0.6.12'
|
||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.turasa:signal-service-java:2.15.3_unofficial_14'
|
implementation 'com.github.turasa:signal-service-java:2.15.3_unofficial_15'
|
||||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.66'
|
implementation 'org.bouncycastle:bcprov-jdk15on:1.67'
|
||||||
implementation 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
implementation 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
||||||
implementation 'com.github.hypfvieh:dbus-java:3.2.3'
|
implementation 'com.github.hypfvieh:dbus-java:3.2.3'
|
||||||
implementation 'org.slf4j:slf4j-nop:1.7.30'
|
implementation 'org.slf4j:slf4j-nop:1.7.30'
|
||||||
|
|
|
@ -54,6 +54,12 @@ Use the verify command to complete the verification.
|
||||||
*-v*, *--voice*::
|
*-v*, *--voice*::
|
||||||
The verification should be done over voice, not SMS.
|
The verification should be done over voice, not SMS.
|
||||||
|
|
||||||
|
*--captcha*::
|
||||||
|
The captcha token, required if registration failed with a captcha required error.
|
||||||
|
To get the token, go to https://signalcaptchas.org/registration/generate.html
|
||||||
|
Check the developer tools for a redirect starting with signalcaptcha://
|
||||||
|
Everything after signalcaptcha:// is the captcha token.
|
||||||
|
|
||||||
=== verify
|
=== verify
|
||||||
|
|
||||||
Verify the number using the code received via SMS or voice.
|
Verify the number using the code received via SMS or voice.
|
||||||
|
|
|
@ -61,16 +61,17 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
} else if (content.getDataMessage().isPresent()) {
|
} else if (content.getDataMessage().isPresent()) {
|
||||||
SignalServiceDataMessage message = content.getDataMessage().get();
|
SignalServiceDataMessage message = content.getDataMessage().get();
|
||||||
|
|
||||||
|
byte[] groupId = getGroupId(m, message);
|
||||||
if (!message.isEndSession() &&
|
if (!message.isEndSession() &&
|
||||||
!(message.getGroupContext().isPresent() &&
|
(groupId == null
|
||||||
message.getGroupContext().get().getGroupV1Type() != SignalServiceGroup.Type.DELIVER)) {
|
|| message.getGroupContext().get().getGroupV1Type() == null
|
||||||
|
|| message.getGroupContext().get().getGroupV1Type() == SignalServiceGroup.Type.DELIVER)) {
|
||||||
try {
|
try {
|
||||||
conn.sendMessage(new Signal.MessageReceived(
|
conn.sendMessage(new Signal.MessageReceived(
|
||||||
objectPath,
|
objectPath,
|
||||||
message.getTimestamp(),
|
message.getTimestamp(),
|
||||||
sender.getLegacyIdentifier(),
|
sender.getLegacyIdentifier(),
|
||||||
message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
|
groupId != null ? groupId : new byte[0],
|
||||||
? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
|
|
||||||
message.getBody().isPresent() ? message.getBody().get() : "",
|
message.getBody().isPresent() ? message.getBody().get() : "",
|
||||||
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
|
@ -84,6 +85,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
|
|
||||||
if (transcript.getDestination().isPresent() || transcript.getMessage().getGroupContext().isPresent()) {
|
if (transcript.getDestination().isPresent() || transcript.getMessage().getGroupContext().isPresent()) {
|
||||||
SignalServiceDataMessage message = transcript.getMessage();
|
SignalServiceDataMessage message = transcript.getMessage();
|
||||||
|
byte[] groupId = getGroupId(m, message);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn.sendMessage(new Signal.SyncMessageReceived(
|
conn.sendMessage(new Signal.SyncMessageReceived(
|
||||||
|
@ -91,8 +93,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
transcript.getTimestamp(),
|
transcript.getTimestamp(),
|
||||||
sender.getLegacyIdentifier(),
|
sender.getLegacyIdentifier(),
|
||||||
transcript.getDestination().isPresent() ? transcript.getDestination().get().getLegacyIdentifier() : "",
|
transcript.getDestination().isPresent() ? transcript.getDestination().get().getLegacyIdentifier() : "",
|
||||||
message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()
|
groupId != null ? groupId : new byte[0],
|
||||||
? message.getGroupContext().get().getGroupV1().get().getGroupId() : new byte[0],
|
|
||||||
message.getBody().isPresent() ? message.getBody().get() : "",
|
message.getBody().isPresent() ? message.getBody().get() : "",
|
||||||
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
JsonDbusReceiveMessageHandler.getAttachments(message, m)));
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
|
@ -104,6 +105,22 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] getGroupId(final Manager m, final SignalServiceDataMessage message) {
|
||||||
|
byte[] groupId;
|
||||||
|
if (message.getGroupContext().isPresent()) {
|
||||||
|
if (message.getGroupContext().get().getGroupV1().isPresent()) {
|
||||||
|
groupId = message.getGroupContext().get().getGroupV1().get().getGroupId();
|
||||||
|
} else if (message.getGroupContext().get().getGroupV2().isPresent()) {
|
||||||
|
groupId = m.getGroupId(message.getGroupContext().get().getGroupV2().get().getMasterKey());
|
||||||
|
} else {
|
||||||
|
groupId = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
groupId = null;
|
||||||
|
}
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
static private List<String> getAttachments(SignalServiceDataMessage message, Manager m) {
|
static private List<String> getAttachments(SignalServiceDataMessage message, Manager m) {
|
||||||
List<String> attachments = new ArrayList<>();
|
List<String> attachments = new ArrayList<>();
|
||||||
if (message.getAttachments().isPresent()) {
|
if (message.getAttachments().isPresent()) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
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.calls.AnswerMessage;
|
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
|
||||||
|
@ -22,6 +24,8 @@ import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMess
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.KeysMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
||||||
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;
|
||||||
|
@ -170,6 +174,15 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
if (configurationMessage.getReadReceipts().isPresent()) {
|
if (configurationMessage.getReadReceipts().isPresent()) {
|
||||||
System.out.println(" - Read receipts: " + (configurationMessage.getReadReceipts().get() ? "enabled" : "disabled"));
|
System.out.println(" - Read receipts: " + (configurationMessage.getReadReceipts().get() ? "enabled" : "disabled"));
|
||||||
}
|
}
|
||||||
|
if (configurationMessage.getLinkPreviews().isPresent()) {
|
||||||
|
System.out.println(" - Link previews: " + (configurationMessage.getLinkPreviews().get() ? "enabled" : "disabled"));
|
||||||
|
}
|
||||||
|
if (configurationMessage.getTypingIndicators().isPresent()) {
|
||||||
|
System.out.println(" - Typing indicators: " + (configurationMessage.getTypingIndicators().get() ? "enabled" : "disabled"));
|
||||||
|
}
|
||||||
|
if (configurationMessage.getUnidentifiedDeliveryIndicators().isPresent()) {
|
||||||
|
System.out.println(" - Unidentified Delivery Indicators: " + (configurationMessage.getUnidentifiedDeliveryIndicators().get() ? "enabled" : "disabled"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (syncMessage.getFetchType().isPresent()) {
|
if (syncMessage.getFetchType().isPresent()) {
|
||||||
final SignalServiceSyncMessage.FetchType fetchType = syncMessage.getFetchType().get();
|
final SignalServiceSyncMessage.FetchType fetchType = syncMessage.getFetchType().get();
|
||||||
|
@ -194,6 +207,26 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (syncMessage.getMessageRequestResponse().isPresent()) {
|
||||||
|
final MessageRequestResponseMessage requestResponseMessage = syncMessage.getMessageRequestResponse().get();
|
||||||
|
System.out.println("Received message request response:");
|
||||||
|
System.out.println(" Type: " + requestResponseMessage.getType());
|
||||||
|
if (requestResponseMessage.getGroupId().isPresent()) {
|
||||||
|
System.out.println(" Group id: " + Base64.encodeBytes(requestResponseMessage.getGroupId().get()));
|
||||||
|
}
|
||||||
|
if (requestResponseMessage.getPerson().isPresent()) {
|
||||||
|
System.out.println(" Person: " + requestResponseMessage.getPerson().get().getLegacyIdentifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (syncMessage.getKeys().isPresent()) {
|
||||||
|
final KeysMessage keysMessage = syncMessage.getKeys().get();
|
||||||
|
System.out.println("Received sync message with keys:");
|
||||||
|
if (keysMessage.getStorageService().isPresent()) {
|
||||||
|
System.out.println(" With storage key length: " + keysMessage.getStorageService().get().serialize().length);
|
||||||
|
} else {
|
||||||
|
System.out.println(" With empty storage key");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (content.getCallMessage().isPresent()) {
|
if (content.getCallMessage().isPresent()) {
|
||||||
System.out.println("Received a call message");
|
System.out.println("Received a call message");
|
||||||
|
@ -242,11 +275,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
System.out.println(" - Action: " + typingMessage.getAction());
|
System.out.println(" - Action: " + typingMessage.getAction());
|
||||||
System.out.println(" - Timestamp: " + DateUtils.formatTimestamp(typingMessage.getTimestamp()));
|
System.out.println(" - Timestamp: " + DateUtils.formatTimestamp(typingMessage.getTimestamp()));
|
||||||
if (typingMessage.getGroupId().isPresent()) {
|
if (typingMessage.getGroupId().isPresent()) {
|
||||||
|
System.out.println(" - Group Info:");
|
||||||
|
System.out.println(" Id: " + Base64.encodeBytes(typingMessage.getGroupId().get()));
|
||||||
GroupInfo group = m.getGroup(typingMessage.getGroupId().get());
|
GroupInfo group = m.getGroup(typingMessage.getGroupId().get());
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
System.out.println(" Name: " + group.name);
|
System.out.println(" Name: " + group.getTitle());
|
||||||
} else {
|
} else {
|
||||||
System.out.println(" Name: <Unknown group>");
|
System.out.println(" Name: <Unknown group>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,38 +294,57 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
|
|
||||||
private void handleSignalServiceDataMessage(SignalServiceDataMessage message) {
|
private void handleSignalServiceDataMessage(SignalServiceDataMessage message) {
|
||||||
System.out.println("Message timestamp: " + DateUtils.formatTimestamp(message.getTimestamp()));
|
System.out.println("Message timestamp: " + DateUtils.formatTimestamp(message.getTimestamp()));
|
||||||
|
if (message.isViewOnce()) {
|
||||||
|
System.out.println("=VIEW ONCE=");
|
||||||
|
}
|
||||||
|
|
||||||
if (message.getBody().isPresent()) {
|
if (message.getBody().isPresent()) {
|
||||||
System.out.println("Body: " + message.getBody().get());
|
System.out.println("Body: " + message.getBody().get());
|
||||||
}
|
}
|
||||||
if (message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()) {
|
if (message.getGroupContext().isPresent()) {
|
||||||
SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
|
|
||||||
System.out.println("Group info:");
|
System.out.println("Group info:");
|
||||||
System.out.println(" Id: " + Base64.encodeBytes(groupInfo.getGroupId()));
|
final SignalServiceGroupContext groupContext = message.getGroupContext().get();
|
||||||
if (groupInfo.getType() == SignalServiceGroup.Type.UPDATE && groupInfo.getName().isPresent()) {
|
if (groupContext.getGroupV1().isPresent()) {
|
||||||
System.out.println(" Name: " + groupInfo.getName().get());
|
SignalServiceGroup groupInfo = groupContext.getGroupV1().get();
|
||||||
} else {
|
System.out.println(" Id: " + Base64.encodeBytes(groupInfo.getGroupId()));
|
||||||
GroupInfo group = m.getGroup(groupInfo.getGroupId());
|
if (groupInfo.getType() == SignalServiceGroup.Type.UPDATE && groupInfo.getName().isPresent()) {
|
||||||
|
System.out.println(" Name: " + groupInfo.getName().get());
|
||||||
|
} else {
|
||||||
|
GroupInfo group = m.getGroup(groupInfo.getGroupId());
|
||||||
|
if (group != null) {
|
||||||
|
System.out.println(" Name: " + group.getTitle());
|
||||||
|
} else {
|
||||||
|
System.out.println(" Name: <Unknown group>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(" Type: " + groupInfo.getType());
|
||||||
|
if (groupInfo.getMembers().isPresent()) {
|
||||||
|
for (SignalServiceAddress member : groupInfo.getMembers().get()) {
|
||||||
|
System.out.println(" Member: " + member.getLegacyIdentifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (groupInfo.getAvatar().isPresent()) {
|
||||||
|
System.out.println(" Avatar:");
|
||||||
|
printAttachment(groupInfo.getAvatar().get());
|
||||||
|
}
|
||||||
|
} else if (groupContext.getGroupV2().isPresent()) {
|
||||||
|
final SignalServiceGroupV2 groupInfo = groupContext.getGroupV2().get();
|
||||||
|
byte[] groupId = m.getGroupId(groupInfo.getMasterKey());
|
||||||
|
System.out.println(" Id: " + Base64.encodeBytes(groupId));
|
||||||
|
GroupInfo group = m.getGroup(groupId);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
System.out.println(" Name: " + group.name);
|
System.out.println(" Name: " + group.getTitle());
|
||||||
} else {
|
} else {
|
||||||
System.out.println(" Name: <Unknown group>");
|
System.out.println(" Name: <Unknown group>");
|
||||||
}
|
}
|
||||||
}
|
System.out.println(" Revision: " + groupInfo.getRevision());
|
||||||
System.out.println(" Type: " + groupInfo.getType());
|
System.out.println(" Master key length: " + groupInfo.getMasterKey().serialize().length);
|
||||||
if (groupInfo.getMembers().isPresent()) {
|
System.out.println(" Has signed group change: " + groupInfo.hasSignedGroupChange());
|
||||||
for (SignalServiceAddress member : groupInfo.getMembers().get()) {
|
|
||||||
System.out.println(" Member: " + member.getLegacyIdentifier());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (groupInfo.getAvatar().isPresent()) {
|
|
||||||
System.out.println(" Avatar:");
|
|
||||||
printAttachment(groupInfo.getAvatar().get());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (message.getPreviews().isPresent()) {
|
if (message.getPreviews().isPresent()) {
|
||||||
final List<SignalServiceDataMessage.Preview> previews = message.getPreviews().get();
|
final List<SignalServiceDataMessage.Preview> previews = message.getPreviews().get();
|
||||||
System.out.println("Previes:");
|
System.out.println("Previews:");
|
||||||
for (SignalServiceDataMessage.Preview preview : previews) {
|
for (SignalServiceDataMessage.Preview preview : previews) {
|
||||||
System.out.println(" - Title: " + preview.getTitle());
|
System.out.println(" - Title: " + preview.getTitle());
|
||||||
System.out.println(" - Url: " + preview.getUrl());
|
System.out.println(" - Url: " + preview.getUrl());
|
||||||
|
@ -332,7 +386,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
final SignalServiceDataMessage.Reaction reaction = message.getReaction().get();
|
final SignalServiceDataMessage.Reaction reaction = message.getReaction().get();
|
||||||
System.out.println("Reaction:");
|
System.out.println("Reaction:");
|
||||||
System.out.println(" - Emoji: " + reaction.getEmoji());
|
System.out.println(" - Emoji: " + reaction.getEmoji());
|
||||||
System.out.println(" - Target author: " + reaction.getTargetAuthor().getLegacyIdentifier()); // todo resolve
|
System.out.println(" - Target author: " + m.resolveSignalServiceAddress(reaction.getTargetAuthor()).getLegacyIdentifier());
|
||||||
System.out.println(" - Target timestamp: " + reaction.getTargetSentTimestamp());
|
System.out.println(" - Target timestamp: " + reaction.getTargetSentTimestamp());
|
||||||
System.out.println(" - Is remove: " + reaction.isRemove());
|
System.out.println(" - Is remove: " + reaction.isRemove());
|
||||||
}
|
}
|
||||||
|
@ -355,6 +409,18 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.getRemoteDelete().isPresent()) {
|
||||||
|
final SignalServiceDataMessage.RemoteDelete remoteDelete = message.getRemoteDelete().get();
|
||||||
|
System.out.println("Remote delete message: timestamp = " + remoteDelete.getTargetSentTimestamp());
|
||||||
|
}
|
||||||
|
if (message.getMentions().isPresent()) {
|
||||||
|
final List<SignalServiceDataMessage.Mention> mentions = message.getMentions().get();
|
||||||
|
System.out.println("Mentions: ");
|
||||||
|
for (SignalServiceDataMessage.Mention mention : mentions) {
|
||||||
|
System.out.println("- " + mention.getUuid() + ": " + mention.getStart() + " (length: " + mention.getLength() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (message.getAttachments().isPresent()) {
|
if (message.getAttachments().isPresent()) {
|
||||||
System.out.println("Attachments: ");
|
System.out.println("Attachments: ");
|
||||||
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
||||||
|
|
|
@ -10,16 +10,23 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.util.Base64;
|
import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ListGroupsCommand implements LocalCommand {
|
public class ListGroupsCommand implements LocalCommand {
|
||||||
|
|
||||||
private static void printGroup(GroupInfo group, boolean detailed, SignalServiceAddress address) {
|
private static void printGroup(Manager m, GroupInfo group, boolean detailed) {
|
||||||
if (detailed) {
|
if (detailed) {
|
||||||
|
Set<String> members = group.getMembers()
|
||||||
|
.stream()
|
||||||
|
.map(m::resolveSignalServiceAddress)
|
||||||
|
.map(SignalServiceAddress::getLegacyIdentifier)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b Members: %s",
|
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b Members: %s",
|
||||||
Base64.encodeBytes(group.groupId), group.name, group.isMember(address), group.blocked, group.getMembersE164()));
|
Base64.encodeBytes(group.groupId), group.getTitle(), group.isMember(m.getSelfAddress()), group.isBlocked(), members));
|
||||||
} else {
|
} else {
|
||||||
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b",
|
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b",
|
||||||
Base64.encodeBytes(group.groupId), group.name, group.isMember(address), group.blocked));
|
Base64.encodeBytes(group.groupId), group.getTitle(), group.isMember(m.getSelfAddress()), group.isBlocked()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +48,7 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
boolean detailed = ns.getBoolean("detailed");
|
boolean detailed = ns.getBoolean("detailed");
|
||||||
|
|
||||||
for (GroupInfo group : groups) {
|
for (GroupInfo group : groups) {
|
||||||
printGroup(group, detailed, m.getSelfAddress());
|
printGroup(m, group, detailed);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,18 @@ import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||||
import org.asamk.signal.util.GroupIdFormatException;
|
import org.asamk.signal.util.GroupIdFormatException;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.libsignal.util.Pair;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleEncapsulatedExceptions;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
||||||
|
import static org.asamk.signal.util.ErrorUtils.handleTimestampAndSendMessageResults;
|
||||||
|
|
||||||
public class QuitGroupCommand implements LocalCommand {
|
public class QuitGroupCommand implements LocalCommand {
|
||||||
|
|
||||||
|
@ -36,14 +38,11 @@ public class QuitGroupCommand implements LocalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m.sendQuitGroupMessage(Util.decodeGroupId(ns.getString("group")));
|
final Pair<Long, List<SendMessageResult>> results = m.sendQuitGroupMessage(Util.decodeGroupId(ns.getString("group")));
|
||||||
return 0;
|
return handleTimestampAndSendMessageResults(results.first(), results.second());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
handleIOException(e);
|
handleIOException(e);
|
||||||
return 3;
|
return 3;
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
handleEncapsulatedExceptions(e);
|
|
||||||
return 3;
|
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
handleAssertionError(e);
|
handleAssertionError(e);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -16,15 +16,19 @@ public class RegisterCommand implements LocalCommand {
|
||||||
subparser.addArgument("-v", "--voice")
|
subparser.addArgument("-v", "--voice")
|
||||||
.help("The verification should be done over voice, not sms.")
|
.help("The verification should be done over voice, not sms.")
|
||||||
.action(Arguments.storeTrue());
|
.action(Arguments.storeTrue());
|
||||||
|
subparser.addArgument("--captcha")
|
||||||
|
.help("The captcha token, required if registration failed with a captcha required error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int handleCommand(final Namespace ns, final Manager m) {
|
public int handleCommand(final Namespace ns, final Manager m) {
|
||||||
try {
|
try {
|
||||||
m.register(ns.getBoolean("voice"));
|
final boolean voiceVerification = ns.getBoolean("voice");
|
||||||
|
final String captcha = ns.getString("captcha");
|
||||||
|
m.register(voiceVerification, captcha);
|
||||||
return 0;
|
return 0;
|
||||||
} catch (CaptchaRequiredException e) {
|
} catch (CaptchaRequiredException e) {
|
||||||
System.err.println("Captcha required for verification (" + e.getMessage() + ")");
|
System.err.println("Captcha invalid or required for verification (" + e.getMessage() + ")");
|
||||||
return 1;
|
return 1;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Request verify error: " + e.getMessage());
|
System.err.println("Request verify error: " + e.getMessage());
|
||||||
|
|
|
@ -9,18 +9,20 @@ import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||||
import org.asamk.signal.util.GroupIdFormatException;
|
import org.asamk.signal.util.GroupIdFormatException;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.libsignal.util.Pair;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleEncapsulatedExceptions;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleInvalidNumberException;
|
import static org.asamk.signal.util.ErrorUtils.handleInvalidNumberException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
||||||
|
import static org.asamk.signal.util.ErrorUtils.handleTimestampAndSendMessageResults;
|
||||||
|
|
||||||
public class SendReactionCommand implements LocalCommand {
|
public class SendReactionCommand implements LocalCommand {
|
||||||
|
|
||||||
|
@ -66,19 +68,18 @@ public class SendReactionCommand implements LocalCommand {
|
||||||
long targetTimestamp = ns.getLong("target_timestamp");
|
long targetTimestamp = ns.getLong("target_timestamp");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
final Pair<Long, List<SendMessageResult>> results;
|
||||||
if (ns.getString("group") != null) {
|
if (ns.getString("group") != null) {
|
||||||
byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
||||||
m.sendGroupMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, groupId);
|
results = m.sendGroupMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, groupId);
|
||||||
} else {
|
} else {
|
||||||
m.sendMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, ns.getList("recipient"));
|
results = m.sendMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, ns.getList("recipient"));
|
||||||
}
|
}
|
||||||
|
handleTimestampAndSendMessageResults(results.first(), results.second());
|
||||||
return 0;
|
return 0;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
handleIOException(e);
|
handleIOException(e);
|
||||||
return 3;
|
return 3;
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
handleEncapsulatedExceptions(e);
|
|
||||||
return 3;
|
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
handleAssertionError(e);
|
handleAssertionError(e);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -6,17 +6,18 @@ import org.asamk.signal.manager.GroupNotFoundException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||||
import org.asamk.signal.storage.groups.GroupInfo;
|
import org.asamk.signal.storage.groups.GroupInfo;
|
||||||
|
import org.asamk.signal.util.ErrorUtils;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
import org.whispersystems.libsignal.util.Pair;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DbusSignalImpl implements Signal {
|
public class DbusSignalImpl implements Signal {
|
||||||
|
|
||||||
|
@ -43,41 +44,28 @@ public class DbusSignalImpl implements Signal {
|
||||||
return sendMessage(message, attachments, recipients);
|
return sendMessage(message, attachments, recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DBusExecutionException convertEncapsulatedExceptions(EncapsulatedExceptions e) {
|
private static void checkSendMessageResults(long timestamp, List<SendMessageResult> results) throws DBusExecutionException {
|
||||||
if (e.getNetworkExceptions().size() + e.getUnregisteredUserExceptions().size() + e.getUntrustedIdentityExceptions().size() == 1) {
|
List<String> errors = ErrorUtils.getErrorMessagesFromSendMessageResults(results);
|
||||||
if (e.getNetworkExceptions().size() == 1) {
|
if (errors.size() == 0) {
|
||||||
NetworkFailureException n = e.getNetworkExceptions().get(0);
|
return;
|
||||||
return new Error.Failure("Network failure for \"" + n.getE164number() + "\": " + n.getMessage());
|
|
||||||
} else if (e.getUnregisteredUserExceptions().size() == 1) {
|
|
||||||
UnregisteredUserException n = e.getUnregisteredUserExceptions().get(0);
|
|
||||||
return new Error.UnregisteredUser("Unregistered user \"" + n.getE164Number() + "\": " + n.getMessage());
|
|
||||||
} else if (e.getUntrustedIdentityExceptions().size() == 1) {
|
|
||||||
UntrustedIdentityException n = e.getUntrustedIdentityExceptions().get(0);
|
|
||||||
return new Error.UntrustedIdentity("Untrusted Identity for \"" + n.getIdentifier() + "\": " + n.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
message.append("Failed to send (some) messages:").append('\n');
|
message.append(timestamp).append('\n');
|
||||||
for (NetworkFailureException n : e.getNetworkExceptions()) {
|
message.append("Failed to send (some) messages:\n");
|
||||||
message.append("Network failure for \"").append(n.getE164number()).append("\": ").append(n.getMessage()).append('\n');
|
for (String error : errors) {
|
||||||
}
|
message.append(error).append('\n');
|
||||||
for (UnregisteredUserException n : e.getUnregisteredUserExceptions()) {
|
|
||||||
message.append("Unregistered user \"").append(n.getE164Number()).append("\": ").append(n.getMessage()).append('\n');
|
|
||||||
}
|
|
||||||
for (UntrustedIdentityException n : e.getUntrustedIdentityExceptions()) {
|
|
||||||
message.append("Untrusted Identity for \"").append(n.getIdentifier()).append("\": ").append(n.getMessage()).append('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Error.Failure(message.toString());
|
throw new Error.Failure(message.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
||||||
try {
|
try {
|
||||||
return m.sendMessage(message, attachments, recipients);
|
final Pair<Long, List<SendMessageResult>> results = m.sendMessage(message, attachments, recipients);
|
||||||
} catch (EncapsulatedExceptions e) {
|
checkSendMessageResults(results.first(), results.second());
|
||||||
throw convertEncapsulatedExceptions(e);
|
return results.first();
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
throw new Error.InvalidNumber(e.getMessage());
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
} catch (AttachmentInvalidException e) {
|
} catch (AttachmentInvalidException e) {
|
||||||
|
@ -90,11 +78,10 @@ public class DbusSignalImpl implements Signal {
|
||||||
@Override
|
@Override
|
||||||
public void sendEndSessionMessage(final List<String> recipients) {
|
public void sendEndSessionMessage(final List<String> recipients) {
|
||||||
try {
|
try {
|
||||||
m.sendEndSessionMessage(recipients);
|
final Pair<Long, List<SendMessageResult>> results = m.sendEndSessionMessage(recipients);
|
||||||
|
checkSendMessageResults(results.first(), results.second());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error.Failure(e.getMessage());
|
throw new Error.Failure(e.getMessage());
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
throw convertEncapsulatedExceptions(e);
|
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
throw new Error.InvalidNumber(e.getMessage());
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -103,11 +90,11 @@ public class DbusSignalImpl implements Signal {
|
||||||
@Override
|
@Override
|
||||||
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
||||||
try {
|
try {
|
||||||
return m.sendGroupMessage(message, attachments, groupId);
|
Pair<Long, List<SendMessageResult>> results = m.sendGroupMessage(message, attachments, groupId);
|
||||||
|
checkSendMessageResults(results.first(), results.second());
|
||||||
|
return results.first();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error.Failure(e.getMessage());
|
throw new Error.Failure(e.getMessage());
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
throw convertEncapsulatedExceptions(e);
|
|
||||||
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||||
throw new Error.GroupNotFound(e.getMessage());
|
throw new Error.GroupNotFound(e.getMessage());
|
||||||
} catch (AttachmentInvalidException e) {
|
} catch (AttachmentInvalidException e) {
|
||||||
|
@ -167,7 +154,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
return group.name;
|
return group.getTitle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,18 +164,18 @@ public class DbusSignalImpl implements Signal {
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
return new ArrayList<>(group.getMembersE164());
|
return group.getMembers().stream().map(m::resolveSignalServiceAddress).map(SignalServiceAddress::getLegacyIdentifier).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] updateGroup(final byte[] groupId, final String name, final List<String> members, final String avatar) {
|
public byte[] updateGroup(final byte[] groupId, final String name, final List<String> members, final String avatar) {
|
||||||
try {
|
try {
|
||||||
return m.updateGroup(groupId, name, members, avatar);
|
final Pair<byte[], List<SendMessageResult>> results = m.updateGroup(groupId, name, members, avatar);
|
||||||
|
checkSendMessageResults(0, results.second());
|
||||||
|
return results.first();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error.Failure(e.getMessage());
|
throw new Error.Failure(e.getMessage());
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
throw convertEncapsulatedExceptions(e);
|
|
||||||
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||||
throw new Error.GroupNotFound(e.getMessage());
|
throw new Error.GroupNotFound(e.getMessage());
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
|
|
|
@ -5,13 +5,14 @@ import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class JsonMessageEnvelope {
|
public class JsonMessageEnvelope {
|
||||||
|
|
||||||
String source;
|
String source;
|
||||||
int sourceDevice;
|
int sourceDevice;
|
||||||
String relay;
|
String relay;
|
||||||
long timestamp;
|
long timestamp;
|
||||||
boolean isReceipt;
|
|
||||||
JsonDataMessage dataMessage;
|
JsonDataMessage dataMessage;
|
||||||
JsonSyncMessage syncMessage;
|
JsonSyncMessage syncMessage;
|
||||||
JsonCallMessage callMessage;
|
JsonCallMessage callMessage;
|
||||||
|
@ -25,7 +26,9 @@ public class JsonMessageEnvelope {
|
||||||
}
|
}
|
||||||
this.sourceDevice = envelope.getSourceDevice();
|
this.sourceDevice = envelope.getSourceDevice();
|
||||||
this.timestamp = envelope.getTimestamp();
|
this.timestamp = envelope.getTimestamp();
|
||||||
this.isReceipt = envelope.isReceipt();
|
if (envelope.isReceipt()) {
|
||||||
|
this.receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp));
|
||||||
|
}
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
if (envelope.isUnidentifiedSender()) {
|
if (envelope.isUnidentifiedSender()) {
|
||||||
this.source = content.getSender().getLegacyIdentifier();
|
this.source = content.getSender().getLegacyIdentifier();
|
||||||
|
@ -55,7 +58,7 @@ public class JsonMessageEnvelope {
|
||||||
public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) {
|
public JsonMessageEnvelope(Signal.ReceiptReceived receiptReceived) {
|
||||||
source = receiptReceived.getSender();
|
source = receiptReceived.getSender();
|
||||||
timestamp = receiptReceived.getTimestamp();
|
timestamp = receiptReceived.getTimestamp();
|
||||||
isReceipt = true;
|
receiptMessage = JsonReceiptMessage.deliveryReceipt(timestamp, List.of(timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) {
|
public JsonMessageEnvelope(Signal.SyncMessageReceived messageReceived) {
|
||||||
|
|
|
@ -22,4 +22,15 @@ class JsonReceiptMessage {
|
||||||
}
|
}
|
||||||
this.timestamps = receiptMessage.getTimestamps();
|
this.timestamps = receiptMessage.getTimestamps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JsonReceiptMessage(final long when, final boolean isDelivery, final boolean isRead, final List<Long> timestamps) {
|
||||||
|
this.when = when;
|
||||||
|
this.isDelivery = isDelivery;
|
||||||
|
this.isRead = isRead;
|
||||||
|
this.timestamps = timestamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JsonReceiptMessage deliveryReceipt(final long when, final List<Long> timestamps) {
|
||||||
|
return new JsonReceiptMessage(when, true, false, timestamps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.asamk.signal.storage.SignalAccount;
|
import org.asamk.signal.storage.SignalAccount;
|
||||||
import org.asamk.signal.storage.contacts.ContactInfo;
|
import org.asamk.signal.storage.contacts.ContactInfo;
|
||||||
import org.asamk.signal.storage.groups.GroupInfo;
|
import org.asamk.signal.storage.groups.GroupInfo;
|
||||||
import org.asamk.signal.storage.groups.JsonGroupStore;
|
import org.asamk.signal.storage.groups.GroupInfoV1;
|
||||||
|
import org.asamk.signal.storage.groups.GroupInfoV2;
|
||||||
import org.asamk.signal.storage.profiles.SignalProfile;
|
import org.asamk.signal.storage.profiles.SignalProfile;
|
||||||
import org.asamk.signal.storage.profiles.SignalProfileEntry;
|
import org.asamk.signal.storage.profiles.SignalProfileEntry;
|
||||||
import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
|
import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
|
||||||
|
import org.asamk.signal.storage.stickers.Sticker;
|
||||||
import org.asamk.signal.util.IOUtils;
|
import org.asamk.signal.util.IOUtils;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.signal.libsignal.metadata.InvalidMetadataMessageException;
|
import org.signal.libsignal.metadata.InvalidMetadataMessageException;
|
||||||
|
@ -39,7 +41,13 @@ import org.signal.libsignal.metadata.ProtocolNoSessionException;
|
||||||
import org.signal.libsignal.metadata.ProtocolUntrustedIdentityException;
|
import org.signal.libsignal.metadata.ProtocolUntrustedIdentityException;
|
||||||
import org.signal.libsignal.metadata.SelfSendException;
|
import org.signal.libsignal.metadata.SelfSendException;
|
||||||
import org.signal.libsignal.metadata.certificate.InvalidCertificateException;
|
import org.signal.libsignal.metadata.certificate.InvalidCertificateException;
|
||||||
|
import org.signal.storageservice.protos.groups.local.DecryptedGroup;
|
||||||
|
import org.signal.storageservice.protos.groups.local.DecryptedMember;
|
||||||
import org.signal.zkgroup.InvalidInputException;
|
import org.signal.zkgroup.InvalidInputException;
|
||||||
|
import org.signal.zkgroup.VerificationFailedException;
|
||||||
|
import org.signal.zkgroup.auth.AuthCredentialResponse;
|
||||||
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
|
import org.signal.zkgroup.groups.GroupSecretParams;
|
||||||
import org.signal.zkgroup.profiles.ClientZkProfileOperations;
|
import org.signal.zkgroup.profiles.ClientZkProfileOperations;
|
||||||
import org.signal.zkgroup.profiles.ProfileKey;
|
import org.signal.zkgroup.profiles.ProfileKey;
|
||||||
import org.whispersystems.libsignal.IdentityKey;
|
import org.whispersystems.libsignal.IdentityKey;
|
||||||
|
@ -67,7 +75,10 @@ import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
|
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
|
||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
|
import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
|
||||||
|
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Api;
|
||||||
|
import org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString;
|
||||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
||||||
|
import org.whispersystems.signalservice.api.groupsv2.InvalidGroupStateException;
|
||||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||||
|
@ -77,6 +88,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifestUpload;
|
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifestUpload;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifestUpload.StickerInfo;
|
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifestUpload.StickerInfo;
|
||||||
|
@ -92,14 +104,12 @@ import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.RequestMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.RequestMessage;
|
||||||
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.messages.multidevice.StickerPackOperationMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||||
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
import org.whispersystems.signalservice.api.util.SleepTimer;
|
import org.whispersystems.signalservice.api.util.SleepTimer;
|
||||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||||
|
@ -124,6 +134,7 @@ import java.io.OutputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
@ -132,8 +143,8 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -158,9 +169,10 @@ public class Manager implements Closeable {
|
||||||
private final SignalAccount account;
|
private final SignalAccount account;
|
||||||
private final PathConfig pathConfig;
|
private final PathConfig pathConfig;
|
||||||
private SignalServiceAccountManager accountManager;
|
private SignalServiceAccountManager accountManager;
|
||||||
|
private GroupsV2Api groupsV2Api;
|
||||||
private SignalServiceMessagePipe messagePipe = null;
|
private SignalServiceMessagePipe messagePipe = null;
|
||||||
private SignalServiceMessagePipe unidentifiedMessagePipe = null;
|
private SignalServiceMessagePipe unidentifiedMessagePipe = null;
|
||||||
private boolean discoverableByPhoneNumber = true;
|
private final boolean discoverableByPhoneNumber = true;
|
||||||
|
|
||||||
public Manager(SignalAccount account, PathConfig pathConfig, SignalServiceConfiguration serviceConfiguration, String userAgent) {
|
public Manager(SignalAccount account, PathConfig pathConfig, SignalServiceConfiguration serviceConfiguration, String userAgent) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
@ -168,6 +180,7 @@ public class Manager implements Closeable {
|
||||||
this.serviceConfiguration = serviceConfiguration;
|
this.serviceConfiguration = serviceConfiguration;
|
||||||
this.userAgent = userAgent;
|
this.userAgent = userAgent;
|
||||||
this.accountManager = createSignalServiceAccountManager();
|
this.accountManager = createSignalServiceAccountManager();
|
||||||
|
this.groupsV2Api = accountManager.getGroupsV2Api();
|
||||||
|
|
||||||
this.account.setResolver(this::resolveSignalServiceAddress);
|
this.account.setResolver(this::resolveSignalServiceAddress);
|
||||||
}
|
}
|
||||||
|
@ -181,12 +194,10 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceAccountManager createSignalServiceAccountManager() {
|
private SignalServiceAccountManager createSignalServiceAccountManager() {
|
||||||
GroupsV2Operations groupsV2Operations;
|
GroupsV2Operations groupsV2Operations = capabilities.isGv2()
|
||||||
try {
|
? new GroupsV2Operations(ClientZkOperations.create(serviceConfiguration))
|
||||||
groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceConfiguration));
|
: null;
|
||||||
} catch (Throwable ignored) {
|
|
||||||
groupsV2Operations = null;
|
|
||||||
}
|
|
||||||
return new SignalServiceAccountManager(serviceConfiguration,
|
return new SignalServiceAccountManager(serviceConfiguration,
|
||||||
new DynamicCredentialsProvider(account.getUuid(), account.getUsername(), account.getPassword(), null, account.getDeviceId()),
|
new DynamicCredentialsProvider(account.getUuid(), account.getUsername(), account.getPassword(), null, account.getDeviceId()),
|
||||||
userAgent,
|
userAgent,
|
||||||
|
@ -239,34 +250,32 @@ public class Manager implements Closeable {
|
||||||
Manager m = new Manager(account, pathConfig, serviceConfiguration, userAgent);
|
Manager m = new Manager(account, pathConfig, serviceConfiguration, userAgent);
|
||||||
|
|
||||||
m.migrateLegacyConfigs();
|
m.migrateLegacyConfigs();
|
||||||
|
m.updateAccountAttributes();
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void migrateLegacyConfigs() {
|
private void migrateLegacyConfigs() {
|
||||||
// Copy group avatars that were previously stored in the attachments folder
|
|
||||||
// to the new avatar folder
|
|
||||||
if (JsonGroupStore.groupsWithLegacyAvatarId.size() > 0) {
|
|
||||||
for (GroupInfo g : JsonGroupStore.groupsWithLegacyAvatarId) {
|
|
||||||
File avatarFile = getGroupAvatarFile(g.groupId);
|
|
||||||
File attachmentFile = getAttachmentFile(new SignalServiceAttachmentRemoteId(g.getAvatarId()));
|
|
||||||
if (!avatarFile.exists() && attachmentFile.exists()) {
|
|
||||||
try {
|
|
||||||
IOUtils.createPrivateDirectories(pathConfig.getAvatarsPath());
|
|
||||||
Files.copy(attachmentFile.toPath(), avatarFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
JsonGroupStore.groupsWithLegacyAvatarId.clear();
|
|
||||||
account.save();
|
|
||||||
}
|
|
||||||
if (account.getProfileKey() == null) {
|
if (account.getProfileKey() == null) {
|
||||||
// Old config file, creating new profile key
|
// Old config file, creating new profile key
|
||||||
account.setProfileKey(KeyUtils.createProfileKey());
|
account.setProfileKey(KeyUtils.createProfileKey());
|
||||||
account.save();
|
account.save();
|
||||||
}
|
}
|
||||||
|
// Store profile keys only in profile store
|
||||||
|
for (ContactInfo contact : account.getContactStore().getContacts()) {
|
||||||
|
String profileKeyString = contact.profileKey;
|
||||||
|
if (profileKeyString == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final ProfileKey profileKey;
|
||||||
|
try {
|
||||||
|
profileKey = new ProfileKey(Base64.decode(profileKeyString));
|
||||||
|
} catch (InvalidInputException | IOException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
contact.profileKey = null;
|
||||||
|
account.getProfileStore().storeProfileKey(contact.getAddress(), profileKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAccountState() throws IOException {
|
public void checkAccountState() throws IOException {
|
||||||
|
@ -286,17 +295,18 @@ public class Manager implements Closeable {
|
||||||
return account.isRegistered();
|
return account.isRegistered();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(boolean voiceVerification) throws IOException {
|
public void register(boolean voiceVerification, String captcha) throws IOException {
|
||||||
account.setPassword(KeyUtils.createPassword());
|
account.setPassword(KeyUtils.createPassword());
|
||||||
|
|
||||||
// Resetting UUID, because registering doesn't work otherwise
|
// Resetting UUID, because registering doesn't work otherwise
|
||||||
account.setUuid(null);
|
account.setUuid(null);
|
||||||
accountManager = createSignalServiceAccountManager();
|
accountManager = createSignalServiceAccountManager();
|
||||||
|
this.groupsV2Api = accountManager.getGroupsV2Api();
|
||||||
|
|
||||||
if (voiceVerification) {
|
if (voiceVerification) {
|
||||||
accountManager.requestVoiceVerificationCode(Locale.getDefault(), Optional.absent(), Optional.absent());
|
accountManager.requestVoiceVerificationCode(Locale.getDefault(), Optional.fromNullable(captcha), Optional.absent());
|
||||||
} else {
|
} else {
|
||||||
accountManager.requestSmsVerificationCode(false, Optional.absent(), Optional.absent());
|
accountManager.requestSmsVerificationCode(false, Optional.fromNullable(captcha), Optional.absent());
|
||||||
}
|
}
|
||||||
|
|
||||||
account.setRegistered(false);
|
account.setRegistered(false);
|
||||||
|
@ -423,18 +433,19 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceMessageReceiver getMessageReceiver() {
|
private SignalServiceMessageReceiver getMessageReceiver() {
|
||||||
// TODO implement ZkGroup support
|
final ClientZkProfileOperations clientZkProfileOperations = capabilities.isGv2()
|
||||||
final ClientZkProfileOperations clientZkProfileOperations = null;
|
? ClientZkOperations.create(serviceConfiguration).getProfileOperations()
|
||||||
|
: null;
|
||||||
return new SignalServiceMessageReceiver(serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(), account.getDeviceId(), account.getSignalingKey(), userAgent, null, timer, clientZkProfileOperations);
|
return new SignalServiceMessageReceiver(serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(), account.getDeviceId(), account.getSignalingKey(), userAgent, null, timer, clientZkProfileOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceMessageSender getMessageSender() {
|
private SignalServiceMessageSender getMessageSender() {
|
||||||
// TODO implement ZkGroup support
|
final ClientZkProfileOperations clientZkProfileOperations = capabilities.isGv2()
|
||||||
final ClientZkProfileOperations clientZkProfileOperations = null;
|
? ClientZkOperations.create(serviceConfiguration).getProfileOperations()
|
||||||
final boolean attachmentsV3 = false;
|
: null;
|
||||||
final ExecutorService executor = null;
|
final ExecutorService executor = null;
|
||||||
return new SignalServiceMessageSender(serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(),
|
return new SignalServiceMessageSender(serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(),
|
||||||
account.getDeviceId(), account.getSignalProtocolStore(), userAgent, account.isMultiDevice(), attachmentsV3, Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.absent(), clientZkProfileOperations, executor);
|
account.getDeviceId(), account.getSignalProtocolStore(), userAgent, account.isMultiDevice(), Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.absent(), clientZkProfileOperations, executor, ServiceConfig.MAX_ENVELOPE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceProfile getEncryptedRecipientProfile(SignalServiceAddress address, Optional<UnidentifiedAccess> unidentifiedAccess) throws IOException {
|
private SignalServiceProfile getEncryptedRecipientProfile(SignalServiceAddress address, Optional<UnidentifiedAccess> unidentifiedAccess) throws IOException {
|
||||||
|
@ -516,7 +527,7 @@ public class Manager implements Closeable {
|
||||||
throw new GroupNotFoundException(groupId);
|
throw new GroupNotFoundException(groupId);
|
||||||
}
|
}
|
||||||
if (!g.isMember(account.getSelfAddress())) {
|
if (!g.isMember(account.getSelfAddress())) {
|
||||||
throw new NotAGroupMemberException(groupId, g.name);
|
throw new NotAGroupMemberException(groupId, g.getTitle());
|
||||||
}
|
}
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
@ -525,44 +536,52 @@ public class Manager implements Closeable {
|
||||||
return account.getGroupStore().getGroups();
|
return account.getGroupStore().getGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long sendGroupMessage(String messageText, List<String> attachments,
|
public Pair<Long, List<SendMessageResult>> sendGroupMessage(
|
||||||
byte[] groupId)
|
String messageText,
|
||||||
throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
List<String> attachments,
|
||||||
|
byte[] groupId
|
||||||
|
)
|
||||||
|
throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||||
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
|
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
|
||||||
if (attachments != null) {
|
if (attachments != null) {
|
||||||
messageBuilder.withAttachments(Utils.getSignalServiceAttachments(attachments));
|
messageBuilder.withAttachments(Utils.getSignalServiceAttachments(attachments));
|
||||||
}
|
}
|
||||||
if (groupId != null) {
|
|
||||||
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
|
|
||||||
.withId(groupId)
|
|
||||||
.build();
|
|
||||||
messageBuilder.asGroupMessage(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
final GroupInfo g = getGroupForSending(groupId);
|
final GroupInfo g = getGroupForSending(groupId);
|
||||||
|
|
||||||
messageBuilder.withExpiration(g.messageExpirationTime);
|
setGroupContext(messageBuilder, g);
|
||||||
|
messageBuilder.withExpiration(g.getMessageExpirationTime());
|
||||||
|
|
||||||
return sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
return sendMessage(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor,
|
private void setGroupContext(final SignalServiceDataMessage.Builder messageBuilder, final GroupInfo groupInfo) {
|
||||||
long targetSentTimestamp, byte[] groupId)
|
if (groupInfo instanceof GroupInfoV1) {
|
||||||
throws IOException, EncapsulatedExceptions, InvalidNumberException, NotAGroupMemberException, GroupNotFoundException {
|
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
|
||||||
|
.withId(groupInfo.groupId)
|
||||||
|
.build();
|
||||||
|
messageBuilder.asGroupMessage(group);
|
||||||
|
} else {
|
||||||
|
final GroupInfoV2 groupInfoV2 = (GroupInfoV2) groupInfo;
|
||||||
|
SignalServiceGroupV2 group = SignalServiceGroupV2.newBuilder(groupInfoV2.getMasterKey())
|
||||||
|
.withRevision(groupInfoV2.getGroup() == null ? 0 : groupInfoV2.getGroup().getRevision())
|
||||||
|
.build();
|
||||||
|
messageBuilder.asGroupMessage(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pair<Long, List<SendMessageResult>> sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor,
|
||||||
|
long targetSentTimestamp, byte[] groupId)
|
||||||
|
throws IOException, InvalidNumberException, NotAGroupMemberException, GroupNotFoundException {
|
||||||
SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp);
|
SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp);
|
||||||
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
||||||
.withReaction(reaction);
|
.withReaction(reaction);
|
||||||
if (groupId != null) {
|
|
||||||
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
|
|
||||||
.withId(groupId)
|
|
||||||
.build();
|
|
||||||
messageBuilder.asGroupMessage(group);
|
|
||||||
}
|
|
||||||
final GroupInfo g = getGroupForSending(groupId);
|
final GroupInfo g = getGroupForSending(groupId);
|
||||||
sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
setGroupContext(messageBuilder, g);
|
||||||
|
return sendMessage(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions, NotAGroupMemberException {
|
public Pair<Long, List<SendMessageResult>> sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, NotAGroupMemberException {
|
||||||
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.QUIT)
|
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.QUIT)
|
||||||
.withId(groupId)
|
.withId(groupId)
|
||||||
.build();
|
.build();
|
||||||
|
@ -571,20 +590,29 @@ public class Manager implements Closeable {
|
||||||
.asGroupMessage(group);
|
.asGroupMessage(group);
|
||||||
|
|
||||||
final GroupInfo g = getGroupForSending(groupId);
|
final GroupInfo g = getGroupForSending(groupId);
|
||||||
g.removeMember(account.getSelfAddress());
|
if (g instanceof GroupInfoV1) {
|
||||||
account.getGroupStore().updateGroup(g);
|
GroupInfoV1 groupInfoV1 = (GroupInfoV1) g;
|
||||||
|
groupInfoV1.removeMember(account.getSelfAddress());
|
||||||
|
account.getGroupStore().updateGroup(groupInfoV1);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("TODO Not implemented!");
|
||||||
|
}
|
||||||
|
|
||||||
sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
return sendMessage(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] sendUpdateGroupMessage(byte[] groupId, String name, Collection<SignalServiceAddress> members, String avatarFile) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
private Pair<byte[], List<SendMessageResult>> sendUpdateGroupMessage(byte[] groupId, String name, Collection<SignalServiceAddress> members, String avatarFile) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||||
GroupInfo g;
|
GroupInfoV1 g;
|
||||||
if (groupId == null) {
|
if (groupId == null) {
|
||||||
// Create new group
|
// Create new group
|
||||||
g = new GroupInfo(KeyUtils.createGroupId());
|
g = new GroupInfoV1(KeyUtils.createGroupId());
|
||||||
g.addMembers(Collections.singleton(account.getSelfAddress()));
|
g.addMembers(Collections.singleton(account.getSelfAddress()));
|
||||||
} else {
|
} else {
|
||||||
g = getGroupForSending(groupId);
|
GroupInfo group = getGroupForSending(groupId);
|
||||||
|
if (!(group instanceof GroupInfoV1)) {
|
||||||
|
throw new RuntimeException("TODO Not implemented!");
|
||||||
|
}
|
||||||
|
g = (GroupInfoV1) group;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
@ -622,27 +650,29 @@ public class Manager implements Closeable {
|
||||||
|
|
||||||
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);
|
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);
|
||||||
|
|
||||||
sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
final Pair<Long, List<SendMessageResult>> result = sendMessage(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
|
||||||
return g.groupId;
|
return new Pair<>(g.groupId, result.second());
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendUpdateGroupMessage(byte[] groupId, SignalServiceAddress recipient) throws IOException, EncapsulatedExceptions, NotAGroupMemberException, GroupNotFoundException, AttachmentInvalidException {
|
Pair<Long, List<SendMessageResult>> sendUpdateGroupMessage(byte[] groupId, SignalServiceAddress recipient) throws IOException, NotAGroupMemberException, GroupNotFoundException, AttachmentInvalidException {
|
||||||
if (groupId == null) {
|
GroupInfoV1 g;
|
||||||
return;
|
GroupInfo group = getGroupForSending(groupId);
|
||||||
|
if (!(group instanceof GroupInfoV1)) {
|
||||||
|
throw new RuntimeException("TODO Not implemented!");
|
||||||
}
|
}
|
||||||
GroupInfo g = getGroupForSending(groupId);
|
g = (GroupInfoV1) group;
|
||||||
|
|
||||||
if (!g.isMember(recipient)) {
|
if (!g.isMember(recipient)) {
|
||||||
return;
|
throw new NotAGroupMemberException(groupId, g.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);
|
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);
|
||||||
|
|
||||||
// Send group message only to the recipient who requested it
|
// Send group message only to the recipient who requested it
|
||||||
sendMessageLegacy(messageBuilder, Collections.singleton(recipient));
|
return sendMessage(messageBuilder, Collections.singleton(recipient));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) throws AttachmentInvalidException {
|
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfoV1 g) throws AttachmentInvalidException {
|
||||||
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.UPDATE)
|
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.UPDATE)
|
||||||
.withId(g.groupId)
|
.withId(g.groupId)
|
||||||
.withName(g.name)
|
.withName(g.name)
|
||||||
|
@ -662,11 +692,7 @@ public class Manager implements Closeable {
|
||||||
.withExpiration(g.messageExpirationTime);
|
.withExpiration(g.messageExpirationTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendGroupInfoRequest(byte[] groupId, SignalServiceAddress recipient) throws IOException, EncapsulatedExceptions {
|
Pair<Long, List<SendMessageResult>> sendGroupInfoRequest(byte[] groupId, SignalServiceAddress recipient) throws IOException {
|
||||||
if (groupId == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.REQUEST_INFO)
|
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.REQUEST_INFO)
|
||||||
.withId(groupId);
|
.withId(groupId);
|
||||||
|
|
||||||
|
@ -674,7 +700,7 @@ public class Manager implements Closeable {
|
||||||
.asGroupMessage(group.build());
|
.asGroupMessage(group.build());
|
||||||
|
|
||||||
// Send group info request message to the recipient who sent us a message with this groupId
|
// Send group info request message to the recipient who sent us a message with this groupId
|
||||||
sendMessageLegacy(messageBuilder, Collections.singleton(recipient));
|
return sendMessage(messageBuilder, Collections.singleton(recipient));
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendReceipt(SignalServiceAddress remoteAddress, long messageId) throws IOException, UntrustedIdentityException {
|
void sendReceipt(SignalServiceAddress remoteAddress, long messageId) throws IOException, UntrustedIdentityException {
|
||||||
|
@ -685,9 +711,9 @@ public class Manager implements Closeable {
|
||||||
getMessageSender().sendReceipt(remoteAddress, getAccessFor(remoteAddress), receiptMessage);
|
getMessageSender().sendReceipt(remoteAddress, getAccessFor(remoteAddress), receiptMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long sendMessage(String messageText, List<String> attachments,
|
public Pair<Long, List<SendMessageResult>> sendMessage(String messageText, List<String> attachments,
|
||||||
List<String> recipients)
|
List<String> recipients)
|
||||||
throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException {
|
throws IOException, AttachmentInvalidException, InvalidNumberException {
|
||||||
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
|
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
|
||||||
if (attachments != null) {
|
if (attachments != null) {
|
||||||
List<SignalServiceAttachment> attachmentStreams = Utils.getSignalServiceAttachments(attachments);
|
List<SignalServiceAttachment> attachmentStreams = Utils.getSignalServiceAttachments(attachments);
|
||||||
|
@ -705,25 +731,25 @@ public class Manager implements Closeable {
|
||||||
|
|
||||||
messageBuilder.withAttachments(attachmentPointers);
|
messageBuilder.withAttachments(attachmentPointers);
|
||||||
}
|
}
|
||||||
return sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients));
|
return sendMessage(messageBuilder, getSignalServiceAddresses(recipients));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageReaction(String emoji, boolean remove, String targetAuthor,
|
public Pair<Long, List<SendMessageResult>> sendMessageReaction(String emoji, boolean remove, String targetAuthor,
|
||||||
long targetSentTimestamp, List<String> recipients)
|
long targetSentTimestamp, List<String> recipients)
|
||||||
throws IOException, EncapsulatedExceptions, InvalidNumberException {
|
throws IOException, InvalidNumberException {
|
||||||
SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp);
|
SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp);
|
||||||
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
||||||
.withReaction(reaction);
|
.withReaction(reaction);
|
||||||
sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients));
|
return sendMessage(messageBuilder, getSignalServiceAddresses(recipients));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, InvalidNumberException {
|
public Pair<Long, List<SendMessageResult>> sendEndSessionMessage(List<String> recipients) throws IOException, InvalidNumberException {
|
||||||
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
||||||
.asEndSessionMessage();
|
.asEndSessionMessage();
|
||||||
|
|
||||||
final Collection<SignalServiceAddress> signalServiceAddresses = getSignalServiceAddresses(recipients);
|
final Collection<SignalServiceAddress> signalServiceAddresses = getSignalServiceAddresses(recipients);
|
||||||
try {
|
try {
|
||||||
sendMessageLegacy(messageBuilder, signalServiceAddresses);
|
return sendMessage(messageBuilder, signalServiceAddresses);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
for (SignalServiceAddress address : signalServiceAddresses) {
|
for (SignalServiceAddress address : signalServiceAddresses) {
|
||||||
handleEndSession(address);
|
handleEndSession(address);
|
||||||
|
@ -773,12 +799,12 @@ public class Manager implements Closeable {
|
||||||
throw new GroupNotFoundException(groupId);
|
throw new GroupNotFoundException(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
group.blocked = blocked;
|
group.setBlocked(blocked);
|
||||||
account.getGroupStore().updateGroup(group);
|
account.getGroupStore().updateGroup(group);
|
||||||
account.save();
|
account.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
public Pair<byte[], List<SendMessageResult>> updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||||
if (groupId.length == 0) {
|
if (groupId.length == 0) {
|
||||||
groupId = null;
|
groupId = null;
|
||||||
}
|
}
|
||||||
|
@ -824,8 +850,13 @@ public class Manager implements Closeable {
|
||||||
*/
|
*/
|
||||||
public void setExpirationTimer(byte[] groupId, int messageExpirationTimer) {
|
public void setExpirationTimer(byte[] groupId, int messageExpirationTimer) {
|
||||||
GroupInfo g = account.getGroupStore().getGroup(groupId);
|
GroupInfo g = account.getGroupStore().getGroup(groupId);
|
||||||
g.messageExpirationTime = messageExpirationTimer;
|
if (g instanceof GroupInfoV1) {
|
||||||
account.getGroupStore().updateGroup(g);
|
GroupInfoV1 groupInfoV1 = (GroupInfoV1) g;
|
||||||
|
groupInfoV1.messageExpirationTime = messageExpirationTimer;
|
||||||
|
account.getGroupStore().updateGroup(groupInfoV1);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("TODO Not implemented!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -842,8 +873,12 @@ public class Manager implements Closeable {
|
||||||
byte[] packKey = KeyUtils.createStickerUploadKey();
|
byte[] packKey = KeyUtils.createStickerUploadKey();
|
||||||
String packId = messageSender.uploadStickerManifest(manifest, packKey);
|
String packId = messageSender.uploadStickerManifest(manifest, packKey);
|
||||||
|
|
||||||
|
Sticker sticker = new Sticker(Hex.fromStringCondensed(packId), packKey);
|
||||||
|
account.getStickerStore().updateSticker(sticker);
|
||||||
|
account.save();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new URI("https", "signal.art", "/addstickers/", "pack_id=" + URLEncoder.encode(packId, "utf-8") + "&pack_key=" + URLEncoder.encode(Hex.toStringCondensed(packKey), "utf-8"))
|
return new URI("https", "signal.art", "/addstickers/", "pack_id=" + URLEncoder.encode(packId, StandardCharsets.UTF_8) + "&pack_key=" + URLEncoder.encode(Hex.toStringCondensed(packKey), StandardCharsets.UTF_8))
|
||||||
.toString();
|
.toString();
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
|
@ -994,16 +1029,10 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getTargetUnidentifiedAccessKey(SignalServiceAddress recipient) {
|
private byte[] getTargetUnidentifiedAccessKey(SignalServiceAddress recipient) {
|
||||||
ContactInfo contact = account.getContactStore().getContact(recipient);
|
ProfileKey theirProfileKey = account.getProfileStore().getProfileKey(recipient);
|
||||||
if (contact == null || contact.profileKey == null) {
|
if (theirProfileKey == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ProfileKey theirProfileKey;
|
|
||||||
try {
|
|
||||||
theirProfileKey = new ProfileKey(Base64.decode(contact.profileKey));
|
|
||||||
} catch (InvalidInputException | IOException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
SignalProfile targetProfile;
|
SignalProfile targetProfile;
|
||||||
try {
|
try {
|
||||||
targetProfile = getRecipientProfile(recipient, Optional.absent(), theirProfileKey);
|
targetProfile = getRecipientProfile(recipient, Optional.absent(), theirProfileKey);
|
||||||
|
@ -1089,34 +1118,6 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method throws an EncapsulatedExceptions exception instead of returning a list of SendMessageResult.
|
|
||||||
*/
|
|
||||||
private long sendMessageLegacy(SignalServiceDataMessage.Builder messageBuilder, Collection<SignalServiceAddress> recipients)
|
|
||||||
throws EncapsulatedExceptions, IOException {
|
|
||||||
final long timestamp = System.currentTimeMillis();
|
|
||||||
messageBuilder.withTimestamp(timestamp);
|
|
||||||
List<SendMessageResult> results = sendMessage(messageBuilder, recipients);
|
|
||||||
|
|
||||||
List<UntrustedIdentityException> untrustedIdentities = new LinkedList<>();
|
|
||||||
List<UnregisteredUserException> unregisteredUsers = new LinkedList<>();
|
|
||||||
List<NetworkFailureException> networkExceptions = new LinkedList<>();
|
|
||||||
|
|
||||||
for (SendMessageResult result : results) {
|
|
||||||
if (result.isUnregisteredFailure()) {
|
|
||||||
unregisteredUsers.add(new UnregisteredUserException(result.getAddress().getLegacyIdentifier(), null));
|
|
||||||
} else if (result.isNetworkFailure()) {
|
|
||||||
networkExceptions.add(new NetworkFailureException(result.getAddress().getLegacyIdentifier(), null));
|
|
||||||
} else if (result.getIdentityFailure() != null) {
|
|
||||||
untrustedIdentities.add(new UntrustedIdentityException("Untrusted", result.getAddress().getLegacyIdentifier(), result.getIdentityFailure().getIdentityKey()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!untrustedIdentities.isEmpty() || !unregisteredUsers.isEmpty() || !networkExceptions.isEmpty()) {
|
|
||||||
throw new EncapsulatedExceptions(untrustedIdentities, unregisteredUsers, networkExceptions);
|
|
||||||
}
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Collection<SignalServiceAddress> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException {
|
private Collection<SignalServiceAddress> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException {
|
||||||
final Set<SignalServiceAddress> signalServiceAddresses = new HashSet<>(numbers.size());
|
final Set<SignalServiceAddress> signalServiceAddresses = new HashSet<>(numbers.size());
|
||||||
|
|
||||||
|
@ -1126,8 +1127,11 @@ public class Manager implements Closeable {
|
||||||
return signalServiceAddresses;
|
return signalServiceAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SendMessageResult> sendMessage(SignalServiceDataMessage.Builder messageBuilder, Collection<SignalServiceAddress> recipients)
|
private Pair<Long, List<SendMessageResult>> sendMessage(SignalServiceDataMessage.Builder messageBuilder, Collection<SignalServiceAddress> recipients)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
recipients = recipients.stream().map(this::resolveSignalServiceAddress).collect(Collectors.toSet());
|
||||||
|
final long timestamp = System.currentTimeMillis();
|
||||||
|
messageBuilder.withTimestamp(timestamp);
|
||||||
if (messagePipe == null) {
|
if (messagePipe == null) {
|
||||||
messagePipe = getMessageReceiver().createMessagePipe();
|
messagePipe = getMessageReceiver().createMessagePipe();
|
||||||
}
|
}
|
||||||
|
@ -1147,10 +1151,10 @@ public class Manager implements Closeable {
|
||||||
account.getSignalProtocolStore().saveIdentity(r.getAddress(), r.getIdentityFailure().getIdentityKey(), TrustLevel.UNTRUSTED);
|
account.getSignalProtocolStore().saveIdentity(r.getAddress(), r.getIdentityFailure().getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return new Pair<>(timestamp, result);
|
||||||
} catch (UntrustedIdentityException e) {
|
} catch (UntrustedIdentityException e) {
|
||||||
account.getSignalProtocolStore().saveIdentity(resolveSignalServiceAddress(e.getIdentifier()), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
account.getSignalProtocolStore().saveIdentity(resolveSignalServiceAddress(e.getIdentifier()), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
return Collections.emptyList();
|
return new Pair<>(timestamp, Collections.emptyList());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Send to all individually, so sync messages are sent correctly
|
// Send to all individually, so sync messages are sent correctly
|
||||||
|
@ -1171,7 +1175,7 @@ public class Manager implements Closeable {
|
||||||
results.add(sendMessage(address, message));
|
results.add(sendMessage(address, message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return new Pair<>(timestamp, results);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (message != null && message.isEndSession()) {
|
if (message != null && message.isEndSession()) {
|
||||||
|
@ -1198,8 +1202,9 @@ public class Manager implements Closeable {
|
||||||
SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);
|
SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
messageSender.sendMessage(syncMessage, unidentifiedAccess);
|
messageSender.sendMessage(syncMessage, unidentifiedAccess);
|
||||||
return SendMessageResult.success(recipient, unidentifiedAccess.isPresent(), false);
|
return SendMessageResult.success(recipient, unidentifiedAccess.isPresent(), false, System.currentTimeMillis() - startTime);
|
||||||
} catch (UntrustedIdentityException e) {
|
} catch (UntrustedIdentityException e) {
|
||||||
account.getSignalProtocolStore().saveIdentity(resolveSignalServiceAddress(e.getIdentifier()), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
account.getSignalProtocolStore().saveIdentity(resolveSignalServiceAddress(e.getIdentifier()), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
return SendMessageResult.identityFailure(recipient, e.getIdentityKey());
|
return SendMessageResult.identityFailure(recipient, e.getIdentityKey());
|
||||||
|
@ -1235,57 +1240,114 @@ public class Manager implements Closeable {
|
||||||
account.getSignalProtocolStore().deleteAllSessions(source);
|
account.getSignalProtocolStore().deleteAllSessions(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int currentTimeDays() {
|
||||||
|
return (int) TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
private GroupsV2AuthorizationString getGroupAuthForToday(final GroupSecretParams groupSecretParams) throws IOException, VerificationFailedException {
|
||||||
|
final int today = currentTimeDays();
|
||||||
|
// Returns credentials for the next 7 days
|
||||||
|
final HashMap<Integer, AuthCredentialResponse> credentials = groupsV2Api.getCredentials(today);
|
||||||
|
// TODO cache credentials until they expire
|
||||||
|
AuthCredentialResponse authCredentialResponse = credentials.get(today);
|
||||||
|
return groupsV2Api.getGroupsV2AuthorizationString(account.getUuid(), today, groupSecretParams, authCredentialResponse);
|
||||||
|
}
|
||||||
|
|
||||||
private List<HandleAction> handleSignalServiceDataMessage(SignalServiceDataMessage message, boolean isSync, SignalServiceAddress source, SignalServiceAddress destination, boolean ignoreAttachments) {
|
private List<HandleAction> handleSignalServiceDataMessage(SignalServiceDataMessage message, boolean isSync, SignalServiceAddress source, SignalServiceAddress destination, boolean ignoreAttachments) {
|
||||||
List<HandleAction> actions = new ArrayList<>();
|
List<HandleAction> actions = new ArrayList<>();
|
||||||
if (message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()) {
|
if (message.getGroupContext().isPresent()) {
|
||||||
SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
|
if (message.getGroupContext().get().getGroupV1().isPresent()) {
|
||||||
GroupInfo group = account.getGroupStore().getGroup(groupInfo.getGroupId());
|
SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
|
||||||
switch (groupInfo.getType()) {
|
GroupInfo group = account.getGroupStore().getGroup(groupInfo.getGroupId());
|
||||||
case UPDATE:
|
if (group == null || group instanceof GroupInfoV1) {
|
||||||
if (group == null) {
|
GroupInfoV1 groupV1 = (GroupInfoV1) group;
|
||||||
group = new GroupInfo(groupInfo.getGroupId());
|
switch (groupInfo.getType()) {
|
||||||
}
|
case UPDATE: {
|
||||||
|
if (groupV1 == null) {
|
||||||
if (groupInfo.getAvatar().isPresent()) {
|
groupV1 = new GroupInfoV1(groupInfo.getGroupId());
|
||||||
SignalServiceAttachment avatar = groupInfo.getAvatar().get();
|
|
||||||
if (avatar.isPointer()) {
|
|
||||||
try {
|
|
||||||
retrieveGroupAvatarAttachment(avatar.asPointer(), group.groupId);
|
|
||||||
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
|
|
||||||
System.err.println("Failed to retrieve group avatar (" + avatar.asPointer().getRemoteId() + "): " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (groupInfo.getAvatar().isPresent()) {
|
||||||
|
SignalServiceAttachment avatar = groupInfo.getAvatar().get();
|
||||||
|
if (avatar.isPointer()) {
|
||||||
|
try {
|
||||||
|
retrieveGroupAvatarAttachment(avatar.asPointer(), groupV1.groupId);
|
||||||
|
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
|
||||||
|
System.err.println("Failed to retrieve group avatar (" + avatar.asPointer().getRemoteId() + "): " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupInfo.getName().isPresent()) {
|
||||||
|
groupV1.name = groupInfo.getName().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupInfo.getMembers().isPresent()) {
|
||||||
|
groupV1.addMembers(groupInfo.getMembers().get()
|
||||||
|
.stream()
|
||||||
|
.map(this::resolveSignalServiceAddress)
|
||||||
|
.collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
|
|
||||||
|
account.getGroupStore().updateGroup(groupV1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case DELIVER:
|
||||||
|
if (groupV1 == null && !isSync) {
|
||||||
|
actions.add(new SendGroupInfoRequestAction(source, groupInfo.getGroupId()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QUIT: {
|
||||||
|
if (groupV1 != null) {
|
||||||
|
groupV1.removeMember(source);
|
||||||
|
account.getGroupStore().updateGroup(groupV1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case REQUEST_INFO:
|
||||||
|
if (groupV1 != null && !isSync) {
|
||||||
|
actions.add(new SendGroupUpdateAction(source, groupV1.groupId));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
System.err.println("Received a group v1 message for a v2 group: " + group.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (message.getGroupContext().get().getGroupV2().isPresent()) {
|
||||||
|
final SignalServiceGroupV2 groupContext = message.getGroupContext().get().getGroupV2().get();
|
||||||
|
final GroupMasterKey groupMasterKey = groupContext.getMasterKey();
|
||||||
|
|
||||||
if (groupInfo.getName().isPresent()) {
|
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||||
group.name = groupInfo.getName().get();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (groupInfo.getMembers().isPresent()) {
|
byte[] groupId = groupSecretParams.getPublicParams().getGroupIdentifier().serialize();
|
||||||
group.addMembers(groupInfo.getMembers().get()
|
GroupInfo groupInfo = account.getGroupStore().getGroup(groupId);
|
||||||
.stream()
|
if (groupInfo instanceof GroupInfoV1) {
|
||||||
.map(this::resolveSignalServiceAddress)
|
// TODO upgrade group
|
||||||
.collect(Collectors.toSet()));
|
} else if (groupInfo == null || groupInfo instanceof GroupInfoV2) {
|
||||||
}
|
GroupInfoV2 groupInfoV2 = groupInfo == null
|
||||||
|
? new GroupInfoV2(groupId, groupMasterKey)
|
||||||
|
: (GroupInfoV2) groupInfo;
|
||||||
|
|
||||||
account.getGroupStore().updateGroup(group);
|
if (groupInfoV2.getGroup() == null || groupInfoV2.getGroup().getRevision() < groupContext.getRevision()) {
|
||||||
break;
|
// TODO check if revision is only 1 behind and a signedGroupChange is available
|
||||||
case DELIVER:
|
try {
|
||||||
if (group == null && !isSync) {
|
final GroupsV2AuthorizationString groupsV2AuthorizationString = getGroupAuthForToday(groupSecretParams);
|
||||||
actions.add(new SendGroupInfoRequestAction(source, groupInfo.getGroupId()));
|
final DecryptedGroup group = groupsV2Api.getGroup(groupSecretParams, groupsV2AuthorizationString);
|
||||||
|
groupInfoV2.setGroup(group);
|
||||||
|
for (DecryptedMember member : group.getMembersList()) {
|
||||||
|
final SignalServiceAddress address = resolveSignalServiceAddress(new SignalServiceAddress(UuidUtil.parseOrThrow(member.getUuid().toByteArray()), null));
|
||||||
|
try {
|
||||||
|
account.getProfileStore().storeProfileKey(address, new ProfileKey(member.getProfileKey().toByteArray()));
|
||||||
|
} catch (InvalidInputException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException | VerificationFailedException | InvalidGroupStateException e) {
|
||||||
|
System.err.println("Failed to retrieve Group V2 info, ignoring ...");
|
||||||
|
}
|
||||||
|
account.getGroupStore().updateGroup(groupInfoV2);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case QUIT:
|
|
||||||
if (group != null) {
|
|
||||||
group.removeMember(source);
|
|
||||||
account.getGroupStore().updateGroup(group);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case REQUEST_INFO:
|
|
||||||
if (group != null && !isSync) {
|
|
||||||
actions.add(new SendGroupUpdateAction(source, group.groupId));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final SignalServiceAddress conversationPartnerAddress = isSync ? destination : source;
|
final SignalServiceAddress conversationPartnerAddress = isSync ? destination : source;
|
||||||
|
@ -1293,15 +1355,18 @@ public class Manager implements Closeable {
|
||||||
handleEndSession(conversationPartnerAddress);
|
handleEndSession(conversationPartnerAddress);
|
||||||
}
|
}
|
||||||
if (message.isExpirationUpdate() || message.getBody().isPresent()) {
|
if (message.isExpirationUpdate() || message.getBody().isPresent()) {
|
||||||
if (message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()) {
|
if (message.getGroupContext().isPresent()) {
|
||||||
SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
|
if (message.getGroupContext().get().getGroupV1().isPresent()) {
|
||||||
GroupInfo group = account.getGroupStore().getGroup(groupInfo.getGroupId());
|
SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
|
||||||
if (group == null) {
|
GroupInfoV1 group = account.getGroupStore().getOrCreateGroupV1(groupInfo.getGroupId());
|
||||||
group = new GroupInfo(groupInfo.getGroupId());
|
if (group != null) {
|
||||||
}
|
if (group.messageExpirationTime != message.getExpiresInSeconds()) {
|
||||||
if (group.messageExpirationTime != message.getExpiresInSeconds()) {
|
group.messageExpirationTime = message.getExpiresInSeconds();
|
||||||
group.messageExpirationTime = message.getExpiresInSeconds();
|
account.getGroupStore().updateGroup(group);
|
||||||
account.getGroupStore().updateGroup(group);
|
}
|
||||||
|
}
|
||||||
|
} else if (message.getGroupContext().get().getGroupV2().isPresent()) {
|
||||||
|
// disappearing message timer already stored in the DecryptedGroup
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ContactInfo contact = account.getContactStore().getContact(conversationPartnerAddress);
|
ContactInfo contact = account.getContactStore().getContact(conversationPartnerAddress);
|
||||||
|
@ -1326,24 +1391,16 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (message.getProfileKey().isPresent() && message.getProfileKey().get().length == 32) {
|
if (message.getProfileKey().isPresent() && message.getProfileKey().get().length == 32) {
|
||||||
if (source.matches(account.getSelfAddress())) {
|
final ProfileKey profileKey;
|
||||||
try {
|
try {
|
||||||
this.account.setProfileKey(new ProfileKey(message.getProfileKey().get()));
|
profileKey = new ProfileKey(message.getProfileKey().get());
|
||||||
} catch (InvalidInputException ignored) {
|
} catch (InvalidInputException e) {
|
||||||
}
|
throw new AssertionError(e);
|
||||||
ContactInfo contact = account.getContactStore().getContact(source);
|
|
||||||
if (contact != null) {
|
|
||||||
contact.profileKey = Base64.encodeBytes(message.getProfileKey().get());
|
|
||||||
account.getContactStore().updateContact(contact);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ContactInfo contact = account.getContactStore().getContact(source);
|
|
||||||
if (contact == null) {
|
|
||||||
contact = new ContactInfo(source);
|
|
||||||
}
|
|
||||||
contact.profileKey = Base64.encodeBytes(message.getProfileKey().get());
|
|
||||||
account.getContactStore().updateContact(contact);
|
|
||||||
}
|
}
|
||||||
|
if (source.matches(account.getSelfAddress())) {
|
||||||
|
this.account.setProfileKey(profileKey);
|
||||||
|
}
|
||||||
|
this.account.getProfileStore().storeProfileKey(source, profileKey);
|
||||||
}
|
}
|
||||||
if (message.getPreviews().isPresent()) {
|
if (message.getPreviews().isPresent()) {
|
||||||
final List<SignalServiceDataMessage.Preview> previews = message.getPreviews().get();
|
final List<SignalServiceDataMessage.Preview> previews = message.getPreviews().get();
|
||||||
|
@ -1358,6 +1415,14 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (message.getSticker().isPresent()) {
|
||||||
|
final SignalServiceDataMessage.Sticker messageSticker = message.getSticker().get();
|
||||||
|
Sticker sticker = account.getStickerStore().getSticker(messageSticker.getPackId());
|
||||||
|
if (sticker == null) {
|
||||||
|
sticker = new Sticker(messageSticker.getPackId(), messageSticker.getPackKey());
|
||||||
|
account.getStickerStore().updateSticker(sticker);
|
||||||
|
}
|
||||||
|
}
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,7 +1463,15 @@ public class Manager implements Closeable {
|
||||||
if (!envelope.isReceipt()) {
|
if (!envelope.isReceipt()) {
|
||||||
try {
|
try {
|
||||||
content = decryptMessage(envelope);
|
content = decryptMessage(envelope);
|
||||||
} catch (Exception e) {
|
} catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
|
||||||
|
return;
|
||||||
|
} catch (Exception er) {
|
||||||
|
// All other errors are not recoverable, so delete the cached message
|
||||||
|
try {
|
||||||
|
Files.delete(fileEntry.toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Failed to delete cached message file “" + fileEntry + "”: " + e.getMessage());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<HandleAction> actions = handleMessage(envelope, content, ignoreAttachments);
|
List<HandleAction> actions = handleMessage(envelope, content, ignoreAttachments);
|
||||||
|
@ -1461,6 +1534,7 @@ public class Manager implements Closeable {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
account.save();
|
||||||
queuedActions.clear();
|
queuedActions.clear();
|
||||||
queuedActions = null;
|
queuedActions = null;
|
||||||
}
|
}
|
||||||
|
@ -1476,6 +1550,7 @@ public class Manager implements Closeable {
|
||||||
System.err.println("Ignoring error: " + e.getMessage());
|
System.err.println("Ignoring error: " + e.getMessage());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envelope.hasSource()) {
|
if (envelope.hasSource()) {
|
||||||
// Store uuid if we don't have it already
|
// Store uuid if we don't have it already
|
||||||
SignalServiceAddress source = envelope.getSourceAddress();
|
SignalServiceAddress source = envelope.getSourceAddress();
|
||||||
|
@ -1541,9 +1616,7 @@ public class Manager implements Closeable {
|
||||||
if (message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()) {
|
if (message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()) {
|
||||||
SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
|
SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
|
||||||
GroupInfo group = getGroup(groupInfo.getGroupId());
|
GroupInfo group = getGroup(groupInfo.getGroupId());
|
||||||
if (groupInfo.getType() == SignalServiceGroup.Type.DELIVER && group != null && group.blocked) {
|
return groupInfo.getType() == SignalServiceGroup.Type.DELIVER && group != null && group.isBlocked();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1588,7 +1661,7 @@ public class Manager implements Closeable {
|
||||||
if (rm.isBlockedListRequest()) {
|
if (rm.isBlockedListRequest()) {
|
||||||
actions.add(SendSyncBlockedListAction.create());
|
actions.add(SendSyncBlockedListAction.create());
|
||||||
}
|
}
|
||||||
// TODO Handle rm.isConfigurationRequest();
|
// TODO Handle rm.isConfigurationRequest(); rm.isKeysRequest();
|
||||||
}
|
}
|
||||||
if (syncMessage.getGroups().isPresent()) {
|
if (syncMessage.getGroups().isPresent()) {
|
||||||
File tmpFile = null;
|
File tmpFile = null;
|
||||||
|
@ -1598,34 +1671,33 @@ public class Manager implements Closeable {
|
||||||
DeviceGroupsInputStream s = new DeviceGroupsInputStream(attachmentAsStream);
|
DeviceGroupsInputStream s = new DeviceGroupsInputStream(attachmentAsStream);
|
||||||
DeviceGroup g;
|
DeviceGroup g;
|
||||||
while ((g = s.read()) != null) {
|
while ((g = s.read()) != null) {
|
||||||
GroupInfo syncGroup = account.getGroupStore().getGroup(g.getId());
|
GroupInfoV1 syncGroup = account.getGroupStore().getOrCreateGroupV1(g.getId());
|
||||||
if (syncGroup == null) {
|
if (syncGroup != null) {
|
||||||
syncGroup = new GroupInfo(g.getId());
|
if (g.getName().isPresent()) {
|
||||||
}
|
syncGroup.name = g.getName().get();
|
||||||
if (g.getName().isPresent()) {
|
}
|
||||||
syncGroup.name = g.getName().get();
|
syncGroup.addMembers(g.getMembers()
|
||||||
}
|
.stream()
|
||||||
syncGroup.addMembers(g.getMembers()
|
.map(this::resolveSignalServiceAddress)
|
||||||
.stream()
|
.collect(Collectors.toSet()));
|
||||||
.map(this::resolveSignalServiceAddress)
|
if (!g.isActive()) {
|
||||||
.collect(Collectors.toSet()));
|
syncGroup.removeMember(account.getSelfAddress());
|
||||||
if (!g.isActive()) {
|
} else {
|
||||||
syncGroup.removeMember(account.getSelfAddress());
|
// Add ourself to the member set as it's marked as active
|
||||||
} else {
|
syncGroup.addMembers(Collections.singleton(account.getSelfAddress()));
|
||||||
// Add ourself to the member set as it's marked as active
|
}
|
||||||
syncGroup.addMembers(Collections.singleton(account.getSelfAddress()));
|
syncGroup.blocked = g.isBlocked();
|
||||||
}
|
if (g.getColor().isPresent()) {
|
||||||
syncGroup.blocked = g.isBlocked();
|
syncGroup.color = g.getColor().get();
|
||||||
if (g.getColor().isPresent()) {
|
}
|
||||||
syncGroup.color = g.getColor().get();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g.getAvatar().isPresent()) {
|
if (g.getAvatar().isPresent()) {
|
||||||
retrieveGroupAvatarAttachment(g.getAvatar().get(), syncGroup.groupId);
|
retrieveGroupAvatarAttachment(g.getAvatar().get(), syncGroup.groupId);
|
||||||
|
}
|
||||||
|
syncGroup.inboxPosition = g.getInboxPosition().orNull();
|
||||||
|
syncGroup.archived = g.isArchived();
|
||||||
|
account.getGroupStore().updateGroup(syncGroup);
|
||||||
}
|
}
|
||||||
syncGroup.inboxPosition = g.getInboxPosition().orNull();
|
|
||||||
syncGroup.archived = g.isArchived();
|
|
||||||
account.getGroupStore().updateGroup(syncGroup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1680,7 +1752,7 @@ public class Manager implements Closeable {
|
||||||
contact.color = c.getColor().get();
|
contact.color = c.getColor().get();
|
||||||
}
|
}
|
||||||
if (c.getProfileKey().isPresent()) {
|
if (c.getProfileKey().isPresent()) {
|
||||||
contact.profileKey = Base64.encodeBytes(c.getProfileKey().get().serialize());
|
account.getProfileStore().storeProfileKey(address, c.getProfileKey().get());
|
||||||
}
|
}
|
||||||
if (c.getVerified().isPresent()) {
|
if (c.getVerified().isPresent()) {
|
||||||
final VerifiedMessage verifiedMessage = c.getVerified().get();
|
final VerifiedMessage verifiedMessage = c.getVerified().get();
|
||||||
|
@ -1715,6 +1787,23 @@ public class Manager implements Closeable {
|
||||||
final VerifiedMessage verifiedMessage = syncMessage.getVerified().get();
|
final VerifiedMessage verifiedMessage = syncMessage.getVerified().get();
|
||||||
account.getSignalProtocolStore().setIdentityTrustLevel(resolveSignalServiceAddress(verifiedMessage.getDestination()), verifiedMessage.getIdentityKey(), TrustLevel.fromVerifiedState(verifiedMessage.getVerified()));
|
account.getSignalProtocolStore().setIdentityTrustLevel(resolveSignalServiceAddress(verifiedMessage.getDestination()), verifiedMessage.getIdentityKey(), TrustLevel.fromVerifiedState(verifiedMessage.getVerified()));
|
||||||
}
|
}
|
||||||
|
if (syncMessage.getStickerPackOperations().isPresent()) {
|
||||||
|
final List<StickerPackOperationMessage> stickerPackOperationMessages = syncMessage.getStickerPackOperations().get();
|
||||||
|
for (StickerPackOperationMessage m : stickerPackOperationMessages) {
|
||||||
|
if (!m.getPackId().isPresent()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Sticker sticker = account.getStickerStore().getSticker(m.getPackId().get());
|
||||||
|
if (sticker == null) {
|
||||||
|
if (!m.getPackKey().isPresent()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sticker = new Sticker(m.getPackId().get(), m.getPackKey().get());
|
||||||
|
}
|
||||||
|
sticker.setInstalled(!m.getType().isPresent() || m.getType().get() == StickerPackOperationMessage.Type.INSTALL);
|
||||||
|
account.getStickerStore().updateSticker(sticker);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (syncMessage.getConfiguration().isPresent()) {
|
if (syncMessage.getConfiguration().isPresent()) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
@ -1824,10 +1913,13 @@ public class Manager implements Closeable {
|
||||||
try (OutputStream fos = new FileOutputStream(groupsFile)) {
|
try (OutputStream fos = new FileOutputStream(groupsFile)) {
|
||||||
DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(fos);
|
DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(fos);
|
||||||
for (GroupInfo record : account.getGroupStore().getGroups()) {
|
for (GroupInfo record : account.getGroupStore().getGroups()) {
|
||||||
out.write(new DeviceGroup(record.groupId, Optional.fromNullable(record.name),
|
if (record instanceof GroupInfoV1) {
|
||||||
new ArrayList<>(record.getMembers()), createGroupAvatarAttachment(record.groupId),
|
GroupInfoV1 groupInfo = (GroupInfoV1) record;
|
||||||
record.isMember(account.getSelfAddress()), Optional.of(record.messageExpirationTime),
|
out.write(new DeviceGroup(groupInfo.groupId, Optional.fromNullable(groupInfo.name),
|
||||||
Optional.fromNullable(record.color), record.blocked, Optional.fromNullable(record.inboxPosition), record.archived));
|
new ArrayList<>(groupInfo.getMembers()), createGroupAvatarAttachment(groupInfo.groupId),
|
||||||
|
groupInfo.isMember(account.getSelfAddress()), Optional.of(groupInfo.messageExpirationTime),
|
||||||
|
Optional.fromNullable(groupInfo.color), groupInfo.blocked, Optional.fromNullable(groupInfo.inboxPosition), groupInfo.archived));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1864,11 +1956,7 @@ public class Manager implements Closeable {
|
||||||
verifiedMessage = new VerifiedMessage(record.getAddress(), currentIdentity.getIdentityKey(), currentIdentity.getTrustLevel().toVerifiedState(), currentIdentity.getDateAdded().getTime());
|
verifiedMessage = new VerifiedMessage(record.getAddress(), currentIdentity.getIdentityKey(), currentIdentity.getTrustLevel().toVerifiedState(), currentIdentity.getDateAdded().getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileKey profileKey = null;
|
ProfileKey profileKey = account.getProfileStore().getProfileKey(record.getAddress());
|
||||||
try {
|
|
||||||
profileKey = record.profileKey == null ? null : new ProfileKey(Base64.decode(record.profileKey));
|
|
||||||
} catch (InvalidInputException ignored) {
|
|
||||||
}
|
|
||||||
out.write(new DeviceContact(record.getAddress(), Optional.fromNullable(record.name),
|
out.write(new DeviceContact(record.getAddress(), Optional.fromNullable(record.name),
|
||||||
createContactAvatarAttachment(record.number), Optional.fromNullable(record.color),
|
createContactAvatarAttachment(record.number), Optional.fromNullable(record.color),
|
||||||
Optional.fromNullable(verifiedMessage), Optional.fromNullable(profileKey), record.blocked,
|
Optional.fromNullable(verifiedMessage), Optional.fromNullable(profileKey), record.blocked,
|
||||||
|
@ -1915,7 +2003,7 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
List<byte[]> groupIds = new ArrayList<>();
|
List<byte[]> groupIds = new ArrayList<>();
|
||||||
for (GroupInfo record : account.getGroupStore().getGroups()) {
|
for (GroupInfo record : account.getGroupStore().getGroups()) {
|
||||||
if (record.blocked) {
|
if (record.isBlocked()) {
|
||||||
groupIds.add(record.groupId);
|
groupIds.add(record.groupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1939,6 +2027,11 @@ public class Manager implements Closeable {
|
||||||
return account.getGroupStore().getGroup(groupId);
|
return account.getGroupStore().getGroup(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getGroupId(GroupMasterKey groupMasterKey) {
|
||||||
|
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||||
|
return groupSecretParams.getPublicParams().getGroupIdentifier().serialize();
|
||||||
|
}
|
||||||
|
|
||||||
public List<JsonIdentityKeyStore.Identity> getIdentities() {
|
public List<JsonIdentityKeyStore.Identity> getIdentities() {
|
||||||
return account.getSignalProtocolStore().getIdentities();
|
return account.getSignalProtocolStore().getIdentities();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.asamk.signal.manager;
|
package org.asamk.signal.manager;
|
||||||
|
|
||||||
|
import org.signal.zkgroup.ServerPublicParams;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
import org.whispersystems.signalservice.api.account.AccountAttributes;
|
||||||
import org.whispersystems.signalservice.api.push.TrustStore;
|
import org.whispersystems.signalservice.api.push.TrustStore;
|
||||||
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
|
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
|
||||||
import org.whispersystems.signalservice.internal.configuration.SignalContactDiscoveryUrl;
|
import org.whispersystems.signalservice.internal.configuration.SignalContactDiscoveryUrl;
|
||||||
|
@ -13,7 +14,6 @@ import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ public class ServiceConfig {
|
||||||
final static int PREKEY_MINIMUM_COUNT = 20;
|
final static int PREKEY_MINIMUM_COUNT = 20;
|
||||||
final static int PREKEY_BATCH_SIZE = 100;
|
final static int PREKEY_BATCH_SIZE = 100;
|
||||||
final static int MAX_ATTACHMENT_SIZE = 150 * 1024 * 1024;
|
final static int MAX_ATTACHMENT_SIZE = 150 * 1024 * 1024;
|
||||||
|
final static int MAX_ENVELOPE_SIZE = 0;
|
||||||
final static long AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE = 10 * 1024 * 1024;
|
final static long AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE = 10 * 1024 * 1024;
|
||||||
|
|
||||||
private final static String URL = "https://textsecure-service.whispersystems.org";
|
private final static String URL = "https://textsecure-service.whispersystems.org";
|
||||||
|
@ -38,8 +39,26 @@ public class ServiceConfig {
|
||||||
private final static Optional<Dns> dns = Optional.absent();
|
private final static Optional<Dns> dns = Optional.absent();
|
||||||
|
|
||||||
private final static String zkGroupServerPublicParamsHex = "AMhf5ywVwITZMsff/eCyudZx9JDmkkkbV6PInzG4p8x3VqVJSFiMvnvlEKWuRob/1eaIetR31IYeAbm0NdOuHH8Qi+Rexi1wLlpzIo1gstHWBfZzy1+qHRV5A4TqPp15YzBPm0WSggW6PbSn+F4lf57VCnHF7p8SvzAA2ZZJPYJURt8X7bbg+H3i+PEjH9DXItNEqs2sNcug37xZQDLm7X0=";
|
private final static String zkGroupServerPublicParamsHex = "AMhf5ywVwITZMsff/eCyudZx9JDmkkkbV6PInzG4p8x3VqVJSFiMvnvlEKWuRob/1eaIetR31IYeAbm0NdOuHH8Qi+Rexi1wLlpzIo1gstHWBfZzy1+qHRV5A4TqPp15YzBPm0WSggW6PbSn+F4lf57VCnHF7p8SvzAA2ZZJPYJURt8X7bbg+H3i+PEjH9DXItNEqs2sNcug37xZQDLm7X0=";
|
||||||
|
private final static byte[] zkGroupServerPublicParams;
|
||||||
|
|
||||||
static final SignalServiceProfile.Capabilities capabilities = new SignalServiceProfile.Capabilities(false, false, false);
|
static final AccountAttributes.Capabilities capabilities;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
zkGroupServerPublicParams = Base64.decode(zkGroupServerPublicParamsHex);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean zkGroupAvailable;
|
||||||
|
try {
|
||||||
|
new ServerPublicParams(zkGroupServerPublicParams);
|
||||||
|
zkGroupAvailable = true;
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
zkGroupAvailable = false;
|
||||||
|
}
|
||||||
|
capabilities = new AccountAttributes.Capabilities(false, zkGroupAvailable, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
public static SignalServiceConfiguration createDefaultServiceConfiguration(String userAgent) {
|
public static SignalServiceConfiguration createDefaultServiceConfiguration(String userAgent) {
|
||||||
final Interceptor userAgentInterceptor = chain ->
|
final Interceptor userAgentInterceptor = chain ->
|
||||||
|
@ -49,13 +68,6 @@ public class ServiceConfig {
|
||||||
|
|
||||||
final List<Interceptor> interceptors = Collections.singletonList(userAgentInterceptor);
|
final List<Interceptor> interceptors = Collections.singletonList(userAgentInterceptor);
|
||||||
|
|
||||||
final byte[] zkGroupServerPublicParams;
|
|
||||||
try {
|
|
||||||
zkGroupServerPublicParams = Base64.decode(zkGroupServerPublicParamsHex);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SignalServiceConfiguration(
|
return new SignalServiceConfiguration(
|
||||||
new SignalServiceUrl[]{new SignalServiceUrl(URL, TRUST_STORE)},
|
new SignalServiceUrl[]{new SignalServiceUrl(URL, TRUST_STORE)},
|
||||||
makeSignalCdnUrlMapFor(new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)}, new SignalCdnUrl[]{new SignalCdnUrl(CDN2_URL, TRUST_STORE)}),
|
makeSignalCdnUrlMapFor(new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)}, new SignalCdnUrl[]{new SignalCdnUrl(CDN2_URL, TRUST_STORE)}),
|
||||||
|
@ -69,10 +81,7 @@ public class ServiceConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<Integer, SignalCdnUrl[]> makeSignalCdnUrlMapFor(SignalCdnUrl[] cdn0Urls, SignalCdnUrl[] cdn2Urls) {
|
private static Map<Integer, SignalCdnUrl[]> makeSignalCdnUrlMapFor(SignalCdnUrl[] cdn0Urls, SignalCdnUrl[] cdn2Urls) {
|
||||||
Map<Integer, SignalCdnUrl[]> result = new HashMap<>();
|
return Map.of(0, cdn0Urls, 2, cdn2Urls);
|
||||||
result.put(0, cdn0Urls);
|
|
||||||
result.put(2, cdn2Urls);
|
|
||||||
return Collections.unmodifiableMap(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServiceConfig() {
|
private ServiceConfig() {
|
||||||
|
|
|
@ -27,11 +27,11 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -107,31 +107,16 @@ class Utils {
|
||||||
String[] params = query.split("&");
|
String[] params = query.split("&");
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
for (String param : params) {
|
for (String param : params) {
|
||||||
String name = null;
|
|
||||||
final String[] paramParts = param.split("=");
|
final String[] paramParts = param.split("=");
|
||||||
try {
|
String name = URLDecoder.decode(paramParts[0], StandardCharsets.UTF_8);
|
||||||
name = URLDecoder.decode(paramParts[0], "utf-8");
|
String value = URLDecoder.decode(paramParts[1], StandardCharsets.UTF_8);
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// Impossible
|
|
||||||
}
|
|
||||||
String value = null;
|
|
||||||
try {
|
|
||||||
value = URLDecoder.decode(paramParts[1], "utf-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// Impossible
|
|
||||||
}
|
|
||||||
map.put(name, value);
|
map.put(name, value);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String createDeviceLinkUri(DeviceLinkInfo info) {
|
static String createDeviceLinkUri(DeviceLinkInfo info) {
|
||||||
try {
|
return "tsdevice:/?uuid=" + URLEncoder.encode(info.deviceIdentifier, StandardCharsets.UTF_8) + "&pub_key=" + URLEncoder.encode(Base64.encodeBytesWithoutPadding(info.deviceKey.serialize()), StandardCharsets.UTF_8);
|
||||||
return "tsdevice:/?uuid=" + URLEncoder.encode(info.deviceIdentifier, "utf-8") + "&pub_key=" + URLEncoder.encode(Base64.encodeBytesWithoutPadding(info.deviceKey.serialize()), "utf-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// Shouldn't happen
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws IOException, InvalidKeyException {
|
static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws IOException, InvalidKeyException {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.asamk.signal.storage.contacts.ContactInfo;
|
import org.asamk.signal.storage.contacts.ContactInfo;
|
||||||
import org.asamk.signal.storage.contacts.JsonContactsStore;
|
import org.asamk.signal.storage.contacts.JsonContactsStore;
|
||||||
import org.asamk.signal.storage.groups.GroupInfo;
|
import org.asamk.signal.storage.groups.GroupInfo;
|
||||||
|
import org.asamk.signal.storage.groups.GroupInfoV1;
|
||||||
import org.asamk.signal.storage.groups.JsonGroupStore;
|
import org.asamk.signal.storage.groups.JsonGroupStore;
|
||||||
import org.asamk.signal.storage.profiles.ProfileStore;
|
import org.asamk.signal.storage.profiles.ProfileStore;
|
||||||
import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
|
import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
|
||||||
|
@ -20,6 +21,7 @@ import org.asamk.signal.storage.protocol.JsonSignalProtocolStore;
|
||||||
import org.asamk.signal.storage.protocol.RecipientStore;
|
import org.asamk.signal.storage.protocol.RecipientStore;
|
||||||
import org.asamk.signal.storage.protocol.SessionInfo;
|
import org.asamk.signal.storage.protocol.SessionInfo;
|
||||||
import org.asamk.signal.storage.protocol.SignalServiceAddressResolver;
|
import org.asamk.signal.storage.protocol.SignalServiceAddressResolver;
|
||||||
|
import org.asamk.signal.storage.stickers.StickerStore;
|
||||||
import org.asamk.signal.storage.threads.LegacyJsonThreadStore;
|
import org.asamk.signal.storage.threads.LegacyJsonThreadStore;
|
||||||
import org.asamk.signal.storage.threads.ThreadInfo;
|
import org.asamk.signal.storage.threads.ThreadInfo;
|
||||||
import org.asamk.signal.util.IOUtils;
|
import org.asamk.signal.util.IOUtils;
|
||||||
|
@ -71,6 +73,7 @@ public class SignalAccount implements Closeable {
|
||||||
private JsonContactsStore contactStore;
|
private JsonContactsStore contactStore;
|
||||||
private RecipientStore recipientStore;
|
private RecipientStore recipientStore;
|
||||||
private ProfileStore profileStore;
|
private ProfileStore profileStore;
|
||||||
|
private StickerStore stickerStore;
|
||||||
|
|
||||||
private SignalAccount(final FileChannel fileChannel, final FileLock lock) {
|
private SignalAccount(final FileChannel fileChannel, final FileLock lock) {
|
||||||
this.fileChannel = fileChannel;
|
this.fileChannel = fileChannel;
|
||||||
|
@ -87,7 +90,7 @@ public class SignalAccount implements Closeable {
|
||||||
final Pair<FileChannel, FileLock> pair = openFileChannel(fileName);
|
final Pair<FileChannel, FileLock> pair = openFileChannel(fileName);
|
||||||
try {
|
try {
|
||||||
SignalAccount account = new SignalAccount(pair.first(), pair.second());
|
SignalAccount account = new SignalAccount(pair.first(), pair.second());
|
||||||
account.load();
|
account.load(dataPath);
|
||||||
return account;
|
return account;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
pair.second().close();
|
pair.second().close();
|
||||||
|
@ -109,10 +112,11 @@ public class SignalAccount implements Closeable {
|
||||||
account.username = username;
|
account.username = username;
|
||||||
account.profileKey = profileKey;
|
account.profileKey = profileKey;
|
||||||
account.signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
|
account.signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
|
||||||
account.groupStore = new JsonGroupStore();
|
account.groupStore = new JsonGroupStore(getGroupCachePath(dataPath, username));
|
||||||
account.contactStore = new JsonContactsStore();
|
account.contactStore = new JsonContactsStore();
|
||||||
account.recipientStore = new RecipientStore();
|
account.recipientStore = new RecipientStore();
|
||||||
account.profileStore = new ProfileStore();
|
account.profileStore = new ProfileStore();
|
||||||
|
account.stickerStore = new StickerStore();
|
||||||
account.registered = false;
|
account.registered = false;
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
|
@ -135,10 +139,11 @@ public class SignalAccount implements Closeable {
|
||||||
account.deviceId = deviceId;
|
account.deviceId = deviceId;
|
||||||
account.signalingKey = signalingKey;
|
account.signalingKey = signalingKey;
|
||||||
account.signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
|
account.signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
|
||||||
account.groupStore = new JsonGroupStore();
|
account.groupStore = new JsonGroupStore(getGroupCachePath(dataPath, username));
|
||||||
account.contactStore = new JsonContactsStore();
|
account.contactStore = new JsonContactsStore();
|
||||||
account.recipientStore = new RecipientStore();
|
account.recipientStore = new RecipientStore();
|
||||||
account.profileStore = new ProfileStore();
|
account.profileStore = new ProfileStore();
|
||||||
|
account.stickerStore = new StickerStore();
|
||||||
account.registered = true;
|
account.registered = true;
|
||||||
account.isMultiDevice = true;
|
account.isMultiDevice = true;
|
||||||
|
|
||||||
|
@ -149,6 +154,10 @@ public class SignalAccount implements Closeable {
|
||||||
return dataPath + "/" + username;
|
return dataPath + "/" + username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static File getGroupCachePath(String dataPath, String username) {
|
||||||
|
return new File(new File(dataPath, username + ".d"), "group-cache");
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean userExists(String dataPath, String username) {
|
public static boolean userExists(String dataPath, String username) {
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -157,7 +166,7 @@ public class SignalAccount implements Closeable {
|
||||||
return !(!f.exists() || f.isDirectory());
|
return !(!f.exists() || f.isDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load() throws IOException {
|
private void load(String dataPath) throws IOException {
|
||||||
JsonNode rootNode;
|
JsonNode rootNode;
|
||||||
synchronized (fileChannel) {
|
synchronized (fileChannel) {
|
||||||
fileChannel.position(0);
|
fileChannel.position(0);
|
||||||
|
@ -209,9 +218,10 @@ public class SignalAccount implements Closeable {
|
||||||
JsonNode groupStoreNode = rootNode.get("groupStore");
|
JsonNode groupStoreNode = rootNode.get("groupStore");
|
||||||
if (groupStoreNode != null) {
|
if (groupStoreNode != null) {
|
||||||
groupStore = jsonProcessor.convertValue(groupStoreNode, JsonGroupStore.class);
|
groupStore = jsonProcessor.convertValue(groupStoreNode, JsonGroupStore.class);
|
||||||
|
groupStore.groupCachePath = getGroupCachePath(dataPath, username);
|
||||||
}
|
}
|
||||||
if (groupStore == null) {
|
if (groupStore == null) {
|
||||||
groupStore = new JsonGroupStore();
|
groupStore = new JsonGroupStore(getGroupCachePath(dataPath, username));
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode contactStoreNode = rootNode.get("contactStore");
|
JsonNode contactStoreNode = rootNode.get("contactStore");
|
||||||
|
@ -236,9 +246,12 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (GroupInfo group : groupStore.getGroups()) {
|
for (GroupInfo group : groupStore.getGroups()) {
|
||||||
group.members = group.members.stream()
|
if (group instanceof GroupInfoV1) {
|
||||||
.map(m -> recipientStore.resolveServiceAddress(m))
|
GroupInfoV1 groupInfoV1 = (GroupInfoV1) group;
|
||||||
.collect(Collectors.toSet());
|
groupInfoV1.members = groupInfoV1.members.stream()
|
||||||
|
.map(m -> recipientStore.resolveServiceAddress(m))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SessionInfo session : signalProtocolStore.getSessions()) {
|
for (SessionInfo session : signalProtocolStore.getSessions()) {
|
||||||
|
@ -258,6 +271,14 @@ public class SignalAccount implements Closeable {
|
||||||
profileStore = new ProfileStore();
|
profileStore = new ProfileStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode stickerStoreNode = rootNode.get("stickerStore");
|
||||||
|
if (stickerStoreNode != null) {
|
||||||
|
stickerStore = jsonProcessor.convertValue(stickerStoreNode, StickerStore.class);
|
||||||
|
}
|
||||||
|
if (stickerStore == null) {
|
||||||
|
stickerStore = new StickerStore();
|
||||||
|
}
|
||||||
|
|
||||||
JsonNode threadStoreNode = rootNode.get("threadStore");
|
JsonNode threadStoreNode = rootNode.get("threadStore");
|
||||||
if (threadStoreNode != null) {
|
if (threadStoreNode != null) {
|
||||||
LegacyJsonThreadStore threadStore = jsonProcessor.convertValue(threadStoreNode, LegacyJsonThreadStore.class);
|
LegacyJsonThreadStore threadStore = jsonProcessor.convertValue(threadStoreNode, LegacyJsonThreadStore.class);
|
||||||
|
@ -273,8 +294,8 @@ public class SignalAccount implements Closeable {
|
||||||
contactStore.updateContact(contactInfo);
|
contactStore.updateContact(contactInfo);
|
||||||
} else {
|
} else {
|
||||||
GroupInfo groupInfo = groupStore.getGroup(Base64.decode(thread.id));
|
GroupInfo groupInfo = groupStore.getGroup(Base64.decode(thread.id));
|
||||||
if (groupInfo != null) {
|
if (groupInfo instanceof GroupInfoV1) {
|
||||||
groupInfo.messageExpirationTime = thread.messageExpirationTime;
|
((GroupInfoV1) groupInfo).messageExpirationTime = thread.messageExpirationTime;
|
||||||
groupStore.updateGroup(groupInfo);
|
groupStore.updateGroup(groupInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,6 +326,7 @@ public class SignalAccount implements Closeable {
|
||||||
.putPOJO("contactStore", contactStore)
|
.putPOJO("contactStore", contactStore)
|
||||||
.putPOJO("recipientStore", recipientStore)
|
.putPOJO("recipientStore", recipientStore)
|
||||||
.putPOJO("profileStore", profileStore)
|
.putPOJO("profileStore", profileStore)
|
||||||
|
.putPOJO("stickerStore", stickerStore)
|
||||||
;
|
;
|
||||||
try {
|
try {
|
||||||
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
||||||
|
@ -370,6 +392,10 @@ public class SignalAccount implements Closeable {
|
||||||
return profileStore;
|
return profileStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StickerStore getStickerStore() {
|
||||||
|
return stickerStore;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.fasterxml.jackson.annotation.JsonProperty.Access.WRITE_ONLY;
|
||||||
|
|
||||||
public class ContactInfo {
|
public class ContactInfo {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
@ -24,7 +26,7 @@ public class ContactInfo {
|
||||||
@JsonProperty(defaultValue = "0")
|
@JsonProperty(defaultValue = "0")
|
||||||
public int messageExpirationTime;
|
public int messageExpirationTime;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty(access = WRITE_ONLY)
|
||||||
public String profileKey;
|
public String profileKey;
|
||||||
|
|
||||||
@JsonProperty(defaultValue = "false")
|
@JsonProperty(defaultValue = "false")
|
||||||
|
|
|
@ -2,98 +2,40 @@ package org.asamk.signal.storage.groups;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class GroupInfo {
|
public abstract class GroupInfo {
|
||||||
|
|
||||||
private static final ObjectMapper jsonProcessor = new ObjectMapper();
|
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
public final byte[] groupId;
|
public final byte[] groupId;
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
public String name;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
@JsonDeserialize(using = MembersDeserializer.class)
|
|
||||||
@JsonSerialize(using = MembersSerializer.class)
|
|
||||||
public Set<SignalServiceAddress> members = new HashSet<>();
|
|
||||||
@JsonProperty
|
|
||||||
public String color;
|
|
||||||
@JsonProperty(defaultValue = "0")
|
|
||||||
public int messageExpirationTime;
|
|
||||||
@JsonProperty(defaultValue = "false")
|
|
||||||
public boolean blocked;
|
|
||||||
@JsonProperty
|
|
||||||
public Integer inboxPosition;
|
|
||||||
@JsonProperty(defaultValue = "false")
|
|
||||||
public boolean archived;
|
|
||||||
|
|
||||||
private long avatarId;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
@JsonIgnore
|
|
||||||
private boolean active;
|
|
||||||
|
|
||||||
public GroupInfo(byte[] groupId) {
|
public GroupInfo(byte[] groupId) {
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupInfo(@JsonProperty("groupId") byte[] groupId, @JsonProperty("name") String name, @JsonProperty("members") Collection<SignalServiceAddress> members, @JsonProperty("avatarId") long avatarId, @JsonProperty("color") String color, @JsonProperty("blocked") boolean blocked, @JsonProperty("inboxPosition") Integer inboxPosition, @JsonProperty("archived") boolean archived, @JsonProperty("messageExpirationTime") int messageExpirationTime) {
|
@JsonIgnore
|
||||||
this.groupId = groupId;
|
public abstract String getTitle();
|
||||||
this.name = name;
|
|
||||||
this.members.addAll(members);
|
|
||||||
this.avatarId = avatarId;
|
|
||||||
this.color = color;
|
|
||||||
this.blocked = blocked;
|
|
||||||
this.inboxPosition = inboxPosition;
|
|
||||||
this.archived = archived;
|
|
||||||
this.messageExpirationTime = messageExpirationTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public long getAvatarId() {
|
public abstract Set<SignalServiceAddress> getMembers();
|
||||||
return avatarId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Set<SignalServiceAddress> getMembers() {
|
public abstract boolean isBlocked();
|
||||||
return members;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Set<String> getMembersE164() {
|
public abstract void setBlocked(boolean blocked);
|
||||||
Set<String> membersE164 = new HashSet<>();
|
|
||||||
for (SignalServiceAddress member : members) {
|
@JsonIgnore
|
||||||
if (!member.getNumber().isPresent()) {
|
public abstract int getMessageExpirationTime();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
membersE164.add(member.getNumber().get());
|
|
||||||
}
|
|
||||||
return membersE164;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Set<SignalServiceAddress> getMembersWithout(SignalServiceAddress address) {
|
public Set<SignalServiceAddress> getMembersWithout(SignalServiceAddress address) {
|
||||||
Set<SignalServiceAddress> members = new HashSet<>(this.members.size());
|
Set<SignalServiceAddress> members = new HashSet<>();
|
||||||
for (SignalServiceAddress member : this.members) {
|
for (SignalServiceAddress member : getMembers()) {
|
||||||
if (!member.matches(address)) {
|
if (!member.matches(address)) {
|
||||||
members.add(member);
|
members.add(member);
|
||||||
}
|
}
|
||||||
|
@ -101,85 +43,13 @@ public class GroupInfo {
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMembers(Collection<SignalServiceAddress> addresses) {
|
|
||||||
for (SignalServiceAddress address : addresses) {
|
|
||||||
if (this.members.contains(address)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
removeMember(address);
|
|
||||||
this.members.add(address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeMember(SignalServiceAddress address) {
|
|
||||||
this.members.removeIf(member -> member.matches(address));
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public boolean isMember(SignalServiceAddress address) {
|
public boolean isMember(SignalServiceAddress address) {
|
||||||
for (SignalServiceAddress member : this.members) {
|
for (SignalServiceAddress member : getMembers()) {
|
||||||
if (member.matches(address)) {
|
if (member.matches(address)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class JsonSignalServiceAddress {
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
private UUID uuid;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
private String number;
|
|
||||||
|
|
||||||
JsonSignalServiceAddress(@JsonProperty("uuid") final UUID uuid, @JsonProperty("number") final String number) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.number = number;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonSignalServiceAddress(SignalServiceAddress address) {
|
|
||||||
this.uuid = address.getUuid().orNull();
|
|
||||||
this.number = address.getNumber().orNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalServiceAddress toSignalServiceAddress() {
|
|
||||||
return new SignalServiceAddress(uuid, number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MembersSerializer extends JsonSerializer<Set<SignalServiceAddress>> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void serialize(final Set<SignalServiceAddress> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
|
|
||||||
jgen.writeStartArray(value.size());
|
|
||||||
for (SignalServiceAddress address : value) {
|
|
||||||
if (address.getUuid().isPresent()) {
|
|
||||||
jgen.writeObject(new JsonSignalServiceAddress(address));
|
|
||||||
} else {
|
|
||||||
jgen.writeString(address.getNumber().get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jgen.writeEndArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MembersDeserializer extends JsonDeserializer<Set<SignalServiceAddress>> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<SignalServiceAddress> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
|
||||||
Set<SignalServiceAddress> addresses = new HashSet<>();
|
|
||||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
|
||||||
for (JsonNode n : node) {
|
|
||||||
if (n.isTextual()) {
|
|
||||||
addresses.add(new SignalServiceAddress(null, n.textValue()));
|
|
||||||
} else {
|
|
||||||
JsonSignalServiceAddress address = jsonProcessor.treeToValue(n, JsonSignalServiceAddress.class);
|
|
||||||
addresses.add(address.toSignalServiceAddress());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return addresses;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
157
src/main/java/org/asamk/signal/storage/groups/GroupInfoV1.java
Normal file
157
src/main/java/org/asamk/signal/storage/groups/GroupInfoV1.java
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
package org.asamk.signal.storage.groups;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
|
||||||
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class GroupInfoV1 extends GroupInfo {
|
||||||
|
|
||||||
|
private static final ObjectMapper jsonProcessor = new ObjectMapper();
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
@JsonDeserialize(using = MembersDeserializer.class)
|
||||||
|
@JsonSerialize(using = MembersSerializer.class)
|
||||||
|
public Set<SignalServiceAddress> members = new HashSet<>();
|
||||||
|
@JsonProperty
|
||||||
|
public String color;
|
||||||
|
@JsonProperty(defaultValue = "0")
|
||||||
|
public int messageExpirationTime;
|
||||||
|
@JsonProperty(defaultValue = "false")
|
||||||
|
public boolean blocked;
|
||||||
|
@JsonProperty
|
||||||
|
public Integer inboxPosition;
|
||||||
|
@JsonProperty(defaultValue = "false")
|
||||||
|
public boolean archived;
|
||||||
|
|
||||||
|
public GroupInfoV1(byte[] groupId) {
|
||||||
|
super(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupInfoV1(@JsonProperty("groupId") byte[] groupId, @JsonProperty("name") String name, @JsonProperty("members") Collection<SignalServiceAddress> members, @JsonProperty("avatarId") long _ignored_avatarId, @JsonProperty("color") String color, @JsonProperty("blocked") boolean blocked, @JsonProperty("inboxPosition") Integer inboxPosition, @JsonProperty("archived") boolean archived, @JsonProperty("messageExpirationTime") int messageExpirationTime, @JsonProperty("active") boolean _ignored_active) {
|
||||||
|
super(groupId);
|
||||||
|
this.name = name;
|
||||||
|
this.members.addAll(members);
|
||||||
|
this.color = color;
|
||||||
|
this.blocked = blocked;
|
||||||
|
this.inboxPosition = inboxPosition;
|
||||||
|
this.archived = archived;
|
||||||
|
this.messageExpirationTime = messageExpirationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public Set<SignalServiceAddress> getMembers() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBlocked() {
|
||||||
|
return blocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlocked(final boolean blocked) {
|
||||||
|
this.blocked = blocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMessageExpirationTime() {
|
||||||
|
return messageExpirationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMembers(Collection<SignalServiceAddress> addresses) {
|
||||||
|
for (SignalServiceAddress address : addresses) {
|
||||||
|
if (this.members.contains(address)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
removeMember(address);
|
||||||
|
this.members.add(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeMember(SignalServiceAddress address) {
|
||||||
|
this.members.removeIf(member -> member.matches(address));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class JsonSignalServiceAddress {
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String number;
|
||||||
|
|
||||||
|
JsonSignalServiceAddress(@JsonProperty("uuid") final UUID uuid, @JsonProperty("number") final String number) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonSignalServiceAddress(SignalServiceAddress address) {
|
||||||
|
this.uuid = address.getUuid().orNull();
|
||||||
|
this.number = address.getNumber().orNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
SignalServiceAddress toSignalServiceAddress() {
|
||||||
|
return new SignalServiceAddress(uuid, number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MembersSerializer extends JsonSerializer<Set<SignalServiceAddress>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(final Set<SignalServiceAddress> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
|
||||||
|
jgen.writeStartArray(value.size());
|
||||||
|
for (SignalServiceAddress address : value) {
|
||||||
|
if (address.getUuid().isPresent()) {
|
||||||
|
jgen.writeObject(new JsonSignalServiceAddress(address));
|
||||||
|
} else {
|
||||||
|
jgen.writeString(address.getNumber().get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jgen.writeEndArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MembersDeserializer extends JsonDeserializer<Set<SignalServiceAddress>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<SignalServiceAddress> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
||||||
|
Set<SignalServiceAddress> addresses = new HashSet<>();
|
||||||
|
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
for (JsonNode n : node) {
|
||||||
|
if (n.isTextual()) {
|
||||||
|
addresses.add(new SignalServiceAddress(null, n.textValue()));
|
||||||
|
} else {
|
||||||
|
JsonSignalServiceAddress address = jsonProcessor.treeToValue(n, JsonSignalServiceAddress.class);
|
||||||
|
addresses.add(address.toSignalServiceAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.asamk.signal.storage.groups;
|
||||||
|
|
||||||
|
import org.signal.storageservice.protos.groups.local.DecryptedGroup;
|
||||||
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class GroupInfoV2 extends GroupInfo {
|
||||||
|
|
||||||
|
private final GroupMasterKey masterKey;
|
||||||
|
|
||||||
|
private boolean blocked;
|
||||||
|
private DecryptedGroup group; // stored as a file with hexadecimal groupId as name
|
||||||
|
|
||||||
|
public GroupInfoV2(final byte[] groupId, final GroupMasterKey masterKey) {
|
||||||
|
super(groupId);
|
||||||
|
this.masterKey = masterKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupMasterKey getMasterKey() {
|
||||||
|
return masterKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroup(final DecryptedGroup group) {
|
||||||
|
this.group = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DecryptedGroup getGroup() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle() {
|
||||||
|
if (this.group == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.group.getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<SignalServiceAddress> getMembers() {
|
||||||
|
if (this.group == null) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
return group.getMembersList().stream()
|
||||||
|
.map(m -> new SignalServiceAddress(UuidUtil.parseOrThrow(m.getUuid().toByteArray()), null))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBlocked() {
|
||||||
|
return blocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlocked(final boolean blocked) {
|
||||||
|
this.blocked = blocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMessageExpirationTime() {
|
||||||
|
return this.group != null && this.group.hasDisappearingMessagesTimer()
|
||||||
|
? this.group.getDisappearingMessagesTimer().getDuration()
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,10 +12,19 @@ import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
|
||||||
|
import org.asamk.signal.util.Hex;
|
||||||
|
import org.asamk.signal.util.IOUtils;
|
||||||
|
import org.signal.storageservice.protos.groups.local.DecryptedGroup;
|
||||||
|
import org.signal.zkgroup.InvalidInputException;
|
||||||
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
import org.whispersystems.util.Base64;
|
import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -23,31 +32,95 @@ import java.util.Map;
|
||||||
public class JsonGroupStore {
|
public class JsonGroupStore {
|
||||||
|
|
||||||
private static final ObjectMapper jsonProcessor = new ObjectMapper();
|
private static final ObjectMapper jsonProcessor = new ObjectMapper();
|
||||||
|
public File groupCachePath;
|
||||||
public static List<GroupInfo> groupsWithLegacyAvatarId = new ArrayList<>();
|
|
||||||
|
|
||||||
@JsonProperty("groups")
|
@JsonProperty("groups")
|
||||||
@JsonSerialize(using = JsonGroupStore.MapToListSerializer.class)
|
@JsonSerialize(using = GroupsSerializer.class)
|
||||||
@JsonDeserialize(using = JsonGroupStore.GroupsDeserializer.class)
|
@JsonDeserialize(using = GroupsDeserializer.class)
|
||||||
private Map<String, GroupInfo> groups = new HashMap<>();
|
private final Map<String, GroupInfo> groups = new HashMap<>();
|
||||||
|
|
||||||
|
private JsonGroupStore() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonGroupStore(final File groupCachePath) {
|
||||||
|
this.groupCachePath = groupCachePath;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateGroup(GroupInfo group) {
|
public void updateGroup(GroupInfo group) {
|
||||||
groups.put(Base64.encodeBytes(group.groupId), group);
|
groups.put(Base64.encodeBytes(group.groupId), group);
|
||||||
|
if (group instanceof GroupInfoV2) {
|
||||||
|
try {
|
||||||
|
IOUtils.createPrivateDirectories(groupCachePath);
|
||||||
|
try (FileOutputStream stream = new FileOutputStream(getGroupFile(group.groupId))) {
|
||||||
|
((GroupInfoV2) group).getGroup().writeTo(stream);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Failed to cache group, ignoring ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupInfo getGroup(byte[] groupId) {
|
public GroupInfo getGroup(byte[] groupId) {
|
||||||
return groups.get(Base64.encodeBytes(groupId));
|
final GroupInfo group = groups.get(Base64.encodeBytes(groupId));
|
||||||
|
loadDecryptedGroup(group);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDecryptedGroup(final GroupInfo group) {
|
||||||
|
if (group instanceof GroupInfoV2 && ((GroupInfoV2) group).getGroup() == null) {
|
||||||
|
try (FileInputStream stream = new FileInputStream(getGroupFile(group.groupId))) {
|
||||||
|
((GroupInfoV2) group).setGroup(DecryptedGroup.parseFrom(stream));
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getGroupFile(final byte[] groupId) {
|
||||||
|
return new File(groupCachePath, Hex.toStringCondensed(groupId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupInfoV1 getOrCreateGroupV1(byte[] groupId) {
|
||||||
|
GroupInfo group = groups.get(Base64.encodeBytes(groupId));
|
||||||
|
if (group instanceof GroupInfoV1) {
|
||||||
|
return (GroupInfoV1) group;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group == null) {
|
||||||
|
return new GroupInfoV1(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GroupInfo> getGroups() {
|
public List<GroupInfo> getGroups() {
|
||||||
return new ArrayList<>(groups.values());
|
final Collection<GroupInfo> groups = this.groups.values();
|
||||||
|
for (GroupInfo group : groups) {
|
||||||
|
loadDecryptedGroup(group);
|
||||||
|
}
|
||||||
|
return new ArrayList<>(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MapToListSerializer extends JsonSerializer<Map<?, ?>> {
|
private static class GroupsSerializer extends JsonSerializer<Map<String, GroupInfo>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(final Map<?, ?> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
|
public void serialize(final Map<String, GroupInfo> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
|
||||||
jgen.writeObject(value.values());
|
final Collection<GroupInfo> groups = value.values();
|
||||||
|
jgen.writeStartArray(groups.size());
|
||||||
|
for (GroupInfo group : groups) {
|
||||||
|
if (group instanceof GroupInfoV1) {
|
||||||
|
jgen.writeObject(group);
|
||||||
|
} else if (group instanceof GroupInfoV2) {
|
||||||
|
final GroupInfoV2 groupV2 = (GroupInfoV2) group;
|
||||||
|
jgen.writeStartObject();
|
||||||
|
jgen.writeStringField("groupId", Base64.encodeBytes(groupV2.groupId));
|
||||||
|
jgen.writeStringField("masterKey", Base64.encodeBytes(groupV2.getMasterKey().serialize()));
|
||||||
|
jgen.writeBooleanField("blocked", groupV2.isBlocked());
|
||||||
|
jgen.writeEndObject();
|
||||||
|
} else {
|
||||||
|
throw new AssertionError("Unknown group version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jgen.writeEndArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,10 +131,19 @@ public class JsonGroupStore {
|
||||||
Map<String, GroupInfo> groups = new HashMap<>();
|
Map<String, GroupInfo> groups = new HashMap<>();
|
||||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||||
for (JsonNode n : node) {
|
for (JsonNode n : node) {
|
||||||
GroupInfo g = jsonProcessor.treeToValue(n, GroupInfo.class);
|
GroupInfo g;
|
||||||
// Check if a legacy avatarId exists
|
if (n.has("masterKey")) {
|
||||||
if (g.getAvatarId() != 0) {
|
// a v2 group
|
||||||
groupsWithLegacyAvatarId.add(g);
|
byte[] groupId = Base64.decode(n.get("groupId").asText());
|
||||||
|
try {
|
||||||
|
GroupMasterKey masterKey = new GroupMasterKey(Base64.decode(n.get("masterKey").asText()));
|
||||||
|
g = new GroupInfoV2(groupId, masterKey);
|
||||||
|
} catch (InvalidInputException e) {
|
||||||
|
throw new AssertionError("Invalid master key for group " + Base64.encodeBytes(groupId));
|
||||||
|
}
|
||||||
|
g.setBlocked(n.get("blocked").asBoolean(false));
|
||||||
|
} else {
|
||||||
|
g = jsonProcessor.treeToValue(n, GroupInfoV1.class);
|
||||||
}
|
}
|
||||||
groups.put(Base64.encodeBytes(g.groupId), g);
|
groups.put(Base64.encodeBytes(g.groupId), g);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -42,6 +41,15 @@ public class ProfileStore {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProfileKey getProfileKey(SignalServiceAddress serviceAddress) {
|
||||||
|
for (SignalProfileEntry entry : profiles) {
|
||||||
|
if (entry.getServiceAddress().matches(serviceAddress)) {
|
||||||
|
return entry.getProfileKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateProfile(SignalServiceAddress serviceAddress, ProfileKey profileKey, long now, SignalProfile profile) {
|
public void updateProfile(SignalServiceAddress serviceAddress, ProfileKey profileKey, long now, SignalProfile profile) {
|
||||||
SignalProfileEntry newEntry = new SignalProfileEntry(serviceAddress, profileKey, now, profile);
|
SignalProfileEntry newEntry = new SignalProfileEntry(serviceAddress, profileKey, now, profile);
|
||||||
for (int i = 0; i < profiles.size(); i++) {
|
for (int i = 0; i < profiles.size(); i++) {
|
||||||
|
@ -54,6 +62,20 @@ public class ProfileStore {
|
||||||
profiles.add(newEntry);
|
profiles.add(newEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void storeProfileKey(SignalServiceAddress serviceAddress, ProfileKey profileKey) {
|
||||||
|
SignalProfileEntry newEntry = new SignalProfileEntry(serviceAddress, profileKey, 0, null);
|
||||||
|
for (int i = 0; i < profiles.size(); i++) {
|
||||||
|
if (profiles.get(i).getServiceAddress().matches(serviceAddress)) {
|
||||||
|
if (!profiles.get(i).getProfileKey().equals(profileKey)) {
|
||||||
|
profiles.set(i, newEntry);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
profiles.add(newEntry);
|
||||||
|
}
|
||||||
|
|
||||||
public static class ProfileStoreDeserializer extends JsonDeserializer<List<SignalProfileEntry>> {
|
public static class ProfileStoreDeserializer extends JsonDeserializer<List<SignalProfileEntry>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.asamk.signal.storage.profiles;
|
package org.asamk.signal.storage.profiles;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||||
|
@ -23,7 +24,7 @@ public class SignalProfile {
|
||||||
private final boolean unrestrictedUnidentifiedAccess;
|
private final boolean unrestrictedUnidentifiedAccess;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private final SignalServiceProfile.Capabilities capabilities;
|
private final Capabilities capabilities;
|
||||||
|
|
||||||
public SignalProfile(final String identityKey, final String name, final File avatarFile, final String unidentifiedAccess, final boolean unrestrictedUnidentifiedAccess, final SignalServiceProfile.Capabilities capabilities) {
|
public SignalProfile(final String identityKey, final String name, final File avatarFile, final String unidentifiedAccess, final boolean unrestrictedUnidentifiedAccess, final SignalServiceProfile.Capabilities capabilities) {
|
||||||
this.identityKey = identityKey;
|
this.identityKey = identityKey;
|
||||||
|
@ -31,10 +32,13 @@ public class SignalProfile {
|
||||||
this.avatarFile = avatarFile;
|
this.avatarFile = avatarFile;
|
||||||
this.unidentifiedAccess = unidentifiedAccess;
|
this.unidentifiedAccess = unidentifiedAccess;
|
||||||
this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess;
|
this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess;
|
||||||
this.capabilities = capabilities;
|
this.capabilities = new Capabilities();
|
||||||
|
this.capabilities.storage = capabilities.isStorage();
|
||||||
|
this.capabilities.gv1Migration = capabilities.isGv1Migration();
|
||||||
|
this.capabilities.gv2 = capabilities.isGv2();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SignalProfile(@JsonProperty("identityKey") final String identityKey, @JsonProperty("name") final String name, @JsonProperty("unidentifiedAccess") final String unidentifiedAccess, @JsonProperty("unrestrictedUnidentifiedAccess") final boolean unrestrictedUnidentifiedAccess, @JsonProperty("capabilities") final SignalServiceProfile.Capabilities capabilities) {
|
public SignalProfile(@JsonProperty("identityKey") final String identityKey, @JsonProperty("name") final String name, @JsonProperty("unidentifiedAccess") final String unidentifiedAccess, @JsonProperty("unrestrictedUnidentifiedAccess") final boolean unrestrictedUnidentifiedAccess, @JsonProperty("capabilities") final Capabilities capabilities) {
|
||||||
this.identityKey = identityKey;
|
this.identityKey = identityKey;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.avatarFile = null;
|
this.avatarFile = null;
|
||||||
|
@ -63,7 +67,7 @@ public class SignalProfile {
|
||||||
return unrestrictedUnidentifiedAccess;
|
return unrestrictedUnidentifiedAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SignalServiceProfile.Capabilities getCapabilities() {
|
public Capabilities getCapabilities() {
|
||||||
return capabilities;
|
return capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,4 +82,19 @@ public class SignalProfile {
|
||||||
", capabilities=" + capabilities +
|
", capabilities=" + capabilities +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Capabilities {
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean uuid;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public boolean gv2;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public boolean storage;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public boolean gv1Migration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
35
src/main/java/org/asamk/signal/storage/stickers/Sticker.java
Normal file
35
src/main/java/org/asamk/signal/storage/stickers/Sticker.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package org.asamk.signal.storage.stickers;
|
||||||
|
|
||||||
|
public class Sticker {
|
||||||
|
|
||||||
|
private final byte[] packId;
|
||||||
|
private final byte[] packKey;
|
||||||
|
private boolean installed;
|
||||||
|
|
||||||
|
public Sticker(final byte[] packId, final byte[] packKey) {
|
||||||
|
this.packId = packId;
|
||||||
|
this.packKey = packKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sticker(final byte[] packId, final byte[] packKey, final boolean installed) {
|
||||||
|
this.packId = packId;
|
||||||
|
this.packKey = packKey;
|
||||||
|
this.installed = installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPackId() {
|
||||||
|
return packId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPackKey() {
|
||||||
|
return packKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInstalled() {
|
||||||
|
return installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstalled(final boolean installed) {
|
||||||
|
this.installed = installed;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.asamk.signal.storage.stickers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
|
||||||
|
import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StickerStore {
|
||||||
|
|
||||||
|
private static final ObjectMapper jsonProcessor = new ObjectMapper();
|
||||||
|
|
||||||
|
@JsonSerialize(using = StickersSerializer.class)
|
||||||
|
@JsonDeserialize(using = StickersDeserializer.class)
|
||||||
|
private final Map<byte[], Sticker> stickers = new HashMap<>();
|
||||||
|
|
||||||
|
public Sticker getSticker(byte[] packId) {
|
||||||
|
return stickers.get(packId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateSticker(Sticker sticker) {
|
||||||
|
stickers.put(sticker.getPackId(), sticker);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class StickersSerializer extends JsonSerializer<Map<byte[], Sticker>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(final Map<byte[], Sticker> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
|
||||||
|
final Collection<Sticker> stickers = value.values();
|
||||||
|
jgen.writeStartArray(stickers.size());
|
||||||
|
for (Sticker sticker : stickers) {
|
||||||
|
jgen.writeStartObject();
|
||||||
|
jgen.writeStringField("packId", Base64.encodeBytes(sticker.getPackId()));
|
||||||
|
jgen.writeStringField("packKey", Base64.encodeBytes(sticker.getPackKey()));
|
||||||
|
jgen.writeBooleanField("installed", sticker.isInstalled());
|
||||||
|
jgen.writeEndObject();
|
||||||
|
}
|
||||||
|
jgen.writeEndArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class StickersDeserializer extends JsonDeserializer<Map<byte[], Sticker>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<byte[], Sticker> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
||||||
|
Map<byte[], Sticker> stickers = new HashMap<>();
|
||||||
|
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
for (JsonNode n : node) {
|
||||||
|
byte[] packId = Base64.decode(n.get("packId").asText());
|
||||||
|
byte[] packKey = Base64.decode(n.get("packKey").asText());
|
||||||
|
boolean installed = n.get("installed").asBoolean(false);
|
||||||
|
stickers.put(packId, new Sticker(packId, packKey, installed));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stickers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,13 +2,12 @@ package org.asamk.signal.util;
|
||||||
|
|
||||||
import org.asamk.signal.manager.GroupNotFoundException;
|
import org.asamk.signal.manager.GroupNotFoundException;
|
||||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ErrorUtils {
|
public class ErrorUtils {
|
||||||
|
|
||||||
|
@ -21,17 +20,36 @@ public class ErrorUtils {
|
||||||
System.err.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README");
|
System.err.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleEncapsulatedExceptions(EncapsulatedExceptions e) {
|
public static int handleTimestampAndSendMessageResults(long timestamp, List<SendMessageResult> results) {
|
||||||
|
System.out.println(timestamp);
|
||||||
|
List<String> errors = getErrorMessagesFromSendMessageResults(results);
|
||||||
|
return handleSendMessageResultErrors(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getErrorMessagesFromSendMessageResults(List<SendMessageResult> results) {
|
||||||
|
List<String> errors = new ArrayList<>();
|
||||||
|
for (SendMessageResult result : results) {
|
||||||
|
if (result.isNetworkFailure()) {
|
||||||
|
errors.add(String.format("Network failure for \"%s\"", result.getAddress().getLegacyIdentifier()));
|
||||||
|
} else if (result.isUnregisteredFailure()) {
|
||||||
|
errors.add(String.format("Unregistered user \"%s\"", result.getAddress().getLegacyIdentifier()));
|
||||||
|
} else if (result.getIdentityFailure() != null) {
|
||||||
|
errors.add(String.format("Untrusted Identity for \"%s\"", result.getAddress().getLegacyIdentifier()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int handleSendMessageResultErrors(List<String> errors) {
|
||||||
|
if (errors.size() == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
System.err.println("Failed to send (some) messages:");
|
System.err.println("Failed to send (some) messages:");
|
||||||
for (NetworkFailureException n : e.getNetworkExceptions()) {
|
for (String error : errors) {
|
||||||
System.err.println("Network failure for \"" + n.getE164number() + "\": " + n.getMessage());
|
System.err.println(error);
|
||||||
}
|
|
||||||
for (UnregisteredUserException n : e.getUnregisteredUserExceptions()) {
|
|
||||||
System.err.println("Unregistered user \"" + n.getE164Number() + "\": " + n.getMessage());
|
|
||||||
}
|
|
||||||
for (UntrustedIdentityException n : e.getUntrustedIdentityExceptions()) {
|
|
||||||
System.err.println("Untrusted Identity for \"" + n.getIdentifier() + "\": " + n.getMessage());
|
|
||||||
}
|
}
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleIOException(IOException e) {
|
public static void handleIOException(IOException e) {
|
||||||
|
|
|
@ -48,6 +48,10 @@ public class IOUtils {
|
||||||
|
|
||||||
public static void createPrivateDirectories(String directoryPath) throws IOException {
|
public static void createPrivateDirectories(String directoryPath) throws IOException {
|
||||||
final File file = new File(directoryPath);
|
final File file = new File(directoryPath);
|
||||||
|
createPrivateDirectories(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createPrivateDirectories(File file) throws IOException {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue