-
Notifications
You must be signed in to change notification settings - Fork 0
[Hotfix] KeyStoreException #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ package com.eatssu.android.di | |
|
|
||
| import android.content.Context | ||
| import android.content.SharedPreferences | ||
| import com.google.firebase.crashlytics.FirebaseCrashlytics | ||
| import timber.log.Timber | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
|
|
@@ -16,6 +18,21 @@ object SecurePrefsModule { | |
| @Provides | ||
| @Singleton | ||
| fun provideSecurePrefs(@ApplicationContext context: Context): SharedPreferences { | ||
| return try { | ||
| createSecurePrefs(context) | ||
| } catch (e: Exception) { | ||
| Timber.e(e, "Failed to create SecurePrefs. Resetting...") | ||
| FirebaseCrashlytics.getInstance().recordException(e) | ||
|
|
||
| // Clear data | ||
| context.deleteSharedPreferences("secure_prefs") | ||
|
|
||
| // Retry | ||
| createSecurePrefs(context) | ||
| } | ||
|
Comment on lines
+23
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이
아래는 이 두 가지 문제를 모두 수정한 제안 코드입니다. 참고로, 제안된 코드를 적용하려면 } catch (e: Exception) {
when (e) {
is java.security.GeneralSecurityException, is java.io.IOException -> {
Timber.e(e, "Failed to create SecurePrefs. Resetting...")
FirebaseCrashlytics.getInstance().recordException(e)
// Clear data
context.deleteSharedPreferences("secure_prefs")
// Retry
try {
createSecurePrefs(context)
} catch (retryException: Exception) {
Timber.e(retryException, "Failed to create SecurePrefs even after reset.")
FirebaseCrashlytics.getInstance().recordException(retryException)
throw IllegalStateException("Could not initialize SecurePrefs after reset.", retryException)
}
}
else -> throw e
}
} |
||
| } | ||
|
|
||
| private fun createSecurePrefs(context: Context): SharedPreferences { | ||
| val masterKey = androidx.security.crypto.MasterKey.Builder(context) | ||
| .setKeyScheme(androidx.security.crypto.MasterKey.KeyScheme.AES256_GCM) | ||
| .build() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
하드코딩된 문자열 "secure_prefs"가 28라인과 41라인 두 곳에서 사용되고 있습니다. 이 문자열을
object내에private const val로 선언하여 재사용하면 오타 발생 가능성을 줄이고 유지보수성을 높일 수 있습니다.예시: