move authentication code to secure store

This commit is contained in:
lucky 2021-11-21 16:57:03 +03:00
parent 089cec82f1
commit 33d872d560
3 changed files with 15 additions and 5 deletions

View File

@ -10,8 +10,8 @@ android {
applicationId "me.lucky.wasted" applicationId "me.lucky.wasted"
minSdk 25 minSdk 25
targetSdk 31 targetSdk 31
versionCode 3 versionCode 4
versionName "1.0.2" versionName "1.0.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@ -45,4 +45,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.security:security-crypto:1.0.0'
} }

View File

@ -3,15 +3,23 @@ package me.lucky.wasted
import android.content.Context import android.content.Context
import androidx.core.content.edit import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
class Preferences(context: Context) { class Preferences(ctx: Context) {
companion object { companion object {
private const val SERVICE_ENABLED = "service_enabled" private const val SERVICE_ENABLED = "service_enabled"
private const val CODE = "code" private const val CODE = "code"
} }
private val prefs = PreferenceManager.getDefaultSharedPreferences(context) private val mk = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
private val prefs = EncryptedSharedPreferences.create(
"s_shared_prefs",
mk,
ctx,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM,
)
var isServiceEnabled: Boolean var isServiceEnabled: Boolean
get() = prefs.getBoolean(SERVICE_ENABLED, false) get() = prefs.getBoolean(SERVICE_ENABLED, false)

View File

@ -0,0 +1 @@
move authentication code to secure store