187 Commits

Author SHA1 Message Date
Alex Klyubin
0ee9376ef4 Add EcIesParameterSpec to enable ECIES crypto.
Bug: 18088752
Change-Id: I597b019106c500188e0fbbc9608722668c08b421
2015-04-10 14:57:28 -07:00
Alex Klyubin
862e6c7814 Track recent keymaster_defs.h changes.
Bug: 18088752
Change-Id: If47bb7cc7a385941db9f12d478676594e9bc9d86
2015-04-09 16:58:58 -07:00
Alex Klyubin
b503c52f07 Split key origin into TEE/not and generated/imported.
This is to match the upcoming changes in Keymaster HAL API.

Bug: 18088752
Change-Id: I602d56d1c29a839583be1d9efa681a6fab6642db
2015-04-09 15:50:17 -07:00
Alex Klyubin
7882a7fcd4 Fix minor issues in new Javadocs of AndroidKeyStore.
Bug: 18088752
Change-Id: Ie84cc6066c82f2659da17a1eb158c2e3acf5094d
2015-04-09 14:33:11 -07:00
Alex Klyubin
aeae0f384f Merge "Add asymmetric crypto constants for AndroidKeyStore API." 2015-04-09 20:02:39 +00:00
Alex Klyubin
8c58ba87bb Merge "Add missing mapping between JCA and keystore HMAC names." 2015-04-09 19:57:13 +00:00
Alex Klyubin
ccfea5024b Add asymmetric crypto constants for AndroidKeyStore API.
Bug: 18088752
Change-Id: Iee72a4c230f3a2cd30d9eb4d29c4301f3e113f31
2015-04-09 11:38:44 -07:00
Alex Klyubin
5324702a02 Add missing mapping between JCA and keystore HMAC names.
This is a follow-up to 70376a77280551791dae62586a6bb0c77ed9429a where
I forgot to update this mapping.

Bug: 18088752
Change-Id: I322a9abd642ddee3bd2b4f49379b121012e32836
2015-04-09 10:10:34 -07:00
Alex Klyubin
223977b914 Hide KeyStoreParameter.Builder.setRandomizedEncryptionRequired.
This wasn't meant to be public API yet.

Bug: 18088752
Change-Id: I40e57fd9121348086ae88ad9fa54f930547b77ba
2015-04-09 09:50:34 -07:00
Alex Klyubin
a482b0469c Merge "Require IND-CPA by default for new AndroidKeyStore keys." 2015-04-09 16:12:09 +00:00
Alex Klyubin
f853f64998 Require IND-CPA by default for new AndroidKeyStore keys.
Bug: 18088752
Change-Id: I01e44b7155df4326b5c9d83dda57f889c1f23ec7
2015-04-08 16:28:27 -07:00
Alex Klyubin
70376a7728 Add more digests to AndroidKeyStore API.
This adds MD5, SHA-1, SHA-224, SHA-384, and SHA-512. SHA-256 was
already there.

MD5 is not exposed for HMAC on purpose, because MD5 has been
deprecated for years.

Bug: 18088752
Change-Id: I4df3d3f6cf10805c7910a1bdb577a91c85055945
2015-04-08 14:17:21 -07:00
Alex Klyubin
6895a549ec Fix typo
Change-Id: I1c47ade98ad3ae41dc55e7bcafcad6901b559c89
2015-04-08 11:08:37 -07:00
Alex Klyubin
edd0e6c098 Merge "Refuse to reuse IV in encryption mode in AndroidKeyStore." 2015-04-08 18:04:39 +00:00
Alex Klyubin
d1ccb45945 Refuse to reuse IV in encryption mode in AndroidKeyStore.
This makes IV-using Cipher implementations backed by AndroidKeyStore
refuse to be reused. After Cipher.doFinal completes, invoking update
or doFinal will raise an exception. This is to make it harder to
violate the security best practice of not reusing IV in encryption
mode.

