Keystore Key Attestation (2024)

Posted by Shawn Willden, Software Engineer

Android's keystore has been available for many years, providing app developerswith a way to use cryptographic keys for authentication and encryption. Keystorekeeps the key material out of the app's process space, so that the app cannotinadvertently reveal it to the user where it could be phished, leak it throughsome other channel, or have it compromised in the event of a compromise of theapp. Many devices also provide hardware-based security for keystore keys insecure hardware, which keeps the key material out of the Android systementirely, so that the key material cannot be leaked even by a Linux kernelcompromise. In the vast majority of Android devices, secure hardware is aspecial mode of the main CPU, with hardware-enforced isolation from the Linuxkernel and Android userspace. Alternatively, some devices use a separate securemicroprocessor.

Android provides APIs that allow the app to determine whether a given keystorekey is in secure hardware, but these APIs could be unreliable if the operatingsystem has been compromised. Key attestation provides a way for a device'ssecure hardware to verify that an asymmetric key is in secure hardware,protected against compromise of the Android OS.

History of Keystore

Keystore was originally introduced in Android 4.0 and keys were encrypted withthe user's passcode. In Android 4.1 the infrastructure to use device securehardware was added.

Up until Android 6.0, Keystore supported RSA and ECDSA. In Android 6.0, Keystorewas significantly enhanced, adding support for AES and HMAC. Also, other crucialelements of cryptographic operations, such as RSA padding1 and AES block chaining2 modes were moved into secure hardware.

In Android 6.0, Keystore also gained the ability to restrict the ways in which aparticular key could be used. The most obviously useful restriction that can beapplied is user authentication binding. This allows a key's usage to be"bound" to the user's passcode—their PIN, pattern, or password—or fingerprint.For passcode authentication binding, the app developer can specify a timeout inseconds. If more than the specified time has elapsed since the user last enteredtheir passcode, the secure hardware refuses any requests to use the key.Fingerprint-bound keys require a new user authentication each time the key isused.

Other, more technical, restrictions can be applied to Android 6.0+ keys as well.In particular, at point of key creation or import, it is necessary to specifythe cryptographic purposes (encrypt, decrypt, sign, or verify) for which the keymay be used, as well as padding and block modes, digests, source of entropy forinitialization vectors or nonces, and other details of the cryptographicoperation. Because the specified information is permanently andcryptographically bound to the key material, Keystore won't allow the key to beused in any other way. Therefore, an attacker who gains control of the app orthe system can't misuse the key. To help prevent attacks, developers shouldspecify the narrowest possible range of uses for a given key.

One of the most important changes to Android Keystore was introduced in Android7.0. New devices that launch with Android 7.0+ with a secure lock screen musthave secure hardware and support hardware-based passcode authentication andkeystore keys. Prior to Android 7.0, secure hardware support was widespread, butover the next few years it will become universal.

In Android 8.0, key attestation was made mandatory for all new devices that shipwith Google Play installed.

Why use key attestation?

Suppose you're developing an app to provide a bank's customers with access totheir bank balance, transaction history, and bill pay system. Security isimportant; you don't want anyone who picks up the user's phone to have access totheir the bank account. One approach would be to use the user's web sitepassword. But that's often inconvenient for the user because web sites oftendemand long, complex passwords, which are inconvenient on a small touchscreen.

With Android Keystore, you can generate an asymmetric authentication key, suchas a 256-bit ECDSA key, and have each user sign in with their complex webpassword once, then register the public key in the bank's customer accountdatabase. Each time they open the app, you can execute a challenge-responseauthentication protocol using that ECDSA key. Further, if you make the keyauthentication-bound, the user can authenticate with their lock screen passcodeor fingerprint each time they open the app. That allows them to use the simplerand more convenient authentication mechanism on their phone.

If an attacker compromises Android and attempts to extract the key, theyshouldn't be able to because the key is in secure hardware.

As an app developer, key attestation allows you to verify on your server thatthe ECDSA key your app requested actually lives in secure hardware. Note thatthere's little point in using the attestation in your app itself; if the AndroidOS is uncompromised and trustworthy, then you can just use the KeyInfoclass introduced in 6.0 to discover whether the key is in secure hardware. If itis compromised, then that API and any attempt you make to validate theattestation on device are both unreliable.

