Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codenameone/fingerprintscanner
Support for fingerprint scanning/TouchID in Codename One mobile applications
https://github.com/codenameone/fingerprintscanner
android-library authentication biometrics codenameone fingerprint fingerprint-sensor fingerprint-validation ios touchid
Last synced: 25 days ago
JSON representation
Support for fingerprint scanning/TouchID in Codename One mobile applications
- Host: GitHub
- URL: https://github.com/codenameone/fingerprintscanner
- Owner: codenameone
- Created: 2017-05-01T07:33:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-27T14:32:16.000Z (10 months ago)
- Last Synced: 2024-05-07T18:07:21.229Z (6 months ago)
- Topics: android-library, authentication, biometrics, codenameone, fingerprint, fingerprint-sensor, fingerprint-validation, ios, touchid
- Language: Java
- Homepage: https://www.codenameone.com/
- Size: 452 KB
- Stars: 4
- Watchers: 5
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
= Fingerprint Scanner
Fingerprint scanning and biometric support for https://www.codenameone.com[Codename One].
image::images/fingerprint-scanner-feature.jpg[]
This cn1lib provides basic support for fingerprint scanning on iOS/Android with one API. Due to the difference between the two implementations we chose a simplified approach that just verifies the fingerprint and doesn't delve into the nuanced complexities for this API.
== Supported Platforms
Currently this library supports only Android (API 23+), and iOS.
== Installation
For instructions on installing cn1libs, see https://www.codenameone.com/blog/automatically-install-update-distribute-cn1libs-extensions.html[this tutorial].
=== Alternate Maven Installation
If your project uses Maven, the above installation instructions will still work, but you can alternately simply add the Maven dependency to your common/pom.xml file:
[source,xml]
----com.codenameone
fingerprint-scanner-lib
1.0
pom----
[IMPORTANT]
====
Android builds *must* use build tools 29 or higher. E.g. Add the following build hints:----
android.buildToolsVersion=29.0.3
android.targetSdkVersion=29.0.3
----
====== Basic Usage
[source,java]
----
Fingerprint.scanFingerprint("Use your finger print to unlock AppName.", value -> {
Log.p("Scan successfull!");
}, (sender, err, errorCode, errorMessage) -> {
Log.p("Scan Failed!");
});
----Note that the values passed to value/fail are `null` and don't include any data at this time...
Also check out the following samples:
. https://github.com/codenameone/FingerprintScannerTest[FingerprintScannerTest App] - Basic usage. Just fingerprint scanning.
. https://github.com/codenameone/CodenameOne/blob/master/Samples/samples/FingerprintScannerSample/FingerprintScannerSample.java[FingerprintScannerSample] - From Codename One samples. Includes sample of storing, retrieving, and deleting passwords.== Protecting Passwords with Fingerprints
This library also allows you to store passwords in the system keychain, protected by biometric authentication. The user will be asked to authenticate with their fingerprint (or Face recognition on supported devices) in order to retrieve passwords using this library. On Android, currently the user is also prompted to authenticate when storing passwords as well.
NOTE: While these methods say that they are for storing passwords, you can use them for storing any text. Both Android and iOS should allow you to store strings of sufficiently large size to store anything you might otherwise store in Preferences.
=== Storing Passwords
[source,java]
----
String account = "[email protected]";
String password = "....";Fingerprint.addPassword(
"Adding secure item to keystore", // Message to display in authentication dialog
account,
password
).onResult((success, err)->{
if (err != null) {
Log.e(err);
ToastBar.showErrorMessage("Failed to add password to keystore: "+ err.getMessage());
} else {
// success always true if there was no error.
ToastBar.showInfoMessage("Successfully added password to keystore");
}
});
----=== Retrieving Passwords
[source,java]
----
String account = "[email protected]";Fingerprint.getPassword(
"Getting secure item", // Message to display in auth dialog
account
).onResult((password, err)->{
if (err != null) {
// Error condition occurs both if the keychain doesn't have
// a password for the given account, or if a failure occurs
// in retrieving it.
// NOTE: If the user adds a finger or face to biometric scanning
// or disables password protection on the device, all passwords
// will be purged automatically.
Log.e(err);
ToastBar.showErrorMessage("Failed to get password: " + err.getMessage());
} else {
System.out.println("The password was "+password);
}
});
----=== Deleting Passwords
[source,java]
----
String account = "[email protected]";Fingerprint.deletePassword(
"Getting secure item", // Message to display in auth dialog
keyName.getText()
).onResult((res, err)->{
if (err != null) {
Log.e(err);
ToastBar.showErrorMessage("Failed to delete password: "+err.getMessage());
} else {
System.out.println("Deleted the password for account "+account);
}
});
----=== Password Invalidation
Passwords stored in the keychain will be automatically purged if any of the following occurs:
. The user adds additional fingers to fingerprint authentication.
. The user adds additional faces to face ID biometric authentication.
. The user turns off phone login security. E.g. if they turn off password or fingerprint requirements for login to the phone.=== Android Implementation
Currently, on Android we are using the https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager[FingerprintManager] class for authentication on API 28 (Android 9) and lower and https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt[BiometricPrompt] on devices running API 29 (Android 10) and higher. This means that Android 9, despite supporting Face recognition at an OS level, will use FingerPrintManager and will not support face recognition for authentication. Future versions may attempt to incorporate workarounds to add this support to Android 9, e.g. https://github.com/sergeykomlach/AdvancedBiometricPromptCompat[AdvancedBiometricPromptCompat].
Passwords are not, themselves, stored inside the system Keystore. Rather, a symmetric Key is generated and stored inside the keychain, which is used to encrypt and decrypt the passwords, which are stored private `SharedPreferences`.
Currently the key specifications are:
[source,java]
----
new KeyGenParameterSpec.Builder(
KEY_ID,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT
)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
----Refer to the https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder[KeyGenParameterSpec.Builder docs] for a more detailed description of what these settings mean.
The `.setUserAuthenticationRequired(true)` call is what causes the key to become invalid when the user adds fingers or faces to authentication.
=== iOS Implementation
On iOS, the library acts as a thin layer on top of the https://developer.apple.com/documentation/security/1401659-secitemadd?language=objc[SecItemAdd], https://developer.apple.com/documentation/security/1398306-secitemcopymatching?language=objc[SecItemCopyMatching], and https://developer.apple.com/documentation/security/1395547-secitemdelete?language=objc[SecItemDelete] functions which directly add passwords to the keychain.
The security settings on the passwords are:
[source,objective-c]
----
SecAccessControlRef sacRef = SecAccessControlCreateWithFlags(kCFAllocatorDefault,
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
kSecAccessControlTouchIDCurrentSet,
nil
);
----For more details on what these mean, see the following documentation pages:
. https://developer.apple.com/documentation/security/secaccesscontrolref?language=objc[SecAccessControlRef]
. https://developer.apple.com/documentation/security/ksecattraccessiblewhenpasscodesetthisdeviceonly?language=objc[kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly]
. https://developer.apple.com/documentation/security/secaccesscontrolcreateflags/ksecaccesscontroltouchidcurrentset?language=objc[kSecAccessControlTouchIDCurrentSet]== Working with the Sources
. Check out with `git clone https://github.com/codenameone/FingerprintScanner`
. Build with `mvn package`
.. You'll find cn1lib in the _common/target_ directory.See https://shannah.github.io/codenameone-maven-manual/[the Codename One Maven Manual] for more information about working with Codename One Maven projects.
=== Releasing to Maven Central
1. Set up your ~/.m2/settings.xml file with credentials for Maven central.
2. Run `bash update-version.sh $NEW_VERSION` where `$NEW_VERSION` is the new version. E.g. "1.1".
3. `git push && git push --tags` to push the new version tag to git.
4. `mvn deploy -Psign-artifacts`
5. Log into Maven central and complete the release.
6. Run `bash update-version $NEW_SNAPSHOT_VERSION` where `$NEW_SNAPSHOT_VERSION` is the next snapshot version E.g. 1.2-SNAPSHOT.