Commit Graph

959 Commits

Author SHA1 Message Date
Treehugger Robot
30841f177c Merge "Keystore 2.0: Android Protected Confirmation" 2021-01-05 23:29:35 +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
Treehugger Robot
372a2c302d Merge "Keystore 2.0 SPI: Switch to aidl union KeyParameters" am: 220d33ce2c am: 1769b6bd16 am: 2fd2954c84
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1532513

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iffa2479320dd97650460690652732b59d23c248c
2020-12-22 07:01:45 +00:00
Treehugger Robot
21e0150463 Merge changes I316fdb8b,I99c1bd49 am: 572416b317 am: a4f1b7e82a am: f491d4bca8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1519116

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I5bd177a8244c91089495d2a9d2a9e9c5ca03d300
2020-12-22 06:56:26 +00:00
Treehugger Robot
220d33ce2c Merge "Keystore 2.0 SPI: Switch to aidl union KeyParameters" 2020-12-21 18:10:58 +00:00
Janis Danisevskis
a80fd14256 Keystore 2.0 SPI: Public key operation workaround.
Test: Keystore cts tests.
Change-Id: I316fdb8beae018ac91c172dede735e6b0759368a
2020-12-18 11:15:27 -08:00
Janis Danisevskis
efaff8f604 Keystore 2.0 SPI: Bug fixes
* Correctly recover public key from certificate.
* KeyStore2ParameterUtils: iterate through set flags instead of unset
  flags.
* Return private key on Keystore.getKey() instead of public key.

Test: Keystore CTS tests
Change-Id: I99c1bd49ff5cf7a2d89b54559504e67b3def0cd3
2020-12-18 11:09:06 -08:00
Janis Danisevskis
ef3aaa2d59 Keystore 2.0 SPI: Switch to aidl union KeyParameters
Test: Compiles
Change-Id: I54b0d7a97954eb45283cf48bf2372db5e7ffa61a
2020-12-17 20:39:45 -07:00
Tianjie Xu
b73401e25c Merge "Make AndroidKeyStoreLoadStoreParameter public" am: 697c19be17 am: 6b1dcd9930 am: f0a33063e8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1531239

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6803a70c387b3dd94ea8d0bedf60ca922e1bb45a
2020-12-17 05:12:42 +00:00
Treehugger Robot
1e051f99ba Merge "Keystore 2.0 SPI: Implement modification time." am: d2e7c2e000 am: f462515bea am: 01cd87c421
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1530772

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ib7eeb2f1733c724a241f6ce0a5a52a60444def83
2020-12-17 05:12:01 +00:00
Tianjie Xu
697c19be17 Merge "Make AndroidKeyStoreLoadStoreParameter public" 2020-12-16 23:22:36 +00:00
Janis Danisevskis
81d75b4c52 Keystore 2.0: Android Protected Confirmation
Bug: 160930927
Test: CtsVerifier
Change-Id: I9cc325eafbee2aa4257a3ccbe525091a1cae806d
2020-12-16 10:47:56 -08:00
Tianjie
c0e116a05c Make AndroidKeyStoreLoadStoreParameter public
So other packages can load the keystore with namespace.

Test: build
Change-Id: I7de3e51df438b794adb3793a189396999bdd1b88
2020-12-15 15:12:37 -08:00
Janis Danisevskis
fbf2ed5f19 Keystore 2.0 SPI: Implement modification time.
Test: Keystore CTS test.
Change-Id: I097b58fa6c403ff426d99ed484ed324e1419b4e3
2020-12-15 13:06:12 -08:00
Treehugger Robot
30f8a371b7 Merge "Revert "Revert "Keystore 2.0 SPI: Move keymint spec to security ..."" am: dd8891acbe am: 4ac4916c8d am: cf7203f5d3
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1525189

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I024a2f38dfd2432ae77d6a032c27fc8389cf62dc
2020-12-12 01:07:05 +00:00
Shawn Willden
f5a002c222 Revert "Revert "Keystore 2.0 SPI: Move keymint spec to security ..."
Revert "Revert "Keystore 2.0: Move keymint spec to security name..."

Revert "Revert "Keystore 2.0: Move keymint spec to security name..."

Revert^2 "Remove references to keymint1"

34536a352803a08776cc4f373d93a94e1fcbf98e

Bug: 175345910
Bug: 171429297
Change-Id: I694e677e4e20419440f12cb7981f0c0c4ca29e08
2020-12-11 20:36:10 +00:00
Orion Hodson
525a22a777 Merge "Revert "Keystore 2.0 SPI: Move keymint spec to security namespace."" am: bc641a41d8 am: 9e21ecbcb4 am: 1de159412b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1525805

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ie45400513bc12278a68c8af1b5a12ba754f048c5
2020-12-11 14:02:26 +00:00
Shawn Willden
577c22a23e Merge "Keystore 2.0 SPI: Move keymint spec to security namespace." am: f0c3865132 am: 50df7a46cf am: ce6b4c47e2
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1521879

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I085ddcc310b6189ae313959c9a0f349404faa178
2020-12-11 11:01:03 +00:00
Orion Hodson
6acd9c63e7 Revert "Keystore 2.0 SPI: Move keymint spec to security namespace."
Revert "Keystore 2.0: Move keymint spec to security namespace."

Revert "Keystore 2.0: Move keymint spec to security namespace."

Revert "Move keymint to android.hardware.security."

Revert "Configure CF to start KeyMint service by default."

Revert "Move keymint to android.hardware.security."

Revert "Move keymint to android.hardware.security."

Revert submission 1522123-move_keymint

Reason for revert: Build breakage
Bug: 175345910
Bug: 171429297
Reverted Changes:
Ief0e9884a:Keystore 2.0: Move keymint spec to security namesp...
Idb54e8846:Keystore 2.0: Move keymint spec to security namesp...
I9f70db0e4:Remove references to keymint1
I2b4ce3349:Keystore 2.0 SPI: Move keymint spec to security na...
I2498073aa:Move keymint to android.hardware.security.
I098711e7d:Move keymint to android.hardware.security.
I3ec8d70fe:Configure CF to start KeyMint service by default.
Icbb373c50:Move keymint to android.hardware.security.
I86bccf40e:Move keymint to android.hardware.security.

Change-Id: Icd279f358db2387bf2bf232b0548762fab51e67d
2020-12-11 10:45:43 +00:00
Janis Danisevskis
8954dfa092 Keystore 2.0 SPI: Move keymint spec to security namespace.
Test: N/A
Change-Id: I2b4ce3349baf29eb67a31f0c436b964d69d70b02
2020-12-09 13:53:32 -08:00
Pavel Grafov
148e31d70c Add DPM.getKeyPairGrants()
The method returns names of the packages that have access
to the key grouped by UID since grants are stored on per-uid
basis. This is expressed as Set<Set<String>>

Since Binder currently doesn't support sets or lists of lists,
this data structure is flattened into a list of strings, with
null values used as a delimiter.

Bug: 160457441
Test: atest com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testKeyManagement
Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testDelegatedCertInstallerDirectly
Test: atest android.admin.cts.DevicePolicyManagerTest
Change-Id: Ieee1048b145fb8400eccbf32c054afc64b5d90c0
2020-12-03 16:50:52 +00:00
Alex Johnston
e17727ebe4 Add KeyChainService credential management app APIs
Background
* This is part of the work to support
  a credential management app on
  unmanaged devices.
Changes
* Add KeyChainService API methods to
  modify the stored credential management app.

Manual Testing
* Install TestDPC
* Request to manage credentials (fire intent).
  Add policy mapping: 'com.android.chrome' ->
  'client.badssl.com:443' -> 'testAlias'
* Install badssl user certificate as credential
  management app (TestDPC). Set alias to 'testAlias'
* Check certificate is installed in Settings
* Go to chrome > client.badssl.com
* Verify no certificate selection prompt is
  displayed. User is automatically authenticated.
* Remove credential management app from Settings
  Security > Encryption and credentials >
  Certificate management app
* Verify credential management app is removed and
  'testAlias' is uninstalled.

Bug: 165641221
Test: Manual Testing
      atest com.android.keychain.KeyChainServiceRoboTest

