652 Commits

Author SHA1 Message Date
Rubin Xu
b3a13e1e2c Add KeyGenParameterSpec.setCriticalToDeviceEncryption
Mirror KeyProtection.setCriticalToDeviceEncryption so
the flag can also be set on keys generated by keystore.

Bug: 72178550
Test: atest android.security.keystore.KeyGenParameterSpecTest
Test: atest android.security.ParcelableKeyGenParameterSpecTest
Change-Id: I7f102c82e60f211028c694d499ffd2838b89bb2b
2020-01-14 17:10:18 +00:00
Automerger Merge Worker
509eee80fa Merge "Make KeyStoreCryptoOperationChunkedStreamer lazy." am: c13f012cc5 am: bb8ecaef09 am: ecb9c6f041
Change-Id: Icbcec2ae8ea5c907d7ce37558b0db0b634643a56
2020-01-06 16:29:26 +00:00
Rob Barnes
c13f012cc5 Merge "Make KeyStoreCryptoOperationChunkedStreamer lazy." 2020-01-06 15:33:06 +00:00
Artur Satayev
53fe96661b Use new UnsupportedAppUsage annotation.
Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library.

Bug: 145132366
Test: m && diff unsupportedappusage_index.csv
Change-Id: I4bc8c9482e4bb1af21363f951affff7ee3fefeab
2019-12-18 15:42:06 +00:00
Automerger Merge Worker
8ccd0f50d4 Merge "Add new Credential prefix for platform VPNs" am: 0ce0c59535 am: 27d405ab14 am: 5a51aa7af8
Change-Id: I9d83aeb57d05baea53d1afb086ae582d18701265
2019-12-17 18:52:38 +00:00
Benedict Wong
048e248537 Add new Credential prefix for platform VPNs
Platform VPN profiles keyed by apps must use a different key prefix to
prevent the Settings app from seeing them (and thus exposing potentially
sensitive credential information). Thus, the profiles will be
partitioned as follows:

Custom (Settings-app) based profiles continues using VPN_* prefix
App provisioned profiles will use the new PLATFORM_VPN_* prefix

Bug: 144245359
Test: Compiles, FrameworksNetTests passing
Change-Id: If8762e468c6cbbeb80738f14b066ebbad5cc665f
2019-12-17 06:02:51 +00:00
Eran Messeri
c54507664b Wire individual attestation
Properly define the constant for requesting the use of device individual
attestation certificate and use it in AttestationUtils.

This lets callers to DevicePolicyManager.generateKeyPair request the use
of device-unique attestation certificate, on Keymaster implementations
that support this.

Bug: 140193672
Bug: 136494773
Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testKeyManagement
Change-Id: I74de89e4c121a27b0495dcb99b0775445c3d4eaf
2019-12-13 10:58:57 +00:00
Rob Barnes
73ea6195ac Make KeyStoreCryptoOperationChunkedStreamer lazy.
Only send updates when a configurable threshold is met.
For some scenarios this results in a significant performance
improvement. Specifically sign operations should be 10-40% faster.

Bug: 139891753
Test: atest CtsKeystoreTestCases
Change-Id: I233679d4f8582eeaaa6f21e3102cce08110f0482
2019-12-04 11:38:13 -07:00
TreeHugger Robot
1c5a4c6ded Merge "Declare public app cert constants in Credentials" 2019-12-03 17:37:10 +00:00
Victor Hsieh
de6cd4744b Declare public app cert constants in Credentials
Test: build
Bug: 112038744

Change-Id: I9f426090a2fc5e8f9a293c5443ac531cb8700912
2019-11-25 11:32:03 -08:00
TreeHugger Robot
2f6c5fe32f Merge changes from topic "broadcast_multiple_perm"
* changes:
  AndroidKeyStoreProvider: Add @throws documentation
  RemoteException: Add @throws documentation
  Context: Rename Context.sendBroadcastMultiplePermissions
2019-11-21 06:28:10 +00:00
Roshan Pius
4241a2866c AndroidKeyStoreProvider: Add @throws documentation
Bug: 144791977
Test: Compiles
Change-Id: I9f19e30d58b1b7d504f9e8f7e79dd71a38f81357
2019-11-20 14:48:34 -08:00
Max Bires
88b99511bd Merge "Removing binder access to deprecated KeyStore function reset" am: 9eb7fcfba6 am: 0ae9cd3faa
am: c47567db49

Change-Id: I8e8d072dbf3edcb53eb32f86e0898c1bef791267
2019-11-19 20:20:36 -08:00
Max Bires
7de99c2f1a Merge "Updating accepted HMAC key sizes" am: 1cf90f78f1 am: 7f813b80d3
am: 432cb5d523

