AuthorizationList

data class AuthorizationList : Asn1Encodable<Asn1Sequence> , PrettyPrintable, AttestationExtension.AuthList(source)

Intro

Authorization List ASN.1 sequence as defined by Android’s attestation schema: https://source.android.com/docs/security/features/keystore/attestation#schema

This is the meat of the AttestationKeyDescription certificate extension and is also used for secure key import.

Sources / Constants

The numeric values and semantics used here are aligned with:

  • KeyMint AIDL definitions (enum values, etc.): https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/keymint/aidl/android/hardware/security/keymint/

  • Keymaster header constants (historical reference): https://android.googlesource.com/platform/hardware/libhardware/+/refs/heads/main/include_all/hardware/keymaster_defs.h

  • Note: some online sources disagree with the schema for certain values (example discussion): https://android.googlesource.com/platform/frameworks/base/+blame/45ff13e/core/java/android/security/keymaster/KeymasterDefs.java

Every value is nullable because two authorization lists are present in an attestation extension: once for software-enforced values, and once for hardware-enforced value. The actual values are scattered across both instances.

On Parsing

Parsing is lenient: If a value fails to parse, it is set to null. In reality, you won't care whether a value is structurally illegal or absent:

  • If you want to enforce it, it must be present and structurally valid, fulfilling your constraints

  • If you don't care for it, you don't care whether it is present, invalid, or absent altogether In case you still want to explore the raw value, check the raw ASN.1 Sequence from the certificate extension and fetch the raw value according to the explicit tag denoting said value.

Structural Properties and Design Decisions

Structurally, this data structure follows the ASN.1 schema exactly, meaning that it is a structural 1:1 mapping if the underlying ASN.1 structure. This as both advantages and disadvantages. The main disadvantage is that it is a bit cumbersome to use. The benefits far outweigh the shortcomings of this approach, though:

  • Just check the schema, and you know what's what. That means that there are no booleans, but an object indicating true or false is either present or absent.

  • Re-Encoding produces the exact same ASN.1 structure that was parsed, byte-for-byte!

  • Creating Attestation statements for testing, fun, profit, or malicious intentions is a peak no-brainer; just follow the schema and set values!

Encoding and Ordering

AuthorizationList preserves the original order of the ASN.1 sequence during decoding by storing all decoded entries (including unknown tags) in elements.

For ASN.1 SET fields (e.g. purpose, blockMode, digest, padding, mgfDigest, and also AttestationApplicationId.packageInfos/AttestationApplicationId.signatureDigests):

  • When decoding, an internal order-preserving Set implementation is used so iteration keeps the original element order from the input (even if the input violates DER sorting).

  • The public API still exposes these values as regular Kotlin Sets.

  • When encoding, if such an order-preserving set is present, the produced ASN.1 SET preserves that iteration order (which may be non-DER-compliant). Otherwise, normal SET encoding is used.

Constructors

