Merge branch 'dev' of https://github.com/loki-project/session-android into restoration-fix

This commit is contained in:
Ryan ZHAO 2020-08-21 15:42:24 +10:00
commit 8a125244f6
5 changed files with 31 additions and 10 deletions

View File

@ -185,8 +185,8 @@ dependencies {
implementation "com.opencsv:opencsv:4.6"
}
def canonicalVersionCode = 69
def canonicalVersionName = "1.4.2"
def canonicalVersionCode = 70
def canonicalVersionName = "1.4.3"
def postFixSize = 10
def abiPostFix = ['armeabi-v7a' : 1,

View File

@ -1387,7 +1387,7 @@
<string name="fragment_view_my_qr_code_explanation">این کد QR شماست. سایر کاربران می‌توانند برای شروع Session با شما آن را اسکن کنند.</string>
<string name="fragment_view_my_qr_code_share_title">کد QR را به اشتراک بگذارید</string>
<string name="session_reset_banner_message">آیا می‌خواهید Session خود را با آن بازیابی کنید s% ؟</string>
<string name="session_reset_banner_message">آیا می‌خواهید Session خود را با آن بازیابی کنید %s ؟</string>
<string name="session_reset_banner_dismiss_button_title">رد</string>
<string name="session_reset_banner_restore_button_title">بازیابی</string>

View File

@ -446,7 +446,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
});
sessionRestoreBannerView.setOnRestore(() -> {
SessionManagementProtocol.startSessionReset(this, recipient, threadId);
SessionManagementProtocol.startSessionReset(this, recipient.getAddress().serialize());
updateSessionRestoreBanner();
return Unit.INSTANCE;
});

View File

@ -98,6 +98,7 @@ import org.thoughtcrime.securesms.util.Hex;
import org.thoughtcrime.securesms.util.IdentityUtil;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.loki.SessionResetProtocol;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.util.guava.Optional;
@ -354,14 +355,14 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
} catch (ProtocolInvalidMessageException e) {
Log.w(TAG, e);
if (!isPushNotification) { // This can be triggered if a PN encrypted with an old session comes in after the user performed a session reset
handleCorruptMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId);
handleCorruptMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId, e);
}
} catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolUntrustedIdentityException e) {
Log.w(TAG, e);
handleCorruptMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId);
handleCorruptMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId, e);
} catch (StorageFailedException e) {
Log.w(TAG, e);
handleCorruptMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId);
handleCorruptMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId, e);
} catch (ProtocolNoSessionException e) {
Log.w(TAG, e);
handleNoSessionMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId);
@ -1069,7 +1070,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
}
private void handleCorruptMessage(@NonNull String sender, int senderDevice, long timestamp,
@NonNull Optional<Long> smsMessageId)
@NonNull Optional<Long> smsMessageId, @NonNull Throwable e)
{
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
if (SessionMetaProtocol.shouldErrorMessageShow(context, timestamp)) {
@ -1084,6 +1085,22 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
smsDatabase.markAsDecryptFailed(smsMessageId.get());
}
}
// FIXME: This is a temporary patch for bad mac issues. At least with this people will be able to message again. We have to figure out the root cause of the issue though.
if (e.getCause() != null) {
Throwable e2 = e.getCause();
if (e2.getCause() != null) {
Throwable e3 = e2.getCause();
if (e3 instanceof InvalidMessageException) {
String message = e3.getMessage();
if (message != null && message.startsWith("Bad Mac!")) {
SessionManagementProtocol.startSessionReset(context, sender);
return; // Don't trigger the session restoration UI
}
}
}
}
SessionManagementProtocol.triggerSessionRestorationUI(context, sender, timestamp);
}

View File

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.loki.protocol
import android.content.Context
import android.os.AsyncTask
import android.util.Log
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
@ -23,15 +24,18 @@ import java.util.*
object SessionManagementProtocol {
@JvmStatic
fun startSessionReset(context: Context, recipient: Recipient, threadID: Long) {
fun startSessionReset(context: Context, publicKey: String) {
val recipient = recipient(context, publicKey)
if (recipient.isGroupRecipient) { return }
val lokiThreadDB = DatabaseFactory.getLokiThreadDatabase(context)
val smsDB = DatabaseFactory.getSmsDatabase(context)
if (lokiThreadDB.getSessionResetStatus(publicKey) != SessionResetStatus.NONE) { return }
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient)
val devices = lokiThreadDB.getSessionRestoreDevices(threadID)
for (device in devices) {
val endSessionMessage = OutgoingEndSessionMessage(OutgoingTextMessage(recipient, "TERMINATE", 0, -1))
MessageSender.send(context, endSessionMessage, threadID, false, null)
}
val smsDB = DatabaseFactory.getSmsDatabase(context)
val infoMessage = OutgoingTextMessage(recipient, "", 0, 0)
val infoMessageID = smsDB.insertMessageOutbox(threadID, infoMessage, false, System.currentTimeMillis(), null)
if (infoMessageID > -1) {