mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Update signal-service-java dependency
This commit is contained in:
parent
69185a937f
commit
4ab904b88e
8 changed files with 275 additions and 82 deletions
|
@ -20,8 +20,8 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.turasa:signal-service-java:2.9.0_unofficial_1'
|
compile 'com.github.turasa:signal-service-java:2.12.2_unofficial_1'
|
||||||
compile 'org.bouncycastle:bcprov-jdk15on:1.59'
|
compile 'org.bouncycastle:bcprov-jdk15on:1.60'
|
||||||
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
||||||
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class Main {
|
||||||
busType = DBusConnection.SESSION;
|
busType = DBusConnection.SESSION;
|
||||||
}
|
}
|
||||||
dBusConn = DBusConnection.getConnection(busType);
|
dBusConn = DBusConnection.getConnection(busType);
|
||||||
ts = (Signal) dBusConn.getRemoteObject(
|
ts = dBusConn.getRemoteObject(
|
||||||
SIGNAL_BUSNAME, SIGNAL_OBJECTPATH,
|
SIGNAL_BUSNAME, SIGNAL_OBJECTPATH,
|
||||||
Signal.class);
|
Signal.class);
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
@ -984,6 +984,9 @@ public class Main {
|
||||||
System.out.println("Relayed by: " + source.getRelay().get());
|
System.out.println("Relayed by: " + source.getRelay().get());
|
||||||
}
|
}
|
||||||
System.out.println("Timestamp: " + formatTimestamp(envelope.getTimestamp()));
|
System.out.println("Timestamp: " + formatTimestamp(envelope.getTimestamp()));
|
||||||
|
if (envelope.isUnidentifiedSender()) {
|
||||||
|
System.out.println("Sent by unidentified/sealed sender");
|
||||||
|
}
|
||||||
|
|
||||||
if (envelope.isReceipt()) {
|
if (envelope.isReceipt()) {
|
||||||
System.out.println("Got receipt.");
|
System.out.println("Got receipt.");
|
||||||
|
@ -1120,6 +1123,20 @@ public class Main {
|
||||||
System.out.println(" " + formatTimestamp(timestamp));
|
System.out.println(" " + formatTimestamp(timestamp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (content.getTypingMessage().isPresent()) {
|
||||||
|
System.out.println("Received a typing message");
|
||||||
|
SignalServiceTypingMessage typingMessage = content.getTypingMessage().get();
|
||||||
|
System.out.println(" - Action: " + typingMessage.getAction());
|
||||||
|
System.out.println(" - Timestamp: " + formatTimestamp(typingMessage.getTimestamp()));
|
||||||
|
if (typingMessage.getGroupId().isPresent()) {
|
||||||
|
GroupInfo group = m.getGroup(typingMessage.getGroupId().get());
|
||||||
|
if (group != null) {
|
||||||
|
System.out.println(" Name: " + group.name);
|
||||||
|
} else {
|
||||||
|
System.out.println(" Name: <Unknown group>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Unknown message received.");
|
System.out.println("Unknown message received.");
|
||||||
|
@ -1167,7 +1184,7 @@ public class Main {
|
||||||
if (message.getExpiresInSeconds() > 0) {
|
if (message.getExpiresInSeconds() > 0) {
|
||||||
System.out.println("Expires in: " + message.getExpiresInSeconds() + " seconds");
|
System.out.println("Expires in: " + message.getExpiresInSeconds() + " seconds");
|
||||||
}
|
}
|
||||||
if (message.isProfileKeyUpdate() && message.getProfileKey().isPresent()) {
|
if (message.getProfileKey().isPresent()) {
|
||||||
System.out.println("Profile key update, key length:" + message.getProfileKey().get().length);
|
System.out.println("Profile key update, key length:" + message.getProfileKey().get().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1201,7 +1218,7 @@ public class Main {
|
||||||
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
|
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
|
||||||
if (attachment.isPointer()) {
|
if (attachment.isPointer()) {
|
||||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||||
System.out.println(" Id: " + pointer.getId() + " Key length: " + pointer.getKey().length + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : ""));
|
System.out.println(" Id: " + pointer.getId() + " Key length: " + pointer.getKey().length);
|
||||||
System.out.println(" Filename: " + (pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-"));
|
System.out.println(" Filename: " + (pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-"));
|
||||||
System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
|
System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
|
||||||
System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no"));
|
System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no"));
|
||||||
|
|
|
@ -35,7 +35,10 @@ import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
|
||||||
import org.asamk.signal.storage.protocol.JsonSignalProtocolStore;
|
import org.asamk.signal.storage.protocol.JsonSignalProtocolStore;
|
||||||
import org.asamk.signal.storage.threads.JsonThreadStore;
|
import org.asamk.signal.storage.threads.JsonThreadStore;
|
||||||
import org.asamk.signal.storage.threads.ThreadInfo;
|
import org.asamk.signal.storage.threads.ThreadInfo;
|
||||||
|
import org.asamk.signal.util.KeyUtils;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
|
import org.signal.libsignal.metadata.*;
|
||||||
|
import org.signal.libsignal.metadata.certificate.CertificateValidator;
|
||||||
import org.whispersystems.libsignal.*;
|
import org.whispersystems.libsignal.*;
|
||||||
import org.whispersystems.libsignal.ecc.Curve;
|
import org.whispersystems.libsignal.ecc.Curve;
|
||||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||||
|
@ -52,13 +55,18 @@ import org.whispersystems.signalservice.api.SignalServiceMessagePipe;
|
||||||
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
||||||
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
||||||
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
|
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
|
||||||
|
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||||
|
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.messages.*;
|
import org.whispersystems.signalservice.api.messages.*;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.*;
|
import org.whispersystems.signalservice.api.messages.multidevice.*;
|
||||||
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.TrustStore;
|
import org.whispersystems.signalservice.api.push.TrustStore;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.*;
|
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
|
||||||
|
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 org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
||||||
import org.whispersystems.signalservice.api.util.SleepTimer;
|
import org.whispersystems.signalservice.api.util.SleepTimer;
|
||||||
|
@ -99,6 +107,7 @@ class Manager implements Signal {
|
||||||
new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)},
|
new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)},
|
||||||
new SignalContactDiscoveryUrl[0]
|
new SignalContactDiscoveryUrl[0]
|
||||||
);
|
);
|
||||||
|
private final static String UNIDENTIFIED_SENDER_TRUST_ROOT = "BXu6QIKVz5MA8gstzfOgRQGqyLqOwNKHL6INkv3IHWMF";
|
||||||
|
|
||||||
public final static String PROJECT_NAME = Manager.class.getPackage().getImplementationTitle();
|
public final static String PROJECT_NAME = Manager.class.getPackage().getImplementationTitle();
|
||||||
public final static String PROJECT_VERSION = Manager.class.getPackage().getImplementationVersion();
|
public final static String PROJECT_VERSION = Manager.class.getPackage().getImplementationVersion();
|
||||||
|
@ -119,9 +128,11 @@ class Manager implements Signal {
|
||||||
private final ObjectMapper jsonProcessor = new ObjectMapper();
|
private final ObjectMapper jsonProcessor = new ObjectMapper();
|
||||||
private String username;
|
private String username;
|
||||||
private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
||||||
|
private boolean isMultiDevice = false;
|
||||||
private String password;
|
private String password;
|
||||||
private String registrationLockPin;
|
private String registrationLockPin;
|
||||||
private String signalingKey;
|
private String signalingKey;
|
||||||
|
private byte[] profileKey;
|
||||||
private int preKeyIdOffset;
|
private int preKeyIdOffset;
|
||||||
private int nextSignedPreKeyId;
|
private int nextSignedPreKeyId;
|
||||||
|
|
||||||
|
@ -133,6 +144,7 @@ class Manager implements Signal {
|
||||||
private JsonContactsStore contactStore;
|
private JsonContactsStore contactStore;
|
||||||
private JsonThreadStore threadStore;
|
private JsonThreadStore threadStore;
|
||||||
private SignalServiceMessagePipe messagePipe = null;
|
private SignalServiceMessagePipe messagePipe = null;
|
||||||
|
private SignalServiceMessagePipe unidentifiedMessagePipe = null;
|
||||||
|
|
||||||
private SleepTimer timer = new UptimeSleepTimer();
|
private SleepTimer timer = new UptimeSleepTimer();
|
||||||
|
|
||||||
|
@ -280,6 +292,13 @@ class Manager implements Signal {
|
||||||
} else {
|
} else {
|
||||||
nextSignedPreKeyId = 0;
|
nextSignedPreKeyId = 0;
|
||||||
}
|
}
|
||||||
|
if (rootNode.has("profileKey")) {
|
||||||
|
profileKey = Base64.decode(getNotNullNode(rootNode, "profileKey").asText());
|
||||||
|
} else {
|
||||||
|
// Old config file, creating new profile key
|
||||||
|
profileKey = KeyUtils.createProfileKey();
|
||||||
|
}
|
||||||
|
|
||||||
signalProtocolStore = jsonProcessor.convertValue(getNotNullNode(rootNode, "axolotlStore"), JsonSignalProtocolStore.class);
|
signalProtocolStore = jsonProcessor.convertValue(getNotNullNode(rootNode, "axolotlStore"), JsonSignalProtocolStore.class);
|
||||||
registered = getNotNullNode(rootNode, "registered").asBoolean();
|
registered = getNotNullNode(rootNode, "registered").asBoolean();
|
||||||
JsonNode groupStoreNode = rootNode.get("groupStore");
|
JsonNode groupStoreNode = rootNode.get("groupStore");
|
||||||
|
@ -370,7 +389,7 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(boolean voiceVerification) throws IOException {
|
public void register(boolean voiceVerification) throws IOException {
|
||||||
password = Util.getSecret(18);
|
password = KeyUtils.createPassword();
|
||||||
|
|
||||||
accountManager = new SignalServiceAccountManager(serviceConfiguration, username, password, USER_AGENT, timer);
|
accountManager = new SignalServiceAccountManager(serviceConfiguration, username, password, USER_AGENT, timer);
|
||||||
|
|
||||||
|
@ -384,7 +403,7 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAccountAttributes() throws IOException {
|
public void updateAccountAttributes() throws IOException {
|
||||||
accountManager.setAccountAttributes(signalingKey, signalProtocolStore.getLocalRegistrationId(), true, registrationLockPin);
|
accountManager.setAccountAttributes(signalingKey, signalProtocolStore.getLocalRegistrationId(), true, registrationLockPin, getSelfUnidentifiedAccessKey(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister() throws IOException {
|
public void unregister() throws IOException {
|
||||||
|
@ -395,7 +414,7 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getDeviceLinkUri() throws TimeoutException, IOException {
|
public URI getDeviceLinkUri() throws TimeoutException, IOException {
|
||||||
password = Util.getSecret(18);
|
password = KeyUtils.createPassword();
|
||||||
|
|
||||||
accountManager = new SignalServiceAccountManager(serviceConfiguration, username, password, USER_AGENT, timer);
|
accountManager = new SignalServiceAccountManager(serviceConfiguration, username, password, USER_AGENT, timer);
|
||||||
String uuid = accountManager.getNewDeviceUuid();
|
String uuid = accountManager.getNewDeviceUuid();
|
||||||
|
@ -410,7 +429,7 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
|
public void finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
|
||||||
signalingKey = Util.getSecret(52);
|
signalingKey = KeyUtils.createSignalingKey();
|
||||||
SignalServiceAccountManager.NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(signalProtocolStore.getIdentityKeyPair(), signalingKey, false, true, signalProtocolStore.getLocalRegistrationId(), deviceName);
|
SignalServiceAccountManager.NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(signalProtocolStore.getIdentityKeyPair(), signalingKey, false, true, signalProtocolStore.getLocalRegistrationId(), deviceName);
|
||||||
deviceId = ret.getDeviceId();
|
deviceId = ret.getDeviceId();
|
||||||
username = ret.getNumber();
|
username = ret.getNumber();
|
||||||
|
@ -421,6 +440,7 @@ class Manager implements Signal {
|
||||||
signalProtocolStore = new JsonSignalProtocolStore(ret.getIdentity(), signalProtocolStore.getLocalRegistrationId());
|
signalProtocolStore = new JsonSignalProtocolStore(ret.getIdentity(), signalProtocolStore.getLocalRegistrationId());
|
||||||
|
|
||||||
registered = true;
|
registered = true;
|
||||||
|
isMultiDevice = true;
|
||||||
refreshPreKeys();
|
refreshPreKeys();
|
||||||
|
|
||||||
requestSyncGroups();
|
requestSyncGroups();
|
||||||
|
@ -430,7 +450,9 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DeviceInfo> getLinkedDevices() throws IOException {
|
public List<DeviceInfo> getLinkedDevices() throws IOException {
|
||||||
return accountManager.getDevices();
|
List<DeviceInfo> devices = accountManager.getDevices();
|
||||||
|
isMultiDevice = devices.size() > 1;
|
||||||
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeLinkedDevices(int deviceId) throws IOException {
|
public void removeLinkedDevices(int deviceId) throws IOException {
|
||||||
|
@ -442,14 +464,15 @@ class Manager implements Signal {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
for (String param : params) {
|
for (String param : params) {
|
||||||
String name = null;
|
String name = null;
|
||||||
|
final String[] paramParts = param.split("=");
|
||||||
try {
|
try {
|
||||||
name = URLDecoder.decode(param.split("=")[0], "utf-8");
|
name = URLDecoder.decode(paramParts[0], "utf-8");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
// Impossible
|
// Impossible
|
||||||
}
|
}
|
||||||
String value = null;
|
String value = null;
|
||||||
try {
|
try {
|
||||||
value = URLDecoder.decode(param.split("=")[1], "utf-8");
|
value = URLDecoder.decode(paramParts[1], "utf-8");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
// Impossible
|
// Impossible
|
||||||
}
|
}
|
||||||
|
@ -476,8 +499,8 @@ class Manager implements Signal {
|
||||||
IdentityKeyPair identityKeyPair = signalProtocolStore.getIdentityKeyPair();
|
IdentityKeyPair identityKeyPair = signalProtocolStore.getIdentityKeyPair();
|
||||||
String verificationCode = accountManager.getNewDeviceVerificationCode();
|
String verificationCode = accountManager.getNewDeviceVerificationCode();
|
||||||
|
|
||||||
// TODO send profile key
|
accountManager.addDevice(deviceIdentifier, deviceKey, identityKeyPair, Optional.of(profileKey), verificationCode);
|
||||||
accountManager.addDevice(deviceIdentifier, deviceKey, identityKeyPair, Optional.<byte[]>absent(), verificationCode);
|
isMultiDevice = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PreKeyRecord> generatePreKeys() {
|
private List<PreKeyRecord> generatePreKeys() {
|
||||||
|
@ -516,8 +539,8 @@ class Manager implements Signal {
|
||||||
|
|
||||||
public void verifyAccount(String verificationCode, String pin) throws IOException {
|
public void verifyAccount(String verificationCode, String pin) throws IOException {
|
||||||
verificationCode = verificationCode.replace("-", "");
|
verificationCode = verificationCode.replace("-", "");
|
||||||
signalingKey = Util.getSecret(52);
|
signalingKey = KeyUtils.createSignalingKey();
|
||||||
accountManager.verifyAccountWithCode(verificationCode, signalingKey, signalProtocolStore.getLocalRegistrationId(), true, pin);
|
accountManager.verifyAccountWithCode(verificationCode, signalingKey, signalProtocolStore.getLocalRegistrationId(), true, pin, getSelfUnidentifiedAccessKey(), false);
|
||||||
|
|
||||||
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
||||||
registered = true;
|
registered = true;
|
||||||
|
@ -566,8 +589,10 @@ class Manager implements Signal {
|
||||||
if (mime == null) {
|
if (mime == null) {
|
||||||
mime = "application/octet-stream";
|
mime = "application/octet-stream";
|
||||||
}
|
}
|
||||||
// TODO mabybe add a parameter to set the voiceNote and preview option
|
// TODO mabybe add a parameter to set the voiceNote, preview, width, height and caption option
|
||||||
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, Optional.<byte[]>absent(), 0, 0, null);
|
Optional<byte[]> preview = Optional.absent();
|
||||||
|
Optional<String> caption = Optional.absent();
|
||||||
|
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, preview, 0, 0, caption, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
|
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
|
||||||
|
@ -629,7 +654,7 @@ class Manager implements Signal {
|
||||||
// Don't send group message to ourself
|
// Don't send group message to ourself
|
||||||
final List<String> membersSend = new ArrayList<>(g.members);
|
final List<String> membersSend = new ArrayList<>(g.members);
|
||||||
membersSend.remove(this.username);
|
membersSend.remove(this.username);
|
||||||
sendMessage(messageBuilder, membersSend);
|
sendMessageLegacy(messageBuilder, membersSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions {
|
public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions {
|
||||||
|
@ -644,7 +669,7 @@ class Manager implements Signal {
|
||||||
g.members.remove(this.username);
|
g.members.remove(this.username);
|
||||||
groupStore.updateGroup(g);
|
groupStore.updateGroup(g);
|
||||||
|
|
||||||
sendMessage(messageBuilder, g.members);
|
sendMessageLegacy(messageBuilder, g.members);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String join(CharSequence separator, Iterable<? extends CharSequence> list) {
|
private static String join(CharSequence separator, Iterable<? extends CharSequence> list) {
|
||||||
|
@ -663,7 +688,7 @@ class Manager implements Signal {
|
||||||
GroupInfo g;
|
GroupInfo g;
|
||||||
if (groupId == null) {
|
if (groupId == null) {
|
||||||
// Create new group
|
// Create new group
|
||||||
g = new GroupInfo(Util.getSecretBytes(16));
|
g = new GroupInfo(KeyUtils.createGroupId());
|
||||||
g.members.add(username);
|
g.members.add(username);
|
||||||
} else {
|
} else {
|
||||||
g = getGroupForSending(groupId);
|
g = getGroupForSending(groupId);
|
||||||
|
@ -714,7 +739,7 @@ class Manager implements Signal {
|
||||||
// Don't send group message to ourself
|
// Don't send group message to ourself
|
||||||
final List<String> membersSend = new ArrayList<>(g.members);
|
final List<String> membersSend = new ArrayList<>(g.members);
|
||||||
membersSend.remove(this.username);
|
membersSend.remove(this.username);
|
||||||
sendMessage(messageBuilder, membersSend);
|
sendMessageLegacy(messageBuilder, membersSend);
|
||||||
return g.groupId;
|
return g.groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,7 +758,7 @@ class Manager implements Signal {
|
||||||
// Send group message only to the recipient who requested it
|
// Send group message only to the recipient who requested it
|
||||||
final List<String> membersSend = new ArrayList<>();
|
final List<String> membersSend = new ArrayList<>();
|
||||||
membersSend.add(recipient);
|
membersSend.add(recipient);
|
||||||
sendMessage(messageBuilder, membersSend);
|
sendMessageLegacy(messageBuilder, membersSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) {
|
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) {
|
||||||
|
@ -769,7 +794,7 @@ class Manager implements Signal {
|
||||||
// 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
|
||||||
final List<String> membersSend = new ArrayList<>();
|
final List<String> membersSend = new ArrayList<>();
|
||||||
membersSend.add(recipient);
|
membersSend.add(recipient);
|
||||||
sendMessage(messageBuilder, membersSend);
|
sendMessageLegacy(messageBuilder, membersSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -788,7 +813,7 @@ class Manager implements Signal {
|
||||||
if (attachments != null) {
|
if (attachments != null) {
|
||||||
messageBuilder.withAttachments(getSignalServiceAttachments(attachments));
|
messageBuilder.withAttachments(getSignalServiceAttachments(attachments));
|
||||||
}
|
}
|
||||||
sendMessage(messageBuilder, recipients);
|
sendMessageLegacy(messageBuilder, recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -796,7 +821,7 @@ class Manager implements Signal {
|
||||||
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
||||||
.asEndSessionMessage();
|
.asEndSessionMessage();
|
||||||
|
|
||||||
sendMessage(messageBuilder, recipients);
|
sendMessageLegacy(messageBuilder, recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -891,42 +916,97 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] getSelfUnidentifiedAccessKey() {
|
||||||
|
return UnidentifiedAccess.deriveAccessKeyFrom(profileKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] getTargetUnidentifiedAccessKey(SignalServiceAddress recipient) {
|
||||||
|
// TODO implement
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<UnidentifiedAccessPair> getAccessForSync() {
|
||||||
|
// TODO implement
|
||||||
|
return Optional.absent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Optional<UnidentifiedAccessPair>> getAccessFor(Collection<SignalServiceAddress> recipients) {
|
||||||
|
List<Optional<UnidentifiedAccessPair>> result = new ArrayList<>(recipients.size());
|
||||||
|
for (SignalServiceAddress recipient : recipients) {
|
||||||
|
result.add(Optional.<UnidentifiedAccessPair>absent());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<UnidentifiedAccessPair> getAccessFor(SignalServiceAddress recipient) {
|
||||||
|
// TODO implement
|
||||||
|
return Optional.absent();
|
||||||
|
}
|
||||||
|
|
||||||
private void sendSyncMessage(SignalServiceSyncMessage message)
|
private void sendSyncMessage(SignalServiceSyncMessage message)
|
||||||
throws IOException, UntrustedIdentityException {
|
throws IOException, UntrustedIdentityException {
|
||||||
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(serviceConfiguration, username, password,
|
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(serviceConfiguration, username, password,
|
||||||
deviceId, signalProtocolStore, USER_AGENT, Optional.fromNullable(messagePipe), Optional.<SignalServiceMessageSender.EventListener>absent());
|
deviceId, signalProtocolStore, USER_AGENT, isMultiDevice, Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.<SignalServiceMessageSender.EventListener>absent());
|
||||||
try {
|
try {
|
||||||
messageSender.sendMessage(message);
|
messageSender.sendMessage(message, getAccessForSync());
|
||||||
} catch (UntrustedIdentityException e) {
|
} catch (UntrustedIdentityException e) {
|
||||||
signalProtocolStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
signalProtocolStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(SignalServiceDataMessage.Builder messageBuilder, Collection<String> recipients)
|
/**
|
||||||
|
* This method throws an EncapsulatedExceptions exception instead of returning a list of SendMessageResult.
|
||||||
|
*/
|
||||||
|
private void sendMessageLegacy(SignalServiceDataMessage.Builder messageBuilder, Collection<String> recipients)
|
||||||
throws EncapsulatedExceptions, IOException {
|
throws EncapsulatedExceptions, IOException {
|
||||||
|
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().getNumber(), null));
|
||||||
|
} else if (result.isNetworkFailure()) {
|
||||||
|
networkExceptions.add(new NetworkFailureException(result.getAddress().getNumber(), null));
|
||||||
|
} else if (result.getIdentityFailure() != null) {
|
||||||
|
untrustedIdentities.add(new UntrustedIdentityException("Untrusted", result.getAddress().getNumber(), result.getIdentityFailure().getIdentityKey()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!untrustedIdentities.isEmpty() || !unregisteredUsers.isEmpty() || !networkExceptions.isEmpty()) {
|
||||||
|
throw new EncapsulatedExceptions(untrustedIdentities, unregisteredUsers, networkExceptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SendMessageResult> sendMessage(SignalServiceDataMessage.Builder messageBuilder, Collection<String> recipients)
|
||||||
|
throws IOException {
|
||||||
Set<SignalServiceAddress> recipientsTS = getSignalServiceAddresses(recipients);
|
Set<SignalServiceAddress> recipientsTS = getSignalServiceAddresses(recipients);
|
||||||
if (recipientsTS == null) return;
|
if (recipientsTS == null) return Collections.emptyList();
|
||||||
|
|
||||||
SignalServiceDataMessage message = null;
|
SignalServiceDataMessage message = null;
|
||||||
try {
|
try {
|
||||||
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(serviceConfiguration, username, password,
|
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(serviceConfiguration, username, password,
|
||||||
deviceId, signalProtocolStore, USER_AGENT, Optional.fromNullable(messagePipe), Optional.<SignalServiceMessageSender.EventListener>absent());
|
deviceId, signalProtocolStore, USER_AGENT, 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()) {
|
||||||
try {
|
try {
|
||||||
messageSender.sendMessage(new ArrayList<>(recipientsTS), message);
|
List<SendMessageResult> result = messageSender.sendMessage(new ArrayList<>(recipientsTS), getAccessFor(recipientsTS), message);
|
||||||
} catch (EncapsulatedExceptions encapsulatedExceptions) {
|
for (SendMessageResult r : result) {
|
||||||
for (UntrustedIdentityException e : encapsulatedExceptions.getUntrustedIdentityExceptions()) {
|
if (r.getIdentityFailure() != null) {
|
||||||
signalProtocolStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
signalProtocolStore.saveIdentity(r.getAddress().getNumber(), r.getIdentityFailure().getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
} catch (UntrustedIdentityException e) {
|
||||||
|
signalProtocolStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Send to all individually, so sync messages are sent correctly
|
// Send to all individually, so sync messages are sent correctly
|
||||||
List<UntrustedIdentityException> untrustedIdentities = new LinkedList<>();
|
List<SendMessageResult> results = new ArrayList<>(recipientsTS.size());
|
||||||
List<UnregisteredUserException> unregisteredUsers = new LinkedList<>();
|
|
||||||
List<NetworkFailureException> networkExceptions = new LinkedList<>();
|
|
||||||
for (SignalServiceAddress address : recipientsTS) {
|
for (SignalServiceAddress address : recipientsTS) {
|
||||||
ThreadInfo thread = threadStore.getThread(address.getNumber());
|
ThreadInfo thread = threadStore.getThread(address.getNumber());
|
||||||
if (thread != null) {
|
if (thread != null) {
|
||||||
|
@ -936,19 +1016,14 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
message = messageBuilder.build();
|
message = messageBuilder.build();
|
||||||
try {
|
try {
|
||||||
messageSender.sendMessage(address, message);
|
SendMessageResult result = messageSender.sendMessage(address, getAccessFor(address), message);
|
||||||
|
results.add(result);
|
||||||
} catch (UntrustedIdentityException e) {
|
} catch (UntrustedIdentityException e) {
|
||||||
signalProtocolStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
signalProtocolStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
|
||||||
untrustedIdentities.add(e);
|
results.add(SendMessageResult.identityFailure(address, e.getIdentityKey()));
|
||||||
} catch (UnregisteredUserException e) {
|
|
||||||
unregisteredUsers.add(e);
|
|
||||||
} catch (PushNetworkException e) {
|
|
||||||
networkExceptions.add(new NetworkFailureException(address.getNumber(), e));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!untrustedIdentities.isEmpty() || !unregisteredUsers.isEmpty() || !networkExceptions.isEmpty()) {
|
return results;
|
||||||
throw new EncapsulatedExceptions(untrustedIdentities, unregisteredUsers, networkExceptions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (message != null && message.isEndSession()) {
|
if (message != null && message.isEndSession()) {
|
||||||
|
@ -975,12 +1050,22 @@ class Manager implements Signal {
|
||||||
return recipientsTS;
|
return recipientsTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws NoSessionException, LegacyMessageException, InvalidVersionException, InvalidMessageException, DuplicateMessageException, InvalidKeyException, InvalidKeyIdException, org.whispersystems.libsignal.UntrustedIdentityException {
|
public static CertificateValidator getCertificateValidator() {
|
||||||
SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(username), signalProtocolStore);
|
try {
|
||||||
|
ECPublicKey unidentifiedSenderTrustRoot = Curve.decodePoint(Base64.decode(UNIDENTIFIED_SENDER_TRUST_ROOT), 0);
|
||||||
|
return new CertificateValidator(unidentifiedSenderTrustRoot);
|
||||||
|
} catch (InvalidKeyException | IOException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws org.whispersystems.libsignal.UntrustedIdentityException, InvalidMetadataMessageException, ProtocolInvalidMessageException, ProtocolDuplicateMessageException, ProtocolLegacyMessageException, ProtocolInvalidKeyIdException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolNoSessionException, ProtocolInvalidKeyException, ProtocolUntrustedIdentityException, SelfSendException {
|
||||||
|
SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(username), signalProtocolStore, getCertificateValidator());
|
||||||
try {
|
try {
|
||||||
return cipher.decrypt(envelope);
|
return cipher.decrypt(envelope);
|
||||||
} catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
|
} catch (ProtocolUntrustedIdentityException e) {
|
||||||
signalProtocolStore.saveIdentity(e.getName(), e.getUntrustedIdentity(), TrustLevel.UNTRUSTED);
|
// TODO We don't get the new untrusted identity from ProtocolUntrustedIdentityException anymore ... we need to get it from somewhere else
|
||||||
|
// signalProtocolStore.saveIdentity(e.getSender(), e.getUntrustedIdentity(), TrustLevel.UNTRUSTED);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1091,6 +1176,14 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (message.getProfileKey().isPresent() && message.getProfileKey().get().length == 32) {
|
||||||
|
ContactInfo contact = contactStore.getContact(source);
|
||||||
|
if (contact == null) {
|
||||||
|
contact = new ContactInfo();
|
||||||
|
contact.number = source;
|
||||||
|
}
|
||||||
|
contact.profileKey = Base64.encodeBytes(message.getProfileKey().get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void retryFailedReceivedMessages(ReceiveMessageHandler handler, boolean ignoreAttachments) {
|
public void retryFailedReceivedMessages(ReceiveMessageHandler handler, boolean ignoreAttachments) {
|
||||||
|
@ -1211,6 +1304,7 @@ class Manager implements Signal {
|
||||||
handleSignalServiceDataMessage(message, false, envelope.getSource(), username, ignoreAttachments);
|
handleSignalServiceDataMessage(message, false, envelope.getSource(), username, ignoreAttachments);
|
||||||
}
|
}
|
||||||
if (content.getSyncMessage().isPresent()) {
|
if (content.getSyncMessage().isPresent()) {
|
||||||
|
isMultiDevice = 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();
|
SignalServiceDataMessage message = syncMessage.getSent().get().getMessage();
|
||||||
|
@ -1298,6 +1392,21 @@ class Manager implements Signal {
|
||||||
if (c.getColor().isPresent()) {
|
if (c.getColor().isPresent()) {
|
||||||
contact.color = c.getColor().get();
|
contact.color = c.getColor().get();
|
||||||
}
|
}
|
||||||
|
if (c.getProfileKey().isPresent()) {
|
||||||
|
contact.profileKey = Base64.encodeBytes(c.getProfileKey().get());
|
||||||
|
}
|
||||||
|
if (c.getVerified().isPresent()) {
|
||||||
|
final VerifiedMessage verifiedMessage = c.getVerified().get();
|
||||||
|
signalProtocolStore.saveIdentity(verifiedMessage.getDestination(), verifiedMessage.getIdentityKey(), TrustLevel.fromVerifiedState(verifiedMessage.getVerified()));
|
||||||
|
}
|
||||||
|
if (c.getExpirationTimer().isPresent()) {
|
||||||
|
ThreadInfo thread = threadStore.getThread(c.getNumber());
|
||||||
|
thread.messageExpirationTime = c.getExpirationTimer().get();
|
||||||
|
threadStore.updateThread(thread);
|
||||||
|
}
|
||||||
|
if (c.isBlocked()) {
|
||||||
|
// TODO store list of blocked numbers
|
||||||
|
}
|
||||||
contactStore.updateContact(contact);
|
contactStore.updateContact(contact);
|
||||||
|
|
||||||
if (c.getAvatar().isPresent()) {
|
if (c.getAvatar().isPresent()) {
|
||||||
|
@ -1329,13 +1438,16 @@ class Manager implements Signal {
|
||||||
try (FileInputStream f = new FileInputStream(file)) {
|
try (FileInputStream f = new FileInputStream(file)) {
|
||||||
DataInputStream in = new DataInputStream(f);
|
DataInputStream in = new DataInputStream(f);
|
||||||
int version = in.readInt();
|
int version = in.readInt();
|
||||||
if (version != 1) {
|
if (version > 2) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int type = in.readInt();
|
int type = in.readInt();
|
||||||
String source = in.readUTF();
|
String source = in.readUTF();
|
||||||
int sourceDevice = in.readInt();
|
int sourceDevice = in.readInt();
|
||||||
String relay = in.readUTF();
|
if (version == 1) {
|
||||||
|
// read legacy relay field
|
||||||
|
in.readUTF();
|
||||||
|
}
|
||||||
long timestamp = in.readLong();
|
long timestamp = in.readLong();
|
||||||
byte[] content = null;
|
byte[] content = null;
|
||||||
int contentLen = in.readInt();
|
int contentLen = in.readInt();
|
||||||
|
@ -1349,18 +1461,26 @@ class Manager implements Signal {
|
||||||
legacyMessage = new byte[legacyMessageLen];
|
legacyMessage = new byte[legacyMessageLen];
|
||||||
in.readFully(legacyMessage);
|
in.readFully(legacyMessage);
|
||||||
}
|
}
|
||||||
return new SignalServiceEnvelope(type, source, sourceDevice, relay, timestamp, legacyMessage, content);
|
long serverTimestamp = 0;
|
||||||
|
String uuid = null;
|
||||||
|
if (version == 2) {
|
||||||
|
serverTimestamp = in.readLong();
|
||||||
|
uuid = in.readUTF();
|
||||||
|
if ("".equals(uuid)) {
|
||||||
|
uuid = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SignalServiceEnvelope(type, source, sourceDevice, timestamp, legacyMessage, content, serverTimestamp, uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException {
|
private void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException {
|
||||||
try (FileOutputStream f = new FileOutputStream(file)) {
|
try (FileOutputStream f = new FileOutputStream(file)) {
|
||||||
try (DataOutputStream out = new DataOutputStream(f)) {
|
try (DataOutputStream out = new DataOutputStream(f)) {
|
||||||
out.writeInt(1); // version
|
out.writeInt(2); // version
|
||||||
out.writeInt(envelope.getType());
|
out.writeInt(envelope.getType());
|
||||||
out.writeUTF(envelope.getSource());
|
out.writeUTF(envelope.getSource());
|
||||||
out.writeInt(envelope.getSourceDevice());
|
out.writeInt(envelope.getSourceDevice());
|
||||||
out.writeUTF(envelope.getRelay());
|
|
||||||
out.writeLong(envelope.getTimestamp());
|
out.writeLong(envelope.getTimestamp());
|
||||||
if (envelope.hasContent()) {
|
if (envelope.hasContent()) {
|
||||||
out.writeInt(envelope.getContent().length);
|
out.writeInt(envelope.getContent().length);
|
||||||
|
@ -1374,6 +1494,9 @@ class Manager implements Signal {
|
||||||
} else {
|
} else {
|
||||||
out.writeInt(0);
|
out.writeInt(0);
|
||||||
}
|
}
|
||||||
|
out.writeLong(envelope.getServerTimestamp());
|
||||||
|
String uuid = envelope.getUuid();
|
||||||
|
out.writeUTF(uuid == null ? "" : uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1547,10 +1670,12 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO include profile key
|
byte[] profileKey = record.profileKey == null ? null : Base64.decode(record.profileKey);
|
||||||
|
// TODO store list of blocked numbers
|
||||||
|
boolean blocked = false;
|
||||||
out.write(new DeviceContact(record.number, Optional.fromNullable(record.name),
|
out.write(new DeviceContact(record.number, Optional.fromNullable(record.name),
|
||||||
createContactAvatarAttachment(record.number), Optional.fromNullable(record.color),
|
createContactAvatarAttachment(record.number), Optional.fromNullable(record.color),
|
||||||
Optional.fromNullable(verifiedMessage), Optional.<byte[]>absent(), false, Optional.fromNullable(info != null ? info.messageExpirationTime : null)));
|
Optional.fromNullable(verifiedMessage), Optional.fromNullable(profileKey), blocked, Optional.fromNullable(info != null ? info.messageExpirationTime : null)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,7 @@ public class ContactInfo {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
public String color;
|
public String color;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public String profileKey;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,25 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IdentityKey getIdentity(SignalProtocolAddress address) {
|
||||||
|
List<Identity> identities = trustedKeys.get(address.getName());
|
||||||
|
if (identities == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
long maxDate = 0;
|
||||||
|
Identity maxIdentity = null;
|
||||||
|
for (Identity id : identities) {
|
||||||
|
final long time = id.getDateAdded().getTime();
|
||||||
|
if (maxDate <= time) {
|
||||||
|
maxDate = time;
|
||||||
|
maxIdentity = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxIdentity.getIdentityKey();
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, List<Identity>> getIdentities() {
|
public Map<String, List<Identity>> getIdentities() {
|
||||||
// TODO deep copy
|
// TODO deep copy
|
||||||
return trustedKeys;
|
return trustedKeys;
|
||||||
|
|
|
@ -87,6 +87,11 @@ public class JsonSignalProtocolStore implements SignalProtocolStore {
|
||||||
return identityKeyStore.isTrustedIdentity(address, identityKey, direction);
|
return identityKeyStore.isTrustedIdentity(address, identityKey, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IdentityKey getIdentity(SignalProtocolAddress address) {
|
||||||
|
return identityKeyStore.getIdentity(address);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
|
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
|
||||||
return preKeyStore.loadPreKey(preKeyId);
|
return preKeyStore.loadPreKey(preKeyId);
|
||||||
|
|
47
src/main/java/org/asamk/signal/util/KeyUtils.java
Normal file
47
src/main/java/org/asamk/signal/util/KeyUtils.java
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package org.asamk.signal.util;
|
||||||
|
|
||||||
|
import org.whispersystems.signalservice.internal.util.Base64;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
public class KeyUtils {
|
||||||
|
|
||||||
|
private KeyUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createSignalingKey() {
|
||||||
|
return getSecret(52);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] createProfileKey() {
|
||||||
|
return getSecretBytes(32);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createPassword() {
|
||||||
|
return getSecret(18);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] createGroupId() {
|
||||||
|
return getSecretBytes(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSecret(int size) {
|
||||||
|
byte[] secret = getSecretBytes(size);
|
||||||
|
return Base64.encodeBytes(secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] getSecretBytes(int size) {
|
||||||
|
byte[] secret = new byte[size];
|
||||||
|
getSecureRandom().nextBytes(secret);
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SecureRandom getSecureRandom() {
|
||||||
|
try {
|
||||||
|
return SecureRandom.getInstance("SHA1PRNG");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,32 +1,9 @@
|
||||||
package org.asamk.signal.util;
|
package org.asamk.signal.util;
|
||||||
|
|
||||||
import org.whispersystems.signalservice.internal.util.Base64;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
public static String getSecret(int size) {
|
|
||||||
byte[] secret = getSecretBytes(size);
|
|
||||||
return Base64.encodeBytes(secret);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getSecretBytes(int size) {
|
|
||||||
byte[] secret = new byte[size];
|
|
||||||
getSecureRandom().nextBytes(secret);
|
|
||||||
return secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SecureRandom getSecureRandom() {
|
|
||||||
try {
|
|
||||||
return SecureRandom.getInstance("SHA1PRNG");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File createTempFile() throws IOException {
|
public static File createTempFile() throws IOException {
|
||||||
return File.createTempFile("signal_tmp_", ".tmp");
|
return File.createTempFile("signal_tmp_", ".tmp");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue