summaryrefslogtreecommitdiff
path: root/keystore/java/android/security/KeyStoreCipherSpi.java
AgeCommit message (Collapse)Author
2015-05-13Move Android Keystore impl to android.security.keystore.Alex Klyubin
This moves the non-public API classes backing Android Keystore from android.security to android.security.keystore, a package specially created for Android Keystore. Bug: 18088752 Change-Id: Ibf04d6a26c54d310b0501fc5e34f37b1176324ad
2015-05-13New AndroidKeyStore API in android.security.keystore.Alex Klyubin
This CL addresses the comments from API Council about Android KeyStore KeyPairGeneratorSpec, KeyGeneratorSpec and KeyStoreParameter: 1. These abstractions should not take or hold references to Context. 2. The Builders of these abstractions should take all mandatory parameters in their constructors rather than expose them as setters -- only optional paratemers should be exposed via setters. These comments cannot be addressed without deprecation in the already launched KeyPairGeneratorSpec and KeyStoreParameter. Instead of deprecating just the getContext methods and Builder constructors, this CL goes for the nuclear option of deprecating KeyPairGeneratorSpec and KeyStoreParameter as a whole and exposing all of the AndroidKeyStore API in the new package android.security.keystore. This enables this CL to correct all of the accrued design issues with KeyPairGeneratorSpec (e.g., naming of certificate-related methods) and KeyStoreParameter. This also makes the transition to API Level M more clear for existing users of the AndroidKeyStore API. These users will only have to deal with the new always-mandatory parameters (e.g., purposes) and sometimes-mandatory (e.g., digests, block modes, paddings) if they switch to the new API. Prior to this CL they would've had to deal with this if they invoked any of the new methods of KeyPairGeneratorSpec or KeyStoreParameter introduced in API Level M. This CL rips out all the new API introduced into KeyPairGeneratorSpec and KeyStoreParameter classes for Android M, thus reverting these classes to the API launched in L MR1. This is because the new API is now in android.security.keystore.KeyGenParameterSpec and KeyProtection respectively. Bug: 21039983 Change-Id: I59672b3c6ef7bc25c40aa85f1c47d9d8a05d627c
2015-05-12Flatten KeyStoreKeyProperties constants.Alex Klyubin
This moves constants/flags declared in inner classes of KeyStoreKeyProperties into KeyStoreKeyProperties, as requested by API Council. Bug: 21039983 Change-Id: I84a3c983e13644a027bed9f605ab8044220a352c
2015-05-07Merge "Use ProviderException in AndroidKeyStore." into mnc-devAlex Klyubin
2015-05-07Merge "Always mix in additional entropy into keymaster." into mnc-devAlex Klyubin
2015-05-06Define String constants for AndroidKeyStore crypto.Alex Klyubin
This defines the String enum values based on JCA standard names for key algorithm, block mode, padding schemes, and digests. This should make it safer to interact with AndroidKeyStore code that uses JCA strings. This was requested by API Council. Bug: 18088752 Change-Id: I241d9225a13b85479d0a84e49d0a98cbc77e5817
2015-05-06Use ProviderException in AndroidKeyStore.Alex Klyubin
This switches to ProviderException in most places in AndroidKeyStore primitives where checked exceptions cannot be thrown. This is to follow JCA design. KeyStoreKeyGeneratorSpi is not touched by this CL because there's another CL already doing that. Bug: 18088752 Change-Id: If7e93042f973334b9bba004f5a330f831c1e77c1
2015-05-06Always mix in additional entropy into keymaster.Alex Klyubin
This makes AndroidKeyStore Cipher and KeyGenerator implementations mix in additional entropy into keymaster's RNG regardless of whether they were provided with a SecureRandom instance. In practice, they are always provided with a SecureRandom instance. However, to be safe, when no SecureRandom instance is provided the code now uses a platform-default SecureRandom implementation. Bug: 18088752 Change-Id: I85bca30d7bdc82c2a342094dcbe6044e48a63dca
2015-05-06Keystore uses 0 for invalid operation handles.Alex Klyubin
This propagates the concept that 0 is an invalid crypto operation handle to the outside of AndroidKeyStore abstraction. Bug: 20864436 Change-Id: I1e5abb66c5d41d8fc32aac44372495a708c2b6e2
2015-04-30Cleanup logic for per-op auth keys.Alex Klyubin
This streamlines the exception throwing logic for per-op auth keys of AndroidKeyStore. Change-Id: I7e27c17fd89d5a7f71f5d7578f584189c5236fb8
2015-04-29Surface KeyPermanentlyInvalidatedException for per-op auth keys.Alex Klyubin
Bug: 20642549 Change-Id: Ibda270921f13a1fd695264583b0e4bd255f63aed
2015-04-29Enable per-use user authenticated keys to be used.Alex Klyubin
This makes symmetric Cipher and Mac implementations backed by AndroidKeyStore succeed in their initialization when the key is configured to require user authentication for every use. Users of such keys should obtain an instance of Cipher or Mac, initialize it with the key, and then authorize the operation by passing this Cipher or Mac instance to FingerprintManager.authenticate. Bug: 18088752 Change-Id: Ia15a1e5f8274c3623f665dae1f400ff539639ab1
2015-04-29Add KeyPermanentlyInvalidatedException.Alex Klyubin
This enables users of AndroidKeyStore crypto to differentiate between the key being unusable until the user is authenticated (UserNotAuthenticatedException) and the key being permanently unusable (KeyPermanentlyInvalidatedException). The latter is the case when the secure lock screen has been disabled or reset, and, for keys that require user authentication for every use, when a new fingerprint is enrolled or all fingerprints are unenrolled. NOTE: The KeyPermanentlyInvalidatedException subsumes/replaces the NewFingerprintEnrolledException which has thus been removed. There is no way to find out whether a key was permenently invalidated specifically because a new fingerprint was added. Bug: 20642549 Bug: 20526234 Change-Id: I0206cd99eef5c605c9c4d6afc5eea02eb3b1fe6b
2015-04-24No runtime exceptions during normal use of AndroidKeyStore crypto.Alex Klyubin
This changes the implementation of AndroidKeyStore-backed Cipher and Mac to avoid throwing runtime exceptions during normal use. Runtime exceptions will now be thrown only due to truly exceptional and unrecoverable errors (e.g., keystore unreachable, or crypto primitive not initialized). This also changes the implementation of Cipher to cache any errors encountered in Cipher.update until Cipher.doFinal which then throws them as checked exceptions. Bug: 20525947 Change-Id: I3c4ad57fe70abfbb817a79402f722a0208660727
2015-04-24Reset AndroidKeyStore Mac and Cipher state when init fails.Alex Klyubin
For consistency, this also switches AndroidKeyStore's Mac init/reset implementation to the same approach as used in Cipher. Bug: 18088752 Change-Id: Id34caf7cfe04f2058e22d8632890f762927bb31c
2015-04-15Remove IV auto-generation workaround.Alex Klyubin
This workaround prevents use of keys with randomized encryption (IND-CPA). Since randomized encryption is on by default, it's better to keep it working and break non-randomized encryption (until Keymaster is fixed). Bug: 18088752 Change-Id: I4b11ce72cff705be41d3e66f28b507d6ddc1da79
2015-04-13Use JCA names for block modes, paddings, and digests.Alex Klyubin
This replaces int-based enums from KeyStoreKeyConstraints with String values commonly used in JCA API. As part of under the hood refactoring: * KeyStoreKeyCharacteristics and KeyStoreKeyConstraints have been merged into KeyStoreKeyProperties. * KeymasterUtils methods operating on KeymasterArguments and KeymasterCharacteristics have been moved to their respective classes. Bug: 18088752 Change-Id: I9c8b984cb3c28184adb617e34d87f2837bd1d3a1
2015-04-08Refuse to reuse IV in encryption mode in AndroidKeyStore.Alex Klyubin
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-02Rename KeymasterException to KeyStoreException.Alex Klyubin
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-01Improve the AndroidKeyStore-backed HMAC state machine.Alex Klyubin
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-01Merge "Hook in user authenticators and their exceptions."Alex Klyubin
2015-03-31A way to obtain KeyStore operation handle from crypto primitives.Alex Klyubin
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-31Hook in user authenticators and their exceptions.Alex Klyubin
Bug: 18088752 Change-Id: I2835dbe51d09587a3081597c6aaf536aa1427e24
2015-03-31Add license banner to recently added AndroidKeyStore files.Alex Klyubin
Bug: 18088752 Change-Id: I027f9530a02cca081aae8eb94833d2fdcb678e9a
2015-03-31Add unauthenticated AES ciphers backed by AndroidKeyStore.Alex Klyubin
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