Skip to content

Commit

Permalink
[feature/remove-security-crypto] Security Crypto 라이브러리 제거 (#730)
Browse files Browse the repository at this point in the history
* [feature/remove-security-crypto] Turn off EncryptedSharedPreferences

* [feature/remove-secutiry-crypto] Refactor config modules

* Remove legacy tests

* Spotless Apply

* Update profiles

* Remove security crypto dependencies

* [skip ci] Update profiles
  • Loading branch information
l2hyunwoo committed Jun 8, 2024
1 parent d00fd98 commit 3c0b1c4
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 4,011 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ dependencies {
implementation(platform(libs.compose.bom))
implementation(libs.bundles.compose)
implementation(libs.startup)
implementation(libs.security)
implementation(libs.swipe.refresh.layout)

implementation(libs.inappupdate)
Expand Down
1,839 changes: 17 additions & 1,822 deletions app/src/release/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

1,839 changes: 17 additions & 1,822 deletions app/src/release/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

71 changes: 0 additions & 71 deletions app/src/test/java/org/sopt/official/datastore/SoptDataStoreTest.kt

This file was deleted.

This file was deleted.

This file was deleted.

58 changes: 0 additions & 58 deletions app/src/test/java/org/sopt/official/datastore/fake/FakeKeyStore.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sopt.official.common.file

import android.content.Context
import android.content.SharedPreferences

fun createSharedPreference(fileName: String, context: Context): SharedPreferences =
context.getSharedPreferences(fileName, Context.MODE_PRIVATE)
1 change: 0 additions & 1 deletion core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ android {

dependencies {
implementation(projects.core.common)
implementation(libs.security)
implementation(platform(libs.okhttp.bom))
implementation(libs.okhttp.logging.interceptor)
implementation(libs.process.phoenix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,16 @@
*/
package org.sopt.official.network.di

import android.content.Context
import androidx.security.crypto.MasterKey
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.sopt.official.common.di.LocalStore
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object SecurityModule {
@Provides
@Singleton
fun provideMasterKey(@ApplicationContext context: Context): MasterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()

object DataStoreModule {
@Provides
@Singleton
@LocalStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,18 @@ package org.sopt.official.network.persistence

import android.content.Context
import androidx.core.content.edit
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import dagger.hilt.android.qualifiers.ApplicationContext
import java.security.KeyStore
import javax.inject.Inject
import javax.inject.Singleton
import org.sopt.official.common.BuildConfig
import org.sopt.official.common.di.LocalStore
import timber.log.Timber
import org.sopt.official.common.file.createSharedPreference

@Singleton
class SoptDataStore @Inject constructor(
@ApplicationContext private val context: Context,
@LocalStore private val fileName: String,
masterKey: MasterKey,
) {
private val store = try {
createSharedPreference(
!BuildConfig.DEBUG,
fileName,
masterKey
)
} catch (e: Exception) {
Timber.e(e)
deleteMasterKeyEntry()
deleteEncryptedPreference()
createSharedPreference(
!BuildConfig.DEBUG,
fileName,
masterKey
)
}

private fun createSharedPreference(isEncrypted: Boolean, fileName: String, masterKey: MasterKey) = if (isEncrypted) {
EncryptedSharedPreferences.create(
context,
fileName,
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
} else {
context.getSharedPreferences(DEBUG_FILE_NAME, Context.MODE_PRIVATE)
}

/**
* androidx.security.crypto.MasterKeys.ANDROID_KEYSTORE 참고
*/
private fun deleteMasterKeyEntry() {
KeyStore.getInstance(ANDROID_KEY_STORE).apply {
load(null)
deleteEntry(KEY_ALIAS_AUTH)
}
}

private fun deleteEncryptedPreference() {
context.deleteSharedPreferences("sampleKey")
}
private val store = createSharedPreference(fileName, context)

fun clear() {
store.edit(true) {
Expand Down
1 change: 0 additions & 1 deletion data/poke/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ dependencies {
implementation(platform(libs.okhttp.bom))
implementation(libs.bundles.okhttp)

implementation(libs.security)
}
Loading

0 comments on commit 3c0b1c4

Please sign in to comment.