Skip to content

Commit

Permalink
Merge pull request #213 from jlewis13/release_fixes
Browse files Browse the repository at this point in the history
Release fixes
  • Loading branch information
jlewis13 authored Oct 19, 2017
2 parents 7b29dbd + b114cba commit 055233f
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 216 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
compile('com.doomonafireball.betterpickers:library:1.5.3') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.github.ForstaLabs:libsignal-service-java:forsta-v2.3.1.8') {
compile('com.github.ForstaLabs:libsignal-service-java:forsta-v2.3.1.14') {
exclude group: 'org.whispersystems', module: 'curve25519-java'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
Expand Down Expand Up @@ -156,8 +156,8 @@ android {
applicationId 'io.forsta.relay'
minSdkVersion 14
targetSdkVersion 22
versionName "0.1.61"
versionCode 161
versionName "0.1.62"
versionCode 162
multiDexEnabled true
buildConfigField "long", "BUILD_TIMESTAMP", getLastCommitTimestamp() + "L"
resValue "string", "forsta_authorities", applicationId + '.provider.ccsm'
Expand Down
16 changes: 9 additions & 7 deletions src/io/forsta/ccsm/api/model/ForstaMessage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.forsta.ccsm.api.model;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
Expand Down Expand Up @@ -28,8 +30,10 @@
import io.forsta.ccsm.util.ForstaUtils;
import io.forsta.ccsm.util.InvalidMessagePayloadException;
import io.forsta.securesms.attachments.Attachment;
import io.forsta.securesms.attachments.DatabaseAttachment;
import io.forsta.securesms.database.DatabaseFactory;
import io.forsta.securesms.database.GroupDatabase;
import io.forsta.securesms.mms.AttachmentManager;
import io.forsta.securesms.recipients.Recipients;
import io.forsta.securesms.util.GroupUtil;
import io.forsta.securesms.util.Util;
Expand Down Expand Up @@ -68,7 +72,7 @@ public static ForstaMessage fromJsonStringOrThrows(String messageBody) throws In
ForstaMessage forstaMessage = new ForstaMessage();
try {
JSONObject jsonBody = getVersion(1, messageBody);
if (forstaMessage.isContentType(jsonBody)) {
if (jsonBody != null && forstaMessage.isContentType(jsonBody)) {
forstaMessage.threadUid = jsonBody.getString("threadId");
forstaMessage.messageId = jsonBody.getString("messageId");
if (jsonBody.has("threadTitle")) {
Expand Down Expand Up @@ -96,15 +100,13 @@ public static ForstaMessage fromJsonStringOrThrows(String messageBody) throws In
JSONObject distribution = jsonBody.getJSONObject("distribution");
forstaMessage.universalExpression = distribution.getString("expression");
} else {
Log.w(TAG, messageBody);
throw new InvalidMessagePayloadException("Control message type");
throw new InvalidMessagePayloadException("Control message type or other");
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON message body");
Log.e(TAG, messageBody);
Log.e(TAG, "Invalid JSON message body: " + e.getMessage());
throw new InvalidMessagePayloadException(e.getMessage());
} catch (Exception e) {
Log.w(TAG, "Exception occurred");
Log.w(TAG, "Exception occurred: " + e.getMessage());
throw new InvalidMessagePayloadException(e.getMessage());
}
return forstaMessage;
Expand Down Expand Up @@ -219,7 +221,7 @@ public static String createForstaMessageBody(Context context, String richTextMes
if (attachments != null) {
for (Attachment attachment : messageAttachments) {
JSONObject attachmentJson = new JSONObject();
attachmentJson.put("name", attachment.getDataUri().getLastPathSegment());
attachmentJson.put("name", "");
attachmentJson.put("size", attachment.getSize());
attachmentJson.put("type", attachment.getContentType());
attachments.put(attachmentJson);
Expand Down
15 changes: 11 additions & 4 deletions src/io/forsta/ccsm/service/ForstaServiceAccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import android.content.Context;
import android.os.Build;
import android.util.Log;

import io.forsta.ccsm.api.CcsmApi;
import io.forsta.securesms.BuildConfig;
import io.forsta.securesms.util.TextSecurePreferences;
Expand All @@ -13,14 +15,16 @@
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import org.whispersystems.signalservice.internal.util.StaticCredentialsProvider;

import static android.content.ContentValues.TAG;

public class ForstaServiceAccountManager extends SignalServiceAccountManager {

private final TrustStore trustStore;

public ForstaServiceAccountManager(String url, TrustStore trustStore,
String addr, String password,
String number, Integer deviceId, String password,
String userAgent) {
super(url, trustStore, addr, password, userAgent);
super(url, trustStore, number, deviceId, password, userAgent);
this.trustStore = trustStore;
}

Expand All @@ -43,12 +47,15 @@ public void createAccount(Context context, String addr, String password,
response = CcsmApi.provisionAccount(context, attrs);
}
/* Retrofit ourself with the new datum provided here and through the provision act. */
this.user = addr + "." + response.get("deviceId");
this.user = addr;
this.deviceId = response.getInt("deviceId");
this.userAgent = userAgent;
String serverUrl = response.get("serverUrl").toString();
TextSecurePreferences.setLocalDeviceID(context, response.getInt("deviceId"));
TextSecurePreferences.setServer(context, serverUrl);
TextSecurePreferences.setUserAgent(context, userAgent);
StaticCredentialsProvider creds = new StaticCredentialsProvider(this.user, password,
String username = addr + "." + this.deviceId;
StaticCredentialsProvider creds = new StaticCredentialsProvider(username, password,
signalingKey);
this.pushServiceSocket = new PushServiceSocket(serverUrl, trustStore, creds, userAgent);
}
Expand Down
23 changes: 12 additions & 11 deletions src/io/forsta/securesms/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,20 +900,20 @@ public void onReceive(Context context, Intent intent) {
recipientsStaleReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.w(TAG, "Group update received...");
if (recipients != null) {
long[] ids = recipients.getIds();
Log.w(TAG, "Looking up new recipients...");
recipients = RecipientFactory.getRecipientsForIds(context, ids, true);
recipients.addListener(ConversationActivity.this);
onModified(recipients);
fragment.reloadList();
}
// Log.w(TAG, "Group update received...");
// if (recipients != null) {
// long[] ids = recipients.getIds();
// Log.w(TAG, "Looking up new recipients...");
// recipients = RecipientFactory.getRecipientsForIds(context, ids, true);
// recipients.addListener(ConversationActivity.this);
// onModified(recipients);
// fragment.reloadList();
// }
}
};

IntentFilter staleFilter = new IntentFilter();
staleFilter.addAction(GroupDatabase.DATABASE_UPDATE_ACTION);
// staleFilter.addAction(GroupDatabase.DATABASE_UPDATE_ACTION);
staleFilter.addAction(RecipientFactory.RECIPIENT_CLEAR_ACTION);

registerReceiver(securityUpdateReceiver,
Expand Down Expand Up @@ -1161,7 +1161,7 @@ private void sendMediaMessage(final boolean forceSms, final long expiresIn, fina
sendMediaMessage(forceSms, getMessage(), attachmentManager.buildSlideDeck(), expiresIn, subscriptionId);
}

private ListenableFuture<Void> sendMediaMessage(final boolean forceSms, String body, SlideDeck slideDeck, final long expiresIn, final int subscriptionId)
private ListenableFuture<Void> sendMediaMessage(final boolean forceSms, String body, final SlideDeck slideDeck, final long expiresIn, final int subscriptionId)
throws InvalidMessageException
{
final SettableFuture<Void> future = new SettableFuture<>();
Expand All @@ -1184,6 +1184,7 @@ protected Long doInBackground(OutgoingMediaMessage... messages) {
OutgoingMediaMessage message = messages[0];

ForstaThread threadData = DatabaseFactory.getThreadDatabase(context).getForstaThread(threadId);
List<Slide> slides = slideDeck.getSlides();


message.setForstaJsonBody(context, threadData);
Expand Down
16 changes: 11 additions & 5 deletions src/io/forsta/securesms/crypto/SessionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
import org.whispersystems.libsignal.state.SessionStore;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;

import java.util.List;

public class SessionUtil {

public static boolean hasSession(Context context, MasterSecret masterSecret, Recipient recipient) {
return hasSession(context, masterSecret, recipient.getNumber());
}

public static boolean hasSession(Context context, MasterSecret masterSecret, @NonNull String number) {
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(number, SignalServiceAddress.DEFAULT_DEVICE_ID);

return sessionStore.containsSession(axolotlAddress);
public static boolean hasSession(Context context, MasterSecret masterSecret, @NonNull String addr) {
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
List<Integer> devices = sessionStore.getDeviceSessions(addr);
for (int device : devices) {
if (sessionStore.containsSession(new SignalProtocolAddress(addr, device))) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public SessionRecord loadSession(SignalProtocolAddress axolotlAddress) {
}

@Override
public List<Integer> getSubDeviceSessions(String number) {
return sessionStore.getSubDeviceSessions(number);
public List<Integer> getDeviceSessions(String number) {
return sessionStore.getDeviceSessions(number);
}

@Override
Expand Down
33 changes: 18 additions & 15 deletions src/io/forsta/securesms/crypto/storage/TextSecureSessionStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,15 @@ public void deleteSession(SignalProtocolAddress address) {

@Override
public void deleteAllSessions(String name) {
List<Integer> devices = getSubDeviceSessions(name);

deleteSession(new SignalProtocolAddress(name, SignalServiceAddress.DEFAULT_DEVICE_ID));
List<Integer> devices = getDeviceSessions(name);

for (int device : devices) {
deleteSession(new SignalProtocolAddress(name, device));
}
}

@Override
public List<Integer> getSubDeviceSessions(String name) {
public List<Integer> getDeviceSessions(String name) {
long recipientId = RecipientFactory.getRecipientsFromString(context, name, true).getPrimaryRecipient().getRecipientId();
List<Integer> results = new LinkedList<>();
File parent = getSessionDirectory();
Expand All @@ -142,8 +140,13 @@ public List<Integer> getSubDeviceSessions(String name) {
String[] parts = child.split("[.]", 2);
long sessionRecipientId = Long.parseLong(parts[0]);

if (sessionRecipientId == recipientId && parts.length > 1) {
results.add(Integer.parseInt(parts[1]));
if (sessionRecipientId == recipientId) {
if (parts.length > 1) {
results.add(Integer.parseInt(parts[1]));
} else {
/* Legacy session entry that treated device id as special */
results.add(new Integer(1));
}
}
} catch (NumberFormatException e) {
Log.w(TAG, e);
Expand Down Expand Up @@ -186,13 +189,10 @@ private File getSessionDirectory() {
return directory;
}

private String getSessionName(SignalProtocolAddress axolotlAddress) {
Recipient recipient = RecipientFactory.getRecipientsFromString(context, axolotlAddress.getName(), true)
.getPrimaryRecipient();
long recipientId = recipient.getRecipientId();
int deviceId = axolotlAddress.getDeviceId();

return recipientId + (deviceId == SignalServiceAddress.DEFAULT_DEVICE_ID ? "" : "." + deviceId);
private String getSessionName(SignalProtocolAddress signalAddr) {
Recipient recipient = RecipientFactory.getRecipientsFromString(context, signalAddr.getName(), true)
.getPrimaryRecipient();
return recipient.getRecipientId() + "." + signalAddr.getDeviceId();
}

private @Nullable SignalProtocolAddress getAddressName(File sessionFile) {
Expand All @@ -202,8 +202,11 @@ private String getSessionName(SignalProtocolAddress axolotlAddress) {

int deviceId;

if (parts.length > 1) deviceId = Integer.parseInt(parts[1]);
else deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
if (parts.length > 1) {
deviceId = Integer.parseInt(parts[1]);
} else {
deviceId = 1; // Legacy session entry without device ID is 1
}

return new SignalProtocolAddress(recipient.getNumber(), deviceId);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ public List<DeviceInfo> loadInBackground() {
try {
List<DeviceInfo> devices = accountManager.getDevices();
Iterator<DeviceInfo> iterator = devices.iterator();

while (iterator.hasNext()) {
if ((iterator.next().getId() == SignalServiceAddress.DEFAULT_DEVICE_ID)) {
iterator.remove();
}
}

Collections.sort(devices, new DeviceInfoComparator());

return devices;
} catch (IOException e) {
Log.w(TAG, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public TextSecureCommunicationModule(Context context) {
return new ForstaServiceAccountManager(TextSecurePreferences.getServer(context),
new TextSecurePushTrustStore(context),
TextSecurePreferences.getLocalNumber(context),
TextSecurePreferences.getLocalDeviceId(context),
TextSecurePreferences.getPushServerPassword(context),
TextSecurePreferences.getUserAgent(context));
}
Expand All @@ -72,6 +73,7 @@ public SignalServiceMessageSender create() {
return new SignalServiceMessageSender(TextSecurePreferences.getServer(context),
new TextSecurePushTrustStore(context),
TextSecurePreferences.getLocalNumber(context),
TextSecurePreferences.getLocalDeviceId(context),
TextSecurePreferences.getPushServerPassword(context),
new SignalProtocolStoreImpl(context),
TextSecurePreferences.getUserAgent(context),
Expand Down Expand Up @@ -101,7 +103,8 @@ private DynamicCredentialsProvider(Context context) {

@Override
public String getUser() {
return TextSecurePreferences.getLocalNumber(context);
return TextSecurePreferences.getLocalNumber(context) + "." + TextSecurePreferences.getLocalDeviceId(context);

}

@Override
Expand Down
16 changes: 10 additions & 6 deletions src/io/forsta/securesms/jobs/PushDecryptJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,24 @@ private void handleMessage(MasterSecretUnion masterSecret, SignalServiceEnvelope
}
} catch (InvalidVersionException e) {
Log.w(TAG, e);
handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
// handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
} catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException e) {
Log.w(TAG, e);
handleCorruptMessage(masterSecret, envelope, smsMessageId);
// handleCorruptMessage(masterSecret, envelope, smsMessageId);
} catch (NoSessionException e) {
Log.w(TAG, e);
handleNoSessionMessage(masterSecret, envelope, smsMessageId);
// handleNoSessionMessage(masterSecret, envelope, smsMessageId);
} catch (LegacyMessageException e) {
Log.w(TAG, e);
handleLegacyMessage(masterSecret, envelope, smsMessageId);
// handleLegacyMessage(masterSecret, envelope, smsMessageId);
} catch (DuplicateMessageException e) {
Log.w(TAG, e);
handleDuplicateMessage(masterSecret, envelope, smsMessageId);
} catch (UntrustedIdentityException e) {
Log.w(TAG, e);
handleUntrustedIdentityMessage(masterSecret, envelope, smsMessageId);
// handleUntrustedIdentityMessage(masterSecret, envelope, smsMessageId);
} catch (InvalidMessagePayloadException e) {
Log.e(TAG, "Invalid Forsta message body");
Log.e(TAG, e.getMessage());
e.printStackTrace();
}
}
Expand Down Expand Up @@ -346,7 +345,12 @@ private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret,
message.getAttachments());

ForstaMessage forstaMessage = ForstaMessage.fromJsonStringOrThrows(body);

Recipients recipients = getDistributionRecipients(forstaMessage.getUniversalExpression());
DirectoryHelper.refreshDirectoryFor(context, masterSecret.getMasterSecret().get(), recipients);
// Refresh recipients cache on message receive to populate new users.
RecipientFactory.clearCache(context);
recipients = RecipientFactory.getRecipientsFromStrings(context, recipients.toNumberStringList(false), false);
long threadId = DatabaseFactory.getThreadDatabase(context).getOrAllocateThreadId(recipients, forstaMessage);

if (message.getExpiresInSeconds() != DatabaseFactory.getThreadPreferenceDatabase(context).getExpireMessages(threadId)) {
Expand Down
Loading

0 comments on commit 055233f

Please sign in to comment.