Commit Graph

101 Commits

Author SHA1 Message Date
Janis Danisevskis
9ba0f37f8a Merge "Keystore 2.0: Remove Keystore 1.0 SPI with all remaining references" am: a8b1b1a2e6 am: 08945c21ef am: 66ead4fb0b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1624872

Change-Id: I08fcf329e59c309d9292edc846653b02e7a60f21
2021-04-03 02:02:03 +00:00
Janis Danisevskis
a6dcf091f5 Keystore 2.0: Remove Keystore 1.0 SPI with all remaining references
Bug: 171305684
Test: CtsKeystoreTestCases
Change-Id: I337515dadc9e45b909bff058d4e13371b4fa843c
2021-04-01 17:06:41 -07:00
Alex Johnston
1d524e6672 Unregister cred mng app KeyChain API
Bug: 177979648
Test: CTSVerifier CredentialManagementAppActivity
Change-Id: I8c9e22b2334e8e060bc00701f1d2bec76950faf3
2021-03-11 11:01:30 +00:00
Pavel Grafov
685bbb18fe Allow WiFi module to request grants from KeyChain
Bug: 160457441
Test: atest MixedDeviceOwnerTest#testAddNetworkWithKeychainKey_granted
Test: atest MixedDeviceOwnerTest#testAddNetworkWithKeychainKey_notGranted
Test: atest MixedManagedProfileOwnerTest#testAddNetworkWithKeychainKey_granted
Change-Id: I89d753f9000ef2616ffbe3df11c003ac54ddee26
2021-03-05 13:05:03 +00:00
Alex Johnston
0f6d014813 Merge "Credential management app follow ups" into sc-dev 2021-02-25 09:56:00 +00:00
Janis Danisevskis
0cdf262ee5 Keystore 2.0: Remove attestKey from KeyChain.
KeyChain supports device id attestation through KeyGenParameterSpec now.
No need to call attest key individually. Also calling attest key
individually is no longer supported by Keystore 2.0 and KeyMint.

Also isBoundKeyAlgorithm returns true.

Test: atest FrameworksServicesTests:DevicePolicyManagerTest
Bug: 171305387
Merged-In: I759fe245b48fe435153fded2c74c9ae99634c146
Change-Id: I759fe245b48fe435153fded2c74c9ae99634c146
2021-02-23 14:41:49 -08:00
Janis Danisevskis
0f138dc0cc Keystore 2.0: Remove attestKey from KeyChain.
KeyChain supports device id attestation through KeyGenParameterSpec now.
No need to call attest key individually. Also calling attest key
individually is no longer supported by Keystore 2.0 and KeyMint.

Also isBoundKeyAlgorithm returns true.

Test: atest FrameworksServicesTests:DevicePolicyManagerTest
Bug: 171305387
Change-Id: I759fe245b48fe435153fded2c74c9ae99634c146
2021-02-23 12:19:47 -08:00
Alex Johnston
42112e1e75 Credential management app follow ups
* KeyChain API to check if the caller is the
  credential management app.
* KeyChain API to get the authentication policy
  if the caller is the credential management app.
* KeyChain createManageCredentialsIntent docs
  mention startActivityForResult should be used

Bug: 177979648
Test: atest android.devicepolicy.cts.CredentialManagementAppTest
Change-Id: Ia5125adb677ec103a9d5a5318edf95050e74916e
2021-02-23 09:32:47 +00:00
Rubin Xu
72ff9029c6 Add KeyChain.createManageCredentialsIntent
Missed from previous cherry-pick.

Test: make -j docs
Bug: 179180345
Merged-In: I1e57ed9c18a1ada463c55dbf17ce30e31aa7bad2
Change-Id: I1d88e11740a13490613962c944b528e6c2bd0fcb
2021-02-14 18:32:02 +00:00
Alex Johnston
ad53ef61e7 Add KeyChain Test API for the credential manager
* Add setCredentialManagementApp and
  removeCredentialManagementApp
  to KeyChain
* Add permission to manage credential
  management app, which is to be used in
  CTS tests

