mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 10:47:46 +00:00
Fix bugs in multi device pairing.
This commit is contained in:
parent
be9afa243c
commit
8e495d087b
@ -994,6 +994,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
|
||||
private void handleTextMessage(@NonNull SignalServiceDataMessage message, @NonNull IncomingTextMessage textMessage, @NonNull Optional<Long> smsMessageId, @NonNull Optional<Long> messageServerIDOrNull) {
|
||||
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
||||
|
||||
// Ignore the message if the body is empty
|
||||
if (textMessage.getMessageBody().length() == 0) { return; }
|
||||
|
||||
// Insert the message into the database
|
||||
Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage);
|
||||
|
||||
Long threadId;
|
||||
@ -1065,7 +1070,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
return;
|
||||
}
|
||||
|
||||
if (LokiDeviceLinkingSession.Companion.getShared().isListeningForLinkingRequest()) {
|
||||
if (!LokiDeviceLinkingSession.Companion.getShared().isListeningForLinkingRequest()) {
|
||||
Log.w("Loki", "Received authorisation but device is not is listening.");
|
||||
return;
|
||||
}
|
||||
@ -1074,15 +1079,15 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
if (authorisation.getType() != LokiPairingAuthorisation.Type.GRANT) { return; }
|
||||
Log.d("Loki", "Receiving pairing authorisation from: " + authorisation.getPrimaryDevicePubKey());
|
||||
|
||||
// Send out accept event
|
||||
LokiDeviceLinkingSession.Companion.getShared().acceptedLinkingRequest(authorisation);
|
||||
|
||||
// Set the current device as secondary and update our authorisations
|
||||
String ourNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
DatabaseFactory.getLokiAPIDatabase(context).removePairingAuthorisations(ourNumber);
|
||||
DatabaseFactory.getLokiAPIDatabase(context).insertOrUpdatePairingAuthorisation(authorisation);
|
||||
TextSecurePreferences.setIsSecondaryDevice(context, true);
|
||||
|
||||
// Send out accept event
|
||||
LokiDeviceLinkingSession.Companion.getShared().acceptedLinkingRequest(authorisation);
|
||||
|
||||
// Send a background message to the primary device
|
||||
sendBackgroundMessage(authorisation.getPrimaryDevicePubKey());
|
||||
|
||||
|
@ -12,7 +12,6 @@ import org.whispersystems.signalservice.loki.api.LokiStorageAPI
|
||||
import org.whispersystems.signalservice.loki.utilities.retryIfNeeded
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
|
||||
|
||||
class DeviceLinkingDialog private constructor(private val context: Context, private val mode: DeviceLinkingView.Mode, private val delegate: DeviceLinkingDialogDelegate? = null): DeviceLinkingViewDelegate, LokiDeviceLinkingSessionListener {
|
||||
private lateinit var view: DeviceLinkingView
|
||||
private lateinit var dialog: AlertDialog
|
||||
@ -56,7 +55,7 @@ class DeviceLinkingDialog private constructor(private val context: Context, priv
|
||||
// region Dialog View Delegate
|
||||
override fun authorise(pairing: LokiPairingAuthorisation): Boolean {
|
||||
val signedAuthorisation = pairing.sign(LokiPairingAuthorisation.Type.GRANT, userPrivateKey)
|
||||
if (signedAuthorisation == null) {
|
||||
if (signedAuthorisation == null || signedAuthorisation.type != LokiPairingAuthorisation.Type.GRANT) {
|
||||
Log.e("Loki", "Failed to sign grant authorisation")
|
||||
return false
|
||||
}
|
||||
|
@ -134,7 +134,8 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
||||
|
||||
fun onDeviceLinkAuthorized(authorisation: LokiPairingAuthorisation) {
|
||||
// To be called when a device link was accepted by the primary device
|
||||
if (mode == Mode.Master || authorisation != pairingAuthorisation) { return }
|
||||
if (mode == Mode.Master || pairingAuthorisation != null) { return }
|
||||
pairingAuthorisation = authorisation
|
||||
|
||||
spinner.visibility = View.GONE
|
||||
val titleTextViewLayoutParams = titleTextView.layoutParams as LayoutParams
|
||||
@ -148,6 +149,7 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
||||
titleTextView.text = resources.getString(R.string.view_device_linking_title_4)
|
||||
mnemonicTextView.visibility = View.GONE
|
||||
buttonContainer.visibility = View.GONE
|
||||
cancelButton.visibility = View.GONE
|
||||
|
||||
Handler().postDelayed({
|
||||
delegate.handleDeviceLinkAuthorized()
|
||||
|
@ -154,7 +154,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
|
||||
override fun getPairingAuthorisations(pubKey: String): List<LokiPairingAuthorisation> {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.getAll(multiDeviceAuthTable, "$primaryDevice = ? OR $secondaryDevice = ?", arrayOf(pubKey)) { cursor ->
|
||||
return database.getAll(multiDeviceAuthTable, "$primaryDevice = ? OR $secondaryDevice = ?", arrayOf(pubKey, pubKey)) { cursor ->
|
||||
val primaryDevicePubKey = cursor.getString(primaryDevice)
|
||||
val secondaryDevicePubKey = cursor.getString(secondaryDevice)
|
||||
val requestSignature: ByteArray? = if (cursor.isNull(cursor.getColumnIndexOrThrow(requestSignature))) null else cursor.getBase64EncodedData(requestSignature)
|
||||
@ -175,7 +175,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
|
||||
override fun removePairingAuthorisations(pubKey: String) {
|
||||
val database = databaseHelper.readableDatabase
|
||||
database.delete(multiDeviceAuthTable, "$primaryDevice = ? OR $secondaryDevice = ?", arrayOf(pubKey))
|
||||
database.delete(multiDeviceAuthTable, "$primaryDevice = ? OR $secondaryDevice = ?", arrayOf(pubKey, pubKey))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user