450 Commits

Author SHA1 Message Date
Alex Klyubin
033dc46bb9 Merge "Switch from FingerprintService to FingerprintManager." into mnc-dev 2015-04-30 19:45:55 +00:00
Alex Klyubin
3cd8ec3c68 Merge "Cleanup logic for per-op auth keys." into mnc-dev 2015-04-30 19:44:15 +00:00
Alex Klyubin
2d7a85cd2b Switch from FingerprintService to FingerprintManager.
FingerprintService is a lower layer of abstraction which should
ideally be accessed only via FingerprintManager from
AndroidKeyStore.

The main issue with the switch is that it requires a reference to a
Context. This is now obtained using ActivityThread's hidden API.

Change-Id: If921e169838ee2cc5c7690b8c8d8ea95c33248aa
2015-04-30 12:43:05 -07:00
Svetoslav
e476267502 Merge "Fix the build" into mnc-dev 2015-04-30 18:31:37 +00:00
Svetoslav
2dac95d033 Fix the build
Change-Id: I24e697e989b5f88c3f5e61343fbff60a09aa4c12
2015-04-30 11:30:33 -07:00
Alex Klyubin
7ea5090264 Track Keymaster changes.
* MAC length is now specified as a parameters to the begin operation
  instead of as a parameter at key generation/import time.
* KM_TAG_MAC_LENGTH is now in bits instead of in bytes.

Change-Id: I752fe232d11d3ac39a575a48948215d84ded8fb9
2015-04-30 11:11:50 -07:00
Alex Klyubin
8c82b4508f Cleanup logic for per-op auth keys.
This streamlines the exception throwing logic for per-op auth keys of
AndroidKeyStore.

Change-Id: I7e27c17fd89d5a7f71f5d7578f584189c5236fb8
2015-04-30 10:13:39 -07:00
Alex Klyubin
403ac2d64f Merge "AndroidKeyStore keys should not be handled by Bouncy Castle." into mnc-dev 2015-04-30 16:12:33 +00:00
Alex Klyubin
459ef1e7ce Surface KeyPermanentlyInvalidatedException for per-op auth keys.
Bug: 20642549
Change-Id: Ibda270921f13a1fd695264583b0e4bd255f63aed
2015-04-29 20:28:41 -07:00
Alex Klyubin
058de02073 Enable per-use user authenticated keys to be used.
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-29 19:23:46 -07:00
Alex Klyubin
4812563f68 AndroidKeyStore keys should not be handled by Bouncy Castle.
Bouncy Castle JCA provider incorrectly declares that its Cipher, Mac,
Signature, and KeyAgreement implementations accept arbitrary keys (
including AndroidKeyStore keys). As a result, when a Cipher, Mac,
Signature, or KeyAgreement instance is requested from JCA without
explicitly specifying the provider (which follows best practices)
and then initialied with an AndroidKeyStore key, JCA chooses the
BouncyCastle's implementation, which in turn blows up because it
can't handle such keys.

The workaround is to install Cipher, Mac, Signature, and
KeyAgreement implementations backed by AndroidKeyStore as a
higher-priority JCA provider than the Bouncy Castle one. This is
achieved by splitting out the above implementations from
AndroidKeyStoreProvider into AndroidKeyStoreBCWorkaroundProvider
and installing the AndroidKeyStoreProvider at the usual priority
(below Bouncy Castle) and the AndroidKeyStoreBCWorkaroundProvider
at above Bouncy Castle priority.

Bug: 20691708
Change-Id: I336464f4a49bc30c6845ddc4e84b07f4105424dd
2015-04-29 13:28:56 -07:00
Alex Klyubin
708fc94045 Add KeyPermanentlyInvalidatedException.
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-29 12:44:10 -07:00
Chad Brubaker
721474bb9c Merge "Add OP_AUTH_NEEDED KeyStore result code" into mnc-dev 2015-04-29 17:17:33 +00:00
Alex Klyubin
1eda77ae21 Align AndroidKeyStore API with user auth API.
This simplifies the AndroidKeyStore API around user authentication: no
more explicit control over which user authenticators are bound to
which keys.

User-authenticated keys with timeout are unlocked by whatever unlocks
the secure lock screen (currently, password/PIN/pattern or
fingerprint). User-authenticated keys that need authentication for
every use are unlocked by fingerprint only.

Bug: 20526234
Bug: 20642549
Change-Id: I1e5e6c988f32657d820797ad5696797477a9ebe9
2015-04-28 17:39:30 -07:00
Chad Brubaker
560d653e55 Add OP_AUTH_NEEDED KeyStore result code
OP_AUTH_NEEDED will be returned from begin when an operation needs
a per operation authentication before calling update. Note that the
begin call succeeds when this error is returned, the token and handle
are valid.

(cherry picked from commit dabe520a3e6b0d0c40adfd748483fa336c43c366)

