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); SendReq message = database.getOutgoingMessage(masterSecret, messageId);
try { try {
deliver(masterSecret, message); if (deliver(masterSecret, message)) {
database.markAsPush(messageId);
database.markAsPush(messageId); database.markAsSecure(messageId);
database.markAsSecure(messageId); database.markAsSent(messageId, "push".getBytes(), 0);
database.markAsSent(messageId, "push".getBytes(), 0); }
} catch (InsecureFallbackApprovalException ifae) { } catch (InsecureFallbackApprovalException ifae) {
Log.w(TAG, ifae); Log.w(TAG, ifae);
database.markAsPendingInsecureSmsFallback(messageId); 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, throws RetryLaterException, SecureFallbackApprovalException,
InsecureFallbackApprovalException, UntrustedIdentityException InsecureFallbackApprovalException, UntrustedIdentityException
{ {
@ -114,6 +114,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
TextSecureMessage mediaMessage = new TextSecureMessage(message.getSentTimestamp(), attachments, body); TextSecureMessage mediaMessage = new TextSecureMessage(message.getSentTimestamp(), attachments, body);
messageSender.sendMessage(address, mediaMessage); messageSender.sendMessage(address, mediaMessage);
return true;
} catch (InvalidNumberException | UnregisteredUserException e) { } catch (InvalidNumberException | UnregisteredUserException e) {
Log.w(TAG, e); Log.w(TAG, e);
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination); if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
@ -123,6 +124,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination); if (isSmsFallbackSupported) fallbackOrAskApproval(masterSecret, message, destination);
else throw new RetryLaterException(e); else throw new RetryLaterException(e);
} }
return false;
} }
private void fallbackOrAskApproval(MasterSecret masterSecret, SendReq mediaMessage, String destination) 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) { 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; return false;
} }
if (!TextSecurePreferences.isFallbackSmsAllowed(context)) {
return false;
}
TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
return directory.isSmsFallbackSupported(destination);
} }
protected PushAddress getPushAddress(Recipient recipient) throws InvalidNumberException { protected PushAddress getPushAddress(Recipient recipient) throws InvalidNumberException {

View File

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