Change-Id: I1308b205762df42ed5fdc23da00f84a8cc31d45e
2019-11-19 19:57:30 -08:00
Rob Barnes
c00713055b Merge "Allow for input_data on finish." am: 4a83b14ada am: 02c287a628
am: 51e842e43c

Change-Id: I3ed4477e925a203ae8a7b1dde9744ade4a32e93c
2019-11-19 19:50:18 -08:00
Treehugger Robot
9eb7fcfba6 Merge "Removing binder access to deprecated KeyStore function reset" 2019-11-20 01:40:28 +00:00
Treehugger Robot
1cf90f78f1 Merge "Updating accepted HMAC key sizes" 2019-11-19 23:59:32 +00:00
Rob Barnes
92743aeb44 Allow for input_data on finish.
This additional input will be unused for now, but future changes are
expected to utilize it.

Test: Keystore CTS Tests
Change-Id: I5c388032e3710e3825bdb06b26443a5ae2c034a3
2019-11-14 16:19:20 -07:00
Robert Horvath
3bb0b61820 Merge "Fix NPE when KeyChain binding dies" 2019-11-14 14:10:36 +00:00
Robert Horvath
54c94398bf Fix NPE when KeyChain binding dies
BlockingQueue does not accept null values, change to CountDownLatch for
synchronization.

Bug: 144477553
Test: Enable multiple managed profiles, and run
      `atest UserLifecycleTests#managedProfileStopped`
Change-Id: I1a003568896ce7983a5ac14a710944d914c86bac
2019-11-14 14:01:46 +01:00
TreeHugger Robot
bc7671b9fb Merge "Add @UnsupportedAppUsage to test apis that are known to be used by apps." 2019-11-13 15:46:27 +00:00
Artur Satayev
5a525851a8 Add @UnsupportedAppUsage to test apis that are known to be used by apps.
go/testapi-enforcement

Bug: 133832325
Test: m
Change-Id: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
Merged-In: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
2019-11-13 15:05:56 +00:00
Roshan Pius
780d117268 keystore: Expose @SystemApi's to wifi mainline module
Two @SystemApi's being added to allow wifi mainline module to access
formal API's:
a) KeyGenParameterSpec.Builder.setUid() to allow wifi to create/store keys
with WIFI_UID.
b) AndroidKeyStoreProvider.getKeyStoreForUid() to allow wifi to get/put
any keys stored with WIFI_UID.

Both of these API's are already permission protected in the lower
layers. There is a map of euid's stored in the native keystore which
limits which uid is allowed to access which other uid's data.

Bug: 142089671
Test: make system-api-stubs-docs-update-current-api
Change-Id: I39b92d2293bcdc26bb0a4a48a1d1e4cc0b20ad0b
2019-11-13 06:08:13 -08:00
Artur Satayev
f0b7d0ba51 Add @UnsupportedAppUsage to test apis that are known to be used by apps.
go/testapi-enforcement

Bug: 133832325
Test: m
Change-Id: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
Merged-In: Ifc8db120640a1554dcbf1722e61e09c7ddc65dd6
2019-11-13 12:58:29 +00:00
Max Bires
ca0d4d8f42 Updating accepted HMAC key sizes
In order to keep conformity across the ecosystem, keystore will enforce
that HMAC key sizes coming in through the framework must be limited to
the range of 64-512 bits, inclusive. This will be the case for both TEE
and StrongBox Keymaster implementations.

Bug: 143404829
Test: atest CtsKeystoreTestCases
Change-Id: I2ea867392060f4478b5a01bd747a4345e1fded4c
2019-11-12 13:42:58 -08:00
Max Bires
b8ae22895c Removing binder access to deprecated KeyStore function reset
This api call is not accessible from the java API and is intended to be
deprecated. This CL cleans up the potential to directly call into binder
and use this functionality.

Also cleans up imports to appease the repo hooks

Test: Android builds
Change-Id: I95b27a001a6d6ba6c7d1f952bdda456a78b7f99c
2019-11-11 17:43:50 -08:00
Rubin Xu
c398627e5e Update keyguard locked state from TrustManagerService
TrustManagerService holds the ground truth about whether a user is
locked or not, so update keystore using the information there,
instead of doing it from KeyguardStateMonitor. This fixes the issue
of work profile locked state not being correctly pushed to keystore.

Note: since this change is likely to be backported as a security
patch, I'm refraining from doing major refactoring right now.

