blob: c48cb6682ea504e0da4268669a152e5ff502422d [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
130 * this is empty, the call fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400131 *
David Zeuthen81603152020-02-11 22:04:24 -0500132 * @return the X.509 certificate chain for the credentialKey
David Zeuthenc75ac312019-10-28 13:16:45 -0400133 */
David Zeuthen81603152020-02-11 22:04:24 -0500134 Certificate[] getAttestationCertificate(in byte[] attestationApplicationId, in byte[] attestationChallenge);
David Zeuthenc75ac312019-10-28 13:16:45 -0400135
136 /**
137 * Start the personalization process.
138 *
139 * startPersonalization must not be called more than once.
140 *
David Zeuthen28edb102020-04-28 18:54:55 -0400141 * The setExpectedProofOfProvisioningSize() method will be called before this method.
142 *
David Zeuthen81603152020-02-11 22:04:24 -0500143 * @param accessControlProfileCount specifies the number of access control profiles that will
144 * be provisioned with addAccessControlProfile().
David Zeuthenc75ac312019-10-28 13:16:45 -0400145 *
146 * @param entryCounts specifies the number of data entries that will be provisioned with
147 * beginAddEntry() and addEntry(). Each item in the array specifies how many entries
148 * will be added for each name space.
David Zeuthenc75ac312019-10-28 13:16:45 -0400149 */
David Zeuthen81603152020-02-11 22:04:24 -0500150 void startPersonalization(in int accessControlProfileCount, in int[] entryCounts);
David Zeuthenc75ac312019-10-28 13:16:45 -0400151
152 /**
153 * Add an access control profile, which defines the requirements or retrieval of one or more
154 * entries. If both readerCertificate and userAuthenticationRequired are empty/false,
155 * associated entries are open access, requiring no authentication to read (though the caller
156 * is free to require other authentication above this HAL).
157 *
158 * This method must be called exactly as many times as specified in the startPersonalization()
159 * accessControlProfileCount parameter. If this is requirement is not met, the method fails
David Zeuthen81603152020-02-11 22:04:24 -0500160 * with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400161 *
162 * @param id a numeric identifier that must be unique within the context of a Credential and may
David Zeuthena0796e92020-04-27 15:24:55 -0400163 * be used to reference the profile. This id must be non-negative and less than 32 (allowing
164 * for a total of 32 profiles). If this is not satisfied the call fails with
David Zeuthen81603152020-02-11 22:04:24 -0500165 * STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400166 *
David Zeuthenc4286922020-03-03 10:09:03 -0500167 * @param readerCertificate if non-empty, specifies a single X.509 certificate (not a chain of
David Zeuthen81603152020-02-11 22:04:24 -0500168 * certificates) that must be used to authenticate requests (see the readerSignature
169 * parameter in IIdentityCredential.startRetrieval).
David Zeuthenc75ac312019-10-28 13:16:45 -0400170 *
171 * @param userAuthenticationRequired if true, specifies that the user is required to
172 * authenticate to allow requests. Required authentication freshness is specified by
173 * timeout below.
174 *
175 * @param timeoutMillis specifies the amount of time, in milliseconds, for which a user
176 * authentication (see userAuthenticationRequired above) is valid, if
177 * userAuthenticationRequired is true. If the timout is zero then authentication is
178 * required for each reader session. If userAuthenticationRequired is false, the timeout
David Zeuthen81603152020-02-11 22:04:24 -0500179 * must be zero. If this requirement is not met the call fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400180 *
181 * @param secureUserId must be non-zero if userAuthenticationRequired is true. It is not
182 * related to any Android user ID or UID, but is created in the Gatekeeper application
183 * in the secure environment. If this requirement is not met the call fails with
David Zeuthen81603152020-02-11 22:04:24 -0500184 * STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400185 *
David Zeuthen81603152020-02-11 22:04:24 -0500186 * @return a structure with the passed-in data and MAC created with storageKey for authenticating
187 * the data at a later point in time.
David Zeuthenc75ac312019-10-28 13:16:45 -0400188 */
David Zeuthen81603152020-02-11 22:04:24 -0500189 SecureAccessControlProfile addAccessControlProfile(in int id, in Certificate readerCertificate,
190 in boolean userAuthenticationRequired, in long timeoutMillis, in long secureUserId);
David Zeuthenc75ac312019-10-28 13:16:45 -0400191
192 /**
193 * Begins the process of adding an entry to the credential. All access control profiles must be
194 * added before calling this method. Entries must be added in namespace "groups", meaning all
195 * entries of one namespace must be added before adding entries from another namespace.
196 *
197 * This method must be called exactly as many times as the sum of the items in the entryCounts
198 * parameter specified in the startPersonalization(), and must be followed by one or more calls
David Zeuthen81603152020-02-11 22:04:24 -0500199 * to addEntryValue(). If this requirement is not met the method fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400200 *
201 * @param accessControlProfileIds specifies the set of access control profiles that can
202 * authorize access to the provisioned element.
203 *
David Zeuthenc4286922020-03-03 10:09:03 -0500204 * @param nameSpace is the namespace of the element, e.g. "org.iso.18013.5.1"
David Zeuthenc75ac312019-10-28 13:16:45 -0400205 *
206 * @param name is the name of the element.
207 *
208 * @param entrySize is the size of the entry value. If this requirement
David Zeuthen81603152020-02-11 22:04:24 -0500209 * is not met this method fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400210 */
David Zeuthen81603152020-02-11 22:04:24 -0500211 void beginAddEntry(in int[] accessControlProfileIds, in @utf8InCpp String nameSpace,
212 in @utf8InCpp String name, in int entrySize);
David Zeuthenc75ac312019-10-28 13:16:45 -0400213
214 /**
215 * Continues the process of adding an entry, providing a value or part of a value.
216 *
217 * In the common case, this method will be called only once per entry added. In the case of
218 * values that are larger than the secure environment's GCM chunk size
219 * (see IIdentityCredentialStore.getHardwareInformation()), the caller must provide the
220 * value in chunks. All chunks must be exactly gcmChunkSize except the last and the sum of all
221 * chunk sizes must equal the value of the beginAddEntry() entrySize argument. If this
David Zeuthen81603152020-02-11 22:04:24 -0500222 * requirement is not met the call fails with STATUS_INVALID_DATA.
David Zeuthenc75ac312019-10-28 13:16:45 -0400223 *
224 * @param content is the entry value, encoded as CBOR. In the case the content exceeds gcmChunkSize,
225 * this may be partial content up to gcmChunkSize bytes long.
226 *
David Zeuthen81603152020-02-11 22:04:24 -0500227 * @return the encrypted and MACed content. For directly-available credentials the contents are
228 * implementation-defined. For other credentials, the result contains
David Zeuthenc75ac312019-10-28 13:16:45 -0400229 *
230 * AES-GCM-ENC(storageKey, R, Data, AdditionalData)
231 *
232 * where:
233 *
234 * Data = any ; value
235 *
236 * AdditionalData = {
237 * "Namespace" : tstr,
238 * "Name" : tstr,
239 * "AccessControlProfileIds" : [ + uint ],
240 * }
241 */
David Zeuthen81603152020-02-11 22:04:24 -0500242 byte[] addEntryValue(in byte[] content);
David Zeuthenc75ac312019-10-28 13:16:45 -0400243
244 /**
David Zeuthen81603152020-02-11 22:04:24 -0500245 * Finishes adding entries and returns a signature that an issuing authority may use to
246 * validate that all data was provisioned correctly.
David Zeuthenc75ac312019-10-28 13:16:45 -0400247 *
248 * After this method is called, the IWritableIdentityCredential is no longer usable.
249 *
David Zeuthen81603152020-02-11 22:04:24 -0500250 * @param out credentialData is a CBOR-encoded structure (in CDDL notation):
David Zeuthenc75ac312019-10-28 13:16:45 -0400251 *
252 * CredentialData = [
253 * tstr, ; docType, an optional name that identifies the type of credential
254 * bool, ; testCredential, indicates if this is a test credential
255 * bstr ; an opaque byte vector with encrypted data, see below
256 * ]
257 *
258 * The last element is an opaque byte vector which contains encrypted copies of the
259 * secrets used to secure the new credential's data and to authenticate the credential to
260 * the issuing authority. It contains:
261 *
262 * AES-GCM-ENC(HBK, R, CredentialKeys, docType)
263 *
264 * where HBK is a unique hardware-bound key that has never existed outside of the secure
265 * environment (except it's all zeroes if testCredential is True) and CredentialKeys is
266 * the CBOR-encoded structure (in CDDL notation):
267 *
268 * CredentialKeys = [
269 * bstr, ; storageKey, a 128-bit AES key
270 * bstr ; credentialPrivKey, the private key for credentialKey
David Zeuthenef739512020-06-03 13:24:52 -0400271 * ; in uncompressed form
David Zeuthenc75ac312019-10-28 13:16:45 -0400272 * ]
273 *
David Zeuthen81603152020-02-11 22:04:24 -0500274 * @param out proofOfProvisioningSignature proves to the IA that the credential was imported
275 * into the secure hardware without alteration or error. When the final addEntry() call is
276 * made (when the number of provisioned entries equals the sum of the items in
277 * startPersonalization() entryCounts parameter), a COSE_Sign1 structure
David Zeuthenc75ac312019-10-28 13:16:45 -0400278 * signed by CredentialKey with payload set to the ProofOfProvisioning CBOR below:
279 *
280 * ProofOfProvisioning = [
281 * "ProofOfProvisioning",
282 * tstr, ; DocType
283 * [ * AccessControlProfile ],
284 * ProvisionedData,
285 * bool ; true if this is a test credential, should
286 * ; always be false.
287 * ]
288 *
289 * AccessControlProfile = {
290 * "id" : uint,
291 * ? "readerCertificate" : bstr,
292 * ? (
293 * "userAuthenticationRequired" : bool,
294 * "timeoutMillis" : uint,
295 * )
296 * }
297 *
298 * ProvisionedData = {
299 * * Namespace => [ + Entry ]
300 * },
301 *
302 * Namespace = tstr
303 *
304 * Entry = {
305 * "name" : tstr,
306 * "value" : any,
307 * "accessControlProfiles" : [ * uint ],
308 * }
309 */
David Zeuthen81603152020-02-11 22:04:24 -0500310 void finishAddingEntries(out byte[] credentialData,
311 out byte[] proofOfProvisioningSignature);
David Zeuthen28edb102020-04-28 18:54:55 -0400312
313 /**
314 * Sets the expected size of the ProofOfProvisioning returned by finishAddingEntries(). This
315 * method must be called before startPersonalization() is called.
316 *
317 * This information is provided to make it possible for a HAL implementation to
318 * incrementally build up cryptographically authenticated data which includes the
319 * ProofOfProvisioning CBOR.
320 *
321 * @param expectedProofOfProvisioningSize the expected size of ProofOfProvisioning.
322 */
323 void setExpectedProofOfProvisioningSize(in int expectedProofOfProvisioningSize);
David Zeuthen81603152020-02-11 22:04:24 -0500324}