Skip to content
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

Merged
merged 11 commits into from
Oct 18, 2023
Merged

Conversation

ganfra
Copy link
Contributor

@ganfra ganfra commented Oct 18, 2023

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 the BiometricPrompt.

Also introduce PinCodeManager to have an entry point to store and verify pin.

Made some code restructuration too (pin module is now called lockscreen) sorry for the review :/

@ElementBot
Copy link
Collaborator

ElementBot commented Oct 18, 2023

Warnings
⚠️

gradle/libs.versions.toml#L64 - A newer version of com.google.android.material:material than 1.9.0 is available: 1.10.0

⚠️

gradle/libs.versions.toml#L114 - A newer version of com.squareup.okhttp3:okhttp-bom than 4.11.0 is available: 4.12.0

Generated by 🚫 dangerJS against 436c9e8

@ganfra ganfra marked this pull request as ready for review October 18, 2023 09:48
@ganfra ganfra requested a review from a team as a code owner October 18, 2023 09:48
@ganfra ganfra requested review from jmartinesp and removed request for a team October 18, 2023 09:48
@github-actions
Copy link
Contributor

github-actions bot commented Oct 18, 2023

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/qpF3Pf

Copy link
Contributor

@jmartinesp jmartinesp left a 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() {
Copy link
Contributor

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
Copy link
Contributor

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.

Comment on lines 70 to 86
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)
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

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 :-)

@ganfra ganfra enabled auto-merge October 18, 2023 14:06
@sonarcloud
Copy link

sonarcloud bot commented Oct 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@ganfra ganfra merged commit 00e885f into develop Oct 18, 2023
13 checks passed
@ganfra ganfra deleted the feature/fga/setup_crypto_for_pin branch October 18, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants