From 33d872d560d177a47d80d7f07f3f74e1116eb8d1 Mon Sep 17 00:00:00 2001 From: lucky <> Date: Sun, 21 Nov 2021 16:57:03 +0300 Subject: [PATCH] move authentication code to secure store --- app/build.gradle | 5 +++-- app/src/main/java/me/lucky/wasted/Preferences.kt | 14 +++++++++++--- fastlane/metadata/android/en-US/changelogs/4.txt | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/4.txt diff --git a/app/build.gradle b/app/build.gradle index 3a5bfc4..176c8e9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "me.lucky.wasted" minSdk 25 targetSdk 31 - versionCode 3 - versionName "1.0.2" + versionCode 4 + versionName "1.0.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -45,4 +45,5 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation 'androidx.preference:preference-ktx:1.1.1' + implementation 'androidx.security:security-crypto:1.0.0' } \ No newline at end of file diff --git a/app/src/main/java/me/lucky/wasted/Preferences.kt b/app/src/main/java/me/lucky/wasted/Preferences.kt index bafa0bb..2aef0ce 100644 --- a/app/src/main/java/me/lucky/wasted/Preferences.kt +++ b/app/src/main/java/me/lucky/wasted/Preferences.kt @@ -3,15 +3,23 @@ package me.lucky.wasted import android.content.Context 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 { private const val SERVICE_ENABLED = "service_enabled" 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 get() = prefs.getBoolean(SERVICE_ENABLED, false) diff --git a/fastlane/metadata/android/en-US/changelogs/4.txt b/fastlane/metadata/android/en-US/changelogs/4.txt new file mode 100644 index 0000000..93eab80 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/4.txt @@ -0,0 +1 @@ +move authentication code to secure store