458 Commits

Author SHA1 Message Date
Alex Klyubin
d6c7799b9a Keymaster key validity dates are optional.
This CL makes Android Keystore framework code add
KM_TAG_ACTIVE_DATETIME, KM_TAG_ORIGINATION_EXPIRE_DATETIME, and
KM_TAG_USAGE_EXPIRE_DATETIME tags to the authorizations set only
if the corresponding time instants were specified through the
framework-level API. This is fine because these tags are optional as
it turns out.

Bug: 18088752
Change-Id: I6a5ae4cadb441e61576231815e6bec6e9248bc72
2015-06-23 12:06:27 -07:00
Alex Klyubin
81d299e4b8 Merge "Don't fail if self-signed certificate can't be signed." into mnc-dev 2015-06-23 18:58:25 +00:00
Alex Klyubin
856aebe571 Don't fail if self-signed certificate can't be signed.
This makes Android Keystore's KeyPairGenerator fall back to generating
a self-signed certificate with an invalid/fake signature when the
attempt to generate a self-signed certificate with a valid signature
fails.

There is a growing number of reasons/authorizations due to which the
generated private key cannot be used to sign the self-signed
certificate. It's safer for KeyPairGenerator to succeed than to fail.

Bug: 22033161
Change-Id: I1ecbd421346166bfd536b5cfbaea169b11f0b1c8
2015-06-23 10:54:44 -07:00
Alex Klyubin
7ecb298c6d Fix typo in Android Keystore KeyFactory exception message.
The typo was pointed out by kroot@ in code review of
4ecd092226fbd748b4a26f3bbb5c4d25a3488fff after it was submitted.

Bug: 18088752
Change-Id: I50d2fa93e1a2d352fe432e34ce98add82a71c483
2015-06-23 09:09:11 -07:00
Alex Klyubin
e26f9d95c6 Merge "Adjust minimum size of PKCS#1 RSA padding overhead." into mnc-dev 2015-06-22 22:27:51 +00:00
Alex Klyubin
3867709fb3 Document that RSA OAEP requires digest authorization.
RSA encryption/decryption keys used with RSA OAEP padding scheme now
require the key to be authorized for the digest used by OAEP.

Bug: 21998286
Change-Id: I1f5eb1b30a1b574c45ffcabed6096de8671882d3
2015-06-22 13:42:46 -07:00
Alex Klyubin
6e90ade5dd Adjust minimum size of PKCS#1 RSA padding overhead.
This raises the space overhead estimate by one byte, due to me having
originally forgotten that when signing using RSA PKCS#1 padding
scheme, the plaintext of the RSA operation needs a leading 0 byte.

Bug: 21955742
Change-Id: If78efcd375afd8902a14a2217ddedfea87d4d337
2015-06-22 13:21:59 -07:00
Alex Klyubin
84a378f256 Merge "Fix a bug in Android Keystore updateAAD." into mnc-dev 2015-06-19 22:53:21 +00:00
Alex Klyubin
ae1e0e9265 Fix a bug in Android Keystore updateAAD.
The variant of CipherSpi.engineUpdateAAD which takes ByteBuffers
delegated to a byte[]-taking variant of superclass instead of its own
class.

Bug: 18088752
Change-Id: I3b426bbdca54bbf7f6f3939589da07b24db14d0d
2015-06-19 15:50:45 -07:00
Alex Klyubin
4ecd092226 Support more KeySpecs in Android Keystore KeyFactory.
This adds support obtaining RSAPublicKeySpec, ECPublicKeySpec,
X509EncodedKeySpec from Android Keystore public keys.

Using a KeyFactory to obtain such specs is the endorsed way for
obtaining algorithm-specific parameters or X.509 encoding of PublicKey
instances.

Bug: 18088752
Change-Id: I2c653238e3c89d9cfc97bea6c8a0ef0c6d039385
2015-06-18 14:18:18 -07:00
Narayan Kamath
240e48d2e1 Use consistent cases for aliases in AndroidKeystoreBCWorkaround.
Should be "with" and not "With". Has the side effect of fixing
a test that assumes that these names are case-sensitive. While the
test must be fixed separately, this is still good for consistency.

bug: 21870226

Change-Id: I884b4abdbb18be064210555aec8e0cd16b0d0bcb
2015-06-18 09:52:11 +00:00
Alex Klyubin
2e3aaa7dc1 Remove unnecessary PKCS#1 authorization on legacy keys.
There is no need to authorize PKCS#1 signature padding scheme when
NONE padding scheme is authorized. NONE authorizes the use of any
padding scheme.

