mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Improve SignalServiceAddress handling
This commit is contained in:
parent
4ca3fe87f4
commit
6cfddc0aff
8 changed files with 101 additions and 60 deletions
|
@ -31,7 +31,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
conn.sendSignal(new Signal.ReceiptReceived(
|
conn.sendSignal(new Signal.ReceiptReceived(
|
||||||
objectPath,
|
objectPath,
|
||||||
envelope.getTimestamp(),
|
envelope.getTimestamp(),
|
||||||
envelope.getSourceE164().get()
|
!envelope.isUnidentifiedSender() && envelope.hasSource() ? envelope.getSourceE164().get() : content.getSender().getNumber().get()
|
||||||
));
|
));
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -55,7 +55,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
conn.sendSignal(new Signal.MessageReceived(
|
conn.sendSignal(new Signal.MessageReceived(
|
||||||
objectPath,
|
objectPath,
|
||||||
message.getTimestamp(),
|
message.getTimestamp(),
|
||||||
envelope.isUnidentifiedSender() ? content.getSender().getNumber().get() : envelope.getSourceE164().get(),
|
envelope.isUnidentifiedSender() || !envelope.hasSource() ? content.getSender().getNumber().get() : envelope.getSourceE164().get(),
|
||||||
message.getGroupInfo().isPresent() ? message.getGroupInfo().get().getGroupId() : new byte[0],
|
message.getGroupInfo().isPresent() ? message.getGroupInfo().get().getGroupId() : new byte[0],
|
||||||
message.getBody().isPresent() ? message.getBody().get() : "",
|
message.getBody().isPresent() ? message.getBody().get() : "",
|
||||||
attachments));
|
attachments));
|
||||||
|
|
|
@ -17,10 +17,12 @@ class JsonMessageEnvelope {
|
||||||
JsonReceiptMessage receiptMessage;
|
JsonReceiptMessage receiptMessage;
|
||||||
|
|
||||||
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content) {
|
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content) {
|
||||||
SignalServiceAddress source = envelope.getSourceAddress();
|
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
|
||||||
this.source = source.getNumber().get();
|
SignalServiceAddress source = envelope.getSourceAddress();
|
||||||
|
this.source = source.getNumber().get();
|
||||||
|
this.relay = source.getRelay().isPresent() ? source.getRelay().get() : null;
|
||||||
|
}
|
||||||
this.sourceDevice = envelope.getSourceDevice();
|
this.sourceDevice = envelope.getSourceDevice();
|
||||||
this.relay = source.getRelay().isPresent() ? source.getRelay().get() : null;
|
|
||||||
this.timestamp = envelope.getTimestamp();
|
this.timestamp = envelope.getTimestamp();
|
||||||
this.isReceipt = envelope.isReceipt();
|
this.isReceipt = envelope.isReceipt();
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
|
|
|
@ -42,11 +42,15 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
||||||
SignalServiceAddress source = envelope.getSourceAddress();
|
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
|
||||||
ContactInfo sourceContact = m.getContact(source.getNumber().get());
|
SignalServiceAddress source = envelope.getSourceAddress();
|
||||||
System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "“" + sourceContact.name + "” ") + source.getNumber(), envelope.getSourceDevice()));
|
ContactInfo sourceContact = m.getContact(source.getNumber().get());
|
||||||
if (source.getRelay().isPresent()) {
|
System.out.println(String.format("Envelope from: %s (device: %d)", (sourceContact == null ? "" : "“" + sourceContact.name + "” ") + source.getNumber().get(), envelope.getSourceDevice()));
|
||||||
System.out.println("Relayed by: " + source.getRelay().get());
|
if (source.getRelay().isPresent()) {
|
||||||
|
System.out.println("Relayed by: " + source.getRelay().get());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Envelope from: unknown source");
|
||||||
}
|
}
|
||||||
System.out.println("Timestamp: " + DateUtils.formatTimestamp(envelope.getTimestamp()));
|
System.out.println("Timestamp: " + DateUtils.formatTimestamp(envelope.getTimestamp()));
|
||||||
if (envelope.isUnidentifiedSender()) {
|
if (envelope.isUnidentifiedSender()) {
|
||||||
|
@ -69,7 +73,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
System.out.println("Failed to decrypt message.");
|
System.out.println("Failed to decrypt message.");
|
||||||
} else {
|
} else {
|
||||||
System.out.println(String.format("Sender: %s (device: %d)", content.getSender(), content.getSenderDevice()));
|
System.out.println(String.format("Sender: %s (device: %d)", content.getSender().getNumber().get(), content.getSenderDevice()));
|
||||||
if (content.getDataMessage().isPresent()) {
|
if (content.getDataMessage().isPresent()) {
|
||||||
SignalServiceDataMessage message = content.getDataMessage().get();
|
SignalServiceDataMessage message = content.getDataMessage().get();
|
||||||
handleSignalServiceDataMessage(message);
|
handleSignalServiceDataMessage(message);
|
||||||
|
|
|
@ -17,7 +17,11 @@
|
||||||
package org.asamk.signal.manager;
|
package org.asamk.signal.manager;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.*;
|
import org.asamk.signal.AttachmentInvalidException;
|
||||||
|
import org.asamk.signal.GroupNotFoundException;
|
||||||
|
import org.asamk.signal.NotAGroupMemberException;
|
||||||
|
import org.asamk.signal.TrustLevel;
|
||||||
|
import org.asamk.signal.UserAlreadyExists;
|
||||||
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;
|
||||||
|
@ -145,6 +149,14 @@ public class Manager implements Signal {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SignalServiceAddress getSelfAddress() {
|
||||||
|
return new SignalServiceAddress(null, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SignalServiceAccountManager getSignalServiceAccountManager() {
|
||||||
|
return new SignalServiceAccountManager(BaseConfig.serviceConfiguration, null, account.getUsername(), account.getPassword(), account.getDeviceId(), BaseConfig.USER_AGENT, timer);
|
||||||
|
}
|
||||||
|
|
||||||
private IdentityKey getIdentity() {
|
private IdentityKey getIdentity() {
|
||||||
return account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey();
|
return account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey();
|
||||||
}
|
}
|
||||||
|
@ -179,7 +191,7 @@ public class Manager implements Signal {
|
||||||
|
|
||||||
migrateLegacyConfigs();
|
migrateLegacyConfigs();
|
||||||
|
|
||||||
accountManager = new SignalServiceAccountManager(BaseConfig.serviceConfiguration, null, username, account.getPassword(), account.getDeviceId(), BaseConfig.USER_AGENT, timer);
|
accountManager = getSignalServiceAccountManager();
|
||||||
try {
|
try {
|
||||||
if (account.isRegistered() && accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
|
if (account.isRegistered() && accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
|
||||||
refreshPreKeys();
|
refreshPreKeys();
|
||||||
|
@ -238,7 +250,7 @@ public class Manager implements Signal {
|
||||||
createNewIdentity();
|
createNewIdentity();
|
||||||
}
|
}
|
||||||
account.setPassword(KeyUtils.createPassword());
|
account.setPassword(KeyUtils.createPassword());
|
||||||
accountManager = new SignalServiceAccountManager(BaseConfig.serviceConfiguration, null, account.getUsername(), account.getPassword(), BaseConfig.USER_AGENT, timer);
|
accountManager = getSignalServiceAccountManager();
|
||||||
|
|
||||||
if (voiceVerification) {
|
if (voiceVerification) {
|
||||||
accountManager.requestVoiceVerificationCode(Locale.getDefault(), Optional.<String>absent(), Optional.<String>absent());
|
accountManager.requestVoiceVerificationCode(Locale.getDefault(), Optional.<String>absent(), Optional.<String>absent());
|
||||||
|
@ -283,7 +295,7 @@ public class Manager implements Signal {
|
||||||
createNewIdentity();
|
createNewIdentity();
|
||||||
}
|
}
|
||||||
account.setPassword(KeyUtils.createPassword());
|
account.setPassword(KeyUtils.createPassword());
|
||||||
accountManager = new SignalServiceAccountManager(BaseConfig.serviceConfiguration, null, username, account.getPassword(), BaseConfig.USER_AGENT, timer);
|
accountManager = getSignalServiceAccountManager();
|
||||||
String uuid = accountManager.getNewDeviceUuid();
|
String uuid = accountManager.getNewDeviceUuid();
|
||||||
|
|
||||||
return Utils.createDeviceLinkUri(new Utils.DeviceLinkInfo(uuid, getIdentity().getPublicKey()));
|
return Utils.createDeviceLinkUri(new Utils.DeviceLinkInfo(uuid, getIdentity().getPublicKey()));
|
||||||
|
@ -414,6 +426,11 @@ public class Manager implements Signal {
|
||||||
return new SignalServiceMessageReceiver(BaseConfig.serviceConfiguration, null, username, account.getPassword(), account.getDeviceId(), account.getSignalingKey(), BaseConfig.USER_AGENT, null, timer);
|
return new SignalServiceMessageReceiver(BaseConfig.serviceConfiguration, null, username, account.getPassword(), account.getDeviceId(), account.getSignalingKey(), BaseConfig.USER_AGENT, null, timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SignalServiceMessageSender getMessageSender() {
|
||||||
|
return new SignalServiceMessageSender(BaseConfig.serviceConfiguration, null, username, account.getPassword(),
|
||||||
|
account.getDeviceId(), account.getSignalProtocolStore(), BaseConfig.USER_AGENT, account.isMultiDevice(), Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.<SignalServiceMessageSender.EventListener>absent());
|
||||||
|
}
|
||||||
|
|
||||||
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
|
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
|
||||||
File file = getGroupAvatarFile(groupId);
|
File file = getGroupAvatarFile(groupId);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
@ -569,15 +586,10 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) {
|
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) {
|
||||||
ArrayList<SignalServiceAddress> members = new ArrayList<>(g.members.size());
|
|
||||||
for (String member : g.members) {
|
|
||||||
members.add(new SignalServiceAddress(null, member));
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
.withMembers(members);
|
.withMembers(new ArrayList<>(g.getMembers()));
|
||||||
|
|
||||||
File aFile = getGroupAvatarFile(g.groupId);
|
File aFile = getGroupAvatarFile(g.groupId);
|
||||||
if (aFile.exists()) {
|
if (aFile.exists()) {
|
||||||
|
@ -802,8 +814,7 @@ public class Manager implements Signal {
|
||||||
|
|
||||||
private void sendSyncMessage(SignalServiceSyncMessage message)
|
private void sendSyncMessage(SignalServiceSyncMessage message)
|
||||||
throws IOException, UntrustedIdentityException {
|
throws IOException, UntrustedIdentityException {
|
||||||
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(BaseConfig.serviceConfiguration, null, username, account.getPassword(),
|
SignalServiceMessageSender messageSender = getMessageSender();
|
||||||
account.getDeviceId(), account.getSignalProtocolStore(), BaseConfig.USER_AGENT, account.isMultiDevice(), Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.<SignalServiceMessageSender.EventListener>absent());
|
|
||||||
try {
|
try {
|
||||||
messageSender.sendMessage(message, getAccessForSync());
|
messageSender.sendMessage(message, getAccessForSync());
|
||||||
} catch (UntrustedIdentityException e) {
|
} catch (UntrustedIdentityException e) {
|
||||||
|
@ -847,8 +858,7 @@ public class Manager implements Signal {
|
||||||
|
|
||||||
SignalServiceDataMessage message = null;
|
SignalServiceDataMessage message = null;
|
||||||
try {
|
try {
|
||||||
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(BaseConfig.serviceConfiguration, null, username, account.getPassword(),
|
SignalServiceMessageSender messageSender = getMessageSender();
|
||||||
account.getDeviceId(), account.getSignalProtocolStore(), BaseConfig.USER_AGENT, account.isMultiDevice(), Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.<SignalServiceMessageSender.EventListener>absent());
|
|
||||||
|
|
||||||
message = messageBuilder.build();
|
message = messageBuilder.build();
|
||||||
if (message.getGroupInfo().isPresent()) {
|
if (message.getGroupInfo().isPresent()) {
|
||||||
|
@ -865,14 +875,14 @@ public class Manager implements Signal {
|
||||||
account.getSignalProtocolStore().saveIdentity(e.getIdentifier(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
account.getSignalProtocolStore().saveIdentity(e.getIdentifier(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
} else if (recipientsTS.size() == 1 && recipientsTS.contains(new SignalServiceAddress(null, username))) {
|
} else if (recipientsTS.size() == 1 && recipientsTS.contains(getSelfAddress())) {
|
||||||
SignalServiceAddress recipient = new SignalServiceAddress(null, username);
|
SignalServiceAddress recipient = getSelfAddress();
|
||||||
final Optional<UnidentifiedAccessPair> unidentifiedAccess = getAccessFor(recipient);
|
final Optional<UnidentifiedAccessPair> unidentifiedAccess = getAccessFor(recipient);
|
||||||
SentTranscriptMessage transcript = new SentTranscriptMessage(Optional.of(new SignalServiceAddress(null, recipient.getNumber().get())),
|
SentTranscriptMessage transcript = new SentTranscriptMessage(Optional.of(recipient),
|
||||||
message.getTimestamp(),
|
message.getTimestamp(),
|
||||||
message,
|
message,
|
||||||
message.getExpiresInSeconds(),
|
message.getExpiresInSeconds(),
|
||||||
Collections.singletonMap(new SignalServiceAddress(null, recipient.getNumber()), unidentifiedAccess.isPresent()),
|
Collections.singletonMap(recipient, unidentifiedAccess.isPresent()),
|
||||||
false);
|
false);
|
||||||
SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);
|
SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);
|
||||||
|
|
||||||
|
@ -916,7 +926,7 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, ProtocolInvalidMessageException, ProtocolDuplicateMessageException, ProtocolLegacyMessageException, ProtocolInvalidKeyIdException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolNoSessionException, ProtocolInvalidKeyException, ProtocolUntrustedIdentityException, SelfSendException, UnsupportedDataMessageException {
|
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, ProtocolInvalidMessageException, ProtocolDuplicateMessageException, ProtocolLegacyMessageException, ProtocolInvalidKeyIdException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolNoSessionException, ProtocolInvalidKeyException, ProtocolUntrustedIdentityException, SelfSendException, UnsupportedDataMessageException {
|
||||||
SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(null, username), account.getSignalProtocolStore(), Utils.getCertificateValidator());
|
SignalServiceCipher cipher = new SignalServiceCipher(getSelfAddress(), account.getSignalProtocolStore(), Utils.getCertificateValidator());
|
||||||
try {
|
try {
|
||||||
return cipher.decrypt(envelope);
|
return cipher.decrypt(envelope);
|
||||||
} catch (ProtocolUntrustedIdentityException e) {
|
} catch (ProtocolUntrustedIdentityException e) {
|
||||||
|
@ -930,7 +940,7 @@ public class Manager implements Signal {
|
||||||
account.getSignalProtocolStore().deleteAllSessions(source);
|
account.getSignalProtocolStore().deleteAllSessions(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSignalServiceDataMessage(SignalServiceDataMessage message, boolean isSync, String source, String destination, boolean ignoreAttachments) {
|
private void handleSignalServiceDataMessage(SignalServiceDataMessage message, boolean isSync, String source, SignalServiceAddress destination, boolean ignoreAttachments) {
|
||||||
String threadId;
|
String threadId;
|
||||||
if (message.getGroupInfo().isPresent()) {
|
if (message.getGroupInfo().isPresent()) {
|
||||||
SignalServiceGroup groupInfo = message.getGroupInfo().get();
|
SignalServiceGroup groupInfo = message.getGroupInfo().get();
|
||||||
|
@ -958,11 +968,7 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (groupInfo.getMembers().isPresent()) {
|
if (groupInfo.getMembers().isPresent()) {
|
||||||
List<String> members = new ArrayList<>(groupInfo.getMembers().get().size());
|
group.addMembers(groupInfo.getMembers().get());
|
||||||
for (SignalServiceAddress address : groupInfo.getMembers().get()) {
|
|
||||||
members.add(address.getNumber().get());
|
|
||||||
}
|
|
||||||
group.members.addAll(members);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
account.getGroupStore().updateGroup(group);
|
account.getGroupStore().updateGroup(group);
|
||||||
|
@ -1002,13 +1008,13 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isSync) {
|
if (isSync) {
|
||||||
threadId = destination;
|
threadId = destination.getNumber().get();
|
||||||
} else {
|
} else {
|
||||||
threadId = source;
|
threadId = source;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (message.isEndSession()) {
|
if (message.isEndSession()) {
|
||||||
handleEndSession(isSync ? destination : source);
|
handleEndSession(isSync ? destination.getNumber().get() : source);
|
||||||
}
|
}
|
||||||
if (message.isExpirationUpdate() || message.getBody().isPresent()) {
|
if (message.isExpirationUpdate() || message.getBody().isPresent()) {
|
||||||
ThreadInfo thread = account.getThreadStore().getThread(threadId);
|
ThreadInfo thread = account.getThreadStore().getThread(threadId);
|
||||||
|
@ -1158,16 +1164,22 @@ public class Manager implements Signal {
|
||||||
|
|
||||||
private void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, boolean ignoreAttachments) {
|
private void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, boolean ignoreAttachments) {
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
|
SignalServiceAddress sender;
|
||||||
|
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
|
||||||
|
sender = envelope.getSourceAddress();
|
||||||
|
} else {
|
||||||
|
sender = content.getSender();
|
||||||
|
}
|
||||||
if (content.getDataMessage().isPresent()) {
|
if (content.getDataMessage().isPresent()) {
|
||||||
SignalServiceDataMessage message = content.getDataMessage().get();
|
SignalServiceDataMessage message = content.getDataMessage().get();
|
||||||
handleSignalServiceDataMessage(message, false, envelope.getSourceE164().get(), username, ignoreAttachments);
|
handleSignalServiceDataMessage(message, false, sender.getNumber().get(), getSelfAddress(), ignoreAttachments);
|
||||||
}
|
}
|
||||||
if (content.getSyncMessage().isPresent()) {
|
if (content.getSyncMessage().isPresent()) {
|
||||||
account.setMultiDevice(true);
|
account.setMultiDevice(true);
|
||||||
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
|
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
|
||||||
if (syncMessage.getSent().isPresent()) {
|
if (syncMessage.getSent().isPresent()) {
|
||||||
SignalServiceDataMessage message = syncMessage.getSent().get().getMessage();
|
SentTranscriptMessage message = syncMessage.getSent().get();
|
||||||
handleSignalServiceDataMessage(message, true, envelope.getSourceE164().get(), syncMessage.getSent().get().getDestination().get().getNumber().get(), ignoreAttachments);
|
handleSignalServiceDataMessage(message.getMessage(), true, sender.getNumber().get(), message.getDestination().orNull(), ignoreAttachments);
|
||||||
}
|
}
|
||||||
if (syncMessage.getRequest().isPresent()) {
|
if (syncMessage.getRequest().isPresent()) {
|
||||||
RequestMessage rm = syncMessage.getRequest().get();
|
RequestMessage rm = syncMessage.getRequest().get();
|
||||||
|
@ -1202,11 +1214,7 @@ public class Manager implements Signal {
|
||||||
if (g.getName().isPresent()) {
|
if (g.getName().isPresent()) {
|
||||||
syncGroup.name = g.getName().get();
|
syncGroup.name = g.getName().get();
|
||||||
}
|
}
|
||||||
List<String> members = new ArrayList<>(g.getMembers().size());
|
syncGroup.addMembers(g.getMembers());
|
||||||
for (SignalServiceAddress member : g.getMembers()) {
|
|
||||||
members.add(member.getNumber().get());
|
|
||||||
}
|
|
||||||
syncGroup.members.addAll(members);
|
|
||||||
syncGroup.active = g.isActive();
|
syncGroup.active = g.isActive();
|
||||||
if (g.getColor().isPresent()) {
|
if (g.getColor().isPresent()) {
|
||||||
syncGroup.color = g.getColor().get();
|
syncGroup.color = g.getColor().get();
|
||||||
|
@ -1245,7 +1253,7 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
DeviceContact c;
|
DeviceContact c;
|
||||||
while ((c = s.read()) != null) {
|
while ((c = s.read()) != null) {
|
||||||
if (c.getAddress().getNumber().get().equals(account.getUsername()) && c.getProfileKey().isPresent()) {
|
if (c.getAddress().matches(account.getSelfAddress()) && c.getProfileKey().isPresent()) {
|
||||||
account.setProfileKey(c.getProfileKey().get());
|
account.setProfileKey(c.getProfileKey().get());
|
||||||
}
|
}
|
||||||
ContactInfo contact = account.getContactStore().getContact(c.getAddress().getNumber().get());
|
ContactInfo contact = account.getContactStore().getContact(c.getAddress().getNumber().get());
|
||||||
|
@ -1402,12 +1410,8 @@ public class Manager implements Signal {
|
||||||
DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(fos);
|
DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(fos);
|
||||||
for (GroupInfo record : account.getGroupStore().getGroups()) {
|
for (GroupInfo record : account.getGroupStore().getGroups()) {
|
||||||
ThreadInfo info = account.getThreadStore().getThread(Base64.encodeBytes(record.groupId));
|
ThreadInfo info = account.getThreadStore().getThread(Base64.encodeBytes(record.groupId));
|
||||||
List<SignalServiceAddress> members = new ArrayList<>(record.members.size());
|
|
||||||
for (String member : record.members) {
|
|
||||||
members.add(new SignalServiceAddress(null, member));
|
|
||||||
}
|
|
||||||
out.write(new DeviceGroup(record.groupId, Optional.fromNullable(record.name),
|
out.write(new DeviceGroup(record.groupId, Optional.fromNullable(record.name),
|
||||||
members, createGroupAvatarAttachment(record.groupId),
|
new ArrayList<>(record.getMembers()), createGroupAvatarAttachment(record.groupId),
|
||||||
record.active, Optional.fromNullable(info != null ? info.messageExpirationTime : null),
|
record.active, Optional.fromNullable(info != null ? info.messageExpirationTime : null),
|
||||||
Optional.fromNullable(record.color), false));
|
Optional.fromNullable(record.color), false));
|
||||||
}
|
}
|
||||||
|
@ -1450,21 +1454,21 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentIdentity != null) {
|
if (currentIdentity != null) {
|
||||||
verifiedMessage = new VerifiedMessage(new SignalServiceAddress(null, record.number), currentIdentity.getIdentityKey(), currentIdentity.getTrustLevel().toVerifiedState(), currentIdentity.getDateAdded().getTime());
|
verifiedMessage = new VerifiedMessage(record.getAddress(), currentIdentity.getIdentityKey(), currentIdentity.getTrustLevel().toVerifiedState(), currentIdentity.getDateAdded().getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] profileKey = record.profileKey == null ? null : Base64.decode(record.profileKey);
|
byte[] profileKey = record.profileKey == null ? null : Base64.decode(record.profileKey);
|
||||||
// TODO store list of blocked numbers
|
// TODO store list of blocked numbers
|
||||||
boolean blocked = false;
|
boolean blocked = false;
|
||||||
out.write(new DeviceContact(new SignalServiceAddress(null, record.number), 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), blocked, Optional.fromNullable(info != null ? info.messageExpirationTime : null)));
|
Optional.fromNullable(verifiedMessage), Optional.fromNullable(profileKey), blocked, Optional.fromNullable(info != null ? info.messageExpirationTime : null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account.getProfileKey() != null) {
|
if (account.getProfileKey() != null) {
|
||||||
// Send our own profile key as well
|
// Send our own profile key as well
|
||||||
out.write(new DeviceContact(new SignalServiceAddress(null, account.getUsername()),
|
out.write(new DeviceContact(account.getSelfAddress(),
|
||||||
Optional.<String>absent(), Optional.<SignalServiceAttachmentStream>absent(),
|
Optional.<String>absent(), Optional.<SignalServiceAttachmentStream>absent(),
|
||||||
Optional.<String>absent(), Optional.<VerifiedMessage>absent(),
|
Optional.<String>absent(), Optional.<VerifiedMessage>absent(),
|
||||||
Optional.of(account.getProfileKey()),
|
Optional.of(account.getProfileKey()),
|
||||||
|
@ -1492,8 +1496,8 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendVerifiedMessage(String destination, IdentityKey identityKey, TrustLevel trustLevel) throws IOException, UntrustedIdentityException {
|
private void sendVerifiedMessage(SignalServiceAddress destination, IdentityKey identityKey, TrustLevel trustLevel) throws IOException, UntrustedIdentityException {
|
||||||
VerifiedMessage verifiedMessage = new VerifiedMessage(new SignalServiceAddress(null, destination), identityKey, trustLevel.toVerifiedState(), System.currentTimeMillis());
|
VerifiedMessage verifiedMessage = new VerifiedMessage(destination, identityKey, trustLevel.toVerifiedState(), System.currentTimeMillis());
|
||||||
sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
|
sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1535,7 +1539,7 @@ public class Manager implements Signal {
|
||||||
|
|
||||||
account.getSignalProtocolStore().saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
account.getSignalProtocolStore().saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
||||||
try {
|
try {
|
||||||
sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
sendVerifiedMessage(new SignalServiceAddress(null, name), id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
||||||
} catch (IOException | UntrustedIdentityException e) {
|
} catch (IOException | UntrustedIdentityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1563,7 +1567,7 @@ public class Manager implements Signal {
|
||||||
|
|
||||||
account.getSignalProtocolStore().saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
account.getSignalProtocolStore().saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
||||||
try {
|
try {
|
||||||
sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
sendVerifiedMessage(new SignalServiceAddress(null, name), id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
|
||||||
} catch (IOException | UntrustedIdentityException e) {
|
} catch (IOException | UntrustedIdentityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1587,7 +1591,7 @@ public class Manager implements Signal {
|
||||||
if (id.getTrustLevel() == TrustLevel.UNTRUSTED) {
|
if (id.getTrustLevel() == TrustLevel.UNTRUSTED) {
|
||||||
account.getSignalProtocolStore().saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED);
|
account.getSignalProtocolStore().saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED);
|
||||||
try {
|
try {
|
||||||
sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED);
|
sendVerifiedMessage(new SignalServiceAddress(null, name), id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED);
|
||||||
} catch (IOException | UntrustedIdentityException e) {
|
} catch (IOException | UntrustedIdentityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,6 +257,8 @@ class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String computeSafetyNumber(String ownUsername, IdentityKey ownIdentityKey, String theirUsername, IdentityKey theirIdentityKey) {
|
static String computeSafetyNumber(String ownUsername, IdentityKey ownIdentityKey, String theirUsername, IdentityKey theirIdentityKey) {
|
||||||
|
// Version 1: E164 user
|
||||||
|
// Version 2: UUID user
|
||||||
Fingerprint fingerprint = new NumericFingerprintGenerator(5200).createFor(1, ownUsername.getBytes(), ownIdentityKey, theirUsername.getBytes(), theirIdentityKey);
|
Fingerprint fingerprint = new NumericFingerprintGenerator(5200).createFor(1, ownUsername.getBytes(), ownIdentityKey, theirUsername.getBytes(), theirIdentityKey);
|
||||||
return fingerprint.getDisplayableFingerprint().getDisplayText();
|
return fingerprint.getDisplayableFingerprint().getDisplayText();
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,6 +271,10 @@ public class SignalAccount {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SignalServiceAddress getSelfAddress() {
|
||||||
|
return new SignalServiceAddress(null, username);
|
||||||
|
}
|
||||||
|
|
||||||
public int getDeviceId() {
|
public int getDeviceId() {
|
||||||
return deviceId;
|
return deviceId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package org.asamk.signal.storage.contacts;
|
package org.asamk.signal.storage.contacts;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
public class ContactInfo {
|
public class ContactInfo {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
@ -15,4 +18,9 @@ public class ContactInfo {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
public String profileKey;
|
public String profileKey;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public SignalServiceAddress getAddress() {
|
||||||
|
return new SignalServiceAddress(null, number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ 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 org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -40,4 +42,19 @@ public class GroupInfo {
|
||||||
public long getAvatarId() {
|
public long getAvatarId() {
|
||||||
return avatarId;
|
return avatarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public Set<SignalServiceAddress> getMembers() {
|
||||||
|
Set<SignalServiceAddress> addresses = new HashSet<>(members.size());
|
||||||
|
for (String member : members) {
|
||||||
|
addresses.add(new SignalServiceAddress(null, member));
|
||||||
|
}
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMembers(Collection<SignalServiceAddress> members) {
|
||||||
|
for (SignalServiceAddress member : members) {
|
||||||
|
this.members.add(member.getNumber().get());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue