Home | History | Annotate | Download | only in AsymmetricFingerprintDialog
      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <!--
      3  Copyright 2015 The Android Open Source Project
      4 
      5  Licensed under the Apache License, Version 2.0 (the "License");
      6  you may not use this file except in compliance with the License.
      7  You may obtain a copy of the License at
      8 
      9      http://www.apache.org/licenses/LICENSE-2.0
     10 
     11  Unless required by applicable law or agreed to in writing, software
     12  distributed under the License is distributed on an "AS IS" BASIS,
     13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  See the License for the specific language governing permissions and
     15  limitations under the License.
     16 -->
     17 <!-- TODO(thagikura) Add tests for Activity and Fragment once InstrumentationTests can be run
     18      on an emulator or a device.
     19      At this moment, due to the different API between the image and the SDK, they can't be launched.
     20      E.g. Skipping device 'Nexus 5 - MNC', due to different API preview 'MNC' and 'android-MNC'
     21      -->
     22 <sample>
     23     <name>AsymmetricFingerprintDialog</name>
     24     <group>Security</group>
     25     <package>com.example.android.asymmetricfingerprintdialog</package>
     26 
     27     <minSdk>23</minSdk>
     28 
     29     <dependency>com.squareup.dagger:dagger:1.2.2</dependency>
     30     <dependency>com.squareup.dagger:dagger-compiler:1.2.2</dependency>
     31 
     32     <!-- TODO(thagikura) These dependencies should be created as testCompile instead of compile but
     33          the template system doesn't allow androidTestCompile dependencies. Change it once fixed.
     34     -->
     35     <dependency>junit:junit:4.12</dependency>
     36     <dependency>org.mockito:mockito-core:1.10.19</dependency>
     37 
     38     <strings>
     39         <intro>
     40             <![CDATA[
     41 This sample demonstrates how you can use registered fingerprints to authenticate the user
     42 before proceeding some actions such as purchasing an item. This version uses asymmetric keys.
     43             ]]>
     44         </intro>
     45     </strings>
     46 
     47     <template src="base" />
     48 
     49     <metadata>
     50         <!-- Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED} -->
     51         <status>PUBLISHED</status>
     52         <categories>security</categories>
     53         <technologies>Android</technologies>
     54         <languages>Java</languages>
     55         <solutions>Mobile</solutions>
     56         <level>INTERMEDIATE</level>
     57         <icon>screenshots/big-icon.png</icon>
     58         <screenshots>
     59             <img>screenshots/1-purchase-screen.png</img>
     60             <img>screenshots/2-fingerprint-dialog.png</img>
     61             <img>screenshots/3-fingerprint-authenticated.png</img>
     62             <img>screenshots/4-new-fingerprint-enrolled.png</img>
     63         </screenshots>
     64 
     65         <api_refs>
     66             <android>android.hardware.fingerprint.FingerprintManager</android>
     67             <android>android.hardware.fingerprint.FingerprintManager.AuthenticationCallback</android>
     68             <android>android.hardware.fingerprint.FingerprintManager.CryptoObject</android>
     69             <android>android.security.KeyGenParameterSpec</android>
     70             <android>java.security.KeyStore</android>
     71             <android>java.security.Signature</android>
     72             <android>java.security.KeyPairGenerator</android>
     73         </api_refs>
     74 
     75         <description>
     76 <![CDATA[
     77 A sample that demonstrates to use registered fingerprints to authenticate the user in your app
     78 ]]>
     79         </description>
     80 
     81         <intro>
     82 <![CDATA[
     83 This sample demonstrates how you can use registered fingerprints in your app to authenticate the
     84 user before proceeding some actions such as purchasing an item.
     85 
     86 First you need to create an asymmetric key pair in the Android Key Store using [KeyPairGenerator][1]
     87 in the way that its private key can only be used after the user has authenticated with fingerprint
     88 and transmit the public key to your backend with the user verified password (In a real world, the
     89 app should show proper UIs).
     90 
     91 By setting [KeyGenParameterSpec.Builder.setUserAuthenticationRequired][2] to true, you can permit the
     92 use of the key only after the user authenticate it including when authenticated with the user's
     93 fingerprint.
     94 
     95 Then start listening to a fingerprint on the fingerprint sensor by calling
     96 [FingerprintManager.authenticate][3] with a [Signature][4] initialized with the asymmetric key pair
     97 created. Or alternatively you can fall back to server-side verified password as an authenticator.
     98 
     99 Once the fingerprint (or password) is verified, the
    100 [FingerprintManager.AuthenticationCallback#onAuthenticationSucceeded()][5] callback is called.
    101 
    102 Then you can verify the purchase transaction on server side with the public key passed from the
    103 client, by verifying the piece of data signed by the Signature.
    104 
    105 [1]: https://developer.android.com/reference/java/security/KeyPairGenerator.html
    106 [2]: https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html#setUserAuthenticationRequired%28boolean%29
    107 [3]: https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html#authenticate%28android.hardware.fingerprint.FingerprintManager.CryptoObject,%20android.os.CancellationSignal,%20int,%20android.hardware.fingerprint.FingerprintManager.AuthenticationCallback,%20android.os.Handler%29
    108 [4]: https://developer.android.com/reference/java/security/Signature.html
    109 [5]: https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.AuthenticationCallback.html#onAuthenticationSucceeded%28android.hardware.fingerprint.FingerprintManager.AuthenticationResult%29
    110 ]]>
    111         </intro>
    112     </metadata>
    113 </sample>
    114