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

Android Fingerprint #195

Closed
wants to merge 38 commits into from
Closed

Android Fingerprint #195

wants to merge 38 commits into from

Conversation

cladjules
Copy link

Refactor Android Support Fingerprint to not use AndroidX.
Still need to refactor to not force FragmentActivity to be used.

@vonovak
Copy link
Collaborator

vonovak commented Feb 14, 2019

hi! Thanks for the PR! For start, can you please rebase on master so there are no conflicts? Thanks.

@MarcoLude
Copy link

any updates on this?

@aeirola
Copy link
Collaborator

aeirola commented Apr 8, 2019

It seems as if there are now two open, but stalled, PRs for implementing Android Fingerprint support, this one and #148. I'm working on an application which is currently using a custom branch from the #148 PR. The feature seems to work reasonably well, and since we depend on this library I'd be willing to help out finalising implementation of this feature in the library.

But before making yet another PR, I'd just like to check in with @vonovak @cladjules and @LinusU about the state of the development, and what functionality is still missing until the feature could be merged.

Some open question I've seen in the discussion:

Would be good to have answers to these questions, or at least plans on how to solve them, before continuing work. All input is welcome.

P.S. I chose this PR as the ground for discussion, as opposed to creating a separate issue for the feature, in order to not spread the discussion any further. I can move the discussion to a separate issue if someone feels like this is not the appropriate place for the discussion.

@cladjules
Copy link
Author

It seems as if there are now two open, but stalled, PRs for implementing Android Fingerprint support, this one and #148. I'm working on an application which is currently using a custom branch from the #148 PR. The feature seems to work reasonably well, and since we depend on this library I'd be willing to help out finalising implementation of this feature in the library.

But before making yet another PR, I'd just like to check in with @vonovak @cladjules and @LinusU about the state of the development, and what functionality is still missing until the feature could be merged.