Bug: 141329041
Test: manually with KeyPairSampleApp
Change-Id: I3472ece73d573a775345ebcceeeb2cc460374c9b
2019-11-08 13:40:42 +00:00
Rubin Xu
3bf1ccc1cf Merge "Handle the case when KeyChain binding fails" 2019-10-28 22:29:59 +00:00
Alex Johnston
fde28690ff Added functionality to select type of certificate to be installed from the Settings app
This is part of the changes to improve the UX and language for installing certificates.
Previously, the different types of certificate used the same installation flow. This CL
introduces a new settings page, where the type of certificate to be installed can be selected.

Bug: 139173976
Test: Atest com.android.settings.security
      manual testing from Settings by selecting the certificate type
	preference and ensuring the installation flow still worked as expected.

Change-Id: I6e0606b00c5f684571ffbd903b9cf55c6911fd0f
2019-10-24 10:32:55 +01:00
Rubin Xu
7629a4b45e Handle the case when KeyChain binding fails
Binding to keychain can fail, for example when the target user
is being removed. Handle this case gracefully and do not block
the system server.

Bug: 139554671
Test: none
Change-Id: Ib68c873e367428b82f3cb2a81cafe1a59776336c
2019-10-23 15:36:17 +01:00
Polina Bondarenko
ecc2cde45b Fix KeyChain.KEY_ALIAS_SELECTION_DENIED
Remove the UUID suffix from the constant to make it less confusing.

Bug: 142347719
Test: compile
Change-Id: I6e73f1ef71c30c5b4388931abc8e431eaede6ece
2019-10-16 13:40:31 +02:00
TreeHugger Robot
8e73c69e91 Merge "Add KeyChain.KEY_ALIAS_SELECTION_DENIED constant." 2019-10-07 14:57:42 +00:00
Polina Bondarenko
a75bf0ca59 Add KeyChain.KEY_ALIAS_SELECTION_DENIED constant.
Add KEY_ALIAS_SELECTION_DENIED contant to flag that no private key alias has
been chosen in onChoosePrivateKeyAlias, but no KeyChainActivity selection dialog
should be presented to the user.

Bug: 136649900
Test: run cts --test MixedManagedProfileOwnerTest#testDelegationCertSelection
Change-Id: I9aeea7be0c2a6172ca054f91d49183c843ecfa6e
2019-10-07 15:05:39 +02:00
Eran Messeri
da05c80d6b API for individual attestation
Introduce a new API to request use of individual attestation
certificate for attesting keys generated by the
DevicePolicyManager.generateKeyPair method.

It builds on existing device ID attestation capabilities in two ways:
(1) Eligibility check: Assuming similar privacy requirements for the use
    of individual attestation certificates, enforce the same conditions
    for using them as the conditions for requesting device identifiers
    in the attestation record.
(2) Keymaster interaction: Passing the right Keymaster tag to the
    attestKey call, which is easily done in AttestationUtils.

Bug: 136494773
Test: CTS test to be added.
Change-Id: Idb5cee66d986a521c17e1955532d0bfae66c035d
2019-09-24 18:14:05 +01:00
Eran Messeri
d6ee4aae9b KeyChain: Unify manual and programmatic key installation flows
Unify the manual certificate installation flow (via "Install from
storage" in the Settings app) with the programmatic one (using
DevicePolicyManager.installKeyPair).

The unification is achieved by extending the KeyChainService API to take
in the UID for which the key is designated (so WiFi keys can be
installed with the unified flow), and making the CredentialStorage
activity call the KeyChainService rather than poke into Keystore
directly.

Framework-related changes to support this:
* Add new constant for specifying the key alias as an extra to the
  install activity, and remove obsolete constants from the Credentials
  class.
* Make KeyChainService definition include key destination UID.
* Make the call to KeyChainService.installKeyPair from the
  DevicePolicyManagerService specify the "self" UID.

Test: Manual CtsVerifier tests: KeyChain Storage Test, CA Cert Notification Test
Test: cts-tradefed run commandAndExit cts-dev -m CtsDevicePolicyManagerTestCases -t  com.android.cts.devicepolicy.MixedDeviceOwnerTest#testKeyManagement
Bug: 138375478
Change-Id: Ib317f85fa6719c70ee3b1da4255c44754fbfa789
2019-09-12 16:02:36 +01:00
Eran Messeri
e7a65b65e5 AttestedKeyPair: Address API review comments
Make AttestedKeyPair c'tor accept a List<Certificate> rather than
Certificate[] to match the getter method on this class.

To make it easier to use this class from other framework code I've
re-instantiated the c'tor with a certificate array which will
convert the array to a list.

Bug: 139092002
Test: cts-tradefed run commandAndExit cts-dev -m CtsDevicePolicyManagerTestCases -t  com.android.cts.devicepolicy.MixedDeviceOwnerTest#testKeyManagement
Change-Id: Ie80dcb28f112efa89d3cc6fdceb1b9e5e26c58b1
2019-08-23 15:33:16 +01:00
Eran Messeri
390539d11b Make AttestedKeyPair constructable
Make the constructor for AttestedKeyPair public so instances of it can
be created for testing.

