summaryrefslogtreecommitdiff
path: root/android_keymaster_test.cpp
AgeCommit message (Collapse)Author
2016-01-27Add attestation support to SoftKeymaster.Shawn Willden
Bug: 22914603 Change-Id: I7650f1b691665bce3024556c2ea38e122c9cb2cf
2016-01-26Update unit tests to use keymaster2 interface.Shawn Willden
We no longer test the keymaster1 interface. That's okay, because it will be gone shortly. Change-Id: Id30c2fcda5d535165a0081a783b2252c112e5474
2015-11-25Fix pass-through of deletion on wrapped KM0 and KM1.Shawn Willden
SoftKeymasterDevice was incorrectly directly sending deletion requests to wrapped hardware. In some cases the key blob passed in by SoftKeymasterDevice is a hardware blob encapsulated by a wrapper, and we need to remove the encapsulation before passing it on. Bug: 25676862 Change-Id: Ic315c6b08d9ec15aa0be8f28f485a221bc7f1135
2015-10-28Return correct error from keymaster0engine for large RSA inputShawn Willden
Also, ensure that we always put some error on the OpenSSL error queue whenever a wrapped keymaster0 operation fails. Higher layers will look a the last entry on the queue and use it to determine what error code to return. Not putting any error on the queue means that those higher layers will get whatever error was last enqueued, making the result effectively random. Non-determinism bad. Bug: 25337630 Change-Id: I701ab735dd089f5258b2252f543906d9f3baa7a2
2015-10-16Fix incorrect initializer in keymaster tests.Shawn Willden
Change-Id: Ic78b0fa12bda1cd361fd505e13002651861c72ef
2015-10-16Do digesting, and sometimes padding, in SW when HW doesnt.Shawn Willden
The keymaster1 specification only requires HW modules to implement SHA256 out of the list of keymaster1 digest modes. That would force many keys to be software only, and would break legacy scenarios. This change uses SoftKeymasterDevice to front keymaster modules that don't implement the full suite of digests, quietly inserting KM_DIGEST_NONE and KM_PAD_NONE into key generation/import requests when necessary, then performing the digesting, and sometimes padding, in software, then delegating crypto operations to the hardware. This is only done for RSA and EC keys. Software digesting isn't possible for HMAC or AES-GCM keys. Note that this is not the complete fix for the bug. Some changes in keystore are also required, coming in another CL. Bug: 24873723 Change-Id: I740572eb11341fb0659085309da01d5cbcd3854d
2015-07-30Left-pad messages when doing "unpadded" RSA operations.marshmallow-devShawn Willden
When RSA messages that are shorter than the key size, and padding is not applied, BoringSSL (sensbibly) refuses, because odds are very high that the caller is doing something dumb. However, this causes some (dumb) things that used to work to no longer work. This CL also fixes the error code returned when a message is signed or encrypted which is the same length as the public modulus but is numerically larger than or equal to the public modulus. Rather than KM_ERROR_UNKNOWN_ERROR, it now returns KM_ERROR_INVALID_ARGUMENT. Bug: 22599805 Change-Id: I99aca5516b092f3676ffdc6c5de39f2777e3d275
2015-07-29Merge "Revert "Revert "Report keymaster0 keys as hardware-backed, origin ↵Shawn Willden
unknown.""" into mnc-dev
2015-07-29Revert "Revert "Report keymaster0 keys as hardware-backed, origin unknown.""Shawn Willden
This reverts commit 0e0cea3bc8aea903a50c1ee18e9f3309e9f67515. Bug: 22511313 Change-Id: I9c31b8ef604d961e20652c69498324b9dfce5911
2015-07-28Make NONE mean NONE only (not ANY)Shawn Willden
KM_DIGEST_NONE and KM_PAD_NONE have implicit meanings of "any digest" and "any padding", respectively, as well as the expected meanings of "no digest" and "no padding". This CL changes that so they mean only "no digest" and "no padding". Bug: 22556114 Change-Id: I7b0b4c079067d85ba1aa39ae7edf0c6b17a9a500
2015-07-28Merge "Use minimum 20 bytes salt for RSA PSS." into mnc-devShawn Willden
2015-07-23Revert "Report keymaster0 keys as hardware-backed, origin unknown."Shawn Willden
This reverts commit 9972a539acb4d17368ee607465d61b48acd71bde. Change-Id: Id5beb9c8ae8f3b106adc5f5e62eca0194b926be8
2015-07-20Use minimum 20 bytes salt for RSA PSS.Shawn Willden
This is for compatibility with Bouncy Castle. Bug: 22492259 Change-Id: I753e5fd223404ba960b6a35862bbd20f519f369b
2015-07-16Report keymaster0 keys as hardware-backed, origin unknown.Shawn Willden
Bug: 22511313 Change-Id: I699df8010e27a546b2186896890c0099bfb149ae
2015-07-16Add support for KM_TAG_MIN_MAC_LENGTH.Shawn Willden
HMAC and AES-GCM keys must be bound to a mininum MAC/tag length at creation, and operations may not specify a length smaller than the minimum, or provide a length smaller than the minimum during verification. Bug: 22337277 Change-Id: Id5ae2f4259045ba1418c28e9de8f4a47e67fd433
2015-07-14Use specified digest for RSA OAEP.Shawn Willden
Bug: 22405614 Change-Id: Ia5eb67a571a9d46acca4b4e708bb8178bd3acd0d
2015-07-09Truncate too-long digests for keymaster 0 ECDSA sign operationsShawn Willden
BoringSSL doesn't pre-truncate too-long digests before calling the ECDSA sign operation via the ENGINE interface, and TrustyKeymaster is picky about accepting them. This means that trying to sign a message with, say, a 256-bit key and a 384-bit hash fails on Volantis. This CL also corrects an error in get_supported_digests for ECDSA, which was advertising support for MD5. BoringSSL doesn't support ECDSA with MD5 and we're not offering it in the JCA API, so the solution is simply not to advertise it and to return a better error code if it's requested anyway. Bug: 22355708 Change-Id: Iba2dad6953db7eda23951760b734f499a13c5191
2015-07-06Fix enforcement of block mode and MAC length on AES opsShawn Willden
Bug: 22301168 Change-Id: I54b4efffa1786b08704dd6e785360870f155ed80
2015-07-01Allow any padding mode to be used with keys with KM_PAD_NONE.Shawn Willden
Bug: 22229156 Change-Id: I5de66c3ed86244452e7776bff9523e35030713e9
2015-06-26Support creation and use of HMAC keys with KM_DIGEST_NONEShawn Willden
KM_DIGEST_NONE should mean "any digest" when applied to HMAC keys, allowing any valid digest to be specified during begin() of an HMAC signature or verification operation. Bug: 22119295 Change-Id: I4698435f5d7aaf0a2f66b9c7aa4097f60c9c6eb3
2015-06-26Add authorization enforcement to AndroidKeymaster.Shawn Willden
Note: Moving List.h into system/keymaster is unfortunate, but required to allow Trusty to use it. b/22088154 tracks cleaning this up. Bug: 19511945 Change-Id: Ia1dfe5fda5ea78935611b0a7656b323770edcbae
2015-06-24Handle ECDSA messages that may be a few bits longer than the key.Shawn Willden
Also fix an RSA error message. Bug: 22064177 Change-Id: If52b29a3e870e0318d9ecc0f124074a013cb491a
2015-06-22Require and handle digest for OAEP mode.Shawn Willden
Bug: 21998286 Change-Id: I03b21da6a71b7a7a01f3743f01925719191b0124
2015-06-22Validate input sizes for RSA and ECDSA signing/verification ops.Shawn Willden
Bug: 21955742 Change-Id: I4385a6539229b174facd5f04ce0391e2e8c3608d
2015-06-17Don't enforce purpose, digest or padding on public key operationsShawn Willden
Bug: 21877150 Change-Id: Iaf00c94aaca892a154aea7aa4e3828bfbd8d9630
2015-06-17GCM tags in ciphertext, rather than in params.Shawn Willden
Also, handle AAD correctly. Bug: 21786749 Change-Id: I26a413f39daf3bd946ed494c7c3b5c6f559fb30b
2015-06-12Restore support for old unversioned OCB-encrypted blobs.Shawn Willden
This support was inadvertently removed in a refactor. There aren't many of these keys around, since they were only created by pre-release verions of Nexus 9 software, but we'll support them anyway. Change-Id: I46c4e9a2866c02b8030d7aef97bb64c45441168b
2015-06-11Make KM_PAD_NONE and KM_DIGEST_NONE mean any padding or digest.Shawn Willden
Bug: 21777596 Change-Id: I3574156902c8e28b42f36462a9aef3f11ce938d3
2015-06-03Fix unused variable issuesChad Brubaker
Also adds -Wunused to bring gcc's -Werror inline with clang's to prevent similar build errors later. Bug:21583577 Change-Id: Ia051adbb3ea92a8ace914ad958a73348d70cca17
2015-06-03Fix support of HW keymaster0 keys.Shawn Willden
Bug: 21593823 Change-Id: Id9ed06b1c6805b1cff36577910715eda7727eef4
2015-06-03Add AES-GCM mode.Shawn Willden
Bug: 19919114 Change-Id: I27efed097efbd93d587a50f5d82fad80a96e7527
2015-06-01Add support for unpadded RSA encryption.Shawn Willden
Bug: 21499189 Change-Id: I895e566f769691f70f431b2ed139e0c94b0f6ab9
2015-06-01Support all digests for RSA.Shawn Willden
Also switch to using the EVP APIs where possible for RSA ops. Change-Id: I092a5c7598073980d36ce5137cfe17f0499a10b9
2015-06-01Add support for all digests for ECDSA.Shawn Willden
Also, switch to useing the EVP API rather than the ECDSA API. Bug: 21048758 Change-Id: I088b3332285ce2060cac5a7282ec42bea2fa5950
2015-05-28Delegate ECDSA keys to keymaster0 in SoftKeymasterDevice.Shawn Willden
Bug: 20912868 Change-Id: If63899e3244aed45d939d0165e6d94a1caa9d220
2015-05-28Fix broken ECDSA default key size test.Shawn Willden
Change-Id: I3b98c0e0463efcbe3d7498a2f71353ed669a11d9
2015-05-28Delegate RSA keys to keymaster0 in SoftKeymasterDevice.Shawn Willden
Bug: 20912868 Change-Id: I515a125f1247357d2cd9b4633c3b223590848093
2015-05-26Make Keymaster1Test parameterizable.Shawn Willden
This enabled running the same test suite across different implementations. Bug: 20912868 Change-Id: Iaa2c4bcb38224d090aa54184a042375eb835ad60
2015-05-26Fix off-by-one error in PKCS#1 v1.5 encryption padding size.Shawn Willden
Change-Id: I0fdfe3223b351d4a064e5dac0aa5d732fa0ab073
2015-05-26Revert "Revert "Large refactor to move context out of AndroidKeymaster.""Shawn Willden
This reverts commit 13fbe3e93247943c26e7ca2ed27b6d650282b8bf. Bug: 20912868, 19799085 Change-Id: Iadd6ce5cbe94956c2a2fe277f1bf5b108e4bcf57
2015-05-23Revert "Large refactor to move context out of AndroidKeymaster."Shawn Willden
This reverts commit 8ba2a043f0d44ad3f58d4af518f9391c03eca9c3. I need to update the Volantis non-secure code in sync. Reverting while I get that done. Change-Id: I0fb9f928e7e624ad678050a04bb873b43b1c9a48
2015-05-20Large refactor to move context out of AndroidKeymaster.Shawn Willden
AndroidKeymaster made a number of assumptions about its context that are really only valid for TEE-based usage. In addition, KeyFactory made some similarly TEE-focused assumptions about key blob creation and parsing. Both concerns have been moved to a new KeymasterContext class, which is responsible for building and parsing key blobs in a manner appropriate for the context in which AndroidKeymaster is running, as well as providing other context-specific services, such as random number generation. In addition, the refactor reduces the need for the KeyBlob and UnencryptedKeyBlob classes, which encode too many assumptions about blob formatting and encryption, to the point that they can be removed and replaced by a handful of utility functions which are much cleaner and more flexible. How to review this CL: I looked hard at breaking this up into smaller CLs, but it's mostly not feasible. However, it's probably easier to approach it by starting with the fundamental changes, and then looking at the cascade effects. 1. Look at keymaster_context.h. The core of the change was pulling this set of features out of AndroidKeymaster. Note that the revised approach to key blob creation does not involve the KeyBlob and UnencryptedKeyBlob classes, but instead goes directly from raw key material plus ancillary data (e.g. auth sets) to a serialized buffer ready to return to keystore. The same is true in reverse direction for parsing key blobs. 2. Look at key.h. The revised KeyFactory GenerateKey, ImportKey and LoadKey methods are essential. GenerateKey and ImportKey no longer produce a Key object, because all that's needed is a returnable blob. LoadKey produces a Key object, but it starts with raw key material, rather than an UnencryptedKeyBlob. Also note the change to the Key class; because Key objects are only created by LoadKey, when there's a need to use a key, there's only one constructor. 3. Look at asymmetric_key.h, rsa_key.h and rsa_key.cpp. rsa_key.cpp provides a good example of how the new structure works. GenerateKey and ImportKey do all of the work necessary to produce an OpenSSL RSA key and extract the internal representation (using EvpToKeyMaterial; defined in asymmetric_key.h because it's the same for EC keys). Then, with the raw key data in hand, they call KeymasterContext::CreateKeyBlob to wrap the key data in a key blob that can be returned to the caller -- whatever that wrapping means in the current context. There's a subtlety not apparent here which is crucial to the rationale for the refactoring: RsaKeyFactory uses KeymasterContext::get_instance to retrieve the context, but key factories which depend on operating in a particular context can use a different way to get their context object, which may have a larger interface. RsaKeymaster0KeyFactory will do this. 4. Look at soft_keymaster_context. In particular, SoftKeymasterContext::CreateKeyBlob and ParseKeyBlob. CreateKeyBlob allocates authorization tags from key_description to hw_enforced and sw_enforced, then encrypts the key material and serializes it to a blob. This approach is compatible with the keys softkeymaster has been producing, but I'm going to change it (post M), because there's no reason to bother encrypting SW keys with a SW key. ParseKeyBlob reverses the process to recover the unencrypted key material and the auth lists. One debatable point was the decision to implement BuildHiddenAuthorizations and SetAuthorizations here, since all contexts will need something similar, and they really should all do it the same. I may refactor later to pull that functionality up to KeymasterContext; it will depend on what I learn implementing TrustyKeymasterContext and HybridKeymasterContext (used for the keymaster0 adapter). 5. Look at ocb_utils and auth_encrypted_key_blob. These contain the key encryption and key blob serialization code which was formerly split between AndroidKeymaster::SerializeKeyBlob, UnencryptedKeyBlob and KeyBlob, now divided into separate encryption and serialization utilities. Note the refactored key_blob_test.cpp, updated to use the new utilities rather than UnencryptedKeyBlob. 6. Look at soft_keymaster_device.cpp. Since KeyBlob no longer exists to provide a nice way to peer into a blob to extract the algorithm, for use in determining how to parse the keymaster0 signing key params (which come in as a void*, yuck), we now have to use get_key_characteristics to recover the params. This was the right way all along; the device layer should not depend on being able to parse key blobs. 7. The rest. Bug: 20912868, 19799085 Change-Id: Ieb74b8da39974f674eb8baa959bde75011fdd2e8
2015-05-18Remove references to Google in Android keymaster reference implementation.Shawn Willden
Change-Id: I05de61353fc806b90232fab7c1d1cf76aefa35fc