515 Commits

Author SHA1 Message Date
Janis Danisevskis
da5dae23f9 Fix use of auth-bound keys after screen lock removal
When an auth-bound key is used after the screen lock has been removed by
the user, KeyStore.begin retruns UNINITIALIZED.

This patch adds handling for this error code, indicating that the key
that was to be used was permanently invalidated.

Bug: 65200397
Test: CtsVerifier ScreenLockBoundKeysTest:
      1. Run test
      2. with CtsVerifier in the background remove the screen lock
         through the settings dialog
      3. Select VtsVerifier in 'recents'
      4. Run test again

Change-Id: If68ba0eb2f9c04655fe8c9eea28c4491eae8e92f
(cherry picked from commit d07d3384279c0c07c5c6747ea8d0c5684264c9d0)
2017-09-12 04:13:11 +00:00
Cindy Kuang
520ba6d132 Merge "docs: corrected code example mistakes" into oc-dev am: 5714da6e93
am: 3311ba316a

Change-Id: I5a7f89494a450d8ff657161e70301aebd93c63b0
2017-08-16 17:28:26 +00:00
Cindy Kuang
3311ba316a Merge "docs: corrected code example mistakes" into oc-dev
am: 5714da6e93

Change-Id: I75b35bd6ff92b345c3fd9d27fdf03e5db2927be9
2017-08-16 17:12:08 +00:00
Cindy Kuang
2b1a5b8fd9 docs: corrected code example mistakes
Test: make ds-docs

Bug: 10808505
Change-Id: I9ee4efab9f0cbac00213179d06a6f0919cb82756
2017-08-11 10:49:04 -07:00
Janis Danisevskis
e06f533726 Refurbish granting mechanism
Keystore stores key blobs in with filenames that include the symbolic
name and the uid of the owner. This behaviour should have been
completely opaque to the user keystore. However, the granting mechanism,
by which an app can allow another app to use one of its keys, leaked the
internal structure in that the grantee had to specify the key name with
the granter's uid prefix in order to use the granted key. This in turn
collided with prefix handling in other parts of the framework.

This patch refurbishes the granting mechanism such that keystore can
choose a name for the grant. It uses the original symbolic key name as
prefix and appends _KEYSTOREGRANT_<grant_no> where the grant_no is
chosen as first free slot starting from 0. Each uid has its own grant_no
space.

This changes the grant call such that it now returns a string, which is
the alias name of the newly created grant. The string is empty if the
grant operation failed.

As before apps can still mask granted keys by importing a key with the
exact same name including the added suffix. But everybody deserves the
right to shoot themselves in the foot if they really want to.

Bug: 37264540
Bug: 62237038
Test: run cts-dev --module CtsDevicePolicyManagerTestCases --test
          com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement
	  because it grants a key
Merged-In: I047512ba345c25e6e691e78f7a37fc3f97b95d32
Change-Id: I047512ba345c25e6e691e78f7a37fc3f97b95d32
2017-07-24 10:58:33 -07:00
Tobias Thierer
05b5fa5027 Revert "Delete obsolete and unused KeyStoreTests". DO NOT MERGE ANYWHERE.
Needed to revert the CL's base CL, which tracks the revert
of the corrsponding conscrypt CL.

This reverts commit 91abf9f6e2c60b05377b2b82ea2a09fc25476e56.

This is a clean revert. The upload hook to fix lint errors was not run
(this CL was uploaded with --no-verify).

Test: Treehugger
Test: make droid cts
Bug: 62424503

Change-Id: Ic7a3a5550b1e2bdfec98acd986a6a4e84eef41ea
2017-06-26 20:38:07 +01:00
Janis Danisevskis
b50e9f65d6 Refurbish granting mechanism
Keystore stores key blobs in with filenames that include the symbolic
name and the uid of the owner. This behaviour should have been
completely opaque to the user keystore. However, the granting mechanism,
by which an app can allow another app to use one of its keys, leaked the
internal structure in that the grantee had to specify the key name with
the granter's uid prefix in order to use the granted key. This in turn
collided with prefix handling in other parts of the framework.