Link copied to clipboard
constructor(purpose: Set<AuthorizationList.KeyPurpose>? = null, algorithm: AuthorizationList.Algorithm? = null, keySize: AuthorizationList.KeySize? = null, blockMode: Set<AuthorizationList.BlockMode>? = null, digest: Set<AuthorizationList.Digest>? = null, padding: Set<AuthorizationList.Padding>? = null, callerNonce: AuthorizationList.CallerNonce? = null, minMacLength: AuthorizationList.MinMacLength? = null, ecCurve: AuthorizationList.ECCurve? = null, rsaPublicExponent: AuthorizationList.RsaPublicExponent? = null, mgfDigest: Set<AuthorizationList.MgfDigest>? = null, rollbackResistance: AuthorizationList.RollbackResistance? = null, earlyBootOnly: AuthorizationList.EarlyBootOnly? = null, activeDateTime: AuthorizationList.ActiveDateTime? = null, originationExpireDateTime: AuthorizationList.OriginationExpireDateTime? = null, usageExpireDateTime: AuthorizationList.UsageExpireDateTime? = null, usageCountLimit: AuthorizationList.UsageCountLimit? = null, userSecureId: AuthorizationList.UserSecureId? = null, noAuthRequired: AuthorizationList.NoAuthRequired? = null, userAuthType: AuthorizationList.UserAuth? = null, authTimeout: AuthorizationList.AuthTimeout? = null, allowWhileOnBody: AuthorizationList.AllowWhileOnBody? = null, trustedUserPresenceRequired: AuthorizationList.TrustedUserPresenceRequired? = null, trustedConfirmationRequired: AuthorizationList.TrustedConfirmationRequired? = null, unlockedDeviceRequired: AuthorizationList.UnlockedDeviceRequired? = null, allApplications: AuthorizationList.AllApplications? = null, creationDateTime: AuthorizationList.CreationDateTime? = null, origin: AuthorizationList.Origin? = null, rollbackResistant: AuthorizationList.RollbackResistent? = null, rootOfTrust: AuthorizationList.RootOfTrust? = null, osVersion: AuthorizationList.OsVersion? = null, osPatchLevel: AuthorizationList.OsPatchLevel? = null, attestationApplicationId: AuthorizationList.AttestationApplicationId? = null, attestationIdBrand: AuthorizationList.AttestationId.Brand? = null, attestationIdDevice: AuthorizationList.AttestationId.Device? = null, attestationIdProduct: AuthorizationList.AttestationId.Product? = null, attestationIdSerial: AuthorizationList.AttestationId.Serial? = null, attestationIdImei: AuthorizationList.AttestationId.Imei? = null, attestationIdMeid: AuthorizationList.AttestationId.Meid? = null, attestationIdManufacturer: AuthorizationList.AttestationId.Manufacturer? = null, attestationIdModel: AuthorizationList.AttestationId.Model? = null, vendorPatchLevel: AuthorizationList.PatchLevel.Vendor? = null, bootPatchLevel: AuthorizationList.PatchLevel.Boot? = null, deviceUniqueAttestation: AuthorizationList.DeviceUniqueAttestation? = null, attestationIdSecondImei: AuthorizationList.AttestationId.SecondImei? = null, moduleHash: AuthorizationList.ModuleHash? = null, trailingProperties: List<Asn1Element> = emptyList())

Convenience constructor that builds an AuthorizationList from the fields defined by Android’s attestation schema.

Types

Link copied to clipboard

“Active date time” (notBefore) timestamp in milliseconds since epoch.

Link copied to clipboard

Key algorithm as defined by KeyMint.

Link copied to clipboard
object AllApplications : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates “all applications”.

Link copied to clipboard
object AllowWhileOnBody : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates “allow while on body”.

Link copied to clipboard
data class AttestationApplicationId(val packageInfos: Set<AuthorizationList.AttestationPackageInfo>, val signatureDigests: Set<ByteArray>) : Asn1Encodable<Asn1Element> , AuthorizationList.Tagged.WithTag<Asn1Element> , PrettyPrintable

Attestation application identifier structure.

Link copied to clipboard
sealed class AttestationId : Asn1Encodable<Asn1Primitive> , AuthorizationList.Tagged.WithTag<Asn1Primitive>

Attestation ID value family (device identifiers).

Link copied to clipboard
data class AttestationPackageInfo(val packageName: String, val version: UInt) : Asn1Encodable<Asn1Sequence>

Package info entry within AttestationApplicationId.packageInfos.

Link copied to clipboard

Authentication timeout.

Link copied to clipboard

Block modes as defined by KeyMint.

Link copied to clipboard
object CallerNonce : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates "caller nonce".

Link copied to clipboard
object Companion : Asn1Decodable<Asn1Sequence, AuthorizationList>
Link copied to clipboard

Key creation timestamp in milliseconds since epoch.

Link copied to clipboard
object DeviceUniqueAttestation : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Can only ever be set by privileged system apps

Link copied to clipboard

Digest modes as defined by KeyMint.

Link copied to clipboard
object EarlyBootOnly : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates “early boot only”.

Link copied to clipboard

Elliptic curve identifiers as defined by KeyMint.

Link copied to clipboard
sealed interface Element

A single entry inside the AuthorizationList ASN.1 sequence.

Link copied to clipboard
interface IntEncodable : Asn1Encodable<Asn1Primitive> , AuthorizationList.Tagged.WithTag<Asn1Primitive>

Helper interface for “integer-backed” authorization list values.

Link copied to clipboard

Key purposes as defined by KeyMint.

Link copied to clipboard

Key size (in bits).

