1*7ca20792SAndroid Build Coastguard WorkerAndroid Key Attestation Sample 2*7ca20792SAndroid Build Coastguard Worker============================== 3*7ca20792SAndroid Build Coastguard Worker 4*7ca20792SAndroid Build Coastguard WorkerThis sample illustrates how to use the [Bouncy Castle ASN.1][1] parser to extract information 5*7ca20792SAndroid Build Coastguard Workerfrom an Android attestation data structure to verify that a key pair has been 6*7ca20792SAndroid Build Coastguard Workergenerated in an Android device. This sample demonstrates how to verify a certificate on a server. 7*7ca20792SAndroid Build Coastguard Worker 8*7ca20792SAndroid Build Coastguard Worker[1]: https://www.bouncycastle.org/ 9*7ca20792SAndroid Build Coastguard Worker 10*7ca20792SAndroid Build Coastguard WorkerIntroduction 11*7ca20792SAndroid Build Coastguard Worker------------ 12*7ca20792SAndroid Build Coastguard Worker 13*7ca20792SAndroid Build Coastguard WorkerThis example demonstrates the following tasks: 14*7ca20792SAndroid Build Coastguard Worker 15*7ca20792SAndroid Build Coastguard Worker1. Loading the certificates from [PEM/DER][2]-encoded strings. 16*7ca20792SAndroid Build Coastguard Worker1. Verifying the [X.509][3] certificate chain, up to the root. This includes checking that the root certificate is one of Google's root certificates listed in https://developer.android.com/training/articles/security-key-attestation. 17*7ca20792SAndroid Build Coastguard Worker1. Extracting the attestation extension data from the attestation 18*7ca20792SAndroid Build Coastguard Worker certificate. 19*7ca20792SAndroid Build Coastguard Worker1. Verifying (and printing) data elements from the attestation extension. 20*7ca20792SAndroid Build Coastguard Worker 21*7ca20792SAndroid Build Coastguard WorkerFor more information about the process of extracting attestation certificate 22*7ca20792SAndroid Build Coastguard Workerextension data, as well as the extension data schema, see the 23*7ca20792SAndroid Build Coastguard Worker[Key Attestation][4] Android developer training article. 24*7ca20792SAndroid Build Coastguard Worker 25*7ca20792SAndroid Build Coastguard WorkerNote that this sample demonstrates the verification of a certificate on a server and not 26*7ca20792SAndroid Build Coastguard Workeron the Android framework. Although you can test the certificate and extensions directly 27*7ca20792SAndroid Build Coastguard Workeron a device, it is safer to run these checks on a separate server you can trust. 28*7ca20792SAndroid Build Coastguard Worker 29*7ca20792SAndroid Build Coastguard Worker[2]: https://developer.android.com/reference/java/security/KeyStore.html#getCertificateChain(java.lang.String) 30*7ca20792SAndroid Build Coastguard Worker[3]: https://developer.android.com/reference/javax/security/cert/X509Certificate.html 31*7ca20792SAndroid Build Coastguard Worker[4]: https://developer.android.com/training/articles/security-key-attestation.html 32*7ca20792SAndroid Build Coastguard Worker 33*7ca20792SAndroid Build Coastguard WorkerPre-requisites 34*7ca20792SAndroid Build Coastguard Worker-------------- 35*7ca20792SAndroid Build Coastguard Worker 36*7ca20792SAndroid Build Coastguard Worker- Up-to-date Java JDK 37*7ca20792SAndroid Build Coastguard Worker- [Bouncy Castle Cryptography Java APIs][5] (included as dependency in gradle build configuration). 38*7ca20792SAndroid Build Coastguard Worker 39*7ca20792SAndroid Build Coastguard Worker[5]: https://www.bouncycastle.org/java.html 40*7ca20792SAndroid Build Coastguard Worker 41*7ca20792SAndroid Build Coastguard WorkerGetting Started 42*7ca20792SAndroid Build Coastguard Worker--------------- 43*7ca20792SAndroid Build Coastguard Worker 44*7ca20792SAndroid Build Coastguard WorkerThis sample uses the Gradle build system. To build this project, use the 45*7ca20792SAndroid Build Coastguard Worker`gradlew build` command or use "Import Project" in IntelliJ or Android Studio. 46*7ca20792SAndroid Build Coastguard Worker 47*7ca20792SAndroid Build Coastguard WorkerRun the main method in `KeyAttestationExample` directly or use the 48*7ca20792SAndroid Build Coastguard Worker`gradlew run --args="<cert-directory>"` task to execute this sample. The `cert-directory` must 49*7ca20792SAndroid Build Coastguard Workercontain the certificate chain, one certificate per file in either DER or PEM encoding and the files 50*7ca20792SAndroid Build Coastguard Workerare read in alphabetical order. For example the provided 51*7ca20792SAndroid Build Coastguard Worker`/examples/pem/algorithm_EC_SecurityLevel_StrongBox/` can be used. 52*7ca20792SAndroid Build Coastguard Worker 53*7ca20792SAndroid Build Coastguard WorkerSupport 54*7ca20792SAndroid Build Coastguard Worker------- 55*7ca20792SAndroid Build Coastguard Worker 56*7ca20792SAndroid Build Coastguard Worker- Stack Overflow: http://stackoverflow.com/questions/tagged/android 57*7ca20792SAndroid Build Coastguard Worker 58*7ca20792SAndroid Build Coastguard WorkerIf you've found an error in this sample, please file an issue: 59*7ca20792SAndroid Build Coastguard Workerhttps://github.com/googlesamples/android-key-attestation 60*7ca20792SAndroid Build Coastguard Worker 61*7ca20792SAndroid Build Coastguard WorkerPatches are encouraged, and may be submitted by forking this project and 62*7ca20792SAndroid Build Coastguard Workersubmitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. 63*7ca20792SAndroid Build Coastguard Worker 64*7ca20792SAndroid Build Coastguard WorkerLicense 65*7ca20792SAndroid Build Coastguard Worker------- 66*7ca20792SAndroid Build Coastguard Worker 67*7ca20792SAndroid Build Coastguard WorkerCopyright 2016, The Android Open Source Project, Inc. 68*7ca20792SAndroid Build Coastguard Worker 69*7ca20792SAndroid Build Coastguard WorkerLicensed to the Apache Software Foundation (ASF) under one or more contributor 70*7ca20792SAndroid Build Coastguard Workerlicense agreements. See the NOTICE file distributed with this work for 71*7ca20792SAndroid Build Coastguard Workeradditional information regarding copyright ownership. The ASF licenses this 72*7ca20792SAndroid Build Coastguard Workerfile to you under the Apache License, Version 2.0 (the "License"); you may not 73*7ca20792SAndroid Build Coastguard Workeruse this file except in compliance with the License. You may obtain a copy of 74*7ca20792SAndroid Build Coastguard Workerthe License at 75*7ca20792SAndroid Build Coastguard Worker 76*7ca20792SAndroid Build Coastguard Workerhttp://www.apache.org/licenses/LICENSE-2.0 77*7ca20792SAndroid Build Coastguard Worker 78*7ca20792SAndroid Build Coastguard WorkerUnless required by applicable law or agreed to in writing, software 79*7ca20792SAndroid Build Coastguard Workerdistributed under the License is distributed on an "AS IS" BASIS, WITHOUT 80*7ca20792SAndroid Build Coastguard WorkerWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 81*7ca20792SAndroid Build Coastguard WorkerLicense for the specific language governing permissions and limitations under 82*7ca20792SAndroid Build Coastguard Workerthe License. 83