Change-Id: I00b7df27a92f6ee4f74546f892c83290fead1112
2020-12-01 20:04:04 +00:00
Pavel Grafov
b73e15249b Add DPM.hasKeyPair()
The method returns true if a private key and a user certifiate are
present in KeyChain under this alias.

Bug: 160457441
Test: atest com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testKeyManagement
Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testDelegatedCertInstallerDirectly
Test: atest android.admin.cts.DevicePolicyManagerTest
Change-Id: I15ca6190db1ef4dbf0caabe9d46008d92f758df5
2020-12-01 12:57:45 +00:00
Alex Johnston
0a6b674c91 Merge "Add credential management app to platform" 2020-11-27 11:20:27 +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
Treehugger Robot
31952c368f Merge "Keystore 2.0 SPI: Fix installation of legacy Keystore provider" am: 5408268606 am: 3a1c6e6b9e am: 2d6247e322
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1503891

Change-Id: I144782a0ccbdfb7b78ce63db9eec8a71e058de9f
2020-11-27 01:41:49 +00:00
Janis Danisevskis
9fb5607114 Keystore 2.0 SPI: Fix installation of legacy Keystore provider
Priviously we installed the legacy keystore SPI by the name
KeyStore.AndroidKeyStore and set an alias to
KeyStore.AndroidKeyStoreLegacy. This conflicted with with the Keystore
provider which also registers as KeyStore.AndroidKeyStore.
This patch registers the old provider only by the name
KeyStore.AndroidKeyStore.

Test: CtsLibcoreTestCases:libcore.java.security.ProviderTest#test_Provider_Properties
      Also, the device boots.
Change-Id: I38a248a996839f397bdcae30fd1b03a883209df2
2020-11-23 21:59:22 -08:00
Treehugger Robot
a6c32cb0e0 Merge "Fix Broken test: libcore.java.security.ProviderTest#test_Provider_Properties" am: c778d8e747 am: 796b8b3687 am: ee01197b77 am: b6b0dee076
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1503571

Change-Id: I5607d564f17134d746431a7e0f024844030a5753
2020-11-18 22:53:50 +00:00
Treehugger Robot
c778d8e747 Merge "Fix Broken test: libcore.java.security.ProviderTest#test_Provider_Properties" 2020-11-18 21:39:54 +00:00
Janis Danisevskis
fc02edb5f5 Fix Broken test: libcore.java.security.ProviderTest#test_Provider_Properties
Test: CtsLibcoreTestCases:libcore.java.security.ProviderTest#test_Provider_Properties
Bug: 173480441
Change-Id: I188cd778a25d221991280eb461a7ec052503790c
2020-11-18 11:49:15 -08:00
Treehugger Robot
2b09184302 Merge changes from topic "ks2_with_keymint" am: ab1b8a7a20 am: 2694b808b2 am: 2eb526a1ae am: 0a9852039f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1475676

Change-Id: Ib18ef9e5fd4203f41af95d916c7e02436f44abfa
2020-11-18 17:28:18 +00:00
Janis Danisevskis
bc119dfb2b Keystore 2.0 SPI: Use KeyMint AIDL types.
We are now using KeyMint types for KeyParameter and SecurityLevel.

Test: None
Change-Id: I3db72c17a9cb999a0248df4c37588dfc2ad84f74
2020-11-17 17:45:08 -08:00
Janis Danisevskis
148e99707e resolve merge conflicts of 07bfeb3630 to master
Test: I solemnly swear I tested this conflict resolution.
Bug: None
Change-Id: Iab84b0fa8c708845aecd13dd45c242147829fd8b
2020-11-16 19:28:35 -08:00
Janis Danisevskis
4392c6977c Keystore 2.0 SPI: Install legacy Keystore provider as AndroidKeyStoreLegacy
With this patch we install the old Keystore provider as
AndroidKeyStoreLegacy when the Keystore 2.0 provider is installed as
AndroidKeyStore. This allows system components to keep using the old
keystore while we can run CTS tests against the new provider.

The tests are still mostly failing at this point. Installing the new SPI
can be enabled by setting the property
ro.android.security.keystore2.enable=true