Link copied to clipboard
data class MgfDigest(val intValue: Asn1Integer) : AuthorizationList.IntEncodable

MGF digest.

Link copied to clipboard

Minimum MAC length (in bits).

Link copied to clipboard
data class ModuleHash(val sha256Digest: ByteArray) : Asn1Encodable<Asn1Primitive> , AuthorizationList.Tagged.WithTag<Asn1Primitive>

In the context of Android's Keymaster and Keystore systems, the moduleHash is a component within the attestation data structure, specifically in the KeyDescription sequence. It provides a cryptographic representation of the software environment associated with the key's creation and usage.

Link copied to clipboard
object NoAuthRequired : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates that no user authentication is required.

Link copied to clipboard

Key origin as defined by KeyMint.

Link copied to clipboard

“Origination expire date time” (notAfter) timestamp in milliseconds since epoch.

Link copied to clipboard
data class OsPatchLevel(val year: UShort, val month: Month) : AuthorizationList.IntEncodable

OS patch level as year and month, encoded as year * 100 + month as per the schema.

Link copied to clipboard
data class OsVersion(val major: UByte, val minor: UByte, val sub: UByte) : AuthorizationList.IntEncodable

OS version, encoded as an integer MMmmss (major/minor/sub) as per the schema.

Link copied to clipboard

Padding modes as defined by KeyMint.

Link copied to clipboard

Patch level value family.

Link copied to clipboard
object RollbackResistance : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates “rollback resistance”.

Link copied to clipboard
object RollbackResistent : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Legacy rollback-resistant indicator (older attestation versions use this tag name/spelling).

Link copied to clipboard
data class RootOfTrust : Asn1Encodable<Asn1Sequence> , AuthorizationList.Tagged.WithTag<Asn1Sequence> , PrettyPrintable

Root of trust structure.

Link copied to clipboard

RSA public exponent.

Link copied to clipboard
sealed class Tagged

Base type for explicit tag constants used by the AuthorizationList schema.

Link copied to clipboard
object TrustedConfirmationRequired : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates “trusted confirmation required”.

Link copied to clipboard
object TrustedUserPresenceRequired : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates “trusted user presence required”.

Link copied to clipboard
object UnlockedDeviceRequired : AuthorizationList.Tagged, Asn1Encodable<Asn1Primitive>

Indicates “unlocked device required”.

Link copied to clipboard
data class UsageCountLimit(val intValue: Asn1Integer) : AuthorizationList.IntEncodable

Limits the number of permitted uses of a key.

Link copied to clipboard

“Usage expire date time” timestamp in milliseconds since epoch.

Link copied to clipboard
data class UserAuth(val intValue: Asn1Integer) : AuthorizationList.IntEncodable

As per the KeyMaster AIDL

Link copied to clipboard

Secure user ID (SID).

Properties

Link copied to clipboard

Key validity "not before" timestamp.

Link copied to clipboard
val additionalProperties: List<Asn1Element>
Link copied to clipboard
Link copied to clipboard

"All applications" flag (legacy / keymaster).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Elliptic curve identifier.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Key origination validity "not after" timestamp.

Link copied to clipboard
Link copied to clipboard

YearMonth representation of AuthorizationList.osPatchLevel, but tolerating a zero-indexed month

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Legacy rollback-resistant flag (keymaster attestation versions 1–2).

Link copied to clipboard

Root of trust information (verified boot state, device lock state, etc).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Key usage validity "not after" timestamp.

Link copied to clipboard

Hardware authenticator type (user authentication type).

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun doPrettyPrint(indent: String): String
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun encodeToDerSafe(): KmmResult<ByteArray>
Link copied to clipboard
open override fun encodeToTlv(): Asn1Sequence
Link copied to clipboard
open fun encodeToTlvOrNull(): Asn1Sequence?
Link copied to clipboard
open fun encodeToTlvSafe(): KmmResult<Asn1Sequence>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun versionCheck(attestationVersion: Int)

Useful for debugging, but too strict in reality

Link copied to clipboard
open infix fun withImplicitTag(tag: Asn1Element.Tag): Asn1Element
open infix fun withImplicitTag(template: Asn1Element.Tag.Template): Asn1Element
open infix fun withImplicitTag(tagValue: ULong): Asn1Element