Store session data in a secure way (#98)
* Replace SessionData DataStore with an encrypted SQLite DB. --------- Co-authored-by: Benoit Marty <benoit@matrix.org>
This commit is contained in:
parent
381bd3fd3f
commit
6677f80abe
38 changed files with 600 additions and 199 deletions
|
|
@ -54,5 +54,6 @@ dependencies {
|
|||
implementation(projects.libraries.dateformatter)
|
||||
implementation(projects.features.roomlist)
|
||||
implementation(projects.features.login)
|
||||
implementation(libs.coroutines.core)
|
||||
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.2")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.samples.minimal
|
||||
|
||||
import io.element.android.libraries.matrix.session.SessionData
|
||||
import io.element.android.libraries.sessionstorage.SessionStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class InMemorySessionStore : SessionStore {
|
||||
|
||||
private var sessionData = MutableStateFlow<SessionData?>(null)
|
||||
|
||||
override fun isLoggedIn(): Flow<Boolean> {
|
||||
return sessionData.map { it != null }
|
||||
}
|
||||
|
||||
override suspend fun storeData(session: SessionData) {
|
||||
sessionData.value = session
|
||||
}
|
||||
|
||||
override suspend fun getSession(sessionId: String): SessionData? {
|
||||
return sessionData.value.takeIf { it?.userId == sessionId }
|
||||
}
|
||||
|
||||
override suspend fun getLatestSession(): SessionData? {
|
||||
return sessionData.value
|
||||
}
|
||||
|
||||
override suspend fun removeSession(sessionId: String) {
|
||||
if (sessionData.value?.userId == sessionId) {
|
||||
sessionData.value = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,6 @@ import androidx.core.view.WindowCompat
|
|||
import io.element.android.libraries.designsystem.theme.ElementTheme
|
||||
import io.element.android.libraries.matrix.auth.MatrixAuthenticationService
|
||||
import io.element.android.libraries.matrix.auth.RustMatrixAuthenticationService
|
||||
import io.element.android.libraries.matrix.session.PreferencesSessionStore
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.matrix.rustcomponents.sdk.AuthenticationService
|
||||
import java.io.File
|
||||
|
|
@ -45,7 +44,7 @@ class MainActivity : ComponentActivity() {
|
|||
baseDirectory = baseDirectory,
|
||||
coroutineScope = Singleton.appScope,
|
||||
coroutineDispatchers = Singleton.coroutineDispatchers,
|
||||
sessionStore = PreferencesSessionStore(applicationContext),
|
||||
sessionStore = InMemorySessionStore(),
|
||||
authService = AuthenticationService(baseDirectory.absolutePath, null, null),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
20
samples/minimal/src/main/res/values-night/themes.xml
Normal file
20
samples/minimal/src/main/res/values-night/themes.xml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2023 New Vector Ltd
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<style name="Theme.ElementX" parent="android:Theme.Material.NoActionBar" />
|
||||
</resources>
|
||||
|
|
@ -16,6 +16,5 @@
|
|||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<style name="Theme.ElementX" parent="android:Theme.Material.Light.NoActionBar" />
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue