Persist notification data. Note that it will break the key storage for the session database.
This commit is contained in:
committed by
Benoit Marty
parent
2696348d46
commit
c0ef4804a1
@@ -34,4 +34,6 @@ dependencies {
|
||||
implementation(libs.sqlcipher)
|
||||
implementation(libs.sqlite)
|
||||
implementation(libs.androidx.security.crypto)
|
||||
|
||||
implementation(projects.libraries.androidutils)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package io.element.encrypteddb.passphrase
|
||||
|
||||
import android.content.Context
|
||||
import androidx.security.crypto.EncryptedFile
|
||||
import io.element.android.libraries.androidutils.file.EncryptedFileFactory
|
||||
import java.io.File
|
||||
import java.security.SecureRandom
|
||||
|
||||
@@ -25,23 +26,16 @@ import java.security.SecureRandom
|
||||
* Provides a secure passphrase for SQLCipher by generating a random secret and storing it into an [EncryptedFile].
|
||||
* @param context Android [Context], used by [EncryptedFile] for cryptographic operations.
|
||||
* @param file Destination file where the key will be stored.
|
||||
* @param alias Alias of the key used to encrypt & decrypt the [EncryptedFile]'s contents.
|
||||
* @param secretSize Length of the generated secret.
|
||||
*/
|
||||
class RandomSecretPassphraseProvider(
|
||||
private val context: Context,
|
||||
private val file: File,
|
||||
private val alias: String,
|
||||
private val secretSize: Int = 256,
|
||||
) : PassphraseProvider {
|
||||
|
||||
override fun getPassphrase(): ByteArray {
|
||||
val encryptedFile = EncryptedFile.Builder(
|
||||
file,
|
||||
context,
|
||||
alias,
|
||||
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
|
||||
).build()
|
||||
val encryptedFile = EncryptedFileFactory(context).create(file)
|
||||
return if (!file.exists()) {
|
||||
val secret = generateSecret()
|
||||
encryptedFile.openFileOutput().use { it.write(secret) }
|
||||
|
||||
Reference in New Issue
Block a user