Change-Id: I0ba4e997360843b5eb6c1db9c5fcd1c4d5a2c717
2015-04-28 15:49:29 -07:00
Kenny Root
22335a9730 am 6c1af7ea: am 8652bce1: am c71f2648: Merge "frameworks/base: switch to using NativeConstants."
* commit '6c1af7ea497b1a2f04bdf45a19d2147f5b9665b9':
  frameworks/base: switch to using NativeConstants.
2015-04-24 22:13:26 +00:00
Kenny Root
c71f264847 Merge "frameworks/base: switch to using NativeConstants." 2015-04-24 21:26:14 +00:00
Alex Klyubin
40485f5aac resolved conflicts for merge of f9c14b7d to master
Change-Id: Ifa29891b8ad7979cbc28c54180b9606bb1319ff0
2015-04-24 14:21:41 -07:00
Alex Klyubin
9716b081a6 am edf5454a: am 3167fb4b: am 71223ebe: Merge "Reset AndroidKeyStore Mac and Cipher state when init fails."
* commit 'edf5454a14cc53de92eaf1ef15fcfb21d8caccca':
  Reset AndroidKeyStore Mac and Cipher state when init fails.
2015-04-24 18:35:37 +00:00
Alex Klyubin
ad9ba10ecd No runtime exceptions during normal use of AndroidKeyStore crypto.
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-24 10:54:45 -07:00
Alex Klyubin
6c4a842129 Reset AndroidKeyStore Mac and Cipher state when init fails.
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-24 10:49:11 -07:00
Adam Langley
6bf52c4271 frameworks/base: switch to using NativeConstants.
NativeCrypto is a conscrypt class that contained several OpenSSL
constants. NativeConstants is the new class that contains the same
thing, but the latter is automatically generated and thus won't drift
from the C headers.

Bug: 20521989

Change-Id: I45c7b9a6844a06e3ffd09be692ebf733e1ebbbcc
2015-04-24 10:00:45 -07:00
Alex Klyubin
ed6b2eb9f4 Merge "Set Secure User ID from app level." 2015-04-16 22:44:23 +00:00
Alex Klyubin
ed7a218592 Unhide KeyStoreKeyProperties.Origin.UNKNOWN.
Bug: 18088752
Change-Id: Idaed45d7e84f5f3eb4f623552b60206c504e967a
2015-04-16 15:26:50 -07:00
Alex Klyubin
10a9f1786b Set Secure User ID from app level.
When AndroidKeyStore keys require used authentication, they need to be
bound to a Keymaster's Secure User ID. This ID will be set by keystore
soon. Until then, set it from the framework level (i.e., from apps
which use AndroidKeyStore).

NOTE: Accessing gatekeeper to obtain the Secure User ID will be
blocked by SELinux policy. To test this code, disable SELinux
enforcing mode.

Bug: 18088752
Change-Id: I7a3315eb52f0fc978d14d5d0e9613f2f36c6c01e
2015-04-16 15:18:13 -07:00
Alex Klyubin
aa0d7f60b6 am b1aa7d0b: am 51884f0e: am 499126c4: Merge "Add Keymaster KM_ORIGIN_UNKNOWN constant."
* commit 'b1aa7d0bc821614d943075c0d786cc3f5eeb8c73':
  Add Keymaster KM_ORIGIN_UNKNOWN constant.
2015-04-16 20:31:46 +00:00
Alex Klyubin
499126c433 Merge "Add Keymaster KM_ORIGIN_UNKNOWN constant." 2015-04-16 19:50:12 +00:00
Alex Klyubin
3abd2b757a am 22b5d9b9: am 28a9089f: am 216d18b9: Merge "Remove IV auto-generation workaround."
* commit '22b5d9b969176a196b0b29ce9441ac3d1d35d208':
  Remove IV auto-generation workaround.
2015-04-16 17:20:23 +00:00
Alex Klyubin
a0d2dddc55 Remove IV auto-generation workaround.
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-15 17:20:23 -07:00
Shawn Willden
250dd26291 am 763100e6: am 1cb119d3: am 71ba4e46: Merge "Unbreak obtaining symmetric keys from AndroidKeyStore."
* commit '763100e6442494a85cfcb7949c8021836071b1f6':
  Unbreak obtaining symmetric keys from AndroidKeyStore.
2015-04-15 18:21:41 +00:00
Alex Klyubin
5eacd777fe Unbreak obtaining symmetric keys from AndroidKeyStore.
This tracks 59f977c6988e21b3b8aa6c83428bd6ee1a98816d due to which
AndroidKeyStore is unable to provide symmetric keys because it
assumes that the digest field is not repeating.

Bug: 18088752
Change-Id: Ie8ed01449280b7c759e81aeaf2066953b0abaf2a
2015-04-14 19:02:46 -07:00
Alex Klyubin
338e74648d resolved conflicts for merge of 1d5a2592 to master
Change-Id: Ia1ea7c9c8c23eeffcd596b96506e961989ccb7a6
2015-04-14 14:23:07 -07:00
Alex Klyubin
8e5fbc70e1 am fa2bd4fe: am 888f5cb7: am ecfda064: Merge "Make specifying self-signed cert parameters optional."
* commit 'fa2bd4fe5c10b8132a155f0f8d0207435ca2c8dc':
  Make specifying self-signed cert parameters optional.
