Update to signal-service-java 2.1.1

This commit is contained in:
AsamK 2016-03-25 16:50:51 +01:00
parent 78252a13df
commit b06fafbf62
10 changed files with 126 additions and 126 deletions

View file

@ -16,7 +16,7 @@ repositories {
}
dependencies {
compile 'org.whispersystems:textsecure-java:1.8.3fetchMessages'
compile 'org.whispersystems:signal-service-java:2.1.1fetchMessages'
compile 'com.madgag.spongycastle:prov:1.54.0.0'
compile 'commons-io:commons-io:2.4'
compile 'net.sourceforge.argparse4j:argparse4j:0.7.0'

View file

@ -5,7 +5,7 @@ import org.asamk.textsecure.GroupNotFoundException;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.exceptions.DBusException;
import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
import java.io.IOException;
import java.util.List;

View file

@ -3,18 +3,18 @@ package org.asamk.textsecure;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.whispersystems.libaxolotl.AxolotlAddress;
import org.whispersystems.libaxolotl.IdentityKey;
import org.whispersystems.libaxolotl.IdentityKeyPair;
import org.whispersystems.libaxolotl.InvalidKeyIdException;
import org.whispersystems.libaxolotl.state.AxolotlStore;
import org.whispersystems.libaxolotl.state.PreKeyRecord;
import org.whispersystems.libaxolotl.state.SessionRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SessionRecord;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import java.util.List;
class JsonAxolotlStore implements AxolotlStore {
class JsonAxolotlStore implements SignalProtocolStore {
@JsonProperty("preKeys")
@JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class)
@ -94,7 +94,7 @@ class JsonAxolotlStore implements AxolotlStore {
}
@Override
public SessionRecord loadSession(AxolotlAddress address) {
public SessionRecord loadSession(SignalProtocolAddress address) {
return sessionStore.loadSession(address);
}
@ -104,17 +104,17 @@ class JsonAxolotlStore implements AxolotlStore {
}
@Override
public void storeSession(AxolotlAddress address, SessionRecord record) {
public void storeSession(SignalProtocolAddress address, SessionRecord record) {
sessionStore.storeSession(address, record);
}
@Override
public boolean containsSession(AxolotlAddress address) {
public boolean containsSession(SignalProtocolAddress address) {
return sessionStore.containsSession(address);
}
@Override
public void deleteSession(AxolotlAddress address) {
public void deleteSession(SignalProtocolAddress address) {
sessionStore.deleteSession(address);
}

View file

@ -4,10 +4,10 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import org.whispersystems.libaxolotl.IdentityKey;
import org.whispersystems.libaxolotl.IdentityKeyPair;
import org.whispersystems.libaxolotl.InvalidKeyException;
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.state.IdentityKeyStore;
import java.io.IOException;
import java.util.HashMap;

View file

@ -4,9 +4,9 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import org.whispersystems.libaxolotl.InvalidKeyIdException;
import org.whispersystems.libaxolotl.state.PreKeyRecord;
import org.whispersystems.libaxolotl.state.PreKeyStore;
import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.PreKeyStore;
import java.io.IOException;
import java.util.HashMap;

View file

@ -4,28 +4,28 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import org.whispersystems.libaxolotl.AxolotlAddress;
import org.whispersystems.libaxolotl.state.SessionRecord;
import org.whispersystems.libaxolotl.state.SessionStore;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.state.SessionRecord;
import org.whispersystems.libsignal.state.SessionStore;
import java.io.IOException;
import java.util.*;
class JsonSessionStore implements SessionStore {
private final Map<AxolotlAddress, byte[]> sessions = new HashMap<>();
private final Map<SignalProtocolAddress, byte[]> sessions = new HashMap<>();
public JsonSessionStore() {
}
public void addSessions(Map<AxolotlAddress, byte[]> sessions) {
public void addSessions(Map<SignalProtocolAddress, byte[]> sessions) {
this.sessions.putAll(sessions);
}
@Override
public synchronized SessionRecord loadSession(AxolotlAddress remoteAddress) {
public synchronized SessionRecord loadSession(SignalProtocolAddress remoteAddress) {
try {
if (containsSession(remoteAddress)) {
return new SessionRecord(sessions.get(remoteAddress));
@ -41,7 +41,7 @@ class JsonSessionStore implements SessionStore {
public synchronized List<Integer> getSubDeviceSessions(String name) {
List<Integer> deviceIds = new LinkedList<>();
for (AxolotlAddress key : sessions.keySet()) {
for (SignalProtocolAddress key : sessions.keySet()) {
if (key.getName().equals(name) &&
key.getDeviceId() != 1) {
deviceIds.add(key.getDeviceId());
@ -52,23 +52,23 @@ class JsonSessionStore implements SessionStore {
}
@Override
public synchronized void storeSession(AxolotlAddress address, SessionRecord record) {
public synchronized void storeSession(SignalProtocolAddress address, SessionRecord record) {
sessions.put(address, record.serialize());
}
@Override
public synchronized boolean containsSession(AxolotlAddress address) {
public synchronized boolean containsSession(SignalProtocolAddress address) {
return sessions.containsKey(address);
}
@Override
public synchronized void deleteSession(AxolotlAddress address) {
public synchronized void deleteSession(SignalProtocolAddress address) {
sessions.remove(address);
}
@Override
public synchronized void deleteAllSessions(String name) {
for (AxolotlAddress key : new ArrayList<>(sessions.keySet())) {
for (SignalProtocolAddress key : new ArrayList<>(sessions.keySet())) {
if (key.getName().equals(name)) {
sessions.remove(key);
}
@ -81,12 +81,12 @@ class JsonSessionStore implements SessionStore {
public JsonSessionStore deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
Map<AxolotlAddress, byte[]> sessionMap = new HashMap<>();
Map<SignalProtocolAddress, byte[]> sessionMap = new HashMap<>();
if (node.isArray()) {
for (JsonNode session : node) {
String sessionName = session.get("name").asText();
try {
sessionMap.put(new AxolotlAddress(sessionName, session.get("deviceId").asInt()), Base64.decode(session.get("record").asText()));
sessionMap.put(new SignalProtocolAddress(sessionName, session.get("deviceId").asInt()), Base64.decode(session.get("record").asText()));
} catch (IOException e) {
System.out.println(String.format("Error while decoding session for: %s", sessionName));
}
@ -106,7 +106,7 @@ class JsonSessionStore implements SessionStore {
@Override
public void serialize(JsonSessionStore jsonSessionStore, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
json.writeStartArray();
for (Map.Entry<AxolotlAddress, byte[]> preKey : jsonSessionStore.sessions.entrySet()) {
for (Map.Entry<SignalProtocolAddress, byte[]> preKey : jsonSessionStore.sessions.entrySet()) {
json.writeStartObject();
json.writeStringField("name", preKey.getKey().getName());
json.writeNumberField("deviceId", preKey.getKey().getDeviceId());

View file

@ -4,9 +4,9 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import org.whispersystems.libaxolotl.InvalidKeyIdException;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
import org.whispersystems.libsignal.InvalidKeyIdException;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyStore;
import java.io.IOException;
import java.util.HashMap;

View file

@ -25,13 +25,13 @@ import org.asamk.TextSecure;
import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
import org.whispersystems.textsecure.api.messages.*;
import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage;
import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.textsecure.api.push.exceptions.NetworkFailureException;
import org.whispersystems.textsecure.api.push.exceptions.UnregisteredUserException;
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.signalservice.api.messages.*;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
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.PhoneNumberFormatter;
import java.io.File;
import java.io.IOException;
@ -486,18 +486,18 @@ public class Main {
}
@Override
public void handleMessage(TextSecureEnvelope envelope, TextSecureContent content, GroupInfo group) {
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, GroupInfo group) {
System.out.println("Envelope from: " + envelope.getSource());
System.out.println("Timestamp: " + envelope.getTimestamp());
if (envelope.isReceipt()) {
System.out.println("Got receipt.");
} else if (envelope.isWhisperMessage() | envelope.isPreKeyWhisperMessage()) {
} else if (envelope.isSignalMessage() | envelope.isPreKeySignalMessage()) {
if (content == null) {
System.out.println("Failed to decrypt message.");
} else {
if (content.getDataMessage().isPresent()) {
TextSecureDataMessage message = content.getDataMessage().get();
SignalServiceDataMessage message = content.getDataMessage().get();
System.out.println("Message timestamp: " + message.getTimestamp());
@ -505,7 +505,7 @@ public class Main {
System.out.println("Body: " + message.getBody().get());
}
if (message.getGroupInfo().isPresent()) {
TextSecureGroup groupInfo = message.getGroupInfo().get();
SignalServiceGroup groupInfo = message.getGroupInfo().get();
System.out.println("Group info:");
System.out.println(" Id: " + Base64.encodeBytes(groupInfo.getGroupId()));
if (groupInfo.getName().isPresent()) {
@ -532,13 +532,13 @@ public class Main {
if (message.getAttachments().isPresent()) {
System.out.println("Attachments: ");
for (TextSecureAttachment attachment : message.getAttachments().get()) {
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
printAttachment(attachment);
}
}
}
if (content.getSyncMessage().isPresent()) {
TextSecureSyncMessage syncMessage = content.getSyncMessage().get();
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
System.out.println("Received sync message");
}
}
@ -548,10 +548,10 @@ public class Main {
System.out.println();
}
private void printAttachment(TextSecureAttachment attachment) {
private void printAttachment(SignalServiceAttachment attachment) {
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
if (attachment.isPointer()) {
final TextSecureAttachmentPointer 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(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
File file = m.getAttachmentFile(pointer.getId());
@ -572,18 +572,18 @@ public class Main {
}
@Override
public void handleMessage(TextSecureEnvelope envelope, TextSecureContent content, GroupInfo group) {
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, GroupInfo group) {
System.out.println("Envelope from: " + envelope.getSource());
System.out.println("Timestamp: " + envelope.getTimestamp());
if (envelope.isReceipt()) {
System.out.println("Got receipt.");
} else if (envelope.isWhisperMessage() | envelope.isPreKeyWhisperMessage()) {
} else if (envelope.isSignalMessage() | envelope.isPreKeySignalMessage()) {
if (content == null) {
System.out.println("Failed to decrypt message.");
} else {
if (content.getDataMessage().isPresent()) {
TextSecureDataMessage message = content.getDataMessage().get();
SignalServiceDataMessage message = content.getDataMessage().get();
System.out.println("Message timestamp: " + message.getTimestamp());
@ -592,7 +592,7 @@ public class Main {
}
if (message.getGroupInfo().isPresent()) {
TextSecureGroup groupInfo = message.getGroupInfo().get();
SignalServiceGroup groupInfo = message.getGroupInfo().get();
System.out.println("Group info:");
System.out.println(" Id: " + Base64.encodeBytes(groupInfo.getGroupId()));
if (groupInfo.getName().isPresent()) {
@ -620,7 +620,7 @@ public class Main {
List<String> attachments = new ArrayList<>();
if (message.getAttachments().isPresent()) {
System.out.println("Attachments: ");
for (TextSecureAttachment attachment : message.getAttachments().get()) {
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
if (attachment.isPointer()) {
attachments.add(m.getAttachmentFile(attachment.asPointer().getId()).getAbsolutePath());
}
@ -628,7 +628,7 @@ public class Main {
}
}
if (!message.isEndSession() &&
!(message.getGroupInfo().isPresent() && message.getGroupInfo().get().getType() != TextSecureGroup.Type.DELIVER)) {
!(message.getGroupInfo().isPresent() && message.getGroupInfo().get().getType() != SignalServiceGroup.Type.DELIVER)) {
try {
conn.sendSignal(new TextSecure.MessageReceived(
TEXTSECURE_OBJECTPATH,
@ -642,7 +642,7 @@ public class Main {
}
}
if (content.getSyncMessage().isPresent()) {
TextSecureSyncMessage syncMessage = content.getSyncMessage().get();
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
System.out.println("Received sync message");
}
}
@ -652,10 +652,10 @@ public class Main {
System.out.println();
}
private void printAttachment(TextSecureAttachment attachment) {
private void printAttachment(SignalServiceAttachment attachment) {
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
if (attachment.isPointer()) {
final TextSecureAttachmentPointer 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(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
File file = m.getAttachmentFile(pointer.getId());

View file

@ -24,25 +24,25 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.asamk.TextSecure;
import org.whispersystems.libaxolotl.*;
import org.whispersystems.libaxolotl.ecc.Curve;
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
import org.whispersystems.libaxolotl.state.PreKeyRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import org.whispersystems.libaxolotl.util.KeyHelper;
import org.whispersystems.libaxolotl.util.Medium;
import org.whispersystems.libaxolotl.util.guava.Optional;
import org.whispersystems.textsecure.api.TextSecureAccountManager;
import org.whispersystems.textsecure.api.TextSecureMessagePipe;
import org.whispersystems.textsecure.api.TextSecureMessageReceiver;
import org.whispersystems.textsecure.api.TextSecureMessageSender;
import org.whispersystems.textsecure.api.crypto.TextSecureCipher;
import org.whispersystems.textsecure.api.messages.*;
import org.whispersystems.textsecure.api.push.TextSecureAddress;
import org.whispersystems.textsecure.api.push.TrustStore;
import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.textsecure.api.util.InvalidNumberException;
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
import org.whispersystems.libsignal.*;
import org.whispersystems.libsignal.ecc.Curve;
import org.whispersystems.libsignal.ecc.ECKeyPair;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.util.KeyHelper;
import org.whispersystems.libsignal.util.Medium;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.SignalServiceMessagePipe;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
import org.whispersystems.signalservice.api.messages.*;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.TrustStore;
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
import java.io.*;
import java.nio.file.Files;
@ -52,7 +52,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
class Manager implements TextSecure {
private final static String URL = "https://textsecure-service.whispersystems.org";
private final static String URL = "https://SignalService-service.whispersystems.org";
private final static TrustStore TRUST_STORE = new WhisperTrustStore();
public final static String PROJECT_NAME = Manager.class.getPackage().getImplementationTitle();
@ -73,7 +73,7 @@ class Manager implements TextSecure {
private boolean registered = false;
private JsonAxolotlStore axolotlStore;
private TextSecureAccountManager accountManager;
private SignalServiceAccountManager accountManager;
private JsonGroupStore groupStore;
public Manager(String username, String settingsPath) {
@ -138,7 +138,7 @@ class Manager implements TextSecure {
if (groupStore == null) {
groupStore = new JsonGroupStore();
}
accountManager = new TextSecureAccountManager(URL, TRUST_STORE, username, password, USER_AGENT);
accountManager = new SignalServiceAccountManager(URL, TRUST_STORE, username, password, USER_AGENT);
}
private void save() {
@ -175,7 +175,7 @@ class Manager implements TextSecure {
public void register(boolean voiceVerication) throws IOException {
password = Util.getSecret(18);
accountManager = new TextSecureAccountManager(URL, TRUST_STORE, username, password, USER_AGENT);
accountManager = new SignalServiceAccountManager(URL, TRUST_STORE, username, password, USER_AGENT);
if (voiceVerication)
accountManager.requestVoiceVerificationCode();
@ -259,54 +259,54 @@ class Manager implements TextSecure {
}
private static List<TextSecureAttachment> getTextSecureAttachments(List<String> attachments) throws AttachmentInvalidException {
List<TextSecureAttachment> textSecureAttachments = null;
private static List<SignalServiceAttachment> getSignalServiceAttachments(List<String> attachments) throws AttachmentInvalidException {
List<SignalServiceAttachment> SignalServiceAttachments = null;
if (attachments != null) {
textSecureAttachments = new ArrayList<>(attachments.size());
SignalServiceAttachments = new ArrayList<>(attachments.size());
for (String attachment : attachments) {
try {
textSecureAttachments.add(createAttachment(attachment));
SignalServiceAttachments.add(createAttachment(attachment));
} catch (IOException e) {
throw new AttachmentInvalidException(attachment, e);
}
}
}
return textSecureAttachments;
return SignalServiceAttachments;
}
private static TextSecureAttachmentStream createAttachment(String attachment) throws IOException {
private static SignalServiceAttachmentStream createAttachment(String attachment) throws IOException {
File attachmentFile = new File(attachment);
InputStream attachmentStream = new FileInputStream(attachmentFile);
final long attachmentSize = attachmentFile.length();
String mime = Files.probeContentType(Paths.get(attachment));
return new TextSecureAttachmentStream(attachmentStream, mime, attachmentSize, null);
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, null);
}
@Override
public void sendGroupMessage(String messageText, List<String> attachments,
byte[] groupId)
throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
final TextSecureDataMessage.Builder messageBuilder = TextSecureDataMessage.newBuilder().withBody(messageText);
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
if (attachments != null) {
messageBuilder.withAttachments(getTextSecureAttachments(attachments));
messageBuilder.withAttachments(getSignalServiceAttachments(attachments));
}
if (groupId != null) {
TextSecureGroup group = TextSecureGroup.newBuilder(TextSecureGroup.Type.DELIVER)
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
.withId(groupId)
.build();
messageBuilder.asGroupMessage(group);
}
TextSecureDataMessage message = messageBuilder.build();
SignalServiceDataMessage message = messageBuilder.build();
sendMessage(message, groupStore.getGroup(groupId).members);
}
public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions {
TextSecureGroup group = TextSecureGroup.newBuilder(TextSecureGroup.Type.QUIT)
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.QUIT)
.withId(groupId)
.build();
TextSecureDataMessage message = TextSecureDataMessage.newBuilder()
SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
.asGroupMessage(group)
.build();
@ -339,7 +339,7 @@ class Manager implements TextSecure {
}
}
TextSecureGroup.Builder group = TextSecureGroup.newBuilder(TextSecureGroup.Type.UPDATE)
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.UPDATE)
.withId(g.groupId)
.withName(g.name)
.withMembers(new ArrayList<>(g.members));
@ -356,7 +356,7 @@ class Manager implements TextSecure {
groupStore.updateGroup(g);
TextSecureDataMessage message = TextSecureDataMessage.newBuilder()
SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
.asGroupMessage(group.build())
.build();
@ -376,30 +376,30 @@ class Manager implements TextSecure {
public void sendMessage(String messageText, List<String> attachments,
List<String> recipients)
throws IOException, EncapsulatedExceptions, AttachmentInvalidException {
final TextSecureDataMessage.Builder messageBuilder = TextSecureDataMessage.newBuilder().withBody(messageText);
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
if (attachments != null) {
messageBuilder.withAttachments(getTextSecureAttachments(attachments));
messageBuilder.withAttachments(getSignalServiceAttachments(attachments));
}
TextSecureDataMessage message = messageBuilder.build();
SignalServiceDataMessage message = messageBuilder.build();
sendMessage(message, recipients);
}
@Override
public void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions {
TextSecureDataMessage message = TextSecureDataMessage.newBuilder()
SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
.asEndSessionMessage()
.build();
sendMessage(message, recipients);
}
private void sendMessage(TextSecureDataMessage message, Collection<String> recipients)
private void sendMessage(SignalServiceDataMessage message, Collection<String> recipients)
throws IOException, EncapsulatedExceptions {
TextSecureMessageSender messageSender = new TextSecureMessageSender(URL, TRUST_STORE, username, password,
axolotlStore, USER_AGENT, Optional.<TextSecureMessageSender.EventListener>absent());
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, username, password,
axolotlStore, USER_AGENT, Optional.<SignalServiceMessageSender.EventListener>absent());
Set<TextSecureAddress> recipientsTS = new HashSet<>(recipients.size());
Set<SignalServiceAddress> recipientsTS = new HashSet<>(recipients.size());
for (String recipient : recipients) {
try {
recipientsTS.add(getPushAddress(recipient));
@ -414,15 +414,15 @@ class Manager implements TextSecure {
messageSender.sendMessage(new ArrayList<>(recipientsTS), message);
if (message.isEndSession()) {
for (TextSecureAddress recipient : recipientsTS) {
for (SignalServiceAddress recipient : recipientsTS) {
handleEndSession(recipient.getNumber());
}
}
save();
}
private TextSecureContent decryptMessage(TextSecureEnvelope envelope) {
TextSecureCipher cipher = new TextSecureCipher(new TextSecureAddress(username), axolotlStore);
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) {
SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(username), axolotlStore);
try {
return cipher.decrypt(envelope);
} catch (Exception e) {
@ -437,19 +437,19 @@ class Manager implements TextSecure {
}
public interface ReceiveMessageHandler {
void handleMessage(TextSecureEnvelope envelope, TextSecureContent decryptedContent, GroupInfo group);
void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, GroupInfo group);
}
public void receiveMessages(int timeoutSeconds, boolean returnOnTimeout, ReceiveMessageHandler handler) throws IOException {
final TextSecureMessageReceiver messageReceiver = new TextSecureMessageReceiver(URL, TRUST_STORE, username, password, signalingKey, USER_AGENT);
TextSecureMessagePipe messagePipe = null;
final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(URL, TRUST_STORE, username, password, signalingKey, USER_AGENT);
SignalServiceMessagePipe messagePipe = null;
try {
messagePipe = messageReceiver.createMessagePipe();
while (true) {
TextSecureEnvelope envelope;
TextSecureContent content = null;
SignalServiceEnvelope envelope;
SignalServiceContent content = null;
GroupInfo group = null;
try {
envelope = messagePipe.read(timeoutSeconds, TimeUnit.SECONDS);
@ -457,9 +457,9 @@ class Manager implements TextSecure {
content = decryptMessage(envelope);
if (content != null) {
if (content.getDataMessage().isPresent()) {
TextSecureDataMessage message = content.getDataMessage().get();
SignalServiceDataMessage message = content.getDataMessage().get();
if (message.getGroupInfo().isPresent()) {
TextSecureGroup groupInfo = message.getGroupInfo().get();
SignalServiceGroup groupInfo = message.getGroupInfo().get();
switch (groupInfo.getType()) {
case UPDATE:
try {
@ -469,7 +469,7 @@ class Manager implements TextSecure {
}
if (groupInfo.getAvatar().isPresent()) {
TextSecureAttachment avatar = groupInfo.getAvatar().get();
SignalServiceAttachment avatar = groupInfo.getAvatar().get();
if (avatar.isPointer()) {
long avatarId = avatar.asPointer().getId();
try {
@ -510,7 +510,7 @@ class Manager implements TextSecure {
handleEndSession(envelope.getSource());
}
if (message.getAttachments().isPresent()) {
for (TextSecureAttachment attachment : message.getAttachments().get()) {
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
if (attachment.isPointer()) {
try {
retrieveAttachment(attachment.asPointer());
@ -542,8 +542,8 @@ class Manager implements TextSecure {
return new File(attachmentsPath, attachmentId + "");
}
private File retrieveAttachment(TextSecureAttachmentPointer pointer) throws IOException, InvalidMessageException {
final TextSecureMessageReceiver messageReceiver = new TextSecureMessageReceiver(URL, TRUST_STORE, username, password, signalingKey, USER_AGENT);
private File retrieveAttachment(SignalServiceAttachmentPointer pointer) throws IOException, InvalidMessageException {
final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(URL, TRUST_STORE, username, password, signalingKey, USER_AGENT);
File tmpFile = File.createTempFile("ts_attach_" + pointer.getId(), ".tmp");
InputStream input = messageReceiver.retrieveAttachment(pointer, tmpFile);
@ -594,9 +594,9 @@ class Manager implements TextSecure {
return PhoneNumberFormatter.formatNumber(number, localNumber);
}
private TextSecureAddress getPushAddress(String number) throws InvalidNumberException {
private SignalServiceAddress getPushAddress(String number) throws InvalidNumberException {
String e164number = canonicalizeNumber(number);
return new TextSecureAddress(e164number);
return new SignalServiceAddress(e164number);
}
@Override

View file

@ -1,6 +1,6 @@
package org.asamk.textsecure;
import org.whispersystems.textsecure.api.push.TrustStore;
import org.whispersystems.signalservice.api.push.TrustStore;
import java.io.InputStream;