Bug: 18088752
Change-Id: I5102f9e8b2ff428254294703e48948ea8576603d
2015-04-08 09:46:16 -07:00
Alex Klyubin
38bb642bbb Add BlockMode.GCM constant to AndroidKeyStore API.
GCM mode is not yet implemented. This is just adding a constant to
KeyStoreKeyConstraints.BlockMode.

Bug: 18088752
Change-Id: Ibba5b393f56ab9f6bb96d994f110687ab8d65ff3
2015-04-07 15:09:12 -07:00
Alex Klyubin
c46e9e7da4 Make the new AndroidKeyStore API conformant.
This makes the new AndroidKeyStore API conform with the latest
Keymaster API changes as well as the latest Android framework API
design guidelines.

Keymaster changes:
* Multiple paddings, block modes, and digests can be set on a key.
* "max uses per boot" and "min seconds between use" restrictions will
  not be exposed in the framework API.
* Padding scheme ZERO will not be exposed.

Changes due to Android framework design guidelines:
* Sets of enum values have been replaced with bitsets represented as
  ints.
* Integer has been replaced with int, with null being represented
  with a special value (e.g., -1 or 0) where possible.

Bug: 18088752
Change-Id: Ib21739aa9b42d48895cb7a681e836a5c6d972ac6
2015-04-07 09:18:00 -07:00
Alex Klyubin
6def5afcbc Load fewer classes when AndroidKeyStore provider is installed.
This avoids loading all AndroidKeyStore crypto SPI classes when the
AndroidKeyStore provider is instantiated and installed. This provider
is installed early on during the initialization of each app. Most apps
don't need these classes loaded.

Bug: 18088752
Change-Id: Ib43c9dd6a7d434b128916e0f9c8652ba61df0d47
2015-04-03 12:45:16 -07:00
Alex Klyubin
08963653fc Merge "Rename KeymasterException to KeyStoreException." 2015-04-03 19:13:49 +00:00
Alex Klyubin
a0f656f9bd Obtain SPI without using Reflection.
Bug: 18088752
Change-Id: I76d42e17f5f28af6fd9a96ee812d286f6c6a085b
2015-04-03 12:09:56 -07:00
Alex Klyubin
b4834ae3fa Rename KeymasterException to KeyStoreException.
The code in question talks to KeyStore which returns error codes
which are a mix of keystore and keymaster error codes. To better
match the layering of KeyStore on top of keystore and keymaster,
this CL renames KeymasterException into KeyStoreException. It also
adds human-readable error messages to exceptions raised by keystore
rather than keymaster (e.g., key not found).

Bug: 18088752
Change-Id: I4cd1235e16518c9f2e8c5557a457774c6e687b88
2015-04-02 15:57:27 -07:00
Alex Klyubin
3cc9e5d68d Merge "Improve the AndroidKeyStore-backed HMAC state machine." 2015-04-02 21:06:28 +00:00
Alex Klyubin
9635a56acf Merge "Expose new key use constraints in KeyPairGeneratorSpec." 2015-04-02 21:03:11 +00:00
Alex Klyubin
855fa31eb5 Expose new key use constraints in KeyPairGeneratorSpec.
The constraints are currently ignored.

Bug: 18088752
Change-Id: Iabd2018200afb2bf8ac1748d1def47af74bfb9d3
2015-04-02 10:04:33 -07:00
Alex Klyubin
0b188927f4 Add exception types for AndroidKeyStore key validity issues.
Bug: 18088752
Change-Id: I7494cb6a793e2b57bb849a4253bba2803778c161
2015-04-01 16:22:00 -07:00
Alex Klyubin
a80eee052d Improve the AndroidKeyStore-backed HMAC state machine.
This defers the start of a new KeyStore operation after Mac.doFinal
until the next Mac.update or .doFinal. Previously, the a new KeyStore
operation was started immediately, at the end of doFinal.

Bug: 18088752
Change-Id: I2d594067ef261f519631d09f7a6087b715801656
2015-04-01 16:03:03 -07:00
Alex Klyubin
5045b7189c Use Keymaster-friendly validity dates.
Keymaster HAL currently requires that key validity start and end dates
always be specified. The framework API does not. This CL expresses
the framework API's "not specified" instants to Keymaster as instants
in distant past or future.