Note that key attestation is distinct from SafetyNetattestation. They're the same concept, but attest to different things andcome from different places. Keystore key attestation affirms that a crypto keylives in secure hardware and has specific characteristics. SafetyNet attestationaffirms that a device is real (not an emulator) and that it's running knownsoftware. SafetyNet uses Keystore key attestation under the covers, so if youwant to know about device integrity use that. If you want to confirm that yourkey is in secure hardware, use key attestation.

For details and sample code, see the keyattestation training article on developer.android.com.

Notes

  1. Keystore supports the recommended OAEP and PSS padding modes for RSA encryption andsigning, respectively, as well as the older PKCS#1 v1.5 modes.

  2. Keystore supports GCM, CBC and ECB block chaining modes.

Keystore Key Attestation (2024)

FAQs

What is a key attestation? ›

Key attestation, in this context, is the technical ability to prove to a remote party that a private key was generated inside, and is managed inside, and not exportable from, a hardware cryptographic module.

What is key attestation? ›

Key attestation aims to provide a way to strongly determine if an asymmetric key pair is hardware-backed, what the properties of the key are, and what constraints are applied to its usage. ID attestation allows the device to provide proof of its hardware identifiers, such as serial number or IMEI.

What is attestation identity key? ›

An Attestation Identity Key (AIK) is used to provide such a cryptographic proof by signing the properties of the non-migratable key and providing the properties and signature to the CA for verification.

What is keystore in authentication? ›

A Keystore is a repository for sensitive cryptographic data, such as private keys and certificates, and helps to secure device communication and authentication. Keystores are crucial in ensuring security for mobile applications.

What is the main purpose of attestation? ›

Attestation is the act of witnessing the signing of a formal document and then also signing it to verify that it was properly signed by those bound by its contents. Attestation is a legal acknowledgment of the authenticity of a document and a verification that proper processes were followed.

What are the two types of attestation? ›

Reviews and audits are two attestation services that extend assurance to outside parties, such as lenders, regulators, and investors. This assurance is often provided for financial data, but it can be applied to other areas, as well, such as a business's controls or compliance with contracts and regulations.

What is an attestation example? ›

For example, a witness attests a will by signing it; their signature may confirm, inter alia, that they witnessed the testator sign the will.

What is the difference between authentication and attestation? ›

An official verification of something as true or authentic (Merriam-Webster). In the Authentifier process, attestation refers to the notarial certification of documents. However, the word attestation is commonly used in the UAE and Qatar interchangeably with the term 'authentication'.

What is attestation in cryptography? ›

The attestation process uses a series of measurements that are unique to an enclave. You can use these measurements to create access policies in external services to grant the enclave access to special cryptographic operations.

What is identity attestation? ›

Identity and access attestation is a process that involves verifying and validating the identity of individuals and managing their access to systems, applications or resources within an organization.

What is the difference between attestation and verification? ›

Attestation: Attestation is confirmation that a photocopy is a true copy of an original document. The British Council will not be responsible for confirming the authenticity of the original certificate. Verification: Verification is the process of ensuring that original documents are genuine.

What is the difference between endorsem*nt key and attestation key? ›

A trusted platform module is identified by its endorsem*nt key, while it uses an attestation key to provide attestation services, for example, signing a set of platform configuration registers, providing a timestamp or certifying another of its keys.

What is keystore key? ›

Keystores and truststores are repositories that contain cryptographic artifacts like certificates and private keys that are used for cryptographic protocols such as TLS. A keystore contains personal certificates, plus the corresponding private keys that are used to identify the owner of the certificate.

Why is keystore needed? ›

Generally speaking, keystores hold keys that our application owns, which we can use to prove the integrity of a message and the authenticity of the sender, say by signing payloads. Usually, we'll use a keystore when we're a server and want to use HTTPS.

What is the keystore signing key? ›

signing-keystore: specifies the location and filename of the existing keystore that contains the private key that will be used to sign the APK file after it is processed by the PEPK tool. The keystore specified here should contain a private key with the alias specified by the signing-key-alias parameter.

What is the difference between notarized and attestation? ›

Notarization primarily serves to prevent fraud and ensure the authenticity of documents within a specific jurisdiction, whereas attestation is required for documents intended for use in foreign countries or legal jurisdictions.

What is attestation in credentialing? ›

Identity and access attestation is a process that involves verifying and validating the identity of individuals and managing their access to systems, applications or resources within an organization.

What is the role of the attestation? ›

Attestation is the act of verifying and certifying the accuracy or truth of a document or statement. An attestation helps provide assurance that the information presented is valid and reliable. Attestation serves several key purposes. First, it helps establish credibility and trust in the information.

Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 6125

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.