Some open question I've seen in the discussion:

  • How should we handle the dialog prompt on older versions of Android?

  • Should we try to get rid of the need for FragmentActivity? Personally I don't have a problem with it.

  • Should we try to switch from RSA to AES (as suggested in #148 (comment)) or OAEP (as suggested in #148 (comment))?

  • Customising the authentication prompt. Currently the displayed texts are hardcoded in both PRs, but the application I work on would really benefit from customised strings. This additional functionality could be added in a separate PR though.

Would be good to have answers to these questions, or at least plans on how to solve them, before continuing work. All input is welcome.

P.S. I chose this PR as the ground for discussion, as opposed to creating a separate issue for the feature, in order to not spread the discussion any further. I can move the discussion to a separate issue if someone feels like this is not the appropriate place for the discussion.

Hi @aeirola sorry for being inactive for so long.
To answer your questions,
this PR doesn't use AndroidX, I have re-used the Google Library and refactored to use compat lib instead.

Forcing all users to switch their own code base to use FragmentActivity could potentially cause some issues with other libraries as well, I am not sure what would be involved in showing it inside a detached dialog or activity, but I could give it a go.

We cannot switch to RSA to AES as we need an algorithm that generate private/public key, that's the reason why the algorithm is different for both file, I don't know about OAEP and how it works, but I think it only generated public key.

Customising the authentication prompt definitely doable and pass it through the options.

@aeirola
Copy link
Collaborator

aeirola commented Apr 8, 2019

Hey @cladjules, thanks for the prompt reply.

Sorry for misinterpreting the source of the biometric prompt fork. Thanks for correcting.

Yeah, I do agree that forcing apps to use the FragmentActvitity wouldn't be optimal, but I could see it at least as a stepping stone towards getting the feature implemented. If you are eager, and have the time, to try out alternative solutions, that would be great! Otherwise I could see it as an option to mere experimental fragment-dependant fingerprint support into the library, and then improve on it later.

Unfortunately I'm not familiar with the cryptosystems available in Android. Could look into them in detail if there is a chance that there would be some potentially undiscovered solutions available.

@aeirola
Copy link
Collaborator

aeirola commented Apr 8, 2019

Quickly browsed through Android keystore documentation, and seems like OAEP is referring to an alternative padding scheme for RSA, which is supported from Android 23+ (https://developer.android.com/training/articles/keystore#SupportedCiphers). Thus it could be used instead of the PKCS1 padding used by the current code. Not an expert on the implications of the different padding methods, but I really don't think there is much difference between them for this use case.

Android 23+ also includes support for elliptic curve keypair generators (https://developer.android.com/training/articles/keystore#SupportedKeyPairGenerators), so if there are some security concerns with RSA, it might be better to switch to it instead.

@poocart
Copy link

poocart commented Oct 4, 2019

Interesting issue @poocart, thanks for bringing it up. I remember there being some previous discussion around setUserAuthenticationValidityDurationSeconds at #148 (comment). Not sure what the cases are that @Jyrno42 referred to when he mentioned that decryption will fail for values less than 2 seconds. Maybe those issues are somehow fixed elsewhere in the code. The comment was for quite an old PR after all.

I'm sorry, actually you're right, setting it as 0 or -1 (as per method description) solves my issue, but then blocks from regular keychain unlock, however I finally managed to get working approach by disabling the code which tries to decrypt from keystore before showing biometrics prompt – this can be found around line 246 in keychain/cipherStorage/CipherStorageKeystoreRSAECB.java.

@vascofg
Copy link
Contributor

vascofg commented Oct 7, 2019

Any ETA on this functionality?

@OleksandrKucherenko
Copy link
Contributor

I start thinking it's much easier to close PR and start a new one than rebase it...

@cladjules
Copy link
Author

Hi everyone. I am now back from holidays.

There are indeed still few crashes.

Google has now officially released to androidx library.
I will give it a go to update this PR using the Gradle package.
And also merge the conflicts.

Copy link
Contributor

@OleksandrKucherenko OleksandrKucherenko left a comment

Choose a reason for hiding this comment

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

@cladjules
If you can fix the conflicts and commit update, then I will be happy to update code by applying android "best practices" on it

}

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation 'com.facebook.conceal:conceal:1.1.3@aar'
implementation 'com.android.support:support-v4:27.0.2'
Copy link
Contributor

Choose a reason for hiding this comment

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

we should align to version 28.0.0 - it guaranty that androidx with jetifier tool will be without any problems.

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Copy link
Contributor

Choose a reason for hiding this comment

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

5.6.2 is the latest

EncryptionResult encrypt(@NonNull String service, @NonNull String username, @NonNull String password, SecurityLevel level) throws CryptoFailedException;

DecryptionResult decrypt(@NonNull String service, @NonNull byte[] username, @NonNull byte[] password) throws CryptoFailedException;
void decrypt(@NonNull DecryptionResultHandler decryptionResultHandler, @NonNull String service, @NonNull byte[] username, @NonNull byte[] password) throws CryptoFailedException, KeyPermanentlyInvalidatedException;
Copy link
Contributor

Choose a reason for hiding this comment

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

Its a bad idea to change existing API. we should extend Public interface with new versions of API methods instead.

Correct approach:

  • mark old api deprecated
  • introduce new api with additional parameters/changes
  • provide a migration code for users
  • after 2-3 releases remove deprecated API methods

int getMinSupportedApiLevel();

void setCurrentActivity(Activity activity);
Copy link
Contributor

Choose a reason for hiding this comment

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

keeping a reference on activity is always not a very good idea. It can cause memory leak.

@OleksandrKucherenko
Copy link
Contributor

Sorry for stupid questions, but I have to ask to make it clear:

  • PR contains 31 commits, and I have a feeling that PR should be rebased on top of the current MASTER. it looks a little strange to me that we instead of rebasing, use merge of original/master into PR branch.

Does it mean that this PR will be a standalone branch in the future? or it was just a tricky way of applying the changes on code?

Thanks for answers

@cladjules
Copy link
Author

Sorry for stupid questions, but I have to ask to make it clear:

  • PR contains 31 commits, and I have a feeling that PR should be rebased on top of the current MASTER. it looks a little strange to me that we instead of rebasing, use merge of original/master into PR branch.

Does it mean that this PR will be a standalone branch in the future? or it was just a tricky way of applying the changes on code?

Thanks for answers

I suggest once we are happy with the state of the PR, we do a rebase?
All the commits are within my fork anyway.

Thanks.

@OleksandrKucherenko
Copy link
Contributor

Sorry for stupid questions, but I have to ask to make it clear:

  • PR contains 31 commits, and I have a feeling that PR should be rebased on top of the current MASTER. it looks a little strange to me that we instead of rebasing, use merge of original/master into PR branch.

Does it mean that this PR will be a standalone branch in the future? or it was just a tricky way of applying the changes on code?
Thanks for answers

I suggest once we are happy with the state of the PR, we do a rebase?
All the commits are within my fork anyway.

Thanks.

I try to rebase it today... and it's somehow become a "falling snowball" that on each applied commit, produces so many changes that it becomes harder and harder to resolve the conflicts.

@OleksandrKucherenko
Copy link
Contributor

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

add this into build.gradle file for enabling lambdas and simplified syntax.

@cladjules
Copy link
Author

Hi all,
I have refactored the library.
It's now using androidX Compat Biometric,
I have merged the current master to it.
And applied some of the comments.

I didn't test it with an RN App as mine is not 0.60 yet.

I will give it a go but I am not sure it will be a simple upgrade.

@OleksandrKucherenko
Copy link
Contributor

OleksandrKucherenko commented Oct 21, 2019

I create alternative implementation, based on AndroidX biometric library - #260

used the same code architecture/design concept as in this PR

@aeirola
Copy link
Collaborator

aeirola commented Oct 30, 2019

Nice to see that @OleksandrKucherenko is also eager about biometric authentication for android in the library. Even though there is now a third PR about the same subject, I would suggest to finalize and merge this PR, and then continue the work Oleksandr has done in separate PRs. This includes some refactoring, Java unit tests etc.

There still seems to be some steps left before this PR could be merged. The most immediate that come to mind are:

  • Fixing the merge conflict markers in gradle/wrapper/gradle-wrapper.properties
  • Removing the now unused string resource files
  • Clean up commented code and old comments
  • Remove editor files like react-native-keychain.iml
  • Check the remaining review comments

Is this something that you @cladjules would have time to finalize in the near future?

@cladjules
Copy link
Author

Hi, @aeirola more than happy to do that.
But is there really a point as @OleksandrKucherenko has already re-used all my code in a separate PR.
My PR now only uses AndroidX as well,
so I guess it would make sense to choose what PR we should merge and work on?

I am migrating to RN 0.6X soon, so happy to do some testing with either PR.

Thanks.

@aeirola
Copy link
Collaborator

aeirola commented Oct 31, 2019

I was thinking that the #260 PR is quite large as it is, and would maybe be easier to progress by first introducing initial fingerprint functionality through this PR, and then separately bring in the additional changes by @OleksandrKucherenko in later PRs. This would make it easier and faster to review the changes. I would imagine all the changes to be released under the same version number though.

@OleksandrKucherenko
Copy link
Contributor

OleksandrKucherenko commented Oct 31, 2019

@aeirola this PR contains files that belong to androidx biometric library. I recommend excluding them from PR and instead use reverse-jetified version of biometric AAR as project dependency.

That will reduce the PR size greatly.

@cladjules
Copy link
Author

Hi guys,
it has been a while.
I have finally upgraded my App to RN 0.6x and fully use AndroidX.

I have done the changes on that lib and only uses AndroidX BiometricPrompt, seems to be working OK on both Android Pie and pre-Pie.

I will look at merging the current master branch and resolve conflict.

Would be good if you can review on your side.

Thanks :)

@oblador
Copy link
Owner

oblador commented Mar 4, 2020

Superseded by #260

@oblador oblador closed this Mar 4, 2020
@oblador
Copy link
Owner

oblador commented Mar 4, 2020

@cladjules Are there are pieces in this PR not currently present in master that you want in?

@cladjules
Copy link
Author

@oblador Sorry, I haven't been very active those last few months.
@OleksandrKucherenko Well done for getting that merged and working.

In my PR, I had done an implementation of canImplyAuthentication for Android, wondering if it may be worth doing a separate PR to add that?

Thanks :)

@oblador
Copy link
Owner

oblador commented Apr 15, 2020

Absolutely!

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.