This patch refurbishes the granting mechanism such that keystore can
choose a name for the grant. It uses the original symbolic key name as
prefix and appends _KEYSTOREGRANT_<grant_no> where the grant_no is
chosen as first free slot starting from 0. Each uid has its own grant_no
space.

This changes the grant call such that it now returns a string, which is
the alias name of the newly created grant. The string is empty if the
grant operation failed.

As before apps can still mask granted keys by importing a key with the
exact same name including the added suffix. But everybody deserves the
right to shoot themselves in the foot if they really want to.

Bug: 37264540
Bug: 62237038
Test: run cts-dev --module CtsDevicePolicyManagerTestCases --test
          com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement
	  because it grants a key
Change-Id: I047512ba345c25e6e691e78f7a37fc3f97b95d32
2017-06-23 09:27:12 -07:00
phweiss
7eeab2cdd9 Implement CACert queries in SecurityController
Cherry-pick note:
testCACertLoader() was flaky, so this cherry-pick contains
two attempted fixes and a CL that disables the test. The original commit
messages of the squashed CLs are below.
Merged-In: I3b9cc3d85c9f49d0a892613b63d1fba184ab647e

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

Increase timeout for flaky testCACertLoader()

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

Fix flaky SecurityControllerTest.testCaCertLoader

Fixes: 38108698
Test: runtest -c .statusbar.policy.SecurityControllerTest systemui
Change-Id: I6029a09984b72599622f0df57187a20aba4dab30

Disable flaky test

Test: treehugger
Bug: 38118260
Change-Id: I05c6504acee6a787e1cc5071bed0118388963212

(cherry picked from commit e375fc441cc889890d1cff5bc771039bb65f08ef)
2017-05-09 15:35:30 +02:00
Kenny Root
d5bcc031d9 Merge changes from topic 'update-conscrypt' am: c497348c74 am: 37607dfca6 am: 9172df0777
am: 76da1723bc

Change-Id: I8e1e1a749831c90ab132df1d481ba314ec5012d5
2017-05-05 21:54:12 +00:00
Kenny Root
76da1723bc Merge changes from topic 'update-conscrypt' am: c497348c74 am: 37607dfca6
am: 9172df0777

Change-Id: I78b96e5ae3231185a1b26e2e8b9f95881c279de0
2017-05-05 21:33:39 +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
Kenny Root
91abf9f6e2 Delete obsolete and unused KeyStoreTests
These depended on internal implementation details of Conscrypt that are
changing. Delete these tests since they're not included in builds any
more.

Test: make checkbuild
Change-Id: I6ddf832c30bcf49e940c55aa81534c3d987393fb
2017-05-01 16:39:20 -07:00
Bartosz Fabianowski
237f4b369b Add device ID attestation method to keymaster
Device ID attestation consists of three steps:
* Generate a temporary key
* Attest the key and desired device IDs
* Delete the temporary key

Rather than being spread over three keymaster APIs, these operations
should happen automatically in a single keymaster method.

Bug: 34734938
Test: GTS com.google.android.gts.security.DeviceIdAttestationHostTest

Change-Id: Ifabb5163b9e4d12cb309a6b0ca8e5f2f92d212f4
2017-04-26 17:40:44 +02:00
Jeff Sharkey
a00c7c0a99 Merge "Fix some issues found by new doclava linter." into oc-dev 2017-04-25 22:11:01 +00: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
Rubin Xu
12b644d275 Introduce KEYSTORE_FLAG_CRITICAL_TO_DEVICE_ENCRYPTION
This flag is used by system server to mark keys used during the
synthetic password auth flow. keys marked with this flag will not
be super encrypted because super encryption requires knowledge of
the synthetic password, causing a chicken-and-egg problem.

Bug: 35849499
Bug: 34600579
Test: cts-tradefed run cts-dev -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.MixedProfileOwnerTest#testResetPasswordWithToken

Change-Id: I474822f2e026f24ce6f6de1aa58b5012922f7b13
2017-04-24 20:04:50 +01:00
Jeff Sharkey
910e081216 More auto-doc work.
Add support for AnyThread, CallSuper, and UiThread.

Another related CL started documenting @RequiresPermission, so remove
duplicated information in existing APIs.

Suppress auto-doc on a handful of classes that are already
well-documented.

