Update dependencies

Sets the complete flag for contacts message, Fixes #81
This commit is contained in:
AsamK 2017-05-20 11:24:58 +02:00
parent d270ea8c2e
commit 0f1d0597ae
6 changed files with 36 additions and 19 deletions

View file

@ -19,7 +19,7 @@ repositories {
} }
dependencies { dependencies {
compile 'com.github.turasa:signal-service-java:2.5.5_unofficial_1' compile 'com.github.turasa:signal-service-java:2.5.7_unofficial_1'
compile 'org.bouncycastle:bcprov-jdk15on:1.55' compile 'org.bouncycastle:bcprov-jdk15on:1.55'
compile 'net.sourceforge.argparse4j:argparse4j:0.7.0' compile 'net.sourceforge.argparse4j:argparse4j:0.7.0'
compile 'org.freedesktop.dbus:dbus-java:2.7.0' compile 'org.freedesktop.dbus:dbus-java:2.7.0'

View file

@ -938,8 +938,13 @@ public class Main {
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get(); SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
if (syncMessage.getContacts().isPresent()) { if (syncMessage.getContacts().isPresent()) {
System.out.println("Received sync contacts"); final ContactsMessage contactsMessage = syncMessage.getContacts().get();
printAttachment(syncMessage.getContacts().get()); if (contactsMessage.isComplete()) {
System.out.println("Received complete sync contacts");
} else {
System.out.println("Received sync contacts");
}
printAttachment(contactsMessage.getContactsStream());
} }
if (syncMessage.getGroups().isPresent()) { if (syncMessage.getGroups().isPresent()) {
System.out.println("Received sync groups"); System.out.println("Received sync groups");
@ -1051,6 +1056,7 @@ public class Main {
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 + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : ""));
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"));
File file = m.getAttachmentFile(pointer.getId()); File file = m.getAttachmentFile(pointer.getId());
if (file.exists()) { if (file.exists()) {
System.out.println(" Stored plaintext in: " + file); System.out.println(" Stored plaintext in: " + file);

View file

@ -558,7 +558,8 @@ class Manager implements Signal {
if (mime == null) { if (mime == null) {
mime = "application/octet-stream"; mime = "application/octet-stream";
} }
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), null); // TODO mabybe add a parameter to set the voiceNote and preview option
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, Optional.<byte[]>absent(),null);
} }
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException { private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
@ -1251,7 +1252,11 @@ class Manager implements Signal {
File tmpFile = null; File tmpFile = null;
try { try {
tmpFile = Util.createTempFile(); tmpFile = Util.createTempFile();
DeviceContactsInputStream s = new DeviceContactsInputStream(retrieveAttachmentAsStream(syncMessage.getContacts().get().asPointer(), tmpFile)); final ContactsMessage contactsMessage = syncMessage.getContacts().get();
DeviceContactsInputStream s = new DeviceContactsInputStream(retrieveAttachmentAsStream(contactsMessage.getContactsStream().asPointer(), tmpFile));
if (contactsMessage.isComplete()) {
contactStore.clear();
}
DeviceContact c; DeviceContact c;
while ((c = s.read()) != null) { while ((c = s.read()) != null) {
ContactInfo contact = contactStore.getContact(c.getNumber()); ContactInfo contact = contactStore.getContact(c.getNumber());
@ -1506,7 +1511,7 @@ class Manager implements Signal {
.withLength(contactsFile.length()) .withLength(contactsFile.length())
.build(); .build();
sendSyncMessage(SignalServiceSyncMessage.forContacts(attachmentStream)); sendSyncMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, true)));
} }
} }
} finally { } finally {

View file

@ -33,6 +33,13 @@ public class JsonContactsStore {
return new ArrayList<>(contacts.values()); return new ArrayList<>(contacts.values());
} }
/**
* Remove all contacts from the store
*/
public void clear() {
contacts.clear();
}
public static class MapToListSerializer extends JsonSerializer<Map<?, ?>> { public static class MapToListSerializer extends JsonSerializer<Map<?, ?>> {
@Override @Override
public void serialize(final Map<?, ?> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException { public void serialize(final Map<?, ?> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {

View file

@ -39,8 +39,8 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
} }
@Override @Override
public void saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) { public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
saveIdentity(address.getName(), identityKey, TrustLevel.TRUSTED_UNVERIFIED, null); return saveIdentity(address.getName(), identityKey, TrustLevel.TRUSTED_UNVERIFIED, null);
} }
/** /**
@ -51,7 +51,7 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
* @param trustLevel * @param trustLevel
* @param added Added timestamp, if null and the key is newly added, the current time is used. * @param added Added timestamp, if null and the key is newly added, the current time is used.
*/ */
public void saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel, Date added) { public boolean saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel, Date added) {
List<Identity> identities = trustedKeys.get(name); List<Identity> identities = trustedKeys.get(name);
if (identities == null) { if (identities == null) {
identities = new ArrayList<>(); identities = new ArrayList<>();
@ -67,14 +67,16 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
if (added != null) { if (added != null) {
id.added = added; id.added = added;
} }
return; return true;
} }
} }
identities.add(new Identity(identityKey, trustLevel, added != null ? added : new Date())); identities.add(new Identity(identityKey, trustLevel, added != null ? added : new Date()));
return false;
} }
@Override @Override
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey) { public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
// TODO implement possibility for different handling of incoming/outgoing trust decisions
List<Identity> identities = trustedKeys.get(address.getName()); List<Identity> identities = trustedKeys.get(address.getName());
if (identities == null) { if (identities == null) {
// Trust on first use // Trust on first use

View file

@ -8,10 +8,7 @@ import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair; import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyIdException; import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.SignalProtocolAddress; import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.state.PreKeyRecord; import org.whispersystems.libsignal.state.*;
import org.whispersystems.libsignal.state.SessionRecord;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -66,8 +63,8 @@ public class JsonSignalProtocolStore implements SignalProtocolStore {
} }
@Override @Override
public void saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) { public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
identityKeyStore.saveIdentity(address, identityKey); return identityKeyStore.saveIdentity(address, identityKey);
} }
public void saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel) { public void saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel) {
@ -83,8 +80,8 @@ public class JsonSignalProtocolStore implements SignalProtocolStore {
} }
@Override @Override
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey) { public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
return identityKeyStore.isTrustedIdentity(address, identityKey); return identityKeyStore.isTrustedIdentity(address, identityKey, direction);
} }
@Override @Override