mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-25 14:37:31 +00:00
Fix session handling
This commit is contained in:
parent
ecd60b8723
commit
a925b17419
@ -93,7 +93,7 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
tools:replace="android:allowBackup"
|
tools:replace="android:allowBackup"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:theme="@style/TextSecure.LightTheme"
|
android:theme="@style/TextSecure.DarkTheme"
|
||||||
android:largeHeap="true">
|
android:largeHeap="true">
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
@ -308,7 +308,7 @@
|
|||||||
|
|
||||||
<activity android:name=".RegistrationActivity"
|
<activity android:name=".RegistrationActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/TextSecure.LightRegistrationTheme"
|
android:theme="@style/TextSecure.DarkRegistrationTheme"
|
||||||
android:windowSoftInputMode="stateUnchanged"
|
android:windowSoftInputMode="stateUnchanged"
|
||||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:background="@color/white"
|
android:background="@color/loki_darkest_gray"
|
||||||
android:fillViewport="true"
|
android:fillViewport="true"
|
||||||
tools:context=".RegistrationActivity">
|
tools:context=".RegistrationActivity">
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:background="@color/loki_darkest_gray"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public class IdentityKeyUtil {
|
|||||||
save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(publicKey.serialize()));
|
save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(publicKey.serialize()));
|
||||||
save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(keyPair.getPrivateKey().serialize()));
|
save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(keyPair.getPrivateKey().serialize()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("Loki", "Couldn't restore key pair from seed due to error: " + e.getMessage());
|
Log.d("Loki", "Couldn't restore key pair from seed due to error: " + e.getMessage() + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,14 +102,12 @@ public class PreKeyUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static List<PreKeyRecord> generatePreKeys(Context context, int amount) {
|
public synchronized static List<PreKeyRecord> generatePreKeys(Context context, int amount) {
|
||||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
|
|
||||||
List<PreKeyRecord> records = new LinkedList<>();
|
List<PreKeyRecord> records = new LinkedList<>();
|
||||||
int preKeyIDOffset = TextSecurePreferences.getNextPreKeyId(context);
|
int preKeyIDOffset = TextSecurePreferences.getNextPreKeyId(context);
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
int preKeyID = (preKeyIDOffset + i) % Medium.MAX_VALUE;
|
int preKeyID = (preKeyIDOffset + i) % Medium.MAX_VALUE;
|
||||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||||
PreKeyRecord record = new PreKeyRecord(preKeyID, keyPair);
|
PreKeyRecord record = new PreKeyRecord(preKeyID, keyPair);
|
||||||
preKeyStore.storePreKey(preKeyID, record);
|
|
||||||
records.add(record);
|
records.add(record);
|
||||||
}
|
}
|
||||||
TextSecurePreferences.setNextPreKeyId(context, (preKeyIDOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
|
TextSecurePreferences.setNextPreKeyId(context, (preKeyIDOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
|
||||||
|
@ -92,8 +92,8 @@ public class TextSecureSessionStore implements LokiSessionDatabaseProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void archiveAllSessions(@NonNull String name) {
|
public void archiveAllSessions(@NonNull String hexEncodedPublicKey) {
|
||||||
SignalProtocolAddress address = new SignalProtocolAddress(name, -1);
|
SignalProtocolAddress address = new SignalProtocolAddress(hexEncodedPublicKey, -1);
|
||||||
archiveSiblingSessions(address);
|
archiveSiblingSessions(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,9 +244,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
LokiPreKeyRecordDatabase lokiPreKeyRecordDatabase = DatabaseFactory.getLokiPreKeyRecordDatabase(context);
|
LokiPreKeyRecordDatabase lokiPreKeyRecordDatabase = DatabaseFactory.getLokiPreKeyRecordDatabase(context);
|
||||||
SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber(context));
|
SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber(context));
|
||||||
LokiServiceCipher cipher = new LokiServiceCipher(localAddress, axolotlStore, lokiThreadDatabase, lokiPreKeyRecordDatabase, UnidentifiedAccessUtil.getCertificateValidator());
|
LokiServiceCipher cipher = new LokiServiceCipher(localAddress, axolotlStore, lokiThreadDatabase, lokiPreKeyRecordDatabase, UnidentifiedAccessUtil.getCertificateValidator());
|
||||||
/* Loki - Original code
|
|
||||||
SignalServiceCipher cipher = new SignalServiceCipher(localAddress, axolotlStore, UnidentifiedAccessUtil.getCertificateValidator());
|
// Loki - Handle session reset logic
|
||||||
*/
|
if (!envelope.isFriendRequest() && cipher.getSessionStatus(envelope) == null && envelope.isPreKeySignalMessage()) {
|
||||||
|
cipher.validateBackgroundMessage(envelope, envelope.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
SignalServiceContent content = cipher.decrypt(envelope);
|
SignalServiceContent content = cipher.decrypt(envelope);
|
||||||
|
|
||||||
@ -255,7 +257,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loki - Handle Loki specific logic if needed
|
// Loki - Store pre key bundle if needed
|
||||||
if (content.lokiMessage.isPresent()) {
|
if (content.lokiMessage.isPresent()) {
|
||||||
LokiServiceMessage lokiMessage = content.lokiMessage.get();
|
LokiServiceMessage lokiMessage = content.lokiMessage.get();
|
||||||
if (lokiMessage.getPreKeyBundleMessage() != null) {
|
if (lokiMessage.getPreKeyBundleMessage() != null) {
|
||||||
@ -272,6 +274,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loki - Get the sender display name if needed
|
||||||
Optional<String> senderDisplayName = content.senderDisplayName;
|
Optional<String> senderDisplayName = content.senderDisplayName;
|
||||||
if (senderDisplayName.isPresent()) {
|
if (senderDisplayName.isPresent()) {
|
||||||
DatabaseFactory.getLokiUserDisplayNameDatabase(context).setDisplayName(envelope.getSource(), senderDisplayName.get());
|
DatabaseFactory.getLokiUserDisplayNameDatabase(context).setDisplayName(envelope.getSource(), senderDisplayName.get());
|
||||||
@ -299,7 +302,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
handleNeedsDeliveryReceipt(content, message);
|
handleNeedsDeliveryReceipt(content, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loki - Handle friend request logic if needed
|
// Loki - Handle friend request logic
|
||||||
handleFriendRequestIfNeeded(envelope, content, message);
|
handleFriendRequestIfNeeded(envelope, content, message);
|
||||||
} else if (content.getSyncMessage().isPresent()) {
|
} else if (content.getSyncMessage().isPresent()) {
|
||||||
TextSecurePreferences.setMultiDevice(context, true);
|
TextSecurePreferences.setMultiDevice(context, true);
|
||||||
@ -336,6 +339,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
if (envelope.isPreKeySignalMessage()) {
|
if (envelope.isPreKeySignalMessage()) {
|
||||||
ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob());
|
ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loki - Handle session reset logic
|
||||||
|
if (!envelope.isFriendRequest()) {
|
||||||
|
cipher.handleSessionResetRequestIfNeeded(envelope, cipher.getSessionStatus(envelope));
|
||||||
|
}
|
||||||
} catch (ProtocolInvalidVersionException e) {
|
} catch (ProtocolInvalidVersionException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
handleInvalidVersionMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId);
|
handleInvalidVersionMessage(e.getSender(), e.getSenderDevice(), envelope.getTimestamp(), smsMessageId);
|
||||||
@ -471,7 +479,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
if (threadId != null) {
|
if (threadId != null) {
|
||||||
TextSecureSessionStore sessionStore = new TextSecureSessionStore(context);
|
TextSecureSessionStore sessionStore = new TextSecureSessionStore(context);
|
||||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||||
// sessionStore.deleteAllSessions(content.getSender());
|
|
||||||
|
|
||||||
Log.d("Loki", "Received a session reset request from: " + content.getSender() + "; archiving the session.");
|
Log.d("Loki", "Received a session reset request from: " + content.getSender() + "; archiving the session.");
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.loki
|
|||||||
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import net.sqlcipher.database.SQLiteDatabase
|
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||||
import org.thoughtcrime.securesms.crypto.PreKeyUtil
|
import org.thoughtcrime.securesms.crypto.PreKeyUtil
|
||||||
import org.thoughtcrime.securesms.database.Database
|
import org.thoughtcrime.securesms.database.Database
|
||||||
@ -73,17 +72,17 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
|
|
||||||
fun setPreKeyBundle(hexEncodedPublicKey: String, preKeyBundle: PreKeyBundle) {
|
fun setPreKeyBundle(hexEncodedPublicKey: String, preKeyBundle: PreKeyBundle) {
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
val contentValues = ContentValues(9)
|
val values = ContentValues(9)
|
||||||
contentValues.put(registrationID, preKeyBundle.registrationId)
|
values.put(registrationID, preKeyBundle.registrationId)
|
||||||
contentValues.put(deviceID, preKeyBundle.deviceId)
|
values.put(deviceID, preKeyBundle.deviceId)
|
||||||
contentValues.put(preKeyID, preKeyBundle.preKeyId)
|
values.put(preKeyID, preKeyBundle.preKeyId)
|
||||||
contentValues.put(preKeyPublic, Base64.encodeBytes(preKeyBundle.preKey.serialize()))
|
values.put(preKeyPublic, Base64.encodeBytes(preKeyBundle.preKey.serialize()))
|
||||||
contentValues.put(signedPreKeyID, preKeyBundle.signedPreKeyId)
|
values.put(signedPreKeyID, preKeyBundle.signedPreKeyId)
|
||||||
contentValues.put(signedPreKeyPublic, Base64.encodeBytes(preKeyBundle.signedPreKey.serialize()))
|
values.put(signedPreKeyPublic, Base64.encodeBytes(preKeyBundle.signedPreKey.serialize()))
|
||||||
contentValues.put(signedPreKeySignature, Base64.encodeBytes(preKeyBundle.signedPreKeySignature))
|
values.put(signedPreKeySignature, Base64.encodeBytes(preKeyBundle.signedPreKeySignature))
|
||||||
contentValues.put(identityKey, Base64.encodeBytes(preKeyBundle.identityKey.serialize()))
|
values.put(identityKey, Base64.encodeBytes(preKeyBundle.identityKey.serialize()))
|
||||||
contentValues.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
values.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
||||||
database.insertWithOnConflict(tableName, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE)
|
database.insertOrUpdate(tableName, values, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey ))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removePreKeyBundle(hexEncodedPublicKey: String) {
|
override fun removePreKeyBundle(hexEncodedPublicKey: String) {
|
||||||
|
@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.loki
|
|||||||
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import net.sqlcipher.database.SQLiteDatabase
|
|
||||||
import org.thoughtcrime.securesms.crypto.PreKeyUtil
|
import org.thoughtcrime.securesms.crypto.PreKeyUtil
|
||||||
import org.thoughtcrime.securesms.database.Database
|
import org.thoughtcrime.securesms.database.Database
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||||
@ -13,9 +12,9 @@ class LokiPreKeyRecordDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val tableName = "loki_pre_key_record_database"
|
private val tableName = "loki_pre_key_record_database"
|
||||||
private val preKeyID = "pre_key_id"
|
|
||||||
private val hexEncodedPublicKey = "public_key"
|
private val hexEncodedPublicKey = "public_key"
|
||||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($preKeyID INTEGER PRIMARY KEY, $hexEncodedPublicKey TEXT);"
|
private val preKeyID = "pre_key_id"
|
||||||
|
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($hexEncodedPublicKey TEXT PRIMARY KEY, $preKeyID INTEGER);"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasPreKey(hexEncodedPublicKey: String): Boolean {
|
fun hasPreKey(hexEncodedPublicKey: String): Boolean {
|
||||||
@ -36,14 +35,14 @@ class LokiPreKeyRecordDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generateAndStorePreKeyRecord(hexEncodedPublicKey: String): PreKeyRecord {
|
private fun generateAndStorePreKeyRecord(hexEncodedPublicKey: String): PreKeyRecord {
|
||||||
val preKeyRecords = PreKeyUtil.generatePreKeys(context, 1)
|
val records = PreKeyUtil.generatePreKeys(context, 1)
|
||||||
PreKeyUtil.storePreKeyRecords(context, preKeyRecords)
|
PreKeyUtil.storePreKeyRecords(context, records)
|
||||||
val record = preKeyRecords.first()
|
val record = records.first()
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
val values = ContentValues(2)
|
val values = ContentValues(2)
|
||||||
values.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
values.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
||||||
values.put(preKeyID, record.id)
|
values.put(preKeyID, record.id)
|
||||||
database.insertWithOnConflict(tableName, null, values, SQLiteDatabase.CONFLICT_REPLACE)
|
database.insertOrUpdate(tableName, values, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey ))
|
||||||
return record
|
return record
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user