Bug: 18088752
Change-Id: I73ccb373d577c988acde372d972092278923c4e4
2015-06-17 13:58:00 -07:00
Alex Klyubin
97f4d3b407 Merge "Prefer GCM to CBC or CTR in documentation." into mnc-dev 2015-06-17 18:32:24 +00:00
Alex Klyubin
211cb7cb98 Merge "Improve documentation for keys requiring user auth." into mnc-dev 2015-06-17 18:28:21 +00:00
Alex Klyubin
a5e21f0ee2 Prefer GCM to CBC or CTR in documentation.
Bug: 21786749
Change-Id: If3824d1321ef1d8730d4384717b0c25d43518fe4
2015-06-17 11:24:45 -07:00
Alex Klyubin
83cc7a347f Improve documentation for keys requiring user auth.
Bug: 18088752
Change-Id: I24eeb33790a74d8d81d10fcdb1eb058d47144c44
2015-06-17 11:08:29 -07:00
Alex Klyubin
4250c8d643 Merge "Expose AES GCM backed by Android Keystore." into mnc-dev 2015-06-17 17:58:35 +00:00
Alex Klyubin
bf5c91c8cd Drop support for P-192 EC keys.
The minimum EC keys size is now 224 bit. This is because keymaster 1.0
does not support EC keys smaller than 224 bit.

Bug: 18088752
Change-Id: I8010ff2d6ccaeea7dcf86f697aee1d9ebd683cb2
2015-06-17 10:51:19 -07:00
Alex Klyubin
00af27b7d9 Expose AES GCM backed by Android Keystore.
Bug: 18088752
Bug: 21786749
Change-Id: Ica90491037d2920f7635195894ba18882fc4406d
2015-06-17 09:24:06 -07:00
Alex Klyubin
ffdfb57931 Harden KeyInfo.
This ensures that KeyInfo instances are truly immutable.

Bug: 18088752
Change-Id: Ic157d3b928b129a02c3cab9dd20ba9936a005813
2015-06-16 13:13:13 -07:00
Alex Klyubin
cb3bb3f03a Harden and clean up KeyProtection.
This ensures that instances of this class are immutable and cleans up
some flawed logic discovered when writing up CTS tests.

Bug: 18088752
Change-Id: If9cc33192ada5a8982a2b200ab24cb18331cf958
2015-06-16 12:31:34 -07:00
Alex Klyubin
1b937eebdd Harden and clean up KeyGenParameterSpec.
This ensures that instances of this class are immutable and cleans up
some flawed logic discovered when writing up CTS tests.

Bug: 18088752
Change-Id: I7a27dbfc3445599bccabbd26e39535ce988a2ab2
2015-06-16 12:11:10 -07:00
Alex Klyubin
a8232452b6 Merge "Fix Android Keystore key gen for keys requiring user auth." into mnc-dev 2015-06-15 22:42:04 +00:00
Alex Klyubin
f78dd677e9 Fix Android Keystore key gen for keys requiring user auth.
When Android Keystore generates an asymmetric key pair, it needs to
create a self-signed certificate for that pair, in order to expose
the key pair in the JCA KeyStore abstraction through which keys are
later retrieved. The self-signed certificate is normally signed with
the private key.

This CL avoids using the private key to sign the certificate if the
private key can be used only once the user has been authenticated.
For such keys, a fake (non-verifying) signature is used on the
certificate, same as for cases where the key is not authorized for
signing.

Bug: 21852844
Change-Id: Id78bc1f51d12950db4e37c1e0da6c60057d4e693
2015-06-15 15:22:19 -07:00
Alex Klyubin
1923da348b Merge "Remove EcIesParameterSpec until it's needed." into mnc-dev 2015-06-15 17:45:48 +00:00
Alex Klyubin
3264599e12 Remove EcIesParameterSpec until it's needed.
This class was added in Android M to enable us to expose ECIES. ECIES
is not going to happen in Android M. I'm thus removing this unused
class until such time when it's needed.

Bug: 18088752
Change-Id: I16ab1bbd0b4334419c9a8f29d64661c150aa8d32
2015-06-15 09:55:36 -07:00
Alex Klyubin
acb7efd0d6 Document when self-signed certs have invalid signature.
This updates the Javadocs of Android Keystore to explain what key
authorizations are needed for the self-signed cert create at key
generation time to have a valid signature.