Bug: 159476414
Test: This enables running CTS tests against Keystore 2.0.
Change-Id: I9731d9783ccf8f2705a5ca7335e00c8f4c8debba
2020-11-13 19:55:41 -08:00
Janis Danisevskis
940e05164e Keystore 2.0 SPI: Evolve the generator SPI.
We delegate the generation of self signed certificates to the KeyMint
backend. Also we use the KeyParamter AIDL type instead of
KeymasterArguments to construct parameter lists.

Bug: 159476414
Test: None
Change-Id: I441a4d4df4ef04e3da8aeaff3274c609d549c979
2020-11-13 19:55:41 -08:00
Janis Danisevskis
e6495d774b Keystore 2.0 SPI: Evolve Factory SPI
We no longer need to get the key characteristics from the Keystore
daemon to construct the KeyInfo for a key. Also we have to extract the
key info from the KeyParameter AIDL type rather than from the hand
written KeymasterArguments.

This patch also exposes the correct security level for a key through
KeyInfo.

Bug: 159476414
Test: None
Change-Id: I86a85e481e19fdadfed38a42aeac4ffe5f8b83fa
2020-11-13 19:55:40 -08:00
Janis Danisevskis
38ab78f0a0 Keystore 2.0 SPI: AndroidKeyStoreProvider loads keys from Keystore 2.0
This patch adjusts the AndroidKeyStoreProvider to register all services
with the correct packages names. And the utility functions load key
using the correct Keystore 2.0 methods.

Bug: 159476414
Test: None
Change-Id: I9268fd66d28e89e188e85991bcf90c7f19809232
2020-11-13 19:55:40 -08:00
Janis Danisevskis
4545933da5 Keystore 2.0 SPI: Evolve the Crypto SPI.
This patch evolves the Crypto SPI to use the new Keystore 2.0 shim.
The main changes are:
 * The SPI uses the AIDL defined KeyParameter instead of
   KeymasterArguments.
 * Operations are created directly from the KeystoreSecurityLevel that
   is part of the AndroidKeyStoreKey object.

Also this patch deletes the DeletatingX509Certificate class. This is no
longer needed, because public key operations are no longer performed by
Keystore 2.0. We can delegate public certificate operations simply by
wrapping such certificates into public keys that are understood by other
providers, such as BouncyCastle.

Bug: 159476414
Test: None
Change-Id: Ice874a8121d80bf788da059b4e8420c7dd799d81
2020-11-13 19:55:40 -08:00
Janis Danisevskis
4be5005c05 Keystore 2.0 SPI: KeyParameter utilities.
The wire type for key parameters is now generated from AIDL rather than
the hand written parcelable KeymasterArguments. So we need some of the
utilities for creating key parameters that the latter provided.
We also nicked some utility function from KeymasterUtils.

Bug: 159476414
Test: None
Change-Id: I12c674b6a00dd3abbed4972d80ceb766a73881e8
2020-11-13 19:55:40 -08:00
Janis Danisevskis
4ba9a09bdd Keystore 2.0 SPI: Update the chunked streamer.
This patch makes the chunked streamer observe the simplified
Keystore 2.0 operation interface. Keystore is now required to consume
all supplied data or reject data outright if too much (more than 32KiB)
is supplied in a single transaction. This allows for a simplified
streamer logic and a simplified interface. We also no longer send
entropy to Keystore. This will be handled by the Keystore 2.0 daemon.

Test: None
Bug: 159476414
Change-Id: Ie75d10fd5d5ac0da60e23e35467d0a7873230dea
2020-11-13 19:55:40 -08:00
Janis Danisevskis
27ee56c021 Keystore 2.0 SPI: KeyStoreCryptoOperationUtils
Keystore 2.0 does no longer report an error code if an operation
requires user authorization. Instead this is indicated by sending us
an operation challenge. In that case we have to check if the
authorization can possibly succeed. We changed the utility class by
adding a predicate function that checks exactly that, and we handle
other errors separately instead of having one exception handling path
that does all.

