AndroidKeystoreKeyStore

The wallet's keys, in Android Keystore: P-256 keys whose private halves never leave its secure hardware — StrongBox where the device has it (Options.strongBox), else the TEE. Each key's ID is its Keystore alias after Options.aliasPrefix. Keys are usable only while the device is unlocked, and holder keys, if Options.holderUserAuthentication, each time they sign only after authenticator has authenticated the holder: the store refuses to be made without one then.

Constructors

Link copied to clipboard
constructor(options: AndroidKeystoreKeyStore.Options = Options(), authenticator: HolderAuthenticator? = null)

Types

Link copied to clipboard
data class Options(val strongBox: AndroidKeystoreKeyStore.StrongBox = StrongBox.PREFERRED, val holderUserAuthentication: Boolean = true, val aliasPrefix: String = "org.idfoundry.oid4vcgo.key.", val holderKeyAgreement: Boolean = false)

How an AndroidKeystoreKeyStore makes keys: by default in StrongBox where the device has it, holder keys asking for the holder each time.

Link copied to clipboard

Where keys are made.

Properties

Link copied to clipboard
open override val isDurable: Boolean

Keystore keys survive the app quitting.

Link copied to clipboard

How the store makes keys.

Functions

Link copied to clipboard
open override fun agree(id: String, peerPublicKey: ByteArray): ByteArray

ECDH between holder key id and peerPublicKey inside Android Keystore. A key made without PURPOSE_AGREE_KEY (see Options.holderKeyAgreement), below API 31, or requiring the holder, throws KeyAgreementUnsupportedException: the wallet signs.

Link copied to clipboard
open override fun createKey(purpose: KeyPurpose): String

Creates a P-256 key for purpose and returns its ID.

Link copied to clipboard
open override fun deleteKey(id: String)

Deletes the key; deleting one that doesn't exist isn't an error.

Link copied to clipboard
fun deleteKeys(except: Set<String>): Int

Deletes every key this store holds except except, and returns how many it deleted. Wallet.sweepOrphanedKeys calls it with the keys the wallet's credentials are bound to.

Link copied to clipboard

The IDs of every key this store holds (under its alias prefix).

Link copied to clipboard
open override fun publicKey(id: String): ByteArray?

The key's public key as an uncompressed X9.63 point (0x04 || X || Y), or null when there's no such key.

Link copied to clipboard

Where key id lives, as a KeyProperties.SECURITY_LEVEL_ value: StrongBox, the TEE, or software. Android 11 can't tell StrongBox from the TEE: there, a key in secure hardware is the TEE's. (The constants are API 31's, but compile-time ints: they work on 30.)

Link copied to clipboard
open override fun sign(id: String, digest: ByteArray): ByteArray

Signs a SHA-256 digest with the key, returning an ASN.1 DER ECDSA signature. A holder key may ask the holder to authenticate here.