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