Bug: 18088752
Bug: 21777596
Change-Id: Id02425133f094a0c5a02e96f4c63aab7175cba5b
2015-06-12 14:29:07 -07:00
Alex Klyubin
6cb8e30bb7 Merge "Fix Android Keystore KeyPairGenerator for RSA PSS keys." into mnc-dev 2015-06-12 19:54:20 +00:00
Alex Klyubin
768695a899 Merge "Update Javadocs to reflect meaning of digest and padding NONE." into mnc-dev 2015-06-12 19:54:19 +00:00
Alex Klyubin
7c475cc7c3 Fix Android Keystore KeyPairGenerator for RSA PSS keys.
This fixes a bug where key pair generation fails for RSA signing keys
which are not authorized for PKCS#1 signature padding, such as keys
authorized only for the RSA PSS signature padding scheme.

The issue was that the KeyPairGenerator was failing when attempting to
sign the self-signed certificate (needed by Android Keystore) using
PKCS#1 padding for which such keys are not authorized. The solution is
to not attempt to sign these certificates and instead use a fake
signature.

Bug: 21809600
Change-Id: I4f04fcf78174937046d2534e0485c6940eae673f
2015-06-12 12:22:58 -07:00
Alex Klyubin
a72b55195c Obtain entropy later in crypto operations, when possible.
This makes Android Keystore crypto operations defer pulling entropy
from provided SecureRandom until KeyStore.finish, where appropriate.
Such as when performing asymmetric encryption or generating
signatures.

Bug: 18088752
Change-Id: I4a897754e9a846214cf0995c5514f98cf0edd76b
2015-06-12 10:35:46 -07:00
Alex Klyubin
dcf3d35f23 Update Javadocs to reflect meaning of digest and padding NONE.
This also adds information about what digests and paddings may need to
be specified for keys used in TLS/SSL for client or server
authentication.

Bug: 21777596
Change-Id: Icd495458c38c4f912b21a64ca7aab2c88d76461c
2015-06-11 17:55:49 -07:00
Alex Klyubin
f7bc24c58b Merge "Update Javadocs: all new features supported for asymmetric crypto." into mnc-dev 2015-06-12 00:26:21 +00:00
Alex Klyubin
bce7efcabf Update Javadocs: all new features supported for asymmetric crypto.
Bug: 20912868
Change-Id: I633d3caa3f40dd0b038b2f7e75825614bed2c0f5
2015-06-11 14:48:06 -07:00
Alex Klyubin
a99b8b5e3f Do not require USE_FINGERPRINT for getAuthenticatorId.
This removes the requirement to hold the USE_FINGERPRINT permission
to successfully invoke FingerprintManager.getAuthenticatorId().

This is needed because Android Keystore classes which run inside app
processes occasionally need to access this authenticator ID. The
access however is not necessarily triggered by the developer using
APIs to do with fingerprints. Thus, if an app does not hold the
USE_FINGERPRINT permission and uses Android Keystore API, it may
unexpectedly encounter a SecurityException.

It's OK to provide access to authenticator ID without requiring
USE_FINGERPRINT permission because there are other ways to access
this ID without holding that permission, such as though hidden
KeyStore API.

Once Android Keystore code is restructured to no longer require
access to authenticator ID, this CL can be reverted.

Bug: 21030147
Change-Id: I9af29830abce34c46e29e5c1682cc3ab88c95c00
2015-06-11 13:41:04 -07:00
Alex Klyubin
4a0ff7ca98 Android Keystore keys are no longer backed by Conscrypt.
This switches Android Keystore asymmetric keys from being backed by
Conscrypt (via keystore-engine which is an OpenSSL/BoringSSL ENGINE
which talks to keystore via the old KeyStore API) to being backed by
the AndroidKeyStore Provider which talks to keystore via the new
KeyStore API. In effect, this switches asymmetric crypto offered by
Android Keystore from old Keystore API to new KeyStore API, enabling
all the new features such as enforcement of authorizations on key use.

Some algorithms offered by Android Keystore, such as RSA with OAEP
or PSS padding schemes, are not supported by other providers. This
complicates matters because Android Keystore only supports public key
operations if the corresponding private key is in the keystore. Thus,
Android Keystore can only offer these operations for its own public
keys only. This requires AndroidKeyStore to use its own subclasses of
PublicKey everywhere. The ugliest place is where it needs to return
its own subclass of X509Certificate only to be able to return its
own subclass of PublicKey from Certificate.getPublicKey().