2015-04-14 20:43:54 +00:00
Alex Klyubin
d693690aee Merge "No need to specify EC curve name in EcIesParameterSpec." 2015-04-14 20:22:52 +00:00
Alex Klyubin
67d21aef98 Make specifying self-signed cert parameters optional.
This removes the need to specify the three parameters of the
self-signed certificate (serial number, subject, validity range) when
generating key pairs in AndroidKeyStore. This is achieved by
providing sensible defaults for these parameters:
* serial number: 1
* subject: CN=fake
* validity range: Jan 1 1970 to Jan 1 2048.

Bug: 18088752
Change-Id: I5df918b1ef8b26ed3ddd43828c4c78c9fa58cd43
2015-04-14 12:56:17 -07:00
Alex Klyubin
45d27836bd Add Keymaster KM_ORIGIN_UNKNOWN constant.
This tracks d359b044830b292f492f8a8df5471f869e358399 from
hardware/libhardware.

Bug: 18088752
Change-Id: I9a7bd8bdee51c18ae0427eff4efe036213d2b175
2015-04-14 10:52:34 -07:00
Alex Klyubin
9b3e005a4e Unhide the new AndroidKeyStore API.
Bug: 18088752
Change-Id: I93f87cbb1cd04a4a2e34f3d544d678c92cf052ee
2015-04-13 11:34:04 -07:00
Alex Klyubin
fbf1472d61 resolved conflicts for merge of a978a3d6 to master
Change-Id: Ifd7ca9e1dfa0d50a87f2bafef377fcaeb5d9f6d5
2015-04-13 10:54:53 -07:00
Alex Klyubin
33454dd569 No need to specify EC curve name in EcIesParameterSpec.
EC curve parameters will be obtained from the provided EC key.

Bug: 18088752
Change-Id: Ic99353a6566c8d4ce2b6b73d0309edaa40f84fa6
2015-04-13 10:20:24 -07:00
Alex Klyubin
d1af38a478 Merge "Use JCA names for block modes, paddings, and digests." 2015-04-13 17:01:30 +00:00
Alex Klyubin
5927c9f1b1 Use JCA names for block modes, paddings, and digests.
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-13 09:59:04 -07:00
Alex Klyubin
0e67d0a1b0 am 651dbfde: am ad48c4c9: am c1c6528d: Merge "Add EcIesParameterSpec to enable ECIES crypto."
* commit '651dbfde73171ad6451dc8f9288fa4df50f99e4c':
  Add EcIesParameterSpec to enable ECIES crypto.
2015-04-11 02:56:44 +00:00
Alex Klyubin
c1c6528d2b Merge "Add EcIesParameterSpec to enable ECIES crypto." 2015-04-11 02:17:01 +00:00
Chad Brubaker
03c13e430d am 93976df8: am 3a9779b6: am 386c4e9e: Merge "Fix testSaw_ungrantedUid_Bluetooth"
* commit '93976df800641c9d56b73af6cb4bab9cc9a5f59e':
  Fix testSaw_ungrantedUid_Bluetooth
2015-04-10 22:26:25 +00:00
Alex Klyubin
0ee9376ef4 Add EcIesParameterSpec to enable ECIES crypto.
Bug: 18088752
Change-Id: I597b019106c500188e0fbbc9608722668c08b421
2015-04-10 14:57:28 -07:00
Chad Brubaker
386c4e9ea9 Merge "Fix testSaw_ungrantedUid_Bluetooth" 2015-04-10 21:42:23 +00:00
Chad Brubaker
6a5af8cf14 Fix testSaw_ungrantedUid_Bluetooth
Keystore.saw returns [] on no result, not null, so the test was
incorrectly failing.

Change-Id: I22dcf85c5d6c5c0368848bc784c3215c092d9ea8
2015-04-10 14:15:17 -07:00
Alex Klyubin
75f6f31db4 am d31d4771: am c5f9683c: am a270264c: Merge "Track more changes to keymaster_defs.h"
* commit 'd31d4771d90277eb246814b6a6f981e0842eb614':
  Track more changes to keymaster_defs.h
2015-04-10 18:29:53 +00:00
Alex Klyubin
55f7c2770f Track more changes to keymaster_defs.h
KeyStoreTest needed to be adjusted because OCB is no longer supported.

Bug: 18088752
Change-Id: I7594daaa5e97423d34726b07cc79e3ee28418d95
2015-04-10 08:58:38 -07:00
Alex Klyubin
8d33804b01 am 037dfb94: am 5f8c17b9: am ba2836e6: Merge "Track recent keymaster_defs.h changes."
* commit '037dfb9423a0988398b67520546dae5673aa54bb':
  Track recent keymaster_defs.h changes.
2015-04-10 04:34:13 +00:00