Bug: 18088752
Change-Id: Ia9d66d5e57bfca30628cdef6e0925a2781a3acfb
2015-04-01 10:44:30 -07:00
Alex Klyubin
c461452eb7 Merge "Hook in user authenticators and their exceptions." 2015-04-01 17:34:37 +00:00
Alex Klyubin
52886ca77d A way to obtain KeyStore operation handle from crypto primitives.
This adds AndroidKeyStore.getKeyStoreOperationHandle method which can
be used to obtain the KeyStore operation handle corresponding to the
provided JCA cryto primitive (provided it's backed by
AndroidKeyStore).

Bug: 18088752
Change-Id: Iaa3b6f9b2281b2ec2de8fd5946d353dc7fdb3d2d
2015-03-31 21:19:26 -07:00
Alex Klyubin
c8e557470f Hook in user authenticators and their exceptions.
Bug: 18088752
Change-Id: I2835dbe51d09587a3081597c6aaf536aa1427e24
2015-03-31 19:50:13 -07:00
Alex Klyubin
cc21bb3a56 Add license banner to recently added AndroidKeyStore files.
Bug: 18088752
Change-Id: I027f9530a02cca081aae8eb94833d2fdcb678e9a
2015-03-31 16:50:37 -07:00
Alex Klyubin
acc835f385 Add SecretKeyFactory backed by AndroidKeyStore.
This factory provides a way to obtain information about a SecretKey
backed by AndroidKeyStore. The information is provided in a form of an
instance of KeyStoreKeySpec class.

EXAMPLE

SecretKeyFactory factory = SecretKeyFactory.getInstance(
        key.getAlgorithm(), "AndroidKeyStore");
KeyStoreKeySpec keySpec =
    factory.getKeySpec(key, KeyStoreKeySpec.class);

Bug: 18088752
Change-Id: I26c9dd544f80230fe7039501eeb471eaf875452b
2015-03-31 15:29:48 -07:00
Alex Klyubin
b406f24291 Add unauthenticated AES ciphers backed by AndroidKeyStore.
This adds the following AES transformations:
* AES/ECB/NoPadding
* AES/ECB/PKCS7Padding
* AES/CBC/NoPadding
* AES/CBC/PKCS7Padding
* AES/CTR/NoPadding

Bug: 18088752
Change-Id: I3e4702e59868f8f2225c31b1c159d20008b9999d
2015-03-31 13:59:07 -07:00
Alex Klyubin
6a6f0c7de2 Merge "Add HmacSHA256 backed by AndroidKeyStore." 2015-03-30 20:34:48 +00:00
Chad Brubaker
f603e28614 Merge "Add authorization binder methods" 2015-03-30 20:06:39 +00:00
Alex Klyubin
4ab8ea4498 Add HmacSHA256 backed by AndroidKeyStore.
This also adds the MAC length constraint on imported HMAC keys. HMAC
doesn't work without this constraint at the moment.

Bug: 18088752
Change-Id: I8613f58f5d2a84df00bcf6179d13e30619440330
2015-03-30 12:53:23 -07:00
Alex Klyubin
d23a1f706f Symmetric key generation for AndroidKeyStore.
This currently supports AES and HMAC with SHA-256.

Bug: 18088752
Change-Id: Ife55438cf4129b895295681bb35091cd37eb73fb
2015-03-27 15:57:53 -07:00
Chad Brubaker
dae79e5408 Allow entropy to be provided to some operations
generateKey and begin can now optionally take an array of bytes to add
to the rng entropy of the device before the operation. If entropy is
specified and the device does not support add_rng_entropy or the call
fails then that device will not be used, leading to fallback or error
depending on the situation.

Change-Id: Id7d33e3cc959594dfa5483d002993ba35c1fb134
2015-03-27 14:28:35 -07:00
Alex Klyubin
baf2838fd2 Symmetric key import for AndroidKeyStore.
AES and HmacSHA256 symmetric keys can now be imported into
AndroidKeyStore. These keys cannot yet be used.