Bug: 138409426
Test: That it compiles
Change-Id: Iab8fbf1ad2293a91347701eb67631a8f3a3bd3fa
2019-08-06 15:55:17 +01:00
Solomon Kinard
2bd792f3de Spelling fix in KeyStore.java
Test: none
Change-Id: I37c535a358b0b157f0e04978658816036c52ebab
2019-07-03 16:37:03 -07:00
Shawn Willden
d8283a81f3 Fix encryption/decryption of large blocks.
There's a long-standing bug (since ~Marshmallow) that causes
AndroidKeyStore to truncate large (>64 KiB) blocks of data.  This can
be avoided by callers by processing data in smaller chunks, and
smaller chunks are more memory-efficient while not being much (if any)
more time-efficient.  But, Keystore should handle large blocks
correctly.  This CL adds a test to all block cipher tests that
attempts to encrypt and then decrypt a 100 KiB block.

Bug: 123391046
Test:  CtsKeystoreTestCases
Change-Id: I0c0286fd5360d4fe62cbd8130aa0c17f97318801
2019-05-24 09:39:50 -06:00
Kevin Chyn
5e052537b7 Merge "Check PackageManager for feature before getting system service" into qt-dev 2019-04-20 02:26:16 +00:00
Kevin Chyn
1e50792d72 Check PackageManager for feature before getting system service
Fixes: 130756217

Test: See comment #3 in the bug above
Change-Id: I0008f2b2958c9ac0df4e1f8ce4f5edcd9aac4292
2019-04-18 13:39:09 -07:00
Janis Danisevskis
f924b7e25d Fix refactoring glitch in KeyStore.java
Bug: 129974578
Test: atest android.keystore.cts
Change-Id: I3ba732e15e522bd31e7eb813677d3ea884328cb6
2019-04-17 14:10:28 -07:00
Kevin Chyn
9374c9f839 Update documentation for fingerprint -> biometric
Fixes: 129909360

Test: Builds
Change-Id: I8e419e4c2b5ca2c1f0fc9d988100ceb41f193a42
2019-04-05 00:49:59 +00:00
Janis Danisevskis
c9277ffd42 Keystore.java: Make apps tolerant to keystore crashes
Since keystore accepts asynchronous requests it may be that apps wait
forever if keystore dies. This patch adds a death recipient to all
keystore promises so that Keystore.java gets notified when keystore
dies.

Test: atest android.keystore.cts
Bug: 111443219
Bug: 128991260
Change-Id: Ie6e4a4f371287f83a2cdf4069d5686c67d8aebc1
2019-04-02 16:13:01 +00:00
Max Bires
f5276800d8 Merge "Fixing engineGetCertificateChain exception" am: 09e3d8c3eb am: 53187655d0
am: efb8468705

Change-Id: I8157345ed59352152c5035467f94836c0c4f216e
2019-03-18 20:45:55 -07:00
Treehugger Robot
09e3d8c3eb Merge "Fixing engineGetCertificateChain exception" 2019-03-19 03:02:31 +00:00
Treehugger Robot
f070b51670 Merge "Add Keystore get option that supresses caught exceptions warnings." 2019-03-08 21:58:46 +00:00
Max Bires
18e0781d3d Merge "Adding KEY_PERMANENTLY_INVALIDATED int" 2019-03-08 17:53:05 +00:00
Irina Dumitrescu
203bd1b113 Add Keystore get option that supresses caught exceptions warnings.
This is useful when the caught exceptions are not informative and they
act as a red herring in the adb logs.

Bug:109791294
Test: call this method in the VpnSettings and manually navigate to
adding a new VPN by searching for VPN in settings and then pressing '+'.

Change-Id: I4bc86e3ea5b11027090fd3a27dc7455557cf66ab
Merged-In: I4bc86e3ea5b11027090fd3a27dc7455557cf66ab
2019-03-07 20:42:22 +00:00
Max Bires
beae8c67dc Fixing engineGetCertificateChain exception
If a certificate is self signed, then currently KeyStore will still
attempt to find the CA certificate. When it obviously fails to find it,
a key not found exception is propagated up and thrown. This CL
suppresses that exception, as it seems to exclusively be thrown in this
condition, which is WAI. Having the stack trace show up can be very
misleading to developers.

Test: atest cts/tests/tests/keystore/src/android/keystore/cts
Change-Id: I192f54d3d8355c183e830ab09314932e8800f7ed
2019-03-07 18:19:29 +00:00