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/biometric unlock #1702

Merged
merged 13 commits into from
Oct 31, 2023
Merged

Feature/fga/biometric unlock #1702

merged 13 commits into from
Oct 31, 2023

Conversation

ganfra
Copy link
Contributor

@ganfra ganfra commented Oct 31, 2023

This PR branches the biometric unlock logic.

@@ -42,7 +42,7 @@ import timber.log.Timber

private val loggerTag = LoggerTag("MainActivity")

class MainActivity : NodeComponentActivity() {
class MainActivity : NodeActivity() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary to have FragmentActivity for Biometric api

@ElementBot
Copy link
Collaborator

ElementBot commented Oct 31, 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#L102 - A newer version of androidx.compose.material3:material3 than 1.2.0-alpha09 is available: 1.2.0-alpha10

Generated by 🚫 dangerJS against c01ed83

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

github-actions bot commented Oct 31, 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/P3chEA

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 thanks! I just have a few nits and one thing we might either want to implement now or as soon as we get some errors we saw back in EA (which we might avoid if we're lucky).

Also, if biometric auth is enabled, shouldn't it be prompted by default, instead of the PIN code?

Feel free to ignore the nits or implement them in another PR.

@@ -48,7 +48,16 @@ data class LockScreenConfig(
/**
* Time period before locking the app once backgrounded.
*/
val gracePeriodInMillis: Long
val gracePeriodInMillis: Long,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe this could be a Duration instead?

override fun setup() {
try {
val secretKey = ensureKey()
val cipher = encryptionDecryptionService.createEncryptionCipher(secretKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this will work in general, on EA we had some nasty issues with 'user not authenticated' errors. To avoid this, one possible workaround may be to create the Cipher on demand and have 2 internal authentication methods, since it seems like this is a possible workaround:

  1. authenticateWithCryptoObject, should be called by default, it will do what's inside authenticate right now. If the createEncryptionCipher inside this authenticate method fails with the 'user not authenticated error', however, we go to the 2nd method.
  2. authenticateWithoutCryptoObject, will call the same prompt.authenticate method without a CryptoObject, which will authenticate the user and get rid of the error, then you should be able to initialize the Cipher and use it as you'd usually do.

I'm not saying you should implement this now, but we definitely should if we see those kind of issues coming back on EXA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user not authenticated error is something different than KeyPermanentlyInvalidatedException?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's completely different. This error should only appear if you tried to use the Cipher before using the biometric prompt I think, but for some reason it sometimes will trigger as soon as you initialize the Cipher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see, otherwise I'll remove the flag for now...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do that we might have to handle key migrations in the future, so be careful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will handle that later if we encounter the issue, no time for now :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, given the deadlines, I think that's the right call too

/**
* Returns true if any biometric method (weak or strong) can be used.
*/
private val canUseBiometricAuth: Boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename this to 'isAuthenticatorAvailable'?

/**
* Returns whether the biometric unlock is allowed or not.
*/
fun isBiometricUnlockAllowed(): Flow<Boolean>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe use enabled here instead of allowed? Allowed sounds like something coming from the OS to me, rather than from a user preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to reflects what we show on the ui...

@ganfra
Copy link
Contributor Author

ganfra commented Oct 31, 2023

LGTM thanks! I just have a few nits and one thing we might either want to implement now or as soon as we get some errors we saw back in EA (which we might avoid if we're lucky).

Also, if biometric auth is enabled, shouldn't it be prompted by default, instead of the PIN code?

This is the case, it automatically opens the Biometric bottom sheet, on top of the PinUnlockView

Feel free to ignore the nits or implement them in another PR.

@jmartinesp
Copy link
Contributor

This is the case, it automatically opens the Biometric bottom sheet, on top of the PinUnlockView

Ah, true, it does by default. However, for me it doesn't anymore after:

  1. I dismiss the biometric prompt.
  2. Unlock using pin code.
  3. Move the app to background.
  4. After the grace period, open the app again.

It won't work automatically, I need to click on 'use biometric'. It does work fine again after restarting the app.

@ganfra
Copy link
Contributor Author

ganfra commented Oct 31, 2023

This is the case, it automatically opens the Biometric bottom sheet, on top of the PinUnlockView

Ah, true, it does by default. However, for me it doesn't anymore after:

  1. I dismiss the biometric prompt.
  2. Unlock using pin code.
  3. Move the app to background.
  4. After the grace period, open the app again.

It won't work automatically, I need to click on 'use biometric'. It does work fine again after restarting the app.

Got it, will fix, thanks!

@ganfra ganfra added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label Oct 31, 2023
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Attention: 187 lines in your changes are missing coverage. Please review.

Comparison is base (5f85707) 63.64% compared to head (35410c4) 63.40%.
Report is 12 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1702      +/-   ##
===========================================
- Coverage    63.64%   63.40%   -0.25%     
===========================================
  Files         1267     1277      +10     
  Lines        32881    33129     +248     
  Branches      6809     6854      +45     
===========================================
+ Hits         20928    21006      +78     
- Misses        8805     8959     +154     
- Partials      3148     3164      +16     
Files Coverage Δ
...ockscreen/impl/settings/LockScreenSettingsState.kt 100.00% <100.00%> (ø)
...n/impl/settings/LockScreenSettingsStateProvider.kt 93.33% <100.00%> (+1.02%) ⬆️
...creen/impl/setup/biometric/SetupBiometricEvents.kt 100.00% <100.00%> (ø)
...screen/impl/setup/biometric/SetupBiometricState.kt 100.00% <100.00%> (ø)
...atures/lockscreen/impl/setup/pin/SetupPinEvents.kt 100.00% <ø> (ø)
...res/lockscreen/impl/setup/pin/SetupPinPresenter.kt 86.84% <ø> (ø)
...eatures/lockscreen/impl/setup/pin/SetupPinState.kt 100.00% <ø> (ø)
...lockscreen/impl/setup/pin/SetupPinStateProvider.kt 96.29% <ø> (ø)
...features/lockscreen/impl/setup/pin/SetupPinView.kt 60.00% <ø> (ø)
...ckscreen/impl/setup/pin/validation/PinValidator.kt 100.00% <ø> (ø)
... and 25 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ganfra ganfra enabled auto-merge October 31, 2023 17:19
@jmartinesp jmartinesp merged commit 6832b1f into develop Oct 31, 2023
10 of 11 checks passed
@jmartinesp jmartinesp deleted the feature/fga/biometric_unlock branch October 31, 2023 18:22
Copy link

sonarcloud bot commented Oct 31, 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants