Google is committed to advancing racial equity for Black communities. See how.

IdentityCredentialStore

abstract class IdentityCredentialStore
kotlin.Any
   ↳ androidx.security.identity.IdentityCredentialStore

An interface to a secure store for user identity documents.

This interface is deliberately fairly general and abstract. To the extent possible, specification of the message formats and semantics of communication with credential verification devices and issuing authorities (IAs) is out of scope. It provides the interface with secure storage but a credential-specific Android application will be required to implement the presentation and verification protocols and processes appropriate for the specific credential type.

Multiple credentials can be created. Each credential comprises:

  • A document type, which is a string.
  • A set of namespaces, which serve to disambiguate value names. It is recommended that namespaces be structured as reverse domain names so that IANA effectively serves as the namespace registrar.
  • For each namespace, a set of name/value pairs, each with an associated set of access control profile IDs. Names are strings and values are typed and can be any value supported by CBOR.
  • A set of access control profiles, each with a profile ID and a specification of the conditions which satisfy the profile's requirements.
  • An asymmetric key pair which is used to authenticate the credential to the Issuing Authority, called the CredentialKey.
  • A set of zero or more named reader authentication public keys, which are used to authenticate an authorized reader to the credential.
  • A set of named signing keys, which are used to sign collections of values and session transcripts.

Implementing support for user identity documents in secure storage requires dedicated hardware-backed support and may not always be available.

Two different credential stores exist - the default store and the direct access store. Most often credentials will be accessed through the default store but that requires that the Android device be powered up and fully functional. It is desirable to allow identity credential usage when the Android device's battery is too low to boot the Android operating system, so direct access to the secure hardware via NFC may allow data retrieval, if the secure hardware chooses to implement it.

Credentials provisioned to the direct access store should always use reader authentication to protect data elements. The reason for this is user authentication or user approval of data release is not possible when the device is off.

Summary

Constants
static Int

Specifies that the cipher suite that will be used to secure communications between the reader and the prover is using the following primitives

  • ECKA-DH (Elliptic Curve Key Agreement Algorithm - Diffie-Hellman, see BSI TR-03111).
  • HKDF-SHA-256 (see RFC 5869).
  • AES-256-GCM (see NIST SP 800-38D).
  • HMAC-SHA-256 (see RFC 2104).

Public methods
abstract WritableIdentityCredential
createCredential(@NonNull credentialName: String, @NonNull docType: String)

Creates a new credential.

abstract ByteArray?
deleteCredentialByName(@NonNull credentialName: String)

Delete a named credential.

abstract IdentityCredential?
getCredentialByName(@NonNull credentialName: String, cipherSuite: Int)

Retrieve a named credential.

open static IdentityCredentialStore
getDirectAccessInstance(@NonNull context: Context)

Gets the IdentityCredentialStore for direct access.

open static IdentityCredentialStore
getInstance(@NonNull context: Context)

Gets the default IdentityCredentialStore.

abstract Array<String!>

Gets a list of supported document types.

open static Boolean
isDirectAccessSupported(@NonNull context: Context)

Checks if direct-access is supported.

Constants

CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256

static val CIPHERSUITE_ECDHE_HKDF_ECDSA_WITH_AES_256_GCM_SHA256: Int

Specifies that the cipher suite that will be used to secure communications between the reader and the prover is using the following primitives

  • ECKA-DH (Elliptic Curve Key Agreement Algorithm - Diffie-Hellman, see BSI TR-03111).
  • HKDF-SHA-256 (see RFC 5869).
  • AES-256-GCM (see NIST SP 800-38D).
  • HMAC-SHA-256 (see RFC 2104).

The exact way these primitives are combined to derive the session key is specified in section 9.2.1.4 of ISO/IEC 18013-5 (see description of cipher suite '1').

At present this is the only supported cipher suite.

Value: 1

Public methods

createCredential

@NonNull abstract fun createCredential(
    @NonNull credentialName: String,
    @NonNull docType: String
): WritableIdentityCredential

Creates a new credential.

Parameters
credentialName String: The name used to identify the credential.
docType String: The document type for the credential.
Return
WritableIdentityCredential A @{link WritableIdentityCredential} that can be used to create a new credential.
Exceptions
AlreadyPersonalizedException if a credential with the given name already exists.
DocTypeNotSupportedException if the given document type isn't supported by the store.

deleteCredentialByName

@Nullable abstract fun deleteCredentialByName(@NonNull credentialName: String): ByteArray?

Delete a named credential.

This method returns a COSE_Sign1 data structure signed by the CredentialKey with payload set to ProofOfDeletion as defined below:

ProofOfDeletion = [
               "ProofOfDeletion",            ; tstr
               tstr,                         ; DocType
               bool                          ; true if this is a test credential, should
                                             ; always be false.
           ]
      
Parameters
credentialName String: the name of the credential to delete.
Return
ByteArray? null if the credential was not found, the COSE_Sign1 data structure above if the credential was found and deleted.

getCredentialByName

@Nullable abstract fun getCredentialByName(
    @NonNull credentialName: String,
    cipherSuite: Int
): IdentityCredential?

Retrieve a named credential.

Parameters
credentialName String: the name of the credential to retrieve.
cipherSuite Int: the cipher suite to use for communicating with the verifier.
Return
IdentityCredential? The named credential, or null if not found.

getDirectAccessInstance

@NonNull open static fun getDirectAccessInstance(@NonNull context: Context): IdentityCredentialStore

Gets the IdentityCredentialStore for direct access. This should only be called if isDirectAccessSupported(Context) returns true.

Parameters
context Context: the application context.
Return
IdentityCredentialStore the IdentityCredentialStore or null if direct access is not supported on this device.

getInstance

@NonNull open static fun getInstance(@NonNull context: Context): IdentityCredentialStore

Gets the default IdentityCredentialStore.

Parameters
context Context: the application context.
Return
IdentityCredentialStore the IdentityCredentialStore.

getSupportedDocTypes

@NonNull abstract fun getSupportedDocTypes(): Array<String!>

Gets a list of supported document types.

Only the direct-access store may restrict the kind of document types that can be used for credentials. The default store always supports any document type.

Return
Array<String!> The supported document types or the empty array if any document type is supported.

isDirectAccessSupported

open static fun isDirectAccessSupported(@NonNull context: Context): Boolean

Checks if direct-access is supported.

Direct access requires specialized NFC hardware and may not be supported on all devices even if default store is available.

Because Android is not running when direct-access credentials are presented, there is no way for the user to consent to release of credential data. Therefore, credentials provisioned to the direct access store should always use reader authentication to protect data elements such that only readers authorized by the issuer can access them. The AccessControlProfile.Builder#setReaderCertificate(X509Certificate) method can be used at provisioning time to set which reader (or group of readers) are authorized to access data elements.

Parameters
context Context: the application context.
Return
Boolean true if direct-access is supported.