blob: 50a41ec6e15ace89f85770417ceeee2f53bfe4e2 [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.
46 */
47 getHardwareFeatures()
48 generates(bool isSecure, bool supportsEllipticCurve,
49 bool supportsSymmetricCryptography, bool supportsAttestation);
50
51 /**
52 * Adds entropy to the RNG used by keymaster. Entropy added through this method is guaranteed
53 * not to be the only source of entropy used, and the mixing function is required to be secure,
54 * in the sense that if the RNG is seeded (from any source) with any data the attacker cannot
55 * predict (or control), then the RNG output is indistinguishable from random. Thus, if the
56 * entropy from any source is good, the output must be good.
57 *
58 * @param data Bytes to be mixed into the RNG.
59 *
60 * @return error See the ErrorCode enum in types.hal.
61 */
62 addRngEntropy(vec<uint8_t> data) generates(ErrorCode error);
63
64 /**
65 * Generates a key, or key pair, returning a key blob and/or a description of the key.
66 *
67 * @param keyParams Key generation parameters are defined as keymaster tag/value pairs, provided
68 * in params. See Tag in types.hal for the full list.
69 *
70 * @return error See the ErrorCode enum in types.hal.
71 *
72 * @return keyBlob Opaque, encrypted descriptor of the generated key, which generally contains a
73 * copy of the key material, wrapped in a key unavailable outside secure hardware.
74 *
75 * @return keyCharacteristics Description of the generated key. See KeyCharacteristis in
76 * types.hal.
77 */
78 generateKey(vec<KeyParameter> keyParams)
79 generates(ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics);
80
81 /**
82 * Imports a key, or key pair, returning a key blob and/or a description of the key.
83 *
84 * @param keyParams Key generation parameters are defined as keymaster tag/value pairs, provided
85 * in params. See Tag for the full list.
86 *
87 * @param keyFormat The format of the key material to import. See KeyFormat in types.hal.
88 *
89 * @pram keyData The key material to import, in the format specifed in keyFormat.
90 *
91 * @return error See the ErrorCode enum.
92 *
93 * @return keyBlob Opaque, encrypted descriptor of the generated key, which will generally
94 * contain a copy of the key material, wrapped in a key unavailable outside secure
95 * hardware.
96 *
97 * @return keyCharacteristics Decription of the generated key. See KeyCharacteristis.
98 *
99 * @return error See the ErrorCode enum.
100 */
101 importKey(vec<KeyParameter> params, KeyFormat keyFormat, vec<uint8_t> keyData)
102 generates(ErrorCode error, vec<uint8_t> keyBlob, KeyCharacteristics keyCharacteristics);
103
104 /**
105 * Returns the characteristics of the specified key, if the keyBlob is valid (implementations
106 * must fully validate the integrity of the key).
107 *
108 * @param keyBlob The opaque descriptor returned by generateKey() or importKey();
109 *
110 * @param clientId An opaque byte string identifying the client. This value must match the
111 * Tag::APPLICATION_ID data provided during key generation/import. Without the
112 * correct value it must be cryptographically impossible for the secure hardware to
113 * obtain the key material.
114 *
115 * @param appData An opaque byte string provided by the application. This value must match the
116 * Tag::APPLICATION_DATA data provided during key generation/import. Without the
117 * correct value it must be cryptographically impossible for the secure hardware to
118 * obtain the key material.
119 *
120 * @return error See the ErrorCode enum in types.hal.
121 *
122 * @return keyCharacteristics Decription of the generated key. See KeyCharacteristis in
123 * types.hal.
124 */
125 getKeyCharacteristics(vec<uint8_t> keyBlob, vec<uint8_t> clientId, vec<uint8_t> appData)
126 generates(ErrorCode error, KeyCharacteristics keyCharacteristics);
127
128 /**
129 * Exports a public key, returning the key in the specified format.
130 *
131 * @parm keyFormat The format used for export. See KeyFormat in types.hal.
132 *
133 * @param keyBlob The opaque descriptor returned by generateKey() or importKey(). The
134 * referenced key must be asymmetric.
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 keyMaterial The public key material in PKCS#8 format.
149 */
150 exportKey(KeyFormat keyFormat, vec<uint8_t> keyBlob, vec<uint8_t> clientId,
151 vec<uint8_t> appData) generates(ErrorCode error, vec<uint8_t> keyMaterial);
152
153 /**
154 * Generates a signed X.509 certificate chain attesting to the presence of keyToAttest in
155 * keymaster. The certificate will contain an extension with OID 1.3.6.1.4.1.11129.2.1.17 and
156 * value defined in:
157 *
158 * https://developer.android.com/training/articles/security-key-attestation.html.
159 *
160 * @param keyToAttest The opaque descriptor returned by generateKey() or importKey(). The
161 * referenced key must be asymmetric.
162 *
163 * @param attestParams Parameters for the attestation, notably Tag::ATTESTATION_CHALLENGE.
164 *
165 * @return error See the ErrorCode enum in types.hal.
166 */
167 attestKey(vec<uint8_t> keyToAttest, vec<KeyParameter> attestParams)
168 generates(ErrorCode error, vec<vec<uint8_t>> certChain);
169
170 /**
171 * Upgrades an old key. Keys can become "old" in two ways: Keymaster can be upgraded to a new
172 * version, or the system can be updated to invalidate the OS version and/or patch level. In
173 * either case, attempts to use an old key with getKeyCharacteristics(), exportKey(),
174 * attestKey() or begin() will result in keymaster returning
175 * ErrorCode::KEY_REQUIRES_UPGRADE. This method must then be called to upgrade the key.
176 *
177 * @param keyBlobToUpgrade The opaque descriptor returned by generateKey() or importKey();
178 *
179 * @param upgradeParams A parameter list containing any parameters needed to complete the
180 * upgrade, including Tag::APPLICATION_ID and Tag::APPLICATION_DATA.
181 *
182 * @return error See the ErrorCode enum.
183 */
184 upgradeKey(vec<uint8_t> keyBlobToUpgrade, vec<KeyParameter> upgradeParams)
185 generates(ErrorCode error, vec<uint8_t> upgradedKeyBlob);
186
187 /**
188 * Deletes the key, or key pair, associated with the key blob. After calling this function it
189 * will be impossible to use the key for any other operations. May be applied to keys from
190 * foreign roots of trust (keys not usable under the current root of trust).
191 *
192 * This is a NOP for keys that don't have rollback protection.
193 *
194 * @param keyBlobToUpgrade The opaque descriptor returned by generateKey() or importKey();
195 *
196 * @return error See the ErrorCode enum.
197 */
198 deleteKey(vec<uint8_t> keyBlob) generates(ErrorCode error);
199
200 /**
201 * Deletes all keys in the hardware keystore. Used when keystore is reset completely. After
202 * calling this function it will be impossible to use any previously generated or imported key
203 * blobs for any operations.
204 *
205 * This is a NOP if keys don't have rollback protection.
206 *
207 * @return error See the ErrorCode enum.
208 */
209 deleteAllKeys() generates(ErrorCode error);
210
211 /**
Bartosz Fabianowskiaac0fc72017-01-23 13:51:10 +0100212 * Destroys knowledge of the device's ids. This prevents all device id attestation in the
213 * future. The destruction must be permanent so that not even a factory reset will restore the
214 * device ids.
215 *
216 * Device id attestation may be provided only if this method is fully implemented, allowing the
217 * user to permanently disable device id attestation. If this cannot be guaranteed, the device
218 * must never attest any device ids.
219 *
220 * This is a NOP if device id attestation is not supported.
221 *
222 * @return error See the ErrorCode enum.
223 */
224 destroyAttestationIds() generates(ErrorCode error);
225
226 /**
Janis Danisevskis34d88092016-10-12 11:23:58 +0100227 * Begins a cryptographic operation using the specified key. If all is well, begin() will return
228 * ErrorCode::OK and create an operation handle which must be passed to subsequent calls to
229 * update(), finish() or abort().
230 *
231 * It is critical that each call to begin() be paired with a subsequent call to finish() or
232 * abort(), to allow the keymaster implementation to clean up any internal operation state.
233 * Failure to do this may leak internal state space or other internal resources and may
234 * eventually cause begin() to return ErrorCode::TOO_MANY_OPERATIONS when it runs out of space
235 * for operations. Any result other than ErrorCode::OK from begin(), update() or finish()
236 * implicitly aborts the operation, in which case abort() need not be called (and will return
237 * ErrorCode::INVALID_OPERATION_HANDLE if called).
238 *
239 * @param purpose The purpose of the operation, one of KeyPurpose::ENCRYPT, KeyPurpose::DECRYPT,
240 * KeyPurpose::SIGN or KeyPurpose::VERIFY. Note that for AEAD modes, encryption and
241 * decryption imply signing and verification, respectively, but must be specified as
242 * KeyPurpose::ENCRYPT and KeyPurpose::DECRYPT.
243 *
244 * @param keyBlob The opaque key descriptor returned by generateKey() or importKey(). The key
245 * must have a purpose compatible with purpose and all of its usage requirements
246 * must be satisfied, or begin() will return an appropriate error code.
247 *
248 * @param inParams Additional parameters for the operation. This is typically used to provide
249 * authentication data, with Tag::AUTH_TOKEN. If Tag::APPLICATION_ID or
250 * Tag::APPLICATION_DATA were provided during generation, they must be provided
251 * here, or the operation will fail with ErrorCode::INVALID_KEY_BLOB. For operations
252 * that require a nonce or IV, on keys that were generated with Tag::CALLER_NONCE,
253 * inParams may contain a tag Tag::NONCE.
254 *
255 * @return error See the ErrorCode enum in types.hal.
256 *
257 * @return outParams Output parameters. Used to return additional data from the operation
258 * initialization, notably to return the IV or nonce from operations that generate
259 * an IV or nonce.
260 *
261 * @return operationHandle The newly-created operation handle which must be passed to update(),
262 * finish() or abort().
263 */
264 begin(KeyPurpose purpose, vec<uint8_t> key, vec<KeyParameter> inParams)
265 generates(ErrorCode error, vec<KeyParameter> outParams, OperationHandle operationHandle);
266
267 /**
268 * Provides data to, and possibly receives output from, an ongoing cryptographic operation begun
269 * with begin().
270 *
271 * If operationHandle is invalid, update() will return ErrorCode::INVALID_OPERATION_HANDLE.
272 *
273 * update() may not consume all of the data provided in the data buffer. update() will return
274 * the amount consumed in inputConsumed. The caller may provide the unconsumed data in a
275 * subsequent call.
276 *
277 * @param operationHandle The operation handle returned by begin().
278 *
279 * @param inParams Additional parameters for the operation. For AEAD modes, this is used to
280 * specify Tag::ADDITIONAL_DATA. Note that additional data may be provided in
281 * multiple calls to update(), but only until input data has been provided.
282 *
283 * @param input Data to be processed, per the parameters established in the call to begin().
284 * Note that update() may or may not consume all of the data provided. See
285 * inputConsumed.
286 *
287 * @return error See the ErrorCode enum in types.hal.
288 *
289 * @return inputConsumed Amount of data that was consumed by update(). If this is less than the
290 * amount provided, the caller may provide the remainder in a subsequent call to
291 * update() or finish().
292 *
293 * @return outParams Output parameters, used to return additional data from the operation The
294 * caller takes ownership of the output parameters array and must free it with
295 * keymaster_free_param_set().
296 *
297 * @return output The output data, if any.
298 */
299 update(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input)
300 generates(ErrorCode error, uint32_t inputConsumed, vec<KeyParameter> outParams,
301 vec<uint8_t> output);
302
303 /**
304 * Finalizes a cryptographic operation begun with begin() and invalidates operationHandle.
305 *
306 * @param operationHandle The operation handle returned by begin(). This handle will be
307 * invalid when finish() returns.
308 *
309 * @param inParams Additional parameters for the operation. For AEAD modes, this is used to
310 * specify Tag::ADDITIONAL_DATA, but only if no input data was provided to update().
311 *
312 * @param input Data to be processed, per the parameters established in the call to
313 * begin(). finish() must consume all provided data or return
314 * ErrorCode::INVALID_INPUT_LENGTH.
315 *
316 * @param signature The signature to be verified if the purpose specified in the begin() call
317 * was KeyPurpose::VERIFY.
318 *
319 * @return error See the ErrorCode enum in types.hal.
320 *
321 * @return outParams Any output parameters generated by finish().
322 *
323 * @return output The output data, if any.
324 */
325 finish(OperationHandle operationHandle, vec<KeyParameter> inParams, vec<uint8_t> input,
326 vec<uint8_t> signature)
327 generates(ErrorCode error, vec<KeyParameter> outParams, vec<uint8_t> output);
328
329 /**
330 * Aborts a cryptographic operation begun with begin(), freeing all internal resources and
331 * invalidating operationHandle.
332 *
333 * @param operationHandle The operation handle returned by begin(). This handle will be
334 * invalid when abort() returns.
335 *
336 * @return error See the ErrorCode enum in types.hal.
337 */
338 abort(OperationHandle operationHandle) generates(ErrorCode error);
339};