Bug: 165641221
Test: atest android.devicepolicy.cts.CredentialManagementAppTest
Change-Id: I8487ebc13758a31639d55c8e380faa51d1cfd843
2021-01-12 14:26:56 +00:00
Rubin Xu
392e1e23e5 Allow KeyChain.bindAsUser() to be called on the main thread
KeyChain.bindAsUser() couldn't be called on the main thread because
it was using the main thread to handle service connection callback.
Add an overload of KeyChain.bindAsUser() that accepts an alternative
handler to process the connection callback, which makes it possible
to call KeyChain from the main UI thread directly.

Bug: 165641221
Test: atest KeyChainTests
Test: m RunKeyChainRoboTests
Change-Id: I4290bccf5ae04de0d84c7091729e86704b937295
2020-12-22 22:38:26 +00:00
Alex Johnston
eff614db00 Add credential management app to platform
- This is part of the work to support
  a credential management app on
  unmanaged devices.
- Add intent and method in KeyChain to allow
  an app to request to become the credential
  management app.
- Add the class CredentialManagementApp to store the
  current credential management app.
- Add the class AppUriAuthenticationPolicy and an
  extra in KeyChain to allow an app to set an
  authentication policy.
- Add API methods to KeyChainService to set, get
  and retrieve the credential management app.

Bug: 165641221
Test: atest CredentialManagementAppTest
      atest AppUriAuthenticationPolicyTest
      adb shell am start -n com.android.keychain.tests/.KeyChainTestActivity
Change-Id: I1e57ed9c18a1ada463c55dbf17ce30e31aa7bad2
2020-11-27 08:25:56 +00:00
Rubin Xu
f12ade33a3 Apply FLAG_IMMUTABLE to KeyChain PendingIntent
Bug: 170425388
Test: make
Change-Id: I4a2914f9f91c27755ee1718048057cb52f8a5631
2020-10-23 13:59:25 +01:00
Eran Messeri
cdcbb66be6 Update KeyChain.createInstallIntent documentation
Update the KeyChain.createInstallIntent method documentation to reflect
the change where CA certificates can no longer be installed using
this intent.

Bug: 156941631
Test: m docs
Change-Id: I3cf2c677c4c772698c8df5f25224dd67d12b5606
2020-05-20 11:14:06 +01:00
Rubin Xu
144b057c26 Ensure user is unlocked before binding to KeyChain service
This stops KeyChain from throwing AssertionError when binding to
service fails due to user being locked, which would have crashed
the entire system server.

Bug: 149912024
Test: atest KeyChainTests
Change-Id: Ie110a4210e157cc9b111d845478bdf21e948ba4f
2020-02-20 15:53:06 +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
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
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
Max Bires
6b850fb4ef Merge "Adding KEY_PERMANENTLY_INVALIDATED int" 2019-02-20 17:21:22 +00:00
Max Bires
13f98ce5aa Adding KEY_PERMANENTLY_INVALIDATED int
This is to keep it in sync with response codes in keystore.h.

This commit also adds the KeyPermanentlyInvalidatedException to all the
methods that could receive this error code out of KeyStore.

Bug: 118883532
Test: atest cts/hostsidetests/appsecurity/src/android/appsecurity/cts/AuthBoundKeyTest.java
Change-Id: I878a628824e2eeb639ec5678b1a5d3d10428a918
2019-02-18 20:45:46 +00:00
Eran Messeri
55b8d082ba KeyChain: Improve key override documentation.
Improve the documentation on the case of key override: When a new key is
generated/installed using an alias that already exists.

In particular, clarify that grants are lost and that a new call to
KeyChain.choosePrivateKeyAlias must be issued in this case.

Bug: 123563258
Test: that it builds.
Change-Id: I055e95f57b9576883736ca0cfa6a998dec08a6c2
2019-02-07 23:45:44 +00:00
Eran Messeri
9ccec4d2d4 Handle issuer and key type restrictions.
The caller to KeyChain.choosePrivateKeyAlias can restrict the set of
aliases that are displayed to the user to select from by specifying the
issuers that the associated certificates should be issued by or the key
types that these certificates should contain.