Bug: 18088752
Bug: 19284418
Bug: 20912868
Change-Id: Id234f9ab9ff72d353ca1ff66768bd3d46da50d64
2015-06-10 14:50:55 -07:00
Alex Klyubin
6a0b8f4d56 Merge "Switch Android Keystore key gen and import to new KeyStore API." into mnc-dev 2015-06-09 20:17:44 +00:00
Alex Klyubin
3ceb1a04b4 Switch Android Keystore key gen and import to new KeyStore API.
This makes Android Keystore's asymmetric key generation and import
use the new KeyStore API (similar to keymaster 1.0 API).

Because the resulting private keys will be used through
Conscrypt/keystore-engine which uses the old Keystore API, this CL
implements a temporary workaround where all generated and imported
keys are authorized for padding NONE and digest NONE, in addition to
padding schemes and digests requested by the user of the Android
Keystore API. This workaround is needed because keystore-engine uses
digest NONE and padding NONE for all its crypto operations.

Bug: 18088752
Bug: 20912868
Change-Id: Idc709039d091294265bd000160b5507f13825849
2015-06-09 13:08:02 -07:00
Alex Klyubin
508e665cea Support for Android Keystore Cipher.wrap and unwrap.
Cipher.wrap and .unwrap are supported by Android Keystore in released
versions of Android. The new Android Keystore provider should thus
continue supporting these for backward compatibility.

Bug: 18088752
Change-Id: I95319b13d5c4e9681f6539016e6449d73f81131d
2015-06-09 10:56:34 -07:00
Alex Klyubin
469cbf5156 Deprecate KeyChain.isBoundKeyAlgorithm.
This is bad API. There was never a guarantee that when this method
returns true for a key algorithm (e.g., RSA or EC), then all keys of
that type will be imported into secure hardware. For example, the
secure hardware may reject a key if it's of unsupported size or uses
an unsupported public exponent or EC curve. In that case, the key
will be imported into keystore/KeyChain without being backed by secure
hardware.

Bug: 18088752
Change-Id: I8daa574a2e703a347d09d93401cd1ea2d0162ed9
2015-06-08 13:22:53 -07:00
Alex Klyubin
266894644a Merge "Remove deprecated android.security.KeyStore methods." into mnc-dev 2015-06-08 18:11:21 +00:00
Alex Klyubin
2c500236f4 Merge "RSA encrypt with private key in Android Keystore." into mnc-dev 2015-06-08 18:10:09 +00:00
Alex Klyubin
4350babc02 Remove deprecated android.security.KeyStore methods.
* delKey -> delete
* getPubkey -> exportKey
* saw -> list.

Bug: 18088752
Change-Id: Ifb794f91a42646d67da1340ee16765cbaf255a49
2015-06-08 10:14:58 -07:00
Alex Klyubin
5552c89fa9 RSA encrypt with private key in Android Keystore.
This adds support for RSA encryption using private key and no padding.
This mode of operation is needed because JCA does not offer an RSA
Signature primitive that does not apply padding.

Bug: 18088752
Bug: 20912868
Change-Id: I0b481b4c19916f601aa270fada5eabfb12987e8d
2015-06-04 17:11:28 -07:00
Alex Klyubin
2c37807801 Merge "Export KeyFactory backed by Android Keystore." into mnc-dev 2015-06-04 22:16:19 +00:00
Alex Klyubin
cb94dd1cee Merge "Expose RSA and ECDSA Signature from Android Keystore Provider." into mnc-dev 2015-06-04 21:19:37 +00:00
Alex Klyubin
df6c67028a Merge "Streamline Android Keystore delete entry operation." into mnc-dev 2015-06-04 21:06:29 +00:00
Alex Klyubin
b070e486c8 Merge "Reliably delete keys if key generation fails." into mnc-dev 2015-06-04 21:05:41 +00:00
Alex Klyubin
ccbe88a505 Expose RSA and ECDSA Signature from Android Keystore Provider.
The RSA Signature supports PKCS#1 and PSS padding.

Bug: 18088752
Bug: 20912868
Change-Id: I03cdc86d1935af36f7c87a0b23d67f813829cfb0
2015-06-04 13:42:43 -07:00
Alex Klyubin
97a27a73e6 Export KeyFactory backed by Android Keystore.
The KeyFactory can be used to obtain information (KeyInfo) about
Android Keystore private keys.

Bug: 18088752
Change-Id: Ied1a69928f391537de6765cef7dc7d7241cf62bb
2015-06-04 13:19:50 -07:00