prepareMessageMedia before we encrypt
and fail more nicely when pdu composition fails // FREEBIE Closes #2338
This commit is contained in:
parent
156cb4034e
commit
d41efdbd1c
2 changed files with 16 additions and 5 deletions
|
@ -8,6 +8,7 @@ import org.thoughtcrime.securesms.protocol.WirePrefix;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
|
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
||||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||||
|
@ -84,7 +85,7 @@ public class MmsCipher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SendReq encrypt(Context context, SendReq message)
|
public SendReq encrypt(Context context, SendReq message)
|
||||||
throws NoSessionException, RecipientFormattingException
|
throws NoSessionException, RecipientFormattingException, UndeliverableMessageException
|
||||||
{
|
{
|
||||||
EncodedStringValue[] encodedRecipient = message.getTo();
|
EncodedStringValue[] encodedRecipient = message.getTo();
|
||||||
String recipientString = encodedRecipient[0].getString();
|
String recipientString = encodedRecipient[0].getString();
|
||||||
|
@ -92,6 +93,10 @@ public class MmsCipher {
|
||||||
long recipientId = recipients.getPrimaryRecipient().getRecipientId();
|
long recipientId = recipients.getPrimaryRecipient().getRecipientId();
|
||||||
byte[] pduBytes = new PduComposer(context, message).make();
|
byte[] pduBytes = new PduComposer(context, message).make();
|
||||||
|
|
||||||
|
if (pduBytes == null) {
|
||||||
|
throw new UndeliverableMessageException("PDU composition failed, null payload");
|
||||||
|
}
|
||||||
|
|
||||||
if (!axolotlStore.containsSession(recipientId, PushAddress.DEFAULT_DEVICE_ID)) {
|
if (!axolotlStore.containsSession(recipientId, PushAddress.DEFAULT_DEVICE_ID)) {
|
||||||
throw new NoSessionException("No session for: " + recipientId);
|
throw new NoSessionException("No session for: " + recipientId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,8 @@ public class MmsSendJob extends SendJob {
|
||||||
String number = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
|
String number = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
|
||||||
boolean upgradedSecure = false;
|
boolean upgradedSecure = false;
|
||||||
|
|
||||||
|
prepareMessageMedia(masterSecret, message, MediaConstraints.MMS_CONSTRAINTS, true);
|
||||||
|
|
||||||
if (MmsDatabase.Types.isSecureType(message.getDatabaseMessageBox())) {
|
if (MmsDatabase.Types.isSecureType(message.getDatabaseMessageBox())) {
|
||||||
message = getEncryptedMessage(masterSecret, message);
|
message = getEncryptedMessage(masterSecret, message);
|
||||||
upgradedSecure = true;
|
upgradedSecure = true;
|
||||||
|
@ -158,10 +160,14 @@ public class MmsSendJob extends SendJob {
|
||||||
message.setFrom(new EncodedStringValue(number));
|
message.setFrom(new EncodedStringValue(number));
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareMessageMedia(masterSecret, message, MediaConstraints.MMS_CONSTRAINTS, true);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OutgoingMmsConnection connection = new OutgoingMmsConnection(context, radio.getApnInformation(), new PduComposer(context, message).make());
|
byte[] pdu = new PduComposer(context, message).make();
|
||||||
|
|
||||||
|
if (pdu == null) {
|
||||||
|
throw new UndeliverableMessageException("PDU composition failed, null payload");
|
||||||
|
}
|
||||||
|
|
||||||
|
OutgoingMmsConnection connection = new OutgoingMmsConnection(context, radio.getApnInformation(), pdu);
|
||||||
SendConf conf = connection.send(usingMmsRadio, useProxy);
|
SendConf conf = connection.send(usingMmsRadio, useProxy);
|
||||||
|
|
||||||
if (conf == null) {
|
if (conf == null) {
|
||||||
|
@ -179,7 +185,7 @@ public class MmsSendJob extends SendJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SendReq getEncryptedMessage(MasterSecret masterSecret, SendReq pdu)
|
private SendReq getEncryptedMessage(MasterSecret masterSecret, SendReq pdu)
|
||||||
throws InsecureFallbackApprovalException
|
throws InsecureFallbackApprovalException, UndeliverableMessageException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
MmsCipher cipher = new MmsCipher(new TextSecureAxolotlStore(context, masterSecret));
|
MmsCipher cipher = new MmsCipher(new TextSecureAxolotlStore(context, masterSecret));
|
||||||
|
|
Loading…
Add table
Reference in a new issue