Bug: 18088752
Change-Id: Iad2fd49d15ac4c2d676abe1153f5b5f0b6ff496c
2015-03-26 15:37:15 -07:00
Chad Brubaker
5e73c0eec2 Make application/client id an object
Having it as a raw byte[] caused issues in keystore because keymaster
handles a null blob differently than a blob with null contents. Make
this explicit in the API.

Change-Id: Ifcf550f438608b8f09fc589d00d06fffa6ee463b
2015-03-21 23:15:20 -07:00
Chad Brubaker
5654b36b46 Add authorization binder methods
Add methods for sending an auth token to keystore and to query the
authorization state of a given operation.

Change-Id: I223df5c56ae2a251ef31cfe60f06c046c12a5cd8
2015-03-17 16:59:52 -07:00
Chad Brubaker
e6a461341c Add new IKeystoreService methods to KeyStore
Add wrappers for all the new IKeystoreService keymaster 0.4 methods to
android.security.KeyStore.

Change-Id: Icb5500cfffb62d1af326edf326e1b9b67e5cece9
2015-02-23 14:12:44 -08:00
Alex Klyubin
0b486da650 Merge "Remove DSA support from Android KeyStore and KeyChain." 2015-01-16 16:44:22 +00:00
Alex Klyubin
590c068e83 Merge "Add KeyPairGenerator.EC backed by Android KeyStore." 2015-01-16 16:44:06 +00:00
Alex Klyubin
cd2329dbfa Remove DSA support from Android KeyStore and KeyChain.
We're switching from OpenSSL to BoringSSL which does not support DSA.

Bug: 17409664
Change-Id: Id9b52666ba9ef234076105c925610b5b312988a5
2015-01-14 16:45:51 -08:00
Alex Klyubin
21a76df55c Add KeyPairGenerator.EC backed by Android KeyStore.
The Android KeyStore backed KeyPairGenerator can generate EC key
pairs, but it cannot be instantiated via the standard JCA approach of
KeyPairGenerator.getInstance("EC", "AndroidKeyStore"). Instead, the
user must invoke KeyPairGenerator.getInstance("RSA",
"AndroidKeyStore") and then tell it to generate an EC key pair.

This CL fixes this weirdness.

The fix requires the introduction of late resolution of key algorithm
and default key size. Prior to this CL, these parameters were resolved
prior to KeyPairGenerator initialization, inside KeyPairGeneratorSpec.
In this CL, these parameters are resolved during KeyPairGenerator
initialization. This is fine because KeyPairGeneratorSpec should be as
dumb as possible and all the logic should reside in KeyPairGenerator
and lower layers.

Bug: 19018089
Change-Id: I114502356e6c9691518cf05b6d9eb0920b4fe0b2
2015-01-14 13:35:32 -08:00
Chad Brubaker
7a2c973db7 Generate IKeystoreService using aidl
This replaces IKeystoreService.java with IKeystoreService.aidl and
changes the methods that passed down a byte[][] to instead pass down a
KeystoreArguments which is currently a thin parcelable wrapper around a byte[][].

Change-Id: I6367bcf57562f41a27aab14f1903b74995cb65c2
2015-01-13 18:29:15 -08:00
Kenny Root
9d2d6b6b4b Track change to Conscrypt
Change-Id: I8814fd0720acf09332927f184fdd9b2cdac4f413
2014-11-26 09:08:40 -08:00
Bernhard Bauer
26408ccd8e Add DevicePolicyManager PrivateKey mgmt
Additional device policy API to install keypairs to the keychain
silently.

Bug: 15065444
Change-Id: Idc25774c9ab1a61080290bebd6f5c4f24e6ee2e0
2014-09-11 19:17:00 +01:00
Zoltan Szatmary-Ban
f0ae135049 Extend IKeyChainService AIDL with CACert retrieval
Bug:16029580
Change-Id: I41a3bd2f3bd95550e59f1d0d0acd0e765d7b62d7
2014-09-08 17:59:42 +01:00