Test: None
Bug: 159476414
Change-Id: I9a373cf8f0a0b181df54c26fe314d71b6835bb97
2020-11-13 19:55:39 -08:00
Janis Danisevskis
e5795a90db Keystore 2.0 SPI: KeyStoreKeys adopt Keystore 2.0
KeyStoreKeys can now be constructed from key entry metadata and key
descriptors as defined by the new Keystore AIDL spec.
AndroidKeystorePublicKey can now create the private key proxy.
KeyStoreKeys also cache the key characteristic, which should drastically
reduce the frequency by which the SPI has to call into the Keystore 2.0
daemon.

Test: None
Bug: 159476414
Change-Id: Ia0a7841582621897760be49d39dd5442b70b3aa0
2020-11-13 19:55:39 -08:00
Janis Danisevskis
ebd964a086 Keystore 2.0: Shim around the basic functionality of Keystore 2.0
This patch adds a shim around the Keystore 2.0 AIDL spec. The new shim
is modularized like the AIDL spec into the base Keystore module
Keystore2, the security level specific interface KeystoreSecurityLevel,
and the operation specific interface KeystoreOperation.

Other system maintenance specific interfaces have yet to be added.

Bug: 159476414
Bug: 171305684
Test: None
Change-Id: I070f73739e4b37ce10568939ac666e40b14a52a8
2020-11-13 19:55:39 -08:00
Janis Danisevskis
f88d3a4b27 Keystore 2.0 SPI: Duplicate Keystore SPI to android.security.keystore2 package
This patch copies the relevant portion of the Keystore SPI to the new
package name android.security.keystore2. The purpose of this is to
illustrate the evolution from the existing Keystore SPI to the
Keystore 2.0 SPI while keeping the existing Keystore SPI intact.
Reviewers are advised to check the equivalence of this code to the
corresponding files in
    android/security/keystore (<-- no 2 here).
Subsequent patches can them be reviewed as evolution towards the new SPI
rather than completely new code.

Test: None. When the evolution is complete, Keystore CTS tests can be
used to check for regressions.
Bug: 159476414

Change-Id: I21a01a679e789868ce820b5f73221e616a456a61
2020-11-13 11:01:47 -08:00
Treehugger Robot
072951e482 Merge "Keystore 2.0 SPI: Add forEach for int arrays to ArrayUtils" am: 47e0d9e30b am: 7afe866370 am: 5427aff46d am: 0486a1aba6
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1470092

Change-Id: I507b40fa2104d85c4f0aab78fef259a7b0988468
2020-11-12 19:44:17 +00:00
Treehugger Robot
47e0d9e30b Merge "Keystore 2.0 SPI: Add forEach for int arrays to ArrayUtils" 2020-11-12 17:57:42 +00:00
Janis Danisevskis
cbab0d133b Keystore 2.0 SPI: Add forEach for int arrays to ArrayUtils
This patch adds a forEach function for int arrays to
android.security.keystore.ArrayUtils. A utility function with the
intendet use in Keystore 2.0 Key paramter handling.

Test: None
Change-Id: I2c02b300ee68fcd548c128deb0266fe603226807
2020-11-12 08:03:25 -08:00
Janis Danisevskis
94f9ea72a0 Merge "Keystore 2.0 SPI: Update KeyInfo and KeyGenParameterSpec" am: 17f24b5799 am: 7d49ae705e am: 7662e81e98 am: b90d33bd18
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1470091

Change-Id: I5728741cdd66f9b6ba6f39310c796cb8b12758e5
2020-11-12 00:55:08 +00:00
Janis Danisevskis
17f24b5799 Merge "Keystore 2.0 SPI: Update KeyInfo and KeyGenParameterSpec" 2020-11-11 23:10:13 +00:00
Janis Danisevskis
c5bdd77f1a Keystore 2.0 SPI: Update KeyInfo and KeyGenParameterSpec
This patch adds set/getSecurityLevel to KeyInfo and KeyGenParameterSpec
and it deprecates the superseded function isInSecureHardware.

It also deprecates the system API set/getUid and replaces it with the
more generic set/getNamespace.

Test: None
Change-Id: Id2f54596510954862b5077a935f3daf07211f29c
2020-11-11 07:53:54 -08:00