Test: make -j32 offline-sdk-docs
Bug: 37526420
Change-Id: I791437dccec0f11d5349a23b982ba098cb551af8
2017-04-21 16:35:08 -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
Bartosz Fabianowski
ad60c0615f Add manufacturer and model to device ID attestation
Discussions have shown that in addition to brand, device and product,
we should also allow devices to attest their manufacturer and model.

Bug: 36433192
Test: GTS com.google.android.gts.security.DeviceIdAttestationHostTest

Change-Id: Idd48929d6a0c9fe6656c6d2656e2c3f6f370a21e
2017-03-20 14:00:25 +01:00
Bartosz Fabianowski
05dc9f764c Add API for checking which CA certs were installed by the DO/PO
With this API, the system can determine whether a CA cert was
installed by the user or the user's DO/PO.

Bug: 32692748
Test: unit tests (see DevicePolicyManagerTest.java for invocation)
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases

Change-Id: I3bcae5ac18ec2b110154184fc515df804fd73da6
2017-03-03 19:42:51 +01:00
Frank Salim
66925ecc64 Revert "Add new key purpose Wrap Key to KeyProperties.java and"
This reverts commit eb30e64f3fac192404a6ae3c162a0770201a7dc2.

Reason for revert: Remove partial support for wrapped key import

Test: CTS tested
Change-Id: I8008494860534257fa983e1a5169d0ed034621f7
2017-03-02 11:16:09 -07:00
TreeHugger Robot
a7aaae881c Merge "Delete ParcelableString, add StringParceledListSlice" 2017-02-28 22:09:06 +00:00
Robin Lee
abaa0695c5 Delete ParcelableString, add StringParceledListSlice
Both inherit from package private BaseParceledListSlice.

This is still bad, but it's not as bad. The existing code that uses
this can just do Foo.bar().getList() now instead of having to marshal
to and from an oddball type at either end as well.

In the longer term ParceledListSlice<> should be eliminated, but it's
not clear how far into the future that is going to happen.

Test: runtest -x services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
Test: runtest -x core/tests/coretests/src/android/content/pm/ParceledListSliceTest.java
Change-Id: Ie69b96b5215d6e04990f6d31345772cdfee21d78
2017-02-28 18:07:08 +00:00
Robin Lee
3e7cf168a5 Make IKeyChainAliasCallback oneway
So it can be sent from devicepolicymanager (system_server) to keychain
(a system_app) without waiting on the response and having to do
everything in a background thread.

Side-effect: the regular keychain => app callback is slightly more
efficient now too. in case anyone particularly needs blazing fast
private key user selections.

Fix: 35675253
Test: cts-tradefed run cts --abi=arm64-v8a --skip-device-info --module CtsDevicePolicyManagerTestCases --test 'com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement' </dev/null 2>&1
Change-Id: I6e9d96ca3c42e6489d879d8cfb0507eb94838bf1
2017-02-25 01:32:54 +00:00
TreeHugger Robot
2c92e9daa4 Merge "Reject HMAC keys smaller than 64 bits." 2017-02-14 15:58:31 +00: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
Rubin Xu
59ced28f0f Add hidden KeyProtection API to specify SID
Allows the caller to specify which SID the given key
should be bound to, overriding the default rule of
binding to the current root/fingerprint SID.

This is a prerequsite for introducing synthetic password
based authentication flow.

Test: cts-tradefed run cts -m CtsKeystoreTestCases
Bug: 33126414
Change-Id: Ide03c0f4fd33ecca7a169ea763c3d4d0b173d1dd
2017-02-02 17:53:32 +00:00
Bartosz Fabianowski
92e8cfd21d Add device id attestation
This adds a new public API for attesting the device's hardware ids
(e.g. serial number and IMEI).

Bug: 34597337
Test: CTS CtsKeystoreTestCases and GTS DeviceIdAttestationHostTest

Change-Id: I2e9c1b4f8eb24afa4a09c71c137ce33a6b87eb27
2017-01-25 04:47:15 +01:00
Crystal Qin
eb30e64f3f Add new key purpose Wrap Key to KeyProperties.java and
KeymasterDefs.java.

