mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 06:02:22 +00:00
Update to latest version of libtextsecure for simplified interface.
1) Switch to new TextSecureAddress addressing, rather than mixing long-based recipient IDs into libtextsecure. 2) Get rid of RecipientFormattingException throws in calls to RecipientFactory. Closes #2570
This commit is contained in:
@@ -72,13 +72,9 @@ public class AvatarDownloadJob extends MasterSecretJob {
|
||||
|
||||
database.updateAvatar(groupId, avatar);
|
||||
|
||||
try {
|
||||
Recipient groupRecipient = RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(groupId), true)
|
||||
.getPrimaryRecipient();
|
||||
groupRecipient.setContactPhoto(avatar);
|
||||
} catch (RecipientFormattingException e) {
|
||||
Log.w("AvatarDownloader", e);
|
||||
}
|
||||
Recipient groupRecipient = RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(groupId), true)
|
||||
.getPrimaryRecipient();
|
||||
groupRecipient.setContactPhoto(avatar);
|
||||
}
|
||||
} catch (InvalidMessageException | BitmapDecodingException | NonSuccessfulResponseCodeException e) {
|
||||
Log.w(TAG, e);
|
||||
|
||||
@@ -3,9 +3,11 @@ package org.thoughtcrime.securesms.jobs;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
||||
import org.whispersystems.textsecure.api.push.TextSecureAddress;
|
||||
import org.whispersystems.textsecure.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
@@ -46,7 +48,7 @@ public class DeliveryReceiptJob extends ContextJob implements InjectableType {
|
||||
public void onRun() throws IOException {
|
||||
Log.w("DeliveryReceiptJob", "Sending delivery receipt...");
|
||||
TextSecureMessageSender messageSender = messageSenderFactory.create(null);
|
||||
TextSecureAddress textSecureAddress = new TextSecureAddress(-1, destination, relay);
|
||||
TextSecureAddress textSecureAddress = new TextSecureAddress(destination, Optional.fromNullable(relay));
|
||||
|
||||
messageSender.sendDeliveryReceipt(textSecureAddress, timestamp);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.libaxolotl.AxolotlAddress;
|
||||
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
@@ -98,15 +99,13 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
|
||||
private void handleMessage(MasterSecret masterSecret, TextSecureEnvelope envelope, long smsMessageId) {
|
||||
try {
|
||||
Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
|
||||
long recipientId = recipients.getPrimaryRecipient().getRecipientId();
|
||||
int deviceId = envelope.getSourceDevice();
|
||||
AxolotlStore axolotlStore = new TextSecureAxolotlStore(context, masterSecret);
|
||||
TextSecureCipher cipher = new TextSecureCipher(axolotlStore, recipientId, deviceId);
|
||||
TextSecureCipher cipher = new TextSecureCipher(axolotlStore, new AxolotlAddress(envelope.getSource(), deviceId));
|
||||
|
||||
TextSecureMessage message = cipher.decrypt(envelope);
|
||||
|
||||
if (message.isEndSession()) handleEndSessionMessage(masterSecret, recipientId, envelope, message, smsMessageId);
|
||||
if (message.isEndSession()) handleEndSessionMessage(masterSecret, envelope, message, smsMessageId);
|
||||
else if (message.isGroupUpdate()) handleGroupMessage(masterSecret, envelope, message, smsMessageId);
|
||||
else if (message.getAttachments().isPresent()) handleMediaMessage(masterSecret, envelope, message, smsMessageId);
|
||||
else handleTextMessage(masterSecret, envelope, message, smsMessageId);
|
||||
@@ -117,7 +116,7 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
} catch (InvalidVersionException e) {
|
||||
Log.w(TAG, e);
|
||||
handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
|
||||
} catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException | RecipientFormattingException e) {
|
||||
} catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException e) {
|
||||
Log.w(TAG, e);
|
||||
handleCorruptMessage(masterSecret, envelope, smsMessageId);
|
||||
} catch (NoSessionException e) {
|
||||
@@ -135,9 +134,8 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEndSessionMessage(MasterSecret masterSecret, long recipientId,
|
||||
TextSecureEnvelope envelope, TextSecureMessage message,
|
||||
long smsMessageId)
|
||||
private void handleEndSessionMessage(MasterSecret masterSecret, TextSecureEnvelope envelope,
|
||||
TextSecureMessage message, long smsMessageId)
|
||||
{
|
||||
EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
|
||||
IncomingTextMessage incomingTextMessage = new IncomingTextMessage(envelope.getSource(),
|
||||
@@ -157,7 +155,7 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
}
|
||||
|
||||
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
|
||||
sessionStore.deleteAllSessions(recipientId);
|
||||
sessionStore.deleteAllSessions(envelope.getSource());
|
||||
|
||||
SecurityEvent.broadcastSecurityUpdateEvent(context, threadId);
|
||||
MessageNotifier.updateNotification(context, masterSecret, threadId);
|
||||
@@ -309,7 +307,7 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
database.markAsPreKeyBundle(smsMessageId);
|
||||
database.addMismatchedIdentity(smsMessageId, recipientId, identityKey);
|
||||
}
|
||||
} catch (RecipientFormattingException | InvalidMessageException | InvalidVersionException e) {
|
||||
} catch (InvalidMessageException | InvalidVersionException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
|
||||
@Override
|
||||
public void onSend(MasterSecret masterSecret)
|
||||
throws MmsException, IOException, NoSuchMessageException, RecipientFormattingException
|
||||
throws MmsException, IOException, NoSuchMessageException
|
||||
{
|
||||
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
||||
SendReq message = database.getOutgoingMessage(masterSecret, messageId);
|
||||
@@ -164,7 +164,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
List<TextSecureAddress> addresses = new LinkedList<>();
|
||||
|
||||
for (Recipient recipient : recipients.getRecipientsList()) {
|
||||
addresses.add(getPushAddress(recipient));
|
||||
addresses.add(getPushAddress(recipient.getNumber()));
|
||||
}
|
||||
|
||||
return addresses;
|
||||
@@ -172,7 +172,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
|
||||
private List<TextSecureAddress> getPushAddresses(long filterRecipientId) throws InvalidNumberException {
|
||||
List<TextSecureAddress> addresses = new LinkedList<>();
|
||||
addresses.add(getPushAddress(RecipientFactory.getRecipientForId(context, filterRecipientId, false)));
|
||||
addresses.add(getPushAddress(RecipientFactory.getRecipientForId(context, filterRecipientId, false).getNumber()));
|
||||
return addresses;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore;
|
||||
import org.thoughtcrime.securesms.crypto.SessionUtil;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||
@@ -14,13 +14,11 @@ import org.thoughtcrime.securesms.mms.MediaConstraints;
|
||||
import org.thoughtcrime.securesms.mms.PartParser;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException;
|
||||
import org.thoughtcrime.securesms.transport.RetryLaterException;
|
||||
import org.thoughtcrime.securesms.transport.SecureFallbackApprovalException;
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||
import org.whispersystems.libaxolotl.state.AxolotlStore;
|
||||
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
||||
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureAttachment;
|
||||
@@ -62,7 +60,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
||||
@Override
|
||||
public void onSend(MasterSecret masterSecret)
|
||||
throws RetryLaterException, MmsException, NoSuchMessageException,
|
||||
UndeliverableMessageException, RecipientFormattingException
|
||||
UndeliverableMessageException
|
||||
{
|
||||
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
||||
SendReq message = database.getOutgoingMessage(masterSecret, messageId);
|
||||
@@ -117,8 +115,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
||||
|
||||
try {
|
||||
prepareMessageMedia(masterSecret, message, MediaConstraints.PUSH_CONSTRAINTS, false);
|
||||
Recipients recipients = RecipientFactory.getRecipientsFromString(context, destination, false);
|
||||
TextSecureAddress address = getPushAddress(recipients.getPrimaryRecipient());
|
||||
TextSecureAddress address = getPushAddress(destination);
|
||||
List<TextSecureAttachment> attachments = getAttachments(masterSecret, message);
|
||||
String body = PartParser.getMessageText(message.getBody());
|
||||
TextSecureMessage mediaMessage = new TextSecureMessage(message.getSentTimestamp(), attachments, body);
|
||||
@@ -129,7 +126,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
||||
Log.w(TAG, e);
|
||||
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
|
||||
else database.markAsSentFailed(messageId);
|
||||
} catch (IOException | RecipientFormattingException e) {
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
|
||||
else throw new RetryLaterException(e);
|
||||
@@ -140,25 +137,18 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
||||
private void fallbackOrAskApproval(MasterSecret masterSecret, SendReq mediaMessage, String destination)
|
||||
throws SecureFallbackApprovalException, InsecureFallbackApprovalException
|
||||
{
|
||||
try {
|
||||
Recipient recipient = RecipientFactory.getRecipientsFromString(context, destination, false).getPrimaryRecipient();
|
||||
boolean isSmsFallbackApprovalRequired = isSmsFallbackApprovalRequired(destination, true);
|
||||
AxolotlStore axolotlStore = new TextSecureAxolotlStore(context, masterSecret);
|
||||
boolean isSmsFallbackApprovalRequired = isSmsFallbackApprovalRequired(destination, true);
|
||||
|
||||
if (!isSmsFallbackApprovalRequired) {
|
||||
Log.w(TAG, "Falling back to MMS");
|
||||
DatabaseFactory.getMmsDatabase(context).markAsForcedSms(mediaMessage.getDatabaseMessageId());
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new MmsSendJob(context, messageId));
|
||||
} else if (!axolotlStore.containsSession(recipient.getRecipientId(), TextSecureAddress.DEFAULT_DEVICE_ID)) {
|
||||
Log.w(TAG, "Marking message as pending insecure SMS fallback");
|
||||
throw new InsecureFallbackApprovalException("Pending user approval for fallback to insecure SMS");
|
||||
} else {
|
||||
Log.w(TAG, "Marking message as pending secure SMS fallback");
|
||||
throw new SecureFallbackApprovalException("Pending user approval for fallback secure to SMS");
|
||||
}
|
||||
} catch (RecipientFormattingException rfe) {
|
||||
Log.w(TAG, rfe);
|
||||
DatabaseFactory.getMmsDatabase(context).markAsSentFailed(messageId);
|
||||
if (!isSmsFallbackApprovalRequired) {
|
||||
Log.w(TAG, "Falling back to MMS");
|
||||
DatabaseFactory.getMmsDatabase(context).markAsForcedSms(mediaMessage.getDatabaseMessageId());
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new MmsSendJob(context, messageId));
|
||||
} else if (!SessionUtil.hasSession(context, masterSecret, destination)) {
|
||||
Log.w(TAG, "Marking message as pending insecure SMS fallback");
|
||||
throw new InsecureFallbackApprovalException("Pending user approval for fallback to insecure SMS");
|
||||
} else {
|
||||
Log.w(TAG, "Marking message as pending secure SMS fallback");
|
||||
throw new SecureFallbackApprovalException("Pending user approval for fallback secure to SMS");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
||||
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureAttachment;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureAttachmentStream;
|
||||
import org.whispersystems.textsecure.api.push.TextSecureAddress;
|
||||
@@ -76,10 +76,10 @@ public abstract class PushSendJob extends SendJob {
|
||||
}
|
||||
}
|
||||
|
||||
protected TextSecureAddress getPushAddress(Recipient recipient) throws InvalidNumberException {
|
||||
String e164number = Util.canonicalizeNumber(context, recipient.getNumber());
|
||||
protected TextSecureAddress getPushAddress(String number) throws InvalidNumberException {
|
||||
String e164number = Util.canonicalizeNumber(context, number);
|
||||
String relay = TextSecureDirectory.getInstance(context).getRelay(e164number);
|
||||
return new TextSecureAddress(recipient.getRecipientId(), e164number, relay);
|
||||
return new TextSecureAddress(e164number, Optional.fromNullable(relay));
|
||||
}
|
||||
|
||||
protected boolean isSmsFallbackApprovalRequired(String destination, boolean media) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore;
|
||||
import org.thoughtcrime.securesms.crypto.SessionUtil;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.EncryptingSmsDatabase;
|
||||
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||
@@ -15,12 +15,10 @@ import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException;
|
||||
import org.thoughtcrime.securesms.transport.RetryLaterException;
|
||||
import org.thoughtcrime.securesms.transport.SecureFallbackApprovalException;
|
||||
import org.whispersystems.libaxolotl.state.AxolotlStore;
|
||||
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
||||
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureMessage;
|
||||
@@ -55,7 +53,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException, RecipientFormattingException {
|
||||
public void onSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
|
||||
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
|
||||
SmsMessageRecord record = database.getMessage(masterSecret, messageId);
|
||||
String destination = record.getIndividualRecipient().getNumber();
|
||||
@@ -111,7 +109,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
||||
boolean isSmsFallbackSupported = isSmsFallbackSupported(context, destination, false);
|
||||
|
||||
try {
|
||||
TextSecureAddress address = getPushAddress(message.getIndividualRecipient());
|
||||
TextSecureAddress address = getPushAddress(message.getIndividualRecipient().getNumber());
|
||||
TextSecureMessageSender messageSender = messageSenderFactory.create(masterSecret);
|
||||
|
||||
if (message.isEndSession()) {
|
||||
@@ -138,15 +136,14 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
||||
private void fallbackOrAskApproval(MasterSecret masterSecret, SmsMessageRecord smsMessage, String destination)
|
||||
throws SecureFallbackApprovalException, InsecureFallbackApprovalException
|
||||
{
|
||||
Recipient recipient = smsMessage.getIndividualRecipient();
|
||||
boolean isSmsFallbackApprovalRequired = isSmsFallbackApprovalRequired(destination, false);
|
||||
AxolotlStore axolotlStore = new TextSecureAxolotlStore(context, masterSecret);
|
||||
Recipient recipient = smsMessage.getIndividualRecipient();
|
||||
boolean isSmsFallbackApprovalRequired = isSmsFallbackApprovalRequired(destination, false);
|
||||
|
||||
if (!isSmsFallbackApprovalRequired) {
|
||||
Log.w(TAG, "Falling back to SMS");
|
||||
DatabaseFactory.getSmsDatabase(context).markAsForcedSms(smsMessage.getId());
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new SmsSendJob(context, messageId, destination));
|
||||
} else if (!axolotlStore.containsSession(recipient.getRecipientId(), TextSecureAddress.DEFAULT_DEVICE_ID)) {
|
||||
} else if (!SessionUtil.hasSession(context, masterSecret, recipient)) {
|
||||
Log.w(TAG, "Marking message as pending insecure fallback.");
|
||||
throw new InsecureFallbackApprovalException("Pending user approval for fallback to insecure SMS");
|
||||
} else {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SmsSentJob extends MasterSecretJob {
|
||||
if (record != null && record.isEndSession()) {
|
||||
Log.w(TAG, "Ending session...");
|
||||
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
|
||||
sessionStore.deleteAllSessions(record.getIndividualRecipient().getRecipientId());
|
||||
sessionStore.deleteAllSessions(record.getIndividualRecipient().getNumber());
|
||||
SecurityEvent.broadcastSecurityUpdateEvent(context, record.getThreadId());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user