Fix for fallback behavior.

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2014-12-03 14:15:54 -08:00
parent 8f79ba1dd1
commit 9d693eef30
3 changed files with 33 additions and 20 deletions

View file

@ -64,11 +64,11 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
SendReq message = database.getOutgoingMessage(masterSecret, messageId);
try {
deliver(masterSecret, message);
database.markAsPush(messageId);
database.markAsSecure(messageId);
database.markAsSent(messageId, "push".getBytes(), 0);
if (deliver(masterSecret, message)) {
database.markAsPush(messageId);
database.markAsSecure(messageId);
database.markAsSent(messageId, "push".getBytes(), 0);
}
} catch (InsecureFallbackApprovalException ifae) {
Log.w(TAG, ifae);
database.markAsPendingInsecureSmsFallback(messageId);
@ -97,7 +97,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
}
private void deliver(MasterSecret masterSecret, SendReq message)
private boolean deliver(MasterSecret masterSecret, SendReq message)
throws RetryLaterException, SecureFallbackApprovalException,
InsecureFallbackApprovalException, UntrustedIdentityException
{
@ -114,6 +114,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
TextSecureMessage mediaMessage = new TextSecureMessage(message.getSentTimestamp(), attachments, body);
messageSender.sendMessage(address, mediaMessage);
return true;
} catch (InvalidNumberException | UnregisteredUserException e) {
Log.w(TAG, e);
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
@ -123,6 +124,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
else throw new RetryLaterException(e);
}
return false;
}
private void fallbackOrAskApproval(MasterSecret masterSecret, SendReq mediaMessage, String destination)

View file

@ -49,16 +49,23 @@ public abstract class PushSendJob extends MasterSecretJob {
}
protected static boolean isSmsFallbackSupported(Context context, String destination) {
if (GroupUtil.isEncodedGroup(destination)) {
try {
String e164number = Util.canonicalizeNumber(context, destination);
if (GroupUtil.isEncodedGroup(e164number)) {
return false;
}
if (!TextSecurePreferences.isFallbackSmsAllowed(context)) {
return false;
}
TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
return directory.isSmsFallbackSupported(e164number);
} catch (InvalidNumberException e) {
Log.w(TAG, e);
return false;
}
if (!TextSecurePreferences.isFallbackSmsAllowed(context)) {
return false;
}
TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
return directory.isSmsFallbackSupported(destination);
}
protected PushAddress getPushAddress(Recipient recipient) throws InvalidNumberException {

View file

@ -59,11 +59,11 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
try {
Log.w(TAG, "Sending message: " + messageId);
deliver(masterSecret, record, destination);
database.markAsPush(messageId);
database.markAsSecure(messageId);
database.markAsSent(messageId);
if (deliver(masterSecret, record, destination)) {
database.markAsPush(messageId);
database.markAsSecure(messageId);
database.markAsSent(messageId);
}
} catch (InsecureFallbackApprovalException e) {
Log.w(TAG, e);
database.markAsPendingInsecureSmsFallback(record.getId());
@ -97,7 +97,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
}
private void deliver(MasterSecret masterSecret, SmsMessageRecord message, String destination)
private boolean deliver(MasterSecret masterSecret, SmsMessageRecord message, String destination)
throws UntrustedIdentityException, SecureFallbackApprovalException,
InsecureFallbackApprovalException, RetryLaterException
{
@ -114,6 +114,8 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
messageSender.sendMessage(address, new TextSecureMessage(message.getDateSent(), null,
message.getBody().getBody()));
}
return true;
} catch (InvalidNumberException | UnregisteredUserException e) {
Log.w(TAG, e);
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
@ -123,6 +125,8 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
else throw new RetryLaterException(e);
}
return false;
}
private void fallbackOrAskApproval(MasterSecret masterSecret, SmsMessageRecord smsMessage, String destination)