blob: 0c59e6c72571b47a327c73779c432ae017572553 [file] [log] [blame]
Janis Danisevskis34d88092016-10-12 11:23:58 +01001/*
2 * Copyright (C) 2016 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.keymaster@3.0;
18
19/**
20 * Keymaster device definition. For thorough documentation see the implementer's reference, at
21 * https://source.android.com/security/keystore/implementer-ref.html
22 */
23interface IKeymasterDevice {
24
25 /**
26 * Returns information about the underlying keymaster hardware.
27 *
28 * @return isSecure is true if keys are stored and never leave secure hardware (Trusted
29 * Execution Environment or similar). CDD requires that all devices initially
30 * launched with Marshmallow or later must have secure hardware.
31 *
32 * @return supportsEllipticCurve is true if the hardware supports Elliptic Curve cryptography
33 * with the NIST curves (P-224, P-256, P-384, and P-521). CDD requires that all
34 * devices initially launched with Nougat or later must support Elliptic Curve
35 * cryptography.
36 *
37 * @return supportsSymmetricCryptography is true if the hardware supports symmetric
38 * cryptography, including AES and HMAC. CDD requires that all devices initially
39 * launched with Nougat or later must support hardware enforcement of Keymaster
40 * authorizations.
41 *
42 * @return supportsAttestation is true if the hardware supports generation of Keymaster public
43 * key attestation certificates, signed with a key injected in a secure
44 * environment. CDD requires that all devices initially launched with Android O or
45 * later must support hardware attestation.
Shawn Willdend4417fb2017-02-23 11:01:49 -070046 *
47 * @return supportsAllDigests is true if the hardware supports all keymaster digest functions,
48 * namely ND-5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512. CDD requires that all
49 * devices launched initially with Android O or later must support all digests.
50 *
51 * @return keymasterName is the name of the keymaster implementation.
52 *
53 * @return keymasterAuthorName is the name of the author of the keymaster implementation
54 * (generally this should be the name of an organization, not an individual.)
Janis Danisevskis34d88092016-10-12 11:23:58 +010055 */
56 getHardwareFeatures()
Shawn Willdend4417fb2017-02-23 11:01:49 -070057 generates(bool isSecure, bool supportsEllipticCurve, bool supportsSymmetricCryptography,
58 bool supportsAttestation, bool supportsAllDigests, string keymasterName,
59 string keymasterAuthorName);
Janis Danisevskis34d88092016-10-12 11:23:58 +010060
61 /**
Shawn Willden62f63c72017-02-17 12:23:51 -070062 * Parses a hardware authentication token blob to extract the details needed to determine if the
63 * token is applicable to a given keymaster operation. This method is intended to be
64 * implemented by the HAL, without requiring a call into the trusted hardware. It is not
65 * necessary for this method to verify that the values in the blob are correct.
66 *
67 * @param token The token blob provided by the authentication app.
68 *
69 * @return error ErrorCode::OK or, if the blob is invalid, ErrorCode::INVALD_ARGUMENT if the
70 * blob is the wrong size, the wrong version, or incorrectly structured.
71 *
72 * @return tokenInfo Information extracted from the auth token.
73 */
74 parseHardwareAuthToken(vec<uint8_t> token)
75 generates(ErrorCode error, HardwareAuthTokenInfo tokenInfo);
76
77 /**
Janis Danisevskis34d88092016-10-12 11:23:58 +010078 * Adds entropy to the RNG used by keymaster. Entropy added through this method is guaranteed
79 * not to be the only source of entropy used, and the mixing function is required to be secure,
80 * in the sense that if the RNG is seeded (from any source) with any data the attacker cannot
81 * predict (or control), then the RNG output is indistinguishable from random. Thus, if the
82 * entropy from any source is good, the output must be good.
83 *
84 * @param data Bytes to be mixed into the RNG.
85 *
86 * @return error See the ErrorCode enum in types.hal.
87 */
88 addRngEntropy(vec<uint8_t> data) generates(ErrorCode error);
89
90 /**
91 * Generates a key, or key pair, returning a key blob and/or a description of the key.
92 *
93 * @param keyParams Key generation parameters are defined as keymaster tag/value pairs, provided
94 * in params. See Tag in types.hal for the full list.
95 *
96 * @return error See the ErrorCode enum in types.hal.
97 *
98 * @return keyBlob Opaque, encrypted descriptor of the generated key, which generally contains a
99 * copy of the key material, wrapped in a key unavailable outside secure hardware.
100 *
101 * @return keyCharacteristics Description of the generated key. See KeyCharacteristis in
102 * types.hal.
103 */
104 generateKey(vec<KeyParameter> keyParams)
105 generates(ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics);
106
107 /**
108 * Imports a key, or key pair, returning a key blob and/or a description of the key.
109 *
110 * @param keyParams Key generation parameters are defined as keymaster tag/value pairs, provided
111 * in params. See Tag for the full list.
112 *
113 * @param keyFormat The format of the key material to import. See KeyFormat in types.hal.
114 *
115 * @pram keyData The key material to import, in the format specifed in keyFormat.
116 *
117 * @return error See the ErrorCode enum.
118 *
119 * @return keyBlob Opaque, encrypted descriptor of the generated key, which will generally
120 * contain a copy of the key material, wrapped in a key unavailable outside secure
121 * hardware.
122 *
123 * @return keyCharacteristics Decription of the generated key. See KeyCharacteristis.
124 *
125 * @return error See the ErrorCode enum.
126 */
127 importKey(vec<KeyParameter> params, KeyFormat keyFormat, vec<uint8_t> keyData)
128 generates(ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics);
129
130 /**
131 * Returns the characteristics of the specified key, if the keyBlob is valid (implementations
132 * must fully validate the integrity of the key).
133 *
134 * @param keyBlob The opaque descriptor returned by generateKey() or importKey();
135 *
136 * @param clientId An opaque byte string identifying the client. This value must match the
137 * Tag::APPLICATION_ID data provided during key generation/import. Without the
138 * correct value it must be cryptographically impossible for the secure hardware to
139 * obtain the key material.
140 *
141 * @param appData An opaque byte string provided by the application. This value must match the
142 * Tag::APPLICATION_DATA data provided during key generation/import. Without the
143 * correct value it must be cryptographically impossible for the secure hardware to
144 * obtain the key material.
145 *
146 * @return error See the ErrorCode enum in types.hal.
147 *
148 * @return keyCharacteristics Decription of the generated key. See KeyCharacteristis in
149 * types.hal.
150 */
151 getKeyCharacteristics(vec<uint8_t> keyBlob, vec<uint8_t> clientId, vec<uint8_t> appData)
152 generates(ErrorCode error, KeyCharacteristics keyCharacteristics);
153
154 /**
155 * Exports a public key, returning the key in the specified format.
156 *
157 * @parm keyFormat The format used for export. See KeyFormat in types.hal.
158 *
159 * @param keyBlob The opaque descriptor returned by generateKey() or importKey(). The
160 * referenced key must be asymmetric.
161 *
162 * @param clientId An opaque byte string identifying the client. This value must match the
163 * Tag::APPLICATION_ID data provided during key generation/import. Without the
164 * correct value it must be cryptographically impossible for the secure hardware to
165 * obtain the key material.
166 *
167 * @param appData An opaque byte string provided by the application. This value must match the
168 * Tag::APPLICATION_DATA data provided during key generation/import. Without the
169 * correct value it must be cryptographically impossible for the secure hardware to
170 * obtain the key material.
171 *
172 * @return error See the ErrorCode enum in types.hal.
173 *
174 * @return keyMaterial The public key material in PKCS#8 format.
175 */
176 exportKey(KeyFormat keyFormat, vec<uint8_t> keyBlob, vec<uint8_t> clientId,
177 vec<uint8_t> appData) generates(ErrorCode error, vec<uint8_t> keyMaterial);
178
179 /**
180 * Generates a signed X.509 certificate chain attesting to the presence of keyToAttest in
181 * keymaster. The certificate will contain an extension with OID 1.3.6.1.4.1.11129.2.1.17 and
182 * value defined in:
183 *
184 * https://developer.android.com/training/articles/security-key-attestation.html.
185 *
186 * @param keyToAttest The opaque descriptor returned by generateKey() or importKey(). The
187 * referenced key must be asymmetric.
188 *
189 * @param attestParams Parameters for the attestation, notably Tag::ATTESTATION_CHALLENGE.
190 *
191 * @return error See the ErrorCode enum in types.hal.
192 */
193 attestKey(vec<uint8_t> keyToAttest, vec<KeyParameter> attestParams)
194 generates(ErrorCode error, vec<vec<uint8_t>> certChain);
195
196 /**
197 * Upgrades an old key. Keys can become "old" in two ways: Keymaster can be upgraded to a new
198 * version, or the system can be updated to invalidate the OS version and/or patch level. In
199 * either case, attempts to use an old key with getKeyCharacteristics(), exportKey(),
200 * attestKey() or begin() will result in keymaster returning
201 * ErrorCode::KEY_REQUIRES_UPGRADE. This method must then be called to upgrade the key.
202 *
203 * @param keyBlobToUpgrade The opaque descriptor returned by generateKey() or importKey();
204 *
205 * @param upgradeParams A parameter list containing any parameters needed to complete the
206 * upgrade, including Tag::APPLICATION_ID and Tag::APPLICATION_DATA.
207 *
208 * @return error See the ErrorCode enum.
209 */
210 upgradeKey(vec<uint8_t> keyBlobToUpgrade, vec<KeyParameter> upgradeParams)
211 generates(ErrorCode error, vec<uint8_t> upgradedKeyBlob);
212
213 /**
214 * Deletes the key, or key pair, associated with the key blob. After calling this function it
215 * will be impossible to use the key for any other operations. May be applied to keys from
216 * foreign roots of trust (keys not usable under the current root of trust).
217 *
218 * This is a NOP for keys that don't have rollback protection.
219 *
220 * @param keyBlobToUpgrade The opaque descriptor returned by generateKey() or importKey();
221 *
222 * @return error See the ErrorCode enum.
223 */
224 deleteKey(vec<uint8_t> keyBlob) generates(ErrorCode error);
225
226 /**
227 * Deletes all keys in the hardware keystore. Used when keystore is reset completely. After
228 * calling this function it will be impossible to use any previously generated or imported key
229 * blobs for any operations.
230 *
231 * This is a NOP if keys don't have rollback protection.
232 *
233 * @return error See the ErrorCode enum.
234 */
235 deleteAllKeys() generates(ErrorCode error);
236
237 /**
Bartosz Fabianowskiaac0fc72017-01-23 13:51:10 +0100238 * Destroys knowledge of the device's ids. This prevents all device id attestation in the
239 * future. The destruction must be permanent so that not even a factory reset will restore the
240 * device ids.
241 *
242 * Device id attestation may be provided only if this method is fully implemented, allowing the
243 * user to permanently disable device id attestation. If this cannot be guaranteed, the device
244 * must never attest any device ids.
245 *
246 * This is a NOP if device id attestation is not supported.
247 *
248 * @return error See the ErrorCode enum.
249 */
250 destroyAttestationIds() generates(ErrorCode error);
251
252 /**
Janis Danisevskis34d88092016-10-12 11:23:58 +0100253 * Begins a cryptographic operation using the specified key. If all is well, begin() will return
254 * ErrorCode::OK and create an operation handle which must be passed to subsequent calls to
255 * update(), finish() or abort().
256 *
257 * It is critical that each call to begin() be paired with a subsequent call to finish() or
258 * abort(), to allow the keymaster implementation to clean up any internal operation state.
259 * Failure to do this may leak internal state space or other internal resources and may
260 * eventually cause begin() to return ErrorCode::TOO_MANY_OPERATIONS when it runs out of space
261 * for operations. Any result other than ErrorCode::OK from begin(), update() or finish()
262 * implicitly aborts the operation, in which case abort() need not be called (and will return
263 * ErrorCode::INVALID_OPERATION_HANDLE if called).
264 *
265 * @param purpose The purpose of the operation, one of KeyPurpose::ENCRYPT, KeyPurpose::DECRYPT,
266 * KeyPurpose::SIGN or KeyPurpose::VERIFY. Note that for AEAD modes, encryption and
267 * decryption imply signing and verification, respectively, but must be specified as
268 * KeyPurpose::ENCRYPT and KeyPurpose::DECRYPT.
269 *
270 * @param keyBlob The opaque key descriptor returned by generateKey() or importKey(). The key
271 * must have a purpose compatible with purpose and all of its usage requirements
272 * must be satisfied, or begin() will return an appropriate error code.
273 *
274 * @param inParams Additional parameters for the operation. This is typically used to provide
275 * authentication data, with Tag::AUTH_TOKEN. If Tag::APPLICATION_ID or
276 * Tag::APPLICATION_DATA were provided during generation, they must be provided
277 * here, or the operation will fail with ErrorCode::INVALID_KEY_BLOB. For operations
278 * that require a nonce or IV, on keys that were generated with Tag::CALLER_NONCE,
279 * inParams may contain a tag Tag::NONCE.
280 *
281 * @return error See the ErrorCode enum in types.hal.
282 *
283 * @return outParams Output parameters. Used to return additional data from the operation
284 * initialization, notably to return the IV or nonce from operations that generate
285 * an IV or nonce.
286 *
287 * @return operationHandle The newly-created operation handle which must be passed to update(),
288 * finish() or abort().
289 */
290 begin(KeyPurpose purpose, vec<uint8_t> key, vec<KeyParameter> inParams)
291 generates(ErrorCode error, vec<KeyParameter> outParams, OperationHandle operationHandle);
292
293 /**
294 * Provides data to, and possibly receives output from, an ongoing cryptographic operation begun
295 * with begin().
296 *
297 * If operationHandle is invalid, update() will return ErrorCode::INVALID_OPERATION_HANDLE.
298 *
299 * update() may not consume all of the data provided in the data buffer. update() will return
300 * the amount consumed in inputConsumed. The caller may provide the unconsumed data in a
301 * subsequent call.
302 *
303 * @param operationHandle The operation handle returned by begin().
304 *
305 * @param inParams Additional parameters for the operation. For AEAD modes, this is used to
306 * specify Tag::ADDITIONAL_DATA. Note that additional data may be provided in
307 * multiple calls to update(), but only until input data has been provided.
308 *
309 * @param input Data to be processed, per the parameters established in the call to begin().
310 * Note that update() may or may not consume all of the data provided. See
311 * inputConsumed.
312 *
313 * @return error See the ErrorCode enum in types.hal.
314 *
315 * @return inputConsumed Amount of data that was consumed by update(). If this is less than the
316 * amount provided, the caller may provide the remainder in a subsequent call to
317 * update() or finish().
318 *
319 * @return outParams Output parameters, used to return additional data from the operation The
320 * caller takes ownership of the output parameters array and must free it with
321 * keymaster_free_param_set().
322 *
323 * @return output The output data, if any.
324 */
325 update(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input)
326 generates(ErrorCode error, uint32_t inputConsumed, vec<KeyParameter> outParams,
327 vec<uint8_t> output);
328
329 /**
330 * Finalizes a cryptographic operation begun with begin() and invalidates operationHandle.
331 *
332 * @param operationHandle The operation handle returned by begin(). This handle will be
333 * invalid when finish() returns.
334 *
335 * @param inParams Additional parameters for the operation. For AEAD modes, this is used to
336 * specify Tag::ADDITIONAL_DATA, but only if no input data was provided to update().
337 *
338 * @param input Data to be processed, per the parameters established in the call to
339 * begin(). finish() must consume all provided data or return
340 * ErrorCode::INVALID_INPUT_LENGTH.
341 *
342 * @param signature The signature to be verified if the purpose specified in the begin() call
343 * was KeyPurpose::VERIFY.
344 *
345 * @return error See the ErrorCode enum in types.hal.
346 *
347 * @return outParams Any output parameters generated by finish().
348 *
349 * @return output The output data, if any.
350 */
351 finish(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input,
352 vec<uint8_t> signature)
353 generates(ErrorCode error, vec<KeyParameter> outParams, vec<uint8_t> output);
354
355 /**
356 * Aborts a cryptographic operation begun with begin(), freeing all internal resources and
357 * invalidating operationHandle.
358 *
359 * @param operationHandle The operation handle returned by begin(). This handle will be
360 * invalid when abort() returns.
361 *
362 * @return error See the ErrorCode enum in types.hal.
363 */
364 abort(OperationHandle operationHandle) generates(ErrorCode error);
365};