Until now this functionality was not implemented. This was mostly
affecting Chrome
(https://bugs.chromium.org/p/chromium/issues/detail?id=753756).

Support this functionality by passing the issuers and key types into the
KeyChainActivity (from KeyChain) and, prior to displaying the aliases
associated with the certificates, check if each certificate adheres to
the criteria (key type, issues) specified.

Bug: 62910781
Test: m -j RunKeyChainRoboTests
Change-Id: I75e071545699891cfbd77d4f706fc5ef35b85516
2018-09-05 13:58:32 +01:00
Eran Messeri
607a995691 DPM: Propagate StrongBox-related exception
When the caller attempts to generate a key via DevicePolicyManager
(using DevicePolicyManager.generateKeyPair), and specifies that
StrongBox should be used, throw the right exception indicating
StrongBox unavailability - the same one that is thrown if the same
parameters were passed to the KeyStore's key generation method.

This is achieved by catching the StrongBoxUnavailableException in
KeyChain, returning an error code indicating this particular failure
to the DevicePolicyManagerService, which then propagates it by
throwing a service-specific exception with a value indicating
StrongBox unavailability.
The DevicePolicyManager then raises StrongBoxUnavailableException.

Prior to this change the exception propagated from KeyChain would be
a generic failure so the caller would simply get a null result.

Bug: 110882855
Bug: 111183576
Bug: 111322478
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedDeviceOwnerTest#testKeyManagement
Change-Id: I9abe3f449b48eb5a960fafbc15c59b9b4ce7a966
2018-07-17 12:58:13 +01:00
Eran Messeri
0bc50f9442 Improve KeyChain documentation
Improve the choosePrivateKeyAlias documentation by:
(1) removing reference to host+port when a URI is being passed in.
(2) Clearing up the language about what a DPC can do.

Test: N/A
Bug: 81522642
Change-Id: I12fbf675536ea5d843dd2eec4f0379daad764bb6
2018-06-04 17:12:41 +01:00
Mike Harris
cd0eb716c5 Use the @Nullable annotations for choosePrivateKeyAlias.
Both the code and docstring support this, but the parameters weren't
annotated.

Test: it builds locally

Change-Id: I16beddcd74a86047ce9aaf37007d96f3e8e0d4e0
Merged-In: I16beddcd74a86047ce9aaf37007d96f3e8e0d4e0
Fix: 78868934
(cherry picked from commit b7c5eddc53)
2018-04-30 09:27:31 +00:00
Eran Messeri
6169239b94 Utilize verbose KeyChain errors
As KeyChain reports detailed error codes about failure to generate keys
or attestation records for them, log these detailed errors and throw an
exception if the hardware does not support Device ID attestation.

Bug: 72642093
Bug: 73448533
Test: cts-tradefed run commandAndExit  cts-dev -s 127.0.0.1:50487 -a x86_64 -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement -l DEBUG
Change-Id: Ib12efcf48c158373e1fc28cc51d67e70282d029e
2018-03-29 10:58:20 +01:00
Eran Messeri
23c438d711 KeyChain: Provide public & private keys
In order for the DevicePolicyManager to provide key generation
functionality, it has to return both the private and public keys
in form of a KeyPair.

Since the KeyChainService will perform the key generation on behalf
of the DevicePolicyManager (so that KeyChain will be the owner of
the generated keys outright), the DevicePolicyManager needs a way
to get both the private and public key representations from KeyChain.

A getKeyPair method is added that gets the private and public
key pair associated with a given alias from Keystore.
The getPrivateKey now delegates to the getKeyPair method and returns
only the private key.

Tested using existing CTS tests.

Bug: 63388672
Test: cts-tradefed run commandAndExit cts-dev -a armeabi-v7a -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement
Change-Id: I06b8511acd2049a0053ec8893de6de7429f7c92e
2017-11-23 17:59:36 +00:00
phweiss
e375fc441c Implement CACert queries in SecurityController
Queries are run (on a AsyncTask) when user is switched and when
ACTION_TRUST_STORE_CHANGED is broadcasted. Otherwise, the result is cached
in the SecurityController.

Bug: 37535489
Test: runtest --path frameworks/base/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SecurityControllerTest.java

Change-Id: I3b9cc3d85c9f49d0a892613b63d1fba184ab647e
2017-05-05 19:03:29 +02:00
Jeff Sharkey
0f3f60b576 Fix some issues found by new doclava linter.
Add missing API annotations for permissions and SdkConstants, and
invoke doclava with new "-android" flag.

Test: make -j32 offline-sdk-docs
Bug: 37526420
Change-Id: I970bb2655eb568fd25004636f134c794663a6c33
2017-04-25 13:12:45 -06:00
Chad Brubaker
8b651bf7d5 Fix ACTION_STORAGE_CHANGED doc
The deprecation note was not quite correct.

Change-Id: I15231881bbf1ee1ee4d342bff74280d7e9807ac0
Fixes: 36493384
Test: builds
2017-03-23 09:26:09 -07:00
Robin Lee
7f5c91c6bc MonitoringCertTask no longer relies on software.device_admin
Added a test to validate that it still works the way it should before
and after the change.

Bug: 33258404
Bug: 35196414
Fix: 35129745
Test: runtest -x services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
Test: also manual, instructions:
Test: (1) Disable software.device_admin from tablet_core_hardware, rebuild.
Test: (2) Install CA cert. Notification should appear.
Test: (3) Reboot. Notification should still be there.
Change-Id: Id992725c1844a2fffbde4d8acaba531e99f853ad
2017-02-14 13:29:31 +00:00
Shawn Willden
dea6614603 Test for null context in getPrivateKey
In N, passing a null context to getPrivateKey provoked a
NullPointerException, which is validated by a CTS test. In commit
28d68b1 this behavior was changed (inadvertently, I believe) causing
getPrivateKey to wrap the NPE in a KeyChainException. This CL restores
the previous behavior, fixing the test and avoiding breaking any apps
that were catching the NPE.

Test: Fixing broken test
Change-Id: Icb0c75b03efc478b7310998cf3e7108a2c419107
2016-11-16 06:06:36 -07:00
Jeff Sharkey
0a17db1cc5 Detect non-oneway calls leaving system_server.
To protect system stability, any Binder calls leaving the
system_server must carefully be performed using FLAG_ONEWAY (or
the 'oneway' verb in AIDL) which prevents the call from blocking
indefinitely on the remote process.

In this CL, the system_server uses the new Binder.setWarnOnBlocking()
method to enable detection by default for all remote Binder
interfaces.  It can also use Binder.allowBlocking() to allow
blocking calls on certain remote interfaces that have been
determined to be safe.

This CL adds the 'oneway' verb to several interfaces and methods
where it should have been added, and marks a handful of system
ContentProviders as being safe to call into.  Also, we assume that
any services obtained from ServiceManager are part of the core
OS, and are okay to make blocking calls to.

Test: builds, boots, runs with minimal logs triggered
Bug: 32715088
Change-Id: Ide476e120cb40436a94b7faf7615c943d691f4c0
2016-11-07 17:03:37 -07:00
Rubin Xu
8910bf2ca0 Merge "Handle null packageName in PendingIntentRecord" into nyc-mr1-dev am: 6acd5e7361 am: 2f6eecbed0
am: f38514ccd6

Change-Id: I1071a92b4ff74a57bf94c9b6aad9df4fb3852072
2016-08-23 22:29:15 +00:00
Robin Lee
c378aabdda Documentation warning against short-lived Contexts
am: da23618043

Change-Id: Ie6e4c05d8d9a273f0f529c2be79f3df4a856fedb
2016-08-23 16:09:41 +00:00
Robin Lee
da23618043 Documentation warning against short-lived Contexts
It's better to use an Application Context rather than hoping the
activity won't be destroyed in another thread (because it will).

Change-Id: I9bf842d0d7dbedcc509a4a314d23a9a6cfca4d48
Fix: 29873669
2016-08-23 12:47:54 +00:00
Robin Lee
28d68b1456 Unbind from KeyChainService before RPCing to keystore
This leaves the binder connection open for far too long, which keeps
the keychain app alive longer than necessary.

Bug: 29873669
Change-Id: I037c2b91400202ba6a474819867df16b6342ec0d
2016-07-27 11:11:13 +01:00
TreeHugger Robot
bea9e036f5 Merge "Fix incorrect @link in ACTION_STORAGE_CHANGED comment" 2016-07-25 23:08:57 +00:00
Chad Brubaker
dbf01c12d0 Fix incorrect @link in ACTION_STORAGE_CHANGED comment
Change-Id: Ibfca8651a55e32e9caed96b04e5a40dc6ebc3019
2016-07-25 14:54:39 -07:00
Robin Lee
f04a663d6a Force application context for KeyChain bindings
Bug: 29873669
Change-Id: I68c11ab19a169498045bbc23bc8fe6a2f46be031
(cherry picked from commit 43e235c0d5)
2016-07-25 17:35:12 +00:00
Robin Lee
43e235c0d5 Force application context for KeyChain bindings
Bug: 29873669
Change-Id: I68c11ab19a169498045bbc23bc8fe6a2f46be031
2016-07-25 16:09:22 +01:00
Chad Brubaker
721afae8f1 Mention target API limits for ACTION_STORAGE_CHANGED
Bug: 28450538
Change-Id: I9c69f9d0bdda5b69aec2dc3014a612d84082dc64
2016-07-08 11:06:09 -07:00
Chad Brubaker
4de59ef323 Deprecate ACTION_STORAGE_CHANGED
ACTION_STORAGE_CHANGED is too noisy and fires on too many events. It has
been split into ACTION_KEYCHAIN_CHANGED for
addition/modification/removal of user certificates and keys,
ACTION_TRUST_STORE_CHANGED for changes the the user added and system CA
stores on the device and ACTION_KEY_ACCESS_CHANGED for changes to key
grants.

ACTION_STORAGE_CHANGED will only be sent to applications targeting N
and below. Applications targeting future releases should use the new
broadcasts.

Bug:28450538
Change-Id: I34ff838e9858db65f7308ca2b0f7d652c48fae17
2016-06-30 09:23:15 -07:00
Rubin Xu
b436591708 Add DevicePolicyManager API to install a client cert chain.
When installing a keypair the caller will have the option to specify a
certificate chain which will later be returned to whoever requests access
to the keypair via KeyChain.

Bug: 18239590
Change-Id: Id21ef026e31537db38d891cb9b712dd4fe7159c7
2016-03-30 11:57:58 +01:00
Robin Lee
21bcbc54dd Guard against null component when binding KeyChain
If keychain is removed from a device, there will be no sensible
resolution and client apps will bind to whatever is available.

Doesn't affect system apps which are forcibly prevented from wildcard
binding.

Bug: 27475655
Change-Id: Ide1aab3778e12f0b9a96662deb297a76d2f4997f
2016-03-03 18:57:32 +00:00
Robin Lee
3a435f0390 Return null on getPrivateKey failure not exception
According to documentation:

Returns the {@code PrivateKey} for the requested alias, or null if
there is no result.

@throws KeyChainException if the alias was valid but there was some
problem accessing it.

@throws IllegalStateException if called from the main thread.

In this case the alias doesn't exist or isn't visible to the caller so
they should get null back instead of KeyChainException.

Change-Id: Ied5603ac6aefbcef79050f24c2aa7ee8f386be0b
2015-12-21 12:09:20 +00:00
Neil Fuller
71fbb81b14 Fix @code escapes
The body of {@code} must not be HTML escaped. This is one of
several changes that fix the source in conjunction with a
doclava fix.

Bug: 25757239
Change-Id: Ib38a0fa2dd2a3d68e467f78a812071e763d7e881
2015-12-02 14:24:11 +00:00
Alex Klyubin
3876b1be27 Support cross-UID access from AndroidKeyStore.
This is meant for exposing the pre-existing cross-UID access to keys
backed by the keystore service via higher-level JCA API. For example,
this lets system_server use Wi-Fi or VPN UID keys via JCA API.

To obtain a JCA AndroidKeyStore KeyStore for another UID, use the
hidden system API AndroidKeyStoreProvider.getKeyStoreForUid(uid).

To generate a key owned by another UID, invoke setUid(uid) on
KeyGenParameterSpec.Builder.

This CL does not change the security policy, such as which UID can
access/modify which UIDs' keys. The policy is that only certain system
UIDs are permitted to access keys of certain other system UIDs.

Bug: 23978113
Change-Id: Ie381530f41dc41c50d52f675fb9e68bc87c006de
2015-09-10 15:35:06 -07:00
Robin Lee
59e3baa8ab KeyChain: annotate with @WorkerThread
Several methods need to be called off the main UI thread. This is
the first documentation of that requirement.

Bug: 19440165
Change-Id: I0303011c0ded6ec1efa92119c1e02a8a39b14a59
2015-06-30 13:08:46 -07:00