blob: 1c80cbbe828e06eb9a522ba4af2fbd95f793ac68 [file] [log] [blame]
David Zeuthenc75ac312019-10-28 13:16:45 -04001/*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
David Zeuthen81603152020-02-11 22:04:24 -050017package android.hardware.identity;
18
19import android.hardware.identity.Certificate;
20import android.hardware.identity.SecureAccessControlProfile;
David Zeuthenc75ac312019-10-28 13:16:45 -040021
22/**
23 * IWritableIdentityCredential is used to personalize a new identity credential. Credentials cannot
24 * be updated or modified after creation; any changes require deletion and re-creation.
25 */
David Zeuthen81603152020-02-11 22:04:24 -050026@VintfStability
David Zeuthenc75ac312019-10-28 13:16:45 -040027interface IWritableIdentityCredential {
28 /**
29 * Gets the certificate chain for credentialKey which can be used to prove the hardware
30 * characteristics to an issuing authority. Must not be called more than once.
31 *
David Zeuthenef739512020-06-03 13:24:52 -040032 * The following non-optional fields for the X.509 certificate shall be set as follows:
33 *
34 * - version: INTEGER 2 (means v3 certificate).
35 *
36 * - serialNumber: INTEGER 1 (fixed value: same on all certs).
37 *
38 * - signature: must be set to ECDSA.
39 *
David Zeuthen34abaae2020-10-26 20:26:36 -040040 * - subject: CN shall be set to "Android Identity Credential Key". (fixed value:
41 * same on all certs)
David Zeuthenef739512020-06-03 13:24:52 -040042 *
David Zeuthen34abaae2020-10-26 20:26:36 -040043 * - issuer: Same as the subject field of the batch attestation key.
David Zeuthenef739512020-06-03 13:24:52 -040044 *
David Zeuthen34abaae2020-10-26 20:26:36 -040045 * - validity: Should be set to current time and expire at the same time as the
David Zeuthenef739512020-06-03 13:24:52 -040046 * attestation batch certificate used.
47 *
48 * - subjectPublicKeyInfo: must contain attested public key.
49 *
David Zeuthenc75ac312019-10-28 13:16:45 -040050 * The certificate chain must be generated using Keymaster Attestation
David Zeuthen87cb07b2020-01-30 16:15:50 -050051 * (see https://source.android.com/security/keystore/attestation) with the
David Zeuthenef739512020-06-03 13:24:52 -040052 * following additional requirements on the data in the attestation extension:
David Zeuthen87cb07b2020-01-30 16:15:50 -050053 *
54 * - The attestationVersion field in the attestation extension must be at least 3.
55 *
56 * - The attestationSecurityLevel field must be set to either Software (0),
57 * TrustedEnvironment (1), or StrongBox (2) depending on how attestation is
David Zeuthen34abaae2020-10-26 20:26:36 -040058 * implemented.
David Zeuthen87cb07b2020-01-30 16:15:50 -050059 *
David Zeuthen34abaae2020-10-26 20:26:36 -040060 * - The keymasterVersion field in the attestation extension must be set to the.
61 * same value as used for Android Keystore keys.
David Zeuthen87cb07b2020-01-30 16:15:50 -050062 *
63 * - The keymasterSecurityLevel field in the attestation extension must be set to
64 * either Software (0), TrustedEnvironment (1), or StrongBox (2) depending on how
David Zeuthen34abaae2020-10-26 20:26:36 -040065 * the Trusted Application backing the HAL implementation is implemented.
David Zeuthen87cb07b2020-01-30 16:15:50 -050066 *
67 * - The attestationChallenge field must be set to the passed-in challenge.
68 *
69 * - The uniqueId field must be empty.
70 *
71 * - The softwareEnforced field in the attestation extension must include
72 * Tag::ATTESTATION_APPLICATION_ID which must be set to the bytes of the passed-in
73 * attestationApplicationId.
74 *
75 * - The teeEnforced field in the attestation extension must include
David Zeuthenc4286922020-03-03 10:09:03 -050076 *
77 * - Tag::IDENTITY_CREDENTIAL_KEY which indicates that the key is an Identity
78 * Credential key (which can only sign/MAC very specific messages) and not an Android
David Zeuthen34abaae2020-10-26 20:26:36 -040079 * Keystore key (which can be used to sign/MAC anything). This must not be set
80 * for test credentials.
David Zeuthenc4286922020-03-03 10:09:03 -050081 *
82 * - Tag::PURPOSE must be set to SIGN
83 *
84 * - Tag::KEY_SIZE must be set to the appropriate key size, in bits (e.g. 256)
85 *
86 * - Tag::ALGORITHM must be set to EC
87 *
88 * - Tag::NO_AUTH_REQUIRED must be set
89 *
90 * - Tag::DIGEST must be set to SHA_2_256
91 *
92 * - Tag::EC_CURVE must be set to P_256
David Zeuthen87cb07b2020-01-30 16:15:50 -050093 *
David Zeuthen34abaae2020-10-26 20:26:36 -040094 * - Tag::ROOT_OF_TRUST must be set
95 *
96 * - Tag::OS_VERSION and Tag::OS_PATCHLEVEL must be set
97 *
98 * Additional authorizations may be appear in the softwareEnforced and teeEnforced
99 * fields. For example if the device has a boot or vendor partitions, then BOOT_PATCHLEVEL
100 * and VENDOR_PATCHLEVEL should be set.
David Zeuthenc4286922020-03-03 10:09:03 -0500101 *
102 * Since the chain is required to be generated using Keymaster Attestation, the returned
103 * certificate chain has the following properties:
104 *
105 * - The certificate chain is of at least length three.
106 *
107 * - The root of trust is the same as for Keymaster Attestation. This is usually
108 * a certificate owned by Google but depending on the specific Android device it may
109 * be another certificate.
110 *
111 * As with any user of attestation, the Issuing Authority (as a relying party) wishing
112 * to issue a credential to a device using these APIs, must carefully examine the
113 * returned certificate chain for all of the above (and more). In particular, the Issuing
David Zeuthen34abaae2020-10-26 20:26:36 -0400114 * Authority should check the root of trust (which include verified boot state), patch level,
115 * attestation application id, etc.
David Zeuthenc4286922020-03-03 10:09:03 -0500116 *
117 * This all depends on the needs of the Issuing Authority and the kind of credential but
118 * in general an Issuing Authority should never issue a credential to a device without
119 * verified boot enabled, to an unrecognized application, or if it appears the device
120 * hasn't been updated for a long time.
121 *
122 * See https://github.com/google/android-key-attestation for an example of how to
123 * examine attestations generated from Android devices.
David Zeuthen87cb07b2020-01-30 16:15:50 -0500124 *
125 * @param attestationApplicationId is the DER encoded value to be stored
126 * in Tag::ATTESTATION_APPLICATION_ID. This schema is described in
127 * https://developer.android.com/training/articles/security-key-attestation#certificate_schema_attestationid
David Zeuthenc75ac312019-10-28 13:16:45 -0400128 *
David Zeuthenef739512020-06-03 13:24:52 -0400129 * @param attestationChallenge a challenge set by the issuer to ensure freshness. If
David Zeuthen834f3222022-01-27 13:43:10 -0500130 * this is empty, the call fails with STATUS_INVALID_DATA. Implementations must
131 * support challenges of at least 32 bytes.
David Zeuthenc75ac312019-10-28 13:16:45 -0400132 *
David Zeuthen81603152020-02-11 22:04:24 -0500133 * @return the X.509 certificate chain for the credentialKey
David Zeuthenc75ac312019-10-28 13:16:45 -0400134 */
Seth Moore801695e2022-01-25 23:04:37 +0000135 Certificate[] getAttestationCertificate(
136 in byte[] attestationApplicationId, in byte[] attestationChallenge);
David Zeuthenc75ac312019-10-28 13:16:45 -0400137
138 /**
139 * Start the personalization process.
140 *
141 * startPersonalization must not be called more than once.
142 *
David Zeuthen28edb102020-04-28 18:54:55 -0400143 * The setExpectedProofOfProvisioningSize() method will be called before this method.
144 *
David Zeuthen81603152020-02-11 22:04:24 -0500145 * @param accessControlProfileCount specifies the number of access control profiles that will
146 * be provisioned with addAccessControlProfile().
David Zeuthenc75ac312019-10-28 13:16:45 -0400147 *
148 * @param entryCounts specifies the number of data entries that will be provisioned with
149 * beginAddEntry() and addEntry(). Each item in the array specifies how many entries
150 * will be added for each name space.
David Zeuthenc75ac312019-10-28 13:16:45 -0400151 */
David Zeuthen81603152020-02-11 22:04:24 -0500152 void startPersonalization(in int accessControlProfileCount, in int[] entryCounts);
David Zeuthenc75ac312019-10-28 13:16:45 -0400153
154 /**
155 * Add an access control profile, which defines the requirements or retrieval of one or more
156 * entries. If both readerCertificate and userAuthenticationRequired are empty/false,
157 * associated entries are open access, requiring no authentication to read (though the caller
158 * is free to require other authentication above this HAL).
159 *
160 * This method must be called exactly as many times as specified in the startPersonalization()
161 * accessControlProfileCount parameter. If this is requirement is not met, the method fails
David Zeuthen81603152020-02-11 22:04:24 -0500162 * with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400163 *
164 * @param id a numeric identifier that must be unique within the context of a Credential and may
David Zeuthena0796e92020-04-27 15:24:55 -0400165 * be used to reference the profile. This id must be non-negative and less than 32 (allowing
166 * for a total of 32 profiles). If this is not satisfied the call fails with
David Zeuthen81603152020-02-11 22:04:24 -0500167 * STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400168 *
David Zeuthenc4286922020-03-03 10:09:03 -0500169 * @param readerCertificate if non-empty, specifies a single X.509 certificate (not a chain of
David Zeuthen81603152020-02-11 22:04:24 -0500170 * certificates) that must be used to authenticate requests (see the readerSignature
171 * parameter in IIdentityCredential.startRetrieval).
David Zeuthenc75ac312019-10-28 13:16:45 -0400172 *
173 * @param userAuthenticationRequired if true, specifies that the user is required to
174 * authenticate to allow requests. Required authentication freshness is specified by
175 * timeout below.
176 *
177 * @param timeoutMillis specifies the amount of time, in milliseconds, for which a user
178 * authentication (see userAuthenticationRequired above) is valid, if
179 * userAuthenticationRequired is true. If the timout is zero then authentication is
180 * required for each reader session. If userAuthenticationRequired is false, the timeout
David Zeuthen81603152020-02-11 22:04:24 -0500181 * must be zero. If this requirement is not met the call fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400182 *
183 * @param secureUserId must be non-zero if userAuthenticationRequired is true. It is not
184 * related to any Android user ID or UID, but is created in the Gatekeeper application
185 * in the secure environment. If this requirement is not met the call fails with
David Zeuthen81603152020-02-11 22:04:24 -0500186 * STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400187 *
Seth Moore801695e2022-01-25 23:04:37 +0000188 * @return a structure with the passed-in data and MAC created with storageKey for
189 * authenticating the data at a later point in time.
David Zeuthenc75ac312019-10-28 13:16:45 -0400190 */
David Zeuthen81603152020-02-11 22:04:24 -0500191 SecureAccessControlProfile addAccessControlProfile(in int id, in Certificate readerCertificate,
Seth Moore801695e2022-01-25 23:04:37 +0000192 in boolean userAuthenticationRequired, in long timeoutMillis, in long secureUserId);
David Zeuthenc75ac312019-10-28 13:16:45 -0400193
194 /**
195 * Begins the process of adding an entry to the credential. All access control profiles must be
196 * added before calling this method. Entries must be added in namespace "groups", meaning all
197 * entries of one namespace must be added before adding entries from another namespace.
198 *
199 * This method must be called exactly as many times as the sum of the items in the entryCounts
200 * parameter specified in the startPersonalization(), and must be followed by one or more calls
David Zeuthen81603152020-02-11 22:04:24 -0500201 * to addEntryValue(). If this requirement is not met the method fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400202 *
203 * @param accessControlProfileIds specifies the set of access control profiles that can
204 * authorize access to the provisioned element.
205 *
David Zeuthenc4286922020-03-03 10:09:03 -0500206 * @param nameSpace is the namespace of the element, e.g. "org.iso.18013.5.1"
David Zeuthenc75ac312019-10-28 13:16:45 -0400207 *
208 * @param name is the name of the element.
209 *
210 * @param entrySize is the size of the entry value. If this requirement
David Zeuthen81603152020-02-11 22:04:24 -0500211 * is not met this method fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400212 */
David Zeuthen81603152020-02-11 22:04:24 -0500213 void beginAddEntry(in int[] accessControlProfileIds, in @utf8InCpp String nameSpace,
Seth Moore801695e2022-01-25 23:04:37 +0000214 in @utf8InCpp String name, in int entrySize);
David Zeuthenc75ac312019-10-28 13:16:45 -0400215
216 /**
217 * Continues the process of adding an entry, providing a value or part of a value.
218 *
219 * In the common case, this method will be called only once per entry added. In the case of
220 * values that are larger than the secure environment's GCM chunk size
221 * (see IIdentityCredentialStore.getHardwareInformation()), the caller must provide the
222 * value in chunks. All chunks must be exactly gcmChunkSize except the last and the sum of all
223 * chunk sizes must equal the value of the beginAddEntry() entrySize argument. If this
David Zeuthen81603152020-02-11 22:04:24 -0500224 * requirement is not met the call fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400225 *
Seth Moore801695e2022-01-25 23:04:37 +0000226 * @param content is the entry value, encoded as CBOR. In the case the content exceeds
227 * gcmChunkSize, this may be partial content up to gcmChunkSize bytes long.
David Zeuthenc75ac312019-10-28 13:16:45 -0400228 *
David Zeuthen81603152020-02-11 22:04:24 -0500229 * @return the encrypted and MACed content. For directly-available credentials the contents are
230 * implementation-defined. For other credentials, the result contains
David Zeuthenc75ac312019-10-28 13:16:45 -0400231 *
232 * AES-GCM-ENC(storageKey, R, Data, AdditionalData)
233 *
234 * where:
235 *
236 * Data = any ; value
237 *
238 * AdditionalData = {
239 * "Namespace" : tstr,
240 * "Name" : tstr,
241 * "AccessControlProfileIds" : [ + uint ],
242 * }
243 */
David Zeuthen81603152020-02-11 22:04:24 -0500244 byte[] addEntryValue(in byte[] content);
David Zeuthenc75ac312019-10-28 13:16:45 -0400245
246 /**
David Zeuthen81603152020-02-11 22:04:24 -0500247 * Finishes adding entries and returns a signature that an issuing authority may use to
248 * validate that all data was provisioned correctly.
David Zeuthenc75ac312019-10-28 13:16:45 -0400249 *
250 * After this method is called, the IWritableIdentityCredential is no longer usable.
251 *
David Zeuthen81603152020-02-11 22:04:24 -0500252 * @param out credentialData is a CBOR-encoded structure (in CDDL notation):
David Zeuthenc75ac312019-10-28 13:16:45 -0400253 *
254 * CredentialData = [
255 * tstr, ; docType, an optional name that identifies the type of credential
256 * bool, ; testCredential, indicates if this is a test credential
257 * bstr ; an opaque byte vector with encrypted data, see below
258 * ]
259 *
260 * The last element is an opaque byte vector which contains encrypted copies of the
261 * secrets used to secure the new credential's data and to authenticate the credential to
262 * the issuing authority. It contains:
263 *
264 * AES-GCM-ENC(HBK, R, CredentialKeys, docType)
265 *
266 * where HBK is a unique hardware-bound key that has never existed outside of the secure
267 * environment (except it's all zeroes if testCredential is True) and CredentialKeys is
David Zeuthen49f2d252020-10-16 11:27:24 -0400268 * the CBOR-encoded structure (in CDDL notation) given below.
269 *
270 * In API versions 1 and 2 it was the following
David Zeuthenc75ac312019-10-28 13:16:45 -0400271 *
272 * CredentialKeys = [
273 * bstr, ; storageKey, a 128-bit AES key
274 * bstr ; credentialPrivKey, the private key for credentialKey
David Zeuthenef739512020-06-03 13:24:52 -0400275 * ; in uncompressed form
David Zeuthenc75ac312019-10-28 13:16:45 -0400276 * ]
277 *
David Zeuthen49f2d252020-10-16 11:27:24 -0400278 * In API version 3 or later it must be the following
279 *
280 * CredentialKeys = [
281 * bstr, ; storageKey, a 128-bit AES key
282 * bstr ; credentialPrivKey, the private key for credentialKey
283 * ; in uncompressed form
284 * bstr ; SHA-256(ProofOfProvisioning)
285 * ]
286 *
287 * Additional elements may be added to the CredentialKeys array in future versions.
288 *
David Zeuthen81603152020-02-11 22:04:24 -0500289 * @param out proofOfProvisioningSignature proves to the IA that the credential was imported
290 * into the secure hardware without alteration or error. When the final addEntry() call is
291 * made (when the number of provisioned entries equals the sum of the items in
292 * startPersonalization() entryCounts parameter), a COSE_Sign1 structure
David Zeuthenc75ac312019-10-28 13:16:45 -0400293 * signed by CredentialKey with payload set to the ProofOfProvisioning CBOR below:
294 *
295 * ProofOfProvisioning = [
296 * "ProofOfProvisioning",
297 * tstr, ; DocType
298 * [ * AccessControlProfile ],
299 * ProvisionedData,
300 * bool ; true if this is a test credential, should
301 * ; always be false.
302 * ]
303 *
304 * AccessControlProfile = {
305 * "id" : uint,
306 * ? "readerCertificate" : bstr,
307 * ? (
308 * "userAuthenticationRequired" : bool,
309 * "timeoutMillis" : uint,
310 * )
311 * }
312 *
313 * ProvisionedData = {
314 * * Namespace => [ + Entry ]
315 * },
316 *
317 * Namespace = tstr
318 *
319 * Entry = {
320 * "name" : tstr,
321 * "value" : any,
322 * "accessControlProfiles" : [ * uint ],
323 * }
324 */
Jooyung Hand63cd3f2021-04-27 10:37:03 +0900325 @SuppressWarnings(value={"out-array"})
Seth Moore801695e2022-01-25 23:04:37 +0000326 void finishAddingEntries(out byte[] credentialData, out byte[] proofOfProvisioningSignature);
David Zeuthen28edb102020-04-28 18:54:55 -0400327
328 /**
329 * Sets the expected size of the ProofOfProvisioning returned by finishAddingEntries(). This
330 * method must be called before startPersonalization() is called.
331 *
332 * This information is provided to make it possible for a HAL implementation to
333 * incrementally build up cryptographically authenticated data which includes the
334 * ProofOfProvisioning CBOR.
335 *
336 * @param expectedProofOfProvisioningSize the expected size of ProofOfProvisioning.
337 */
338 void setExpectedProofOfProvisioningSize(in int expectedProofOfProvisioningSize);
Seth Moore1bf823c2022-01-25 23:04:37 +0000339
340 /**
341 * Sets the attestation key used to sign the credentialKey certificate. This method is used to
342 * support remotely provisioned attestation keys, removing the credential's dependency on any
343 * factory-provisioned attestation key.
344 *
345 * This method must be called before getAttestationCertificate. After this method is called,
346 * the certificate chain returned by getAttestationCertificate will contain a leaf certificate
347 * signed by attestationKeyBlob and the chain in attestationCertificate will make up the rest
348 * of the returned chain.
349 *
350 * Returns EX_UNSUPPORTED_FUNCTION if remote provisioning is not supported
351 * (see IIdentityCredentialStore.getHardwareInformation()).
352 *
353 * This method was added in API version 4.
354 *
355 * @param attestationKeyBlob is a key blob generated by the IRemotelyProvisionedComponent that
356 * is returned by ICredentialStore.getRemotelyProvisionedComponent. The format is vendor-
357 * specified, and matches the key blob returned by IKeyMintDevice.generateKey.
358 *
359 * @param attestationCertificate contains the X.509 certificate chain that certifies the
360 * attestationKeyBlob. This certificate is expected to have been remotely provisioned
361 * by a trusted authority. This parameter must contain a concatenated chain of DER-encoded
362 * X.509 certificates. The certificates must be ordered such that the attestation key
363 * certificate is first (starting at byte 0). The issuer certificate for the attestation
364 * certificate immediately follows, continuing this chain to the final, root certificate.
365 *
366 * @see getAttestationCertificate
367 * @see android.hardware.identity.ICredentialStore#getRemotelyProvisionedComponent
368 */
369 void setRemotelyProvisionedAttestationKey(
370 in byte[] attestationKeyBlob, in byte[] attestationCertificate);
David Zeuthen81603152020-02-11 22:04:24 -0500371}