blob: b1ce00de4f5228333174944810c1f410bc15b37c [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
17package android.hardware.identity@1.0;
18
19/**
20 * IWritableIdentityCredential is used to personalize a new identity credential. Credentials cannot
21 * be updated or modified after creation; any changes require deletion and re-creation.
22 */
23interface IWritableIdentityCredential {
24 /**
25 * Gets the certificate chain for credentialKey which can be used to prove the hardware
26 * characteristics to an issuing authority. Must not be called more than once.
27 *
28 * The certificate chain must be generated using Keymaster Attestation
29 * (see https://source.android.com/security/keystore/attestation) and must also
30 * have the Tag::IDENTITY_CREDENTIAL_KEY tag from KeyMaster 4.1 set. This tag indicates
31 * that this key is an Identity Credential key (which can only sign/MAC very
32 * specific messages) and not an Android Keystore key (which can be used to sign/MAC
33 * anything).
34 *
35 * @param attestationChallenge a challenge set by the issuer to ensure freshness.
36 *
37 * @return result is OK on success, FAILED if an error occurred.
38 *
39 * @return certificate is the X.509 certificate chain for the credentialKey
40 */
41 getAttestationCertificate(vec<uint8_t> attestationChallenge)
42 generates(Result result, vec<uint8_t> certificate);
43
44 /**
45 * Start the personalization process.
46 *
47 * startPersonalization must not be called more than once.
48 *
49 * @param accessControlProfileCount specifies the number of access control profiles that will be
50 * provisioned with addAccessControlProfile().
51 *
52 * @param entryCounts specifies the number of data entries that will be provisioned with
53 * beginAddEntry() and addEntry(). Each item in the array specifies how many entries
54 * will be added for each name space.
55 *
56 * @return result is OK on success, FAILED if an error occurred.
57 *
58 */
59 startPersonalization(uint16_t accessControlProfileCount, vec<uint16_t> entryCounts)
60 generates(Result result);
61
62 /**
63 * Add an access control profile, which defines the requirements or retrieval of one or more
64 * entries. If both readerCertificate and userAuthenticationRequired are empty/false,
65 * associated entries are open access, requiring no authentication to read (though the caller
66 * is free to require other authentication above this HAL).
67 *
68 * This method must be called exactly as many times as specified in the startPersonalization()
69 * accessControlProfileCount parameter. If this is requirement is not met, the method fails
70 * with INVALID_DATA.
71 *
72 * @param id a numeric identifier that must be unique within the context of a Credential and may
73 * be used to reference the profile. If this is not satisfied the call fails with
74 * INVALID_DATA.
75 *
76 * @param readerCertificate if non-empty, specifies a X.509 certificate (or chain of certificates)
77 * that must be used to authenticate requests (see the readerSignature parameter in
78 * IIdentityCredential.startRetrieval).
79 *
80 * @param userAuthenticationRequired if true, specifies that the user is required to
81 * authenticate to allow requests. Required authentication freshness is specified by
82 * timeout below.
83 *
84 * @param timeoutMillis specifies the amount of time, in milliseconds, for which a user
85 * authentication (see userAuthenticationRequired above) is valid, if
86 * userAuthenticationRequired is true. If the timout is zero then authentication is
87 * required for each reader session. If userAuthenticationRequired is false, the timeout
88 * must be zero. If this requirement is not met the call fails with INVALID_DATA.
89 *
90 * @param secureUserId must be non-zero if userAuthenticationRequired is true. It is not
91 * related to any Android user ID or UID, but is created in the Gatekeeper application
92 * in the secure environment. If this requirement is not met the call fails with
93 * INVALID_DATA.
94 *
95 * @return result is OK on success, INVALID_DATA or FAILED if an error occurred.
96 *
97 * @return secureAccessControlProfile is a structure with the passed-in data and MAC created
98 * with storageKey for authenticating the data at a later point in time.
99 */
100 addAccessControlProfile(uint16_t id, vec<uint8_t> readerCertificate,
101 bool userAuthenticationRequired, uint64_t timeoutMillis,
102 uint64_t secureUserId)
103 generates(Result result, SecureAccessControlProfile secureAccessControlProfile);
104
105 /**
106 * Begins the process of adding an entry to the credential. All access control profiles must be
107 * added before calling this method. Entries must be added in namespace "groups", meaning all
108 * entries of one namespace must be added before adding entries from another namespace.
109 *
110 * This method must be called exactly as many times as the sum of the items in the entryCounts
111 * parameter specified in the startPersonalization(), and must be followed by one or more calls
112 * to addEntryValue(). If this requirement is not met the method fails with INVALID_DATA.
113 *
114 * @param accessControlProfileIds specifies the set of access control profiles that can
115 * authorize access to the provisioned element.
116 *
117 * @param nameSpace is the namespace of the element, e.g. "org.iso.18013"
118 *
119 * @param name is the name of the element.
120 *
121 * @param entrySize is the size of the entry value. If this requirement
122 * is not met this method fails with INVALID_DATA.
123 *
124 * @return result is OK on success, INVALID_DATA or FAILED if an error occurred.
125 */
126 beginAddEntry(vec<uint16_t> accessControlProfileIds, string nameSpace,
127 string name, uint32_t entrySize)
128 generates(Result result);
129
130 /**
131 * Continues the process of adding an entry, providing a value or part of a value.
132 *
133 * In the common case, this method will be called only once per entry added. In the case of
134 * values that are larger than the secure environment's GCM chunk size
135 * (see IIdentityCredentialStore.getHardwareInformation()), the caller must provide the
136 * value in chunks. All chunks must be exactly gcmChunkSize except the last and the sum of all
137 * chunk sizes must equal the value of the beginAddEntry() entrySize argument. If this
138 * requirement is not met the call fails with INVALID_DATA.
139 *
140 * @param content is the entry value, encoded as CBOR. In the case the content exceeds gcmChunkSize,
141 * this may be partial content up to gcmChunkSize bytes long.
142 *
143 * @return result is OK on success, INVALID_DATA or FAILED if an error occurred.
144 *
145 * @return encryptedContent contains the encrypted and MACed content. For directly-available
146 * credentials the contents are implementation-defined but must not exceed 32 bytes in
147 * length.
148 *
149 * For other credentials, encryptedContent contains:
150 *
151 * AES-GCM-ENC(storageKey, R, Data, AdditionalData)
152 *
153 * where:
154 *
155 * Data = any ; value
156 *
157 * AdditionalData = {
158 * "Namespace" : tstr,
159 * "Name" : tstr,
160 * "AccessControlProfileIds" : [ + uint ],
161 * }
162 */
163 addEntryValue(vec<uint8_t> content)
164 generates(Result result, vec<uint8_t> encryptedContent);
165
166 /**
167 * Finishes adding entries and returns a signature that an issuing authority may use to validate
168 * that all data was provisioned correctly.
169 *
170 * After this method is called, the IWritableIdentityCredential is no longer usable.
171 *
172 * @return result is OK on success or FAILED if an error occurred.
173 *
174 * @return credentialData is a CBOR-encoded structure (in CDDL notation):
175 *
176 * CredentialData = [
177 * tstr, ; docType, an optional name that identifies the type of credential
178 * bool, ; testCredential, indicates if this is a test credential
179 * bstr ; an opaque byte vector with encrypted data, see below
180 * ]
181 *
182 * The last element is an opaque byte vector which contains encrypted copies of the
183 * secrets used to secure the new credential's data and to authenticate the credential to
184 * the issuing authority. It contains:
185 *
186 * AES-GCM-ENC(HBK, R, CredentialKeys, docType)
187 *
188 * where HBK is a unique hardware-bound key that has never existed outside of the secure
189 * environment (except it's all zeroes if testCredential is True) and CredentialKeys is
190 * the CBOR-encoded structure (in CDDL notation):
191 *
192 * CredentialKeys = [
193 * bstr, ; storageKey, a 128-bit AES key
194 * bstr ; credentialPrivKey, the private key for credentialKey
195 * ]
196 *
197 * @return proofOfProvisioningSignature proves to the IA that the credential was imported into the
198 * secure hardware without alteration or error. When the final addEntry() call is made
199 * (when the number of provisioned entries equals the sum of the items in
200 * startPersonalization() entryCounts parameter), it a COSE_Sign1 structure
201 * signed by CredentialKey with payload set to the ProofOfProvisioning CBOR below:
202 *
203 * ProofOfProvisioning = [
204 * "ProofOfProvisioning",
205 * tstr, ; DocType
206 * [ * AccessControlProfile ],
207 * ProvisionedData,
208 * bool ; true if this is a test credential, should
209 * ; always be false.
210 * ]
211 *
212 * AccessControlProfile = {
213 * "id" : uint,
214 * ? "readerCertificate" : bstr,
215 * ? (
216 * "userAuthenticationRequired" : bool,
217 * "timeoutMillis" : uint,
218 * )
219 * }
220 *
221 * ProvisionedData = {
222 * * Namespace => [ + Entry ]
223 * },
224 *
225 * Namespace = tstr
226 *
227 * Entry = {
228 * "name" : tstr,
229 * "value" : any,
230 * "accessControlProfiles" : [ * uint ],
231 * }
232 */
233 finishAddingEntries()
234 generates(Result result, vec<uint8_t> credentialData,
235 vec<uint8_t> proofOfProvisioningSignature);
236};