-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Git via SSH: Various fixes related to Ed25519 keys
Access to the master key that is used to wrap Ed25519 keys relies on Android Keystore, Google Tink and androidx.security.crypto. We are using alpha versions of the latter library, and it is notoriously flaky (see e.g. tink-crypto/tink#535). The main issue that caused me to go over this class was that on newly created API 30 devices, a Ed25519 key with device lock protection could never be used, even if they had just been created (i.e. the newly created master key was probably not corrupted). I realized that *something* had changed so that we now need to authenticate in order to just create the private key object. This has not been the case in my previous tests; authentication was not required until we tried to _use_ they key to do something (in our case, sign an arbitrary string). Since we need to authenticate in more situations than before, I added a function which can be called whenever we catch a UserNotAuthenticatedException. Concrete changes: - Upgrade androidx.security.crypto from 1.1.0-alpha06 (which relies on a newer version of Google Tink, which is hopefully more stable). Note that this requires compiling against SDK >= 33, but I believe that should be fine. - When preparing to use a Ed25519 key for signing, use a signing algorithm which actually works with those keys. This has been causing an InvalidKeyException during each use of a Ed25519 for a long time. - Catch all UserNotAuthenticatedExceptions and try biometric auth when they occur. - Remove the mustAuthenticate attribute, as it becomes useless now that we rely on catching UserNotAuthenticatedExceptions. - Make privateKeyLoadAttempts a class attribute which can be updated from many places. - Don't swallow and silently log all other exception types when failing to use a key for signing. We want to know when (yes, when, not if...) this code breaks again. - Clean up duplicated RequiresApi annotations.
- Loading branch information
Showing
3 changed files
with
56 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters