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