1 page.title=Features 2 @jd:body 3 4 <!-- 5 Copyright 2015 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 --> 19 <div id="qv-wrapper"> 20 <div id="qv"> 21 <h2>In this document</h2> 22 <ol id="auto-toc"> 23 </ol> 24 </div> 25 </div> 26 27 <p>This page contains information about the features of <a href="index.html">Keystore</a> 28 in Android 6.0.</p> 29 30 <h2 id=cryptographic_primitives>Cryptographic primitives</h2> 31 32 <p>Keystore provides the following categories of operations:</p> 33 34 <ul> 35 <li>Key generation 36 <li>Import and export of asymmetric keys (no key wrapping) 37 <li>Import of raw symmetric keys (again, no wrapping) 38 <li>Asymmetric encryption and decryption with appropriate padding modes 39 <li>Asymmetric signing and verification with digesting and appropriate padding 40 modes 41 <li>Symmetric encryption and decryption in appropriate modes, including an AEAD 42 mode 43 <li>Generation and verification of symmetric message authentication codes 44 </ul> 45 46 <p>Protocol elements, such as purpose, mode and padding, as well 47 as <a href="#key_access_control">access control constraints</a>, 48 must be specified when keys are generated or imported and are permanently 49 bound to the key, ensuring the key cannot be used in any other way.</p> 50 51 <p>In addition to the list above, there is one more service that Keymaster 52 implementations must provide but which is not exposed as an API: Random number 53 generation. This is used internally for generation of keys, Initialization 54 Vectors (IVs), random padding and other elements of secure protocols that 55 require randomness.</p> 56 57 <h2 id=required_primitives>Required primitives</h2> 58 59 <p>All implementations must provide:</p> 60 61 <ul> 62 <li><a href="http://en.wikipedia.org/wiki/RSA_(cryptosystem)">RSA</a> 63 <ul> 64 <li>2048, 3072 and 4096-bit key support are required 65 <li>Support for public exponent F4 (2^16+1) 66 <li>Required padding modes for RSA signing are: 67 <ul> 68 <li>No padding (deprecated, will be removed in the future) 69 <li>RSASSA-PSS (<code>KM_PAD_RSA_PSS</code>) 70 <li>RSASSA-PKCS1-v1_5 (<code>KM_PAD_RSA_PKCS1_1_5_SIGN</code>) 71 </ul> 72 <li>Required digest modes for RSA signing are: 73 <ul> 74 <li>No digest (deprecated, will be removed in the future) 75 <li>SHA-256 76 </ul> 77 <li>Required padding modes for RSA encryption/decryption are: 78 <ul> 79 <li>Unpadded 80 <li>RSAES-OAEP (<code>KM_PAD_RSA_OAEP</code>) 81 <li>RSAES-PKCS1-v1_5 (<code>KM_PAD_RSA_PKCS1_1_5_ENCRYPT</code>) 82 </ul> 83 </ul> 84 <li><a href="http://en.wikipedia.org/wiki/Elliptic_Curve_DSA">ECDSA</a> 85 <ul> 86 <li>224, 256, 384 and 521-bit key support are required, using the NIST P-224, 87 P-256, P-384 and P-521 curves, respectively 88 <li>Required digest modes for ECDSA are: 89 <ul> 90 <li>No digest (deprecated, will be removed in the future) 91 <li>SHA-256 92 </ul> 93 </ul> 94 <li><a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a> 95 <ul> 96 <li>128 and 256-bit keys are required 97 <li><a href="http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_chaining_.28CBC.29">CBC</a>, 98 CTR, ECB and and GCM. The GCM implementation must not allow the use of tags 99 smaller than 96 bits or nonce lengths other than 96 bits. 100 <li>Padding modes <code>KM_PAD_NONE</code> and <code>KM_PAD_PKCS7</code> must 101 be supported for CBC and ECB modes. With no padding, CBC or ECB mode 102 encryption must fail if the input isn't a multiple of the block size. 103 </ul> 104 <li><a href="http://en.wikipedia.org/wiki/Hash-based_message_authentication_code">HMAC</a> 105 <a href="http://en.wikipedia.org/wiki/SHA-2">SHA-256</a>, with any key size up to at least 32 bytes. 106 </ul> 107 </ul> 108 109 <p>SHA1 and the other members of the SHA2 family (SHA-224, SHA384 and SHA512) are 110 strongly recommended, but not required. Keystore will provide them in software 111 if the hardware Keymaster implementation doesn't provide them.</p> 112 113 <p>Some primitives are also recommended for interoperability with other systems:</p> 114 115 <ul> 116 <li>Smaller key sizes for RSA 117 <li>Arbitrary public exponents for RSA 118 </ul> 119 120 <h2 id=key_access_control>Key access control</h2> 121 122 <p>Hardware-based keys that can never be extracted from the device don't provide 123 much security if an attacker can use them at will (though they're more secure 124 than keys which <em>can</em> be exfiltrated). Thus, it's crucial that Keystore 125 enforce access controls.</p> 126 127 <p>Access controls are defined as an "authorization list" of tag/value pairs. 128 Authorization tags are 32-bit integers and the values are a variety of types. 129 Some tags may be repeated to specify multiple values. Whether a tag may be 130 repeated is specified in the documentation for the tag. When a key is created, 131 the caller specifies an authorization list. The Keymaster implementation 132 underlying Keystore will modify the list to specify some additional information, 133 such as whether the key has rollback protection, and return a "final" 134 authorization list, encoded into the returned key blob. Any attempt to use the 135 key for any cryptographic operation must fail if the final authorization list is 136 modified.</p> 137 138 <p>The set of possible tags is defined in the enumeration <code>keymaster_authorization_tag_t</code> and 139 the set must be permanently fixed (though it can be extended). 140 Names are prefixed with <code>KM_TAG_</code>. The top 141 four bits of tag IDs are used to indicate the type.</p> 142 143 <p>Possible types include:</p> 144 145 <p><strong><code>KM_ENUM</code>:</strong> Many tags' values are defined in enumerations. For example, the possible 146 values of <code>KM_TAG_PURPOSE</code> are defined in enum <code>keymaster_purpose_t</code>.</p> 147 148 <p><strong><code>KM_ENUM_REP</code></strong>: Same as <code>KM_ENUM</code>, except that the tag may 149 be repeated in an authorization list. Repetition 150 indicates multiple authorized values. For example, an encryption key will 151 likely have <code>KM_PURPOSE_ENCRYPT</code> and <code>KM_PURPOSE_DECRYPT</code>.</p> 152 153 <p><strong><code>KM_UINT</code>:</strong> 32-bit unsigned integers. Example: <code>KM_TAG_KEY_SIZE</code></p> 154 155 <p><strong><code>KM_UINT_REP</code></strong>: Same as <code>KM_UINT</code>, except that the tag may be 156 repeated in an authorization list. Repetition indicates multiple authorized values.</p> 157 158 <p><strong><code>KM_ULONG</code></strong>: 64-bit unsigned integers. Example: <code>KM_TAG_RSA_PUBLIC_EXPONENT</code></p> 159 160 <p><strong><code>KM_ULONG_REP</code></strong>: Same as <code>KM_ULONG</code>, except that the tag may be 161 repeated in an authorization list. Repetition 162 indicates multiple authorized values.</p> 163 164 <p><strong><code>KM_DATE</code></strong>: Date/time values, expressed as milliseconds since January 1, 1970. 165 Example: <code>KM_TAG_PRIVKEY_EXPIRE_DATETIME</code></p> 166 167 <p><strong><code>KM_BOOL</code></strong>: True or false. A tag of type <code>KM_BOOL</code> is assumed 168 to be "false" if the tag is not present and "true" if present. Example: <code>KM_TAG_ROLLBACK_RESISTANT</code></p> 169 170 <p><strong><code>KM_BIGNUM</code></strong>: Arbitrary-length integers, expressed as a byte array 171 in big-endian order. Example: <code>KM_TAG_RSA_PUBLIC_EXPONENT</code></p> 172 173 <p><strong><code>KM_BYTES</code></strong>: A sequence of bytes. Example: <code>KM_TAG_ROOT_OF_TRUST</code></p> 174 175 <h3 id=hardware_vs_software_enforcement>Hardware vs. software enforcement</h3> 176 177 <p>Not all secure hardware will implement the same features. To support a 178 variety of approaches, Keymaster 1.0 distinguishes between secure and non-secure 179 world access control enforcement, which we call hardware and software 180 enforcement, respectively.</p> 181 182 <p>Implementations are required to:</p> 183 184 <ul> 185 186 <li>Enforce exact matching (not enforcement) of all authorizations. 187 Authorization lists in key blobs must exactly match the authorizations 188 returned during key generation, including ordering. Any mismatch must cause an 189 error diagnostic. 190 191 <li>Declare the authorizations whose semantic values are enforced. 192 193 </ul> 194 195 <p>The API mechanism for declaring hardware-enforced authorizations is in the 196 <code>keymaster_key_characteristics_t</code> structure. It divides the 197 authorization list into two sub-lists, <code>hw_enforced</code> and 198 <code>sw_enforced</code>. The secure hardware is responsible for placing the 199 appropriate values in each, based on what it can enforce.</p> 200 201 <p>In addition, Keystore implements software-based enforcement of <em>all</em> 202 authorizations, whether they're enforced by the secure hardware or not.</p> 203 204 <p>For example, consider a TrustZone-based implementation that does not support 205 key expiration. A key with an expiration date may still be created. That key's 206 authorization list will include the tag 207 <code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code> with the expiration date. A 208 request to Keystore for the key characteristics will find this tag in the 209 <code>sw_enforced</code> list and the secure hardware will not enforce the 210 expiration requirement. However, attempts to use the key after expiration will 211 be rejected by Keystore.</p> 212 213 <p>If the device is then upgraded with secure hardware that does support 214 expiration, then a request for key characteristics will find 215 <code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code> in the <code>hw_enforced</code> 216 list, and attempts to use the key after expiration will fail even if the 217 keystore is somehow subverted or bypassed.</p> 218 219 <h3 id=cryptographic_message_construction_authorizations>Cryptographic message construction authorizations</h3> 220 221 <p>The following tags are used to define the cryptographic characteristics of 222 operations using the associated key: <code>KM_TAG_ALGORITHM</code>, <code>KM_TAG_KEY_SIZE</code>, 223 <code>KM_TAG_BLOCK_MODE</code>, <code>KM_TAG_PADDING</code>, <code>KM_TAG_CALLER_NONCE</code>, and <code>KM_TAG_DIGEST</code></p> 224 225 <p><code>KM_TAG_PADDING</code>, <code>KM_TAG_DIGEST</code>, and <code>KM_PAD_BLOCK_MODE</code> 226 are repeatable, meaning that multiple values may be associated with a single 227 key, and the value to be used will be specified at operation time.</p> 228 229 <h3 id=purpose>Purpose</h3> 230 231 <p>Keys have an associated set of purposes, expressed as one or more authorization 232 entries with tag <code>KM_TAG_PURPOSE</code>, which defines how they can be used. The purposes are:</p> 233 234 <ul> 235 <li><code>KM_PURPOSE_ENCRYPT</code> 236 <li><code>KM_PURPOSE_DECRYPT</code> 237 <li><code>KM_PURPOSE_SIGN</code> 238 <li><code>KM_PURPOSE_VERIFY</code> 239 </ul> 240 241 <p>Any key can have any subset of these purposes. Note that some combinations 242 create security problems. For example, an RSA key that can be used to both 243 encrypt and to sign allows an attacker who can convince the system to decrypt 244 arbitrary data to generate signatures.</p> 245 246 <h3 id=import_and_export>Import and export</h3> 247 248 <p>Keymaster supports export of public keys only, in X.509 format, and import of:</p> 249 250 <ul> 251 <li>Public and private key pairs in DER-encoded PKCS#8 format, without 252 password-based encryption, and 253 <li>Symmetric keys as raw bytes 254 </ul> 255 256 <p>To ensure that imported keys can be distinguished from securely-generated 257 keys, <code>KM_TAG_ORIGIN</code> is included in the appropriate key 258 authorization list. For example, if a key 259 was generated in secure hardware, <code>KM_TAG_ORIGIN</code> with 260 value <code>KM_ORIGIN_GENERATED</code> will be found in 261 the <code>hw_enforced</code> list of the key characteristics, while a key 262 that was imported into secure 263 hardware will have the value <code>KM_ORIGIN_IMPORTED</code>.</p> 264 265 <h3 id=user_authentication>User authentication</h3> 266 267 <p>Secure Keymaster implementations do not implement user authentication, but 268 depend on other trusted apps which do. For the interface that must be 269 implemented by these apps, see the Gatekeeper page.</p> 270 271 <p>User authentication requirements are specified via two sets of tags. The first 272 set indicate which user can use the key:</p> 273 274 <ul> 275 <li><code>KM_TAG_ALL_USERS</code> indicates the key is usable by all users. If 276 present, <code>KM_TAG_USER_ID</code> and <code>KM_TAG_SECURE_USER_ID</code> must not be present. 277 <li><code>KM_TAG_USER_ID</code> has a numeric value specifying the ID of the authorized user. 278 Note that this 279 is the Android user ID (for multi-user), not the application UID, and it is 280 enforced by non-secure software only. If present, <code>KM_TAG_ALL_USERS</code> must not be present. 281 <li><code>KM_TAG_SECURE_USER_ID</code> has a 64-bit numeric value specifying the secure user ID 282 that must be provided 283 in a secure authentication token to unlock use of the key. If repeated, the key 284 may be used if any of the values is provided in a secure authentication token. 285 </ul> 286 287 <p>The second set indicate whether and when the user must be authenticated. If 288 neither of these tags is present, but <code>KM_TAG_SECURE_USER_ID</code> is, authentication is 289 required for every use of the key.</p> 290 291 <ul> 292 <li><code>KM_NO_AUTHENTICATION_REQUIRED</code> indicates no user authentication is required, though 293 the key still may only be 294 used by apps running as the user(s) specified by <code>KM_TAG_USER_ID</code>. 295 <li><code>KM_TAG_AUTH_TIMEOUT</code> is a numeric value specifying, in seconds, how fresh the user 296 authentication 297 must be to authorize key usage. This applies only to private/secret key 298 operations. Public key operations don't require authentication. Timeouts do not 299 cross reboots; after a reboot, all keys are "never authenticated." The timeout 300 may be set to a large value to indicate that authentication is required once 301 per boot (2^32 seconds is ~136 years; presumably Android devices are rebooted 302 more often than that). 303 </ul> 304 305 <h3 id=client_binding>Client binding</h3> 306 307 <p>Client binding, the association of a key with a particular client 308 application, is done via an optional client ID and some optional client data 309 (<code>KM_TAG_APPLICATION_ID</code> and <code>KM_TAG_APPLICATION_DATA</code>, 310 respectively). Keystore treats these values as opaque blobs, only ensuring that 311 the same blobs presented during key generation/import are presented for every 312 use and are byte-for-byte identical. The client binding data is not returned by 313 Keymaster. The caller must know it in order to use the key.</p> 314 315 <p>This feature is not exposed to applications. 316 317 <h3 id=expiration>Expiration</h3> 318 319 <p>Keystore supports restricting key usage by date. Key start of validity and 320 key expirations can be associated with a key and Keymaster will refuse to 321 perform key operations if the current date/time is outside of the valid 322 range. The key validity range is specified with the tags 323 <code>KM_TAG_ACTIVE_DATETIME</code>, 324 <code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code>, and 325 <code>KM_TAG_USAGE_EXPIRE_DATETIME</code>. The distinction between 326 "origination" and "usage" is based on whether the key is being used to 327 "originate" a new ciphertext/signature/etc., or to "use" an existing 328 ciphertext/signature/etc. Note that this distinction is not exposed to 329 applications.</p> 330 331 <p>The <code>KM_TAG_ACTIVE_DATETIME</code>, <code>KM_TAG_ORIGINATION_EXPIRE_DATETIME</code>, 332 and <code>KM_TAG_USAGE_EXPIRE_DATETIME</code> tags are optional. If the tags are absent, it is 333 assumed that the key in 334 question can always be used to decrypt/verify messages.</p> 335 336 <p>Because wall-clock time is provided by the non-secure world, it's unlikely that 337 the expiration-related tags will be in the hardware-enforced list. Hardware 338 enforcement of expiry would require that the secure world somehow obtain 339 trusted time and data, for example via a challenge response protocol with a 340 trusted remote timeserver.</p> 341 342 <h3 id=root_of_trust_binding>Root of trust binding</h3> 343 344 <p>Keystore requires keys to be bound to a root of trust, which is a bitstring 345 provided to the Keymaster secure hardware during startup, preferably by the 346 bootloader. This bitstring must be cryptographically bound to every key managed 347 by Keymaster.</p> 348 349 <p>The root of trust consists of the public key used to verify the signature on 350 the boot image and the lock state of the device. If the public key is changed to 351 allow a different system image to be used or if the lock state is changed, then 352 none of the Keymaster-protected keys created by the previous system will be 353 usable, unless the previous root of trust is restored and a system that is 354 signed by that key is booted. The goal is to increase the value of the 355 software-enforced key access controls by making it impossible for an 356 attacker-installed operating system to use Keymaster keys.</p> 357 358 <h3 id=standalone_keys>Standalone keys</h3> 359 360 <p>Some Keymaster secure hardware may choose to store key material internally 361 and return handles rather than encrypted key material. Or there may be other 362 cases in which keys cannot be used until some other non-secure or secure world 363 system component is available. The Keymaster 1.0 HAL allows the caller to 364 request that a key be "standalone," via the <code>KM_TAG_STANDALONE</code> tag, 365 meaning that no resources other than the blob and the running Keymaster system 366 are required. The tags associated with a key may be inspected to see whether a 367 key is standalone. At present, only two values are defined:</p> 368 369 <ul> 370 <li><code>KM_BLOB_STANDALONE</code> 371 <li><code>KM_BLOB_REQUIRES_FILE_SYSTEM</code> 372 </ul> 373 374 <p>This feature is not exposed to applications. 375 376 <h3 id=velocity>Velocity</h3> 377 378 <p>When it's created, the maximum usage velocity can be specified 379 with <code>KM_TAG_MIN_SECONDS_BETWEEN_OPS</code>. 380 TrustZone implementations will refuse to perform cryptographic operations 381 with that key if an operation was performed less 382 than <code>KM_TAG_MIN_SECONDS_BETWEEN_OPS</code> seconds earlier.</p> 383 384 <p>The simple approach to implementing velocity limits is a table of key IDs and 385 last-use timestamps. This table will likely be of limited size, but must 386 accommodate at least 16 entries. In the event that the table is full and no 387 entries may be updated or discarded, secure hardware implementations must "fail 388 safe," preferring to refuse all velocity-limited key operations until one of the 389 entries expires. It is acceptable for all entries to expire upon reboot.</p> 390 391 <p>Keys can also be limited to <em>n</em> uses per boot with 392 <code>KM_TAG_MAX_USES_PER_BOOT</code>. This also requires a tracking table, 393 which must accommodate at least four keys, and must also fail safe. Note that 394 applications will be unable to create per-boot limited keys. This feature will 395 not be exposed through Keystore and will be reserved for system operations.</p> 396 397 <p>This feature is not exposed to applications.</p> 398 399 <h3 id=random_number_generator_re-seeding>Random number generator re-seeding</h3> 400 401 <p>Because secure hardware must generate random numbers for key material and 402 Initialization Vectors (IVs), and because hardware random number generators may 403 not always be fully trustworthy, the Keymaster HAL provides an interface to 404 allow the client to provide additional entropy which will be mixed into the 405 random numbers generated.</p> 406 407 <p>A hardware random-number generator must be used as the primary seed source, 408 and the seed data provided through the external API must not be the sole source 409 of randomness used for number generation. Further, the mixing operation used 410 must ensure that the random output is unpredictable if any one of the seed 411 sources is unpredictable.</p> 412 413 <p>This feature is not exposed to applications but is used by the framework, 414 which regularly provides additional entropy, retrieved from a Java SecureRandom 415 instance, to the secure hardware. 416