-
Notifications
You must be signed in to change notification settings - Fork 170
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
Feature/fga/setup crypto for pin #1592
Conversation
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
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.
LGTM, a few comments but feel free to ignore them.
private val encryptionDecryptionService = AESEncryptionDecryptionService() | ||
|
||
@Test | ||
fun given_a_valid_key_then_encrypt_decrypt_work() { |
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.
Nit: these can use backticks and whitespaces when running in JVM, in case you want to change them.
class InMemoryPinCodeStore : PinCodeStore { | ||
|
||
private var pinCode: String? = null | ||
private var remainingAttempts: Int = 3 |
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.
Nit: these could be moved to a constant.
override suspend fun getRemainingPinCodeAttemptsNumber(): Int = withContext(dispatchers.io) { | ||
sharedPreferences.getInt(REMAINING_PIN_CODE_ATTEMPTS_KEY, MAX_PIN_CODE_ATTEMPTS_NUMBER_BEFORE_LOGOUT) | ||
} | ||
|
||
override suspend fun onWrongPin(): Int = withContext(dispatchers.io) { | ||
val remaining = getRemainingPinCodeAttemptsNumber() - 1 | ||
sharedPreferences.edit { | ||
putInt(REMAINING_PIN_CODE_ATTEMPTS_KEY, remaining) | ||
} | ||
remaining | ||
} | ||
|
||
override suspend fun resetCounter() = withContext(dispatchers.io) { | ||
sharedPreferences.edit { | ||
remove(REMAINING_PIN_CODE_ATTEMPTS_KEY) | ||
} | ||
} |
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.
This should never happen in a normal usage, but I'm wondering if using a Mutex
here could help ensure we don't end up overwriting the remaining attempts.
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.
Yeah I can add this for safety :-)
Kudos, SonarCloud Quality Gate passed! |
This PR introduces a cryptography library to easily encrypt/decrypt data.
It'll be used to store the pin code encrypted to SharedPreferences, and also be able to provide a
CryptoObject
for theBiometricPrompt
.Also introduce
PinCodeManager
to have an entry point to store and verify pin.Made some code restructuration too (
pin
module is now calledlockscreen
) sorry for the review :/