Test: There will be a CTS test CL submitted together.
Change-Id: Ic60c3efc451cd7cbb04689b3d7bf9d607fae6c1f
2017-01-19 21:02:10 -08:00
Paul Duffin
ccb0445027 Prepare for removal of legacy-test from default targets
In preparation for removing junit classes from the Android API
the legacy-test target will be removed from the
TARGET_DEFAULT_JAVA_LIBRARIES. This change adds explicit
dependencies on junit and/or legacy-android-test to ensure that
modules will compile properly once it is removed.

(cherry picked from 6387604f9e672ece85e07c4bcbd7be396867f06f)

Bug: 30188076
Test: make checkbuild
Merged-In: I13e88297731253420e4e5f5291d503f13a39a156
Change-Id: I58446eb8c45d8ac2bcdbc9fa40d1321e811bdd4b
2017-01-19 09:43:05 +00:00
Paul Duffin
8aeb59ebcd Prepare for removal of legacy-test from default targets
In preparation for removing junit classes from the Android API
the legacy-test target will be removed from the
TARGET_DEFAULT_JAVA_LIBRARIES. This change adds explicit
dependencies on junit and/or legacy-android-test to ensure that
modules will compile properly once it is removed.

Bug: 30188076
Test: make checkbuild
Change-Id: I13e88297731253420e4e5f5291d503f13a39a156
2017-01-18 16:39:34 +00:00
Shawn Willden
7c3b65e9b1 Reject HMAC keys smaller than 64 bits.
Test: CTS test has been updated to verify this.
Change-Id: I6389d9fa2ff75d08a2223c789e5437190c4b82c6
2017-01-17 05:05:56 -07: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
Tucker Sylvestro
7f99db4e63 Add the onDeviceOffBody API method to KeyStore am: b32aae2a46
am: 8f75adc624

Change-Id: Ib8d7bc19a167999894b90b45e7eb1cadb2a85d24
2016-10-06 16:20:19 +00:00
Tucker Sylvestro
8f75adc624 Add the onDeviceOffBody API method to KeyStore
am: b32aae2a46

Change-Id: Idbf7f1d505b1d446a3d648dcf1b0f334a629110a
2016-10-06 16:13:48 +00:00
Kevin Hufnagle
c8d45456bd docs: Fixed broken link to Android KeyStore facility am: c0c4ac5e35 am: 507a5c03da
am: f4ac919849

Change-Id: I20e5abdffd9ac4fd8b4164ef56c1b3bafb58ad2b
2016-09-27 02:06:09 +00:00
Kevin Hufnagle
f4ac919849 docs: Fixed broken link to Android KeyStore facility am: c0c4ac5e35
am: 507a5c03da

Change-Id: Iec80ad1c7127efb7e257be0625988ef1b2588b0f
2016-09-26 23:47:39 +00:00
Tucker Sylvestro
b32aae2a46 Add the onDeviceOffBody API method to KeyStore
This is necessary for allowing the KeyStore to lock keys that remain
authorized as long as the device is on-body.

Bug 28911985

Change-Id: If50bc84d5a1cb23f9b01b1950c3676d1519cc4f5
2016-09-23 15:11:42 -04:00
Kevin Hufnagle
c0c4ac5e35 docs: Fixed broken link to Android KeyStore facility
Bug: 13663279
Change-Id: I859b3c9a35f9e6c63cb0c29260f4aa1aa33ab15c
2016-09-19 11:31:08 -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
4f7d56a706 Force application context for KeyChain bindings
am: f04a663d6a

Change-Id: I16c31a9c31527a79addbd2b44003f8fe56cb652f
2016-08-23 16:06:39 +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
Shawn Willden
e5d71c4cfa Fix @link tags in keystore doc am: 3f0526ea09
am: 9e8b4ad9c9

Change-Id: Iadb16bd13d4bb525805dd0266aea046c4c472309
2016-08-09 19:38:00 +00:00
Shawn Willden
3f0526ea09 Fix @link tags in keystore doc
Bug: 30258412
Change-Id: I370a53ebad29ff0471e4b7776cd76b2530efe760
(cherry picked from commit 9739d48a2101e49b0936096d69c29006f9acdeb5)
2016-08-02 16:45:06 +00:00
TreeHugger Robot
1c23ed9601 Merge "Fix @link tags in keystore doc" 2016-08-01 23:49:53 +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