1078 Commits

Author SHA1 Message Date
Eran Messeri
fda47fb1ca KeyStore: Surface RKP failures
On systems that rely solely on remotely-provisioned keys (RKP),
the attestation keys may run out or be unavailable for attesting
a newly-generated key. This could happen when:
* the device first connects to the Internet
* The device had all the keys used and:
 ** It hadn't yet completed obtaining new ones.
 ** The RKP server declines to issue new keys.

In these cases, the caller must be informed that their key generation
request failed (likely temporarily), and that they should retry it.

The retry policy returned tells the caller when to re-try.
Bug: 227306369
Test: atest android.keystore.cts.KeyStoreExceptionTest

Change-Id: Ief30a3ab97da95b68d172e725c38acbefab92fa9
2022-03-30 15:03:16 +01:00
John Wu
7128e88488 Merge "Revert "Update AndroidKeyStoreMaintenance framework API"" am: b8ebf69571 am: 2e64dda571 am: 289609bdb3
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2017095

Change-Id: Iddeb472553b4713fc51613effa6e565188119bf8
2022-03-23 17:20:24 +00:00
John Wu
23571e176a Revert "Update AndroidKeyStoreMaintenance framework API"
This reverts commit bb5c49e5108262f42dceb61620c6c530dd529579.

Reason for revert: functionality removed

Change-Id: Ib04a1690b8892af53ca6449e3a38e10490baf9da
2022-03-14 15:20:38 -07:00
Treehugger Robot
6de84e117e Merge "Curve 25519: Support use via Android Keystore provider (part 1)" am: bab26cc607 am: 050d61f1b3 am: 8249f4a893
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2015496

Change-Id: I666cce14a67b605c9cc64991ee07755b4d85173a
2022-03-09 22:51:22 +00:00
Eran Messeri
3875cf7e0c Curve 25519: Support use via Android Keystore provider (part 1)
Ensure that the user gets an accurate error message when they try to
generate Curve 25519 keys according to JEP 324
(https://openjdk.java.net/jeps/324).

Android Keystore requires every key to have a name, so it is not
possible to generate a key using NamedParameterSpec only (with a
KeyPairGenerator).

Support this and throw an exception to the caller indicating how they
_can_ generate keys with this curve.

Bug: 222440855
Bug: 195309719
Bug: 194359292
Test: atest android.keystore.cts.KeyFactoryTest android.keystore.cts.Curve25519Test
Test: atest CtsLibcoreTestCases:libcore.java.security.ProviderTest
Change-Id: I5aa163f177507906c6482d079eb6cb55d93accf7
2022-03-09 13:07:52 +00:00
Eran Messeri
259ca1ec61 Do not register Curve25519 as a key factory directly
Do not register Curve 25519 algorithms as key factories, until we fix
the registration to be in compliance with JEP 324.

Bug: 222440855
Bug: 222194540
Test: atest android.keystore.cts.Curve25519Test android.keystore.cts.KeyFactoryTest#testAlgorithmList CtsLibcoreTestCases:libcore.java.security.ProviderTest#test_Provider_getServices
Merged-In: Ibd53070a890955affaff5e4e7213892afd423db7
Change-Id: I11b3574aeff54b3eb8bf496c4c14aa1338629ce5
2022-03-09 11:03:12 +00:00
Eran Messeri
7dece49438 Do not register Curve25519 as a key factory directly
Do not register Curve 25519 algorithms as key factories, until we fix
the registration to be in compliance with JEP 324.

Bug: 222440855
Bug: 222194540
Test: atest android.keystore.cts.Curve25519Test android.keystore.cts.KeyFactoryTest#testAlgorithmList CtsLibcoreTestCases:libcore.java.security.ProviderTest#test_Provider_getServices
Change-Id: Ibd53070a890955affaff5e4e7213892afd423db7
2022-03-07 18:33:56 +00:00
Treehugger Robot
452fdef120 Merge "Keystore: Support Curve 25519 in the SPI layer" am: 76cee808e2 am: 7b17653639 am: cb479e0827
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1984970

Change-Id: Ib9fc34d05614192e4762b9e7934738e074728fca
2022-03-01 21:07:01 +00:00
Eran Messeri
5deebdd570 Keystore: Support Curve 25519 in the SPI layer
Add support for Curve 25519 in the public API.
This requires upgrading the keymint dependency to V2.

Note that this CL only passes tha tags to Keystore,
but does not yet let the caller use the generated keys
because of missing Conscrypt classes.

Bug: 194359292
Test: atest android.keystore.cts.Curve25519Test
Change-Id: I15223abec34b72c857e26fcc47d8ecf08c1f8c8d
2022-03-01 15:00:19 +00:00
Rubin Xu
c96b611d14 KeyChain: always unbind service
Context.unbindService() should always be called even if the
previous bindService() call returns false. Otherwise the service
might be left dangling.

Bug: 211582968
Test: None
Change-Id: Ic1705096254afa12993d8992303432896bfecd57
2022-02-24 15:44:55 +00:00
Treehugger Robot
a383db6684 Merge "Add myself to Keystore owners" am: ba28bb57ad am: 6de68cc45a am: 43341a7841 am: c93730dadf
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1976666

Change-Id: I24615c1283356bfe733d790c5868d7f364198ead
2022-02-09 12:49:28 +00:00
Treehugger Robot
ba28bb57ad Merge "Add myself to Keystore owners" 2022-02-09 11:41:25 +00:00
Eran Messeri
ee3c80f288 Merge "Keystore: Surface service error message" am: af771eb908 am: b3612e019f am: e53fd593b5 am: a2b165989b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1969819

Change-Id: I0f3d9721af9aa47bf7f7ae6a419d79ec3547210b
2022-02-08 19:50:28 +00:00
Eran Messeri
5eedf5a373 Keystore: Surface service error message
Surface the service-specific error message. To avoid API changes, the
error message is surfaced in the toString / getMessage methods.

Test: atest android.security.keystore.KeyStoreExceptionTest
Bug: 217593122
Change-Id: Id4090564b46db9b3b10ea390390f6683f7314463
2022-02-08 13:26:57 +00:00
Eran Messeri
9422f2076d Add myself to Keystore owners
Update the Keystore owners file:
* Remove Rob Barnes
* Add myself.

This will remove the dependency on US-based reviewers for all Keystore
Java CLs.
Non-trivial CLs, CLs that are not strictly in the Java layer, or both,
would still be sent to the right US-based reviewer.

Bug: N/A
Test: N/A
Change-Id: Id8931516b90be4b97e684cb8d7f9de8d71643db4
2022-02-08 11:45:23 +00:00
Eran Messeri
a31689bc37 KeyStore: Verbose error reporting
Report KeyStore/KeyMint error messages via public API.

This lets developers find out:
* Whether an error is transient or not.
* Whether a failure is due to a system error
(system configuration/state/capabilities), or a key-related error.
* Whether user authentication is required to use the key.

Test: atest CtsKeystorePerformanceTestCases CtsKeystoreTestCases
Bug: 197890905
Merged-In: I776d9e9cc01a9dc3542a63000ee0709847760963
Change-Id: Ica0c93fdd4b89255ee0a03a9b9b948202777d4d4
2022-02-02 22:11:44 +00:00
John Wu
14ce8bc120 Framework support for AndroidKeyStore migration
- Add a new boolean attribute `inheritKeyStoreKeys` to allow apps to
  indicate whether they want keys to be transferred to the updated app
- Call the appropriate KeyStore method to migrate keys from the old
  namespace to the new one
- Clear keys owned by the previous app ID if it is removed

Test: atest SharedUserMigrationTest#testKeyMigration
Test: atest AndroidPackageTest
Bug: 179284822
Change-Id: I321b85b88c150f17709a2270c0cbaf368ca035cc
2022-01-21 01:36:43 +00:00
John Wu
1c632f80e8 Merge "Update AndroidKeyStoreMaintenance framework API" am: 8c34efd29a am: be201a0ed5 am: 7d7010dcf8 am: 253c91192f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1950401

Change-Id: I8b3f892d829decc104ef2a732af5fbbfa3e08fa8
2022-01-19 01:13:31 +00:00
John Wu
bb5c49e510 Update AndroidKeyStoreMaintenance framework API
Update the Java framework accordingly with the underlying keystore2
changes for key migration.

Test: atest SharedUserMigrationTest#testDataMigration (in internal)
Bug: 211665859
Change-Id: I26c817dffdf2e50a43373114a63242644ee7e712
2022-01-14 15:35:07 -08:00
Seth Moore
ea9d0dd167 Merge "Add missing </pre> to Javadoc" am: 076fb5e987 am: d084c0202a am: 33e0b830dc am: a665f6bd93
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1905490

Change-Id: I5965b31cb15b2cf30596939d4c5cb70e51b332b9
2022-01-07 17:34:34 +00:00
Seth Moore
076fb5e987 Merge "Add missing </pre> to Javadoc" 2022-01-07 16:40:32 +00:00
Eran Messeri
5da05ee3ed KeyStore: Verbose error reporting
Report KeyStore/KeyMint error messages via public API.

This lets developers find out:
* Whether an error is transient or not.
* Whether a failure is due to a system error
(system configuration/state/capabilities), or a key-related error.
* Whether user authentication is required to use the key.

Test: atest CtsKeystorePerformanceTestCases CtsKeystoreTestCases
Bug: 197890905
Change-Id: I776d9e9cc01a9dc3542a63000ee0709847760963
2021-12-14 15:22:35 +00:00
Seth Moore
c78e369c4c Fix incorrect SID matching for bio prompts
The default value for canUnlockViaBiometrics, which determines if we
are able to show a bio prompt, is true. However, if there are 0
biometric authenticator IDs, then it's impossible for the user to
satisfy a bio prompt. In this case, we should set canUnlockViaBiometrics
to false.

The loop that is normally expected to invert canUnlockViaBiometrics was
never run in the case of 0 bio authenticator ids, so we mistakenly
let the crypto init operation succeed when we should have blocked it.

Bug: 188864794
Test: Manual, using sample app that displays a biometric prompt.
Change-Id: Ib95b0564aa098157718b8d4a45b11baa69dad71b
2021-12-01 14:59:24 -08:00
Shawn Willden
f3aac252f7 Add missing </pre> to Javadoc
Change-Id: Iedf0f7f85fecbc2ee274a108887c77add62dcb31
2021-11-29 19:20:19 +00:00
Treehugger Robot
70e7dd44b4 Merge changes Ic6e60752,I2b8b7e74
* changes:
  Test for contract between AndroidKeyStoreKey hash and equals.
  Keystore 2.0 SPI: Fix contract between equals and hashCode 2
2021-10-08 15:31:03 +00:00
Janis Danisevskis
2eef723ced Merge "Keystore 2.0 SPI: Fix NullPointerException in setKeyEntry." 2021-10-08 14:57:47 +00:00
Janis Danisevskis
5fe5f2def0 Test for contract between AndroidKeyStoreKey hash and equals.
Test: atest KeystoreTests
Bug: 196118021

Merged-In: Ic6e60752faa986debe3d325f54242cffaa03b336
Change-Id: Ic6e60752faa986debe3d325f54242cffaa03b336
2021-10-07 16:39:39 -07:00
Janis Danisevskis
e36fe6bf46 Keystore 2.0 SPI: Fix contract between equals and hashCode 2
This fixes the contract between equals and hashCode in
AndroidKeystorePublicKey. The previous fix made only a reference
comparisson between certificate blobs. In this patch java.util.Arrays is
used to compare and compute the hash of the array.

Bug: 196118021
Test: See following CL.
Change-Id: I2b8b7e740fb377de39fd21f763e15cb00024b2fc
2021-10-07 16:24:46 -07:00
Janis Danisevskis
4ff6274fa7 Keystore 2.0 SPI: Fix NullPointerException in setKeyEntry.
Fix a NullPointerException when trying to insert SecretKey that already
exists.

Bug: 202146009
Test: atest android.keystore.cts.AndroidKeyStoreTest#testKeyStore_SetKeyEntry_ReplacedWithSameGeneratedSecretKey
Change-Id: If3a4bd6677ab3173c5c1a7c921ba567b7981662b
2021-10-07 08:24:42 -07:00
Treehugger Robot
6939d8d665 Merge "Fix key alias string comparison" am: 15d1ab2fdd
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1802873

Change-Id: I20bb1006d93233dfe7dd73c12a0eaadee229e3d5
2021-08-24 17:52:12 +00:00
Seth Moore
11cce949b6 Fix key alias string comparison
The code was doing a reference compare, not object value comparison,
resulting in failures in the KeyStore setEntry API.

Test: CtsKeystoreTestCases:android.keystore.cts.AndroidKeyStoreTest
Fixes: 197138784
Change-Id: I2c5e47283eed5694951869e9ea3853364ddef9d1
2021-08-19 12:44:08 -07:00
Max Bires
f5e0c3e257 Merge "Fixing a condition that can cause deadlock" am: 773a378390
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1797475

Change-Id: Id20947de8b039d4a468127a446266c30fbbd1659
2021-08-18 02:06:57 +00:00
Max Bires
773a378390 Merge "Fixing a condition that can cause deadlock" 2021-08-18 01:45:15 +00:00
Max Bires
c9be198afe Fixing a condition that can cause deadlock
Callbacks on ServiceConnection happen on the main UI thread for an
application. Since the thread that calls bindService then immediately
blocks to wait for the service to be connected, this will cause a
deadlock if key operations are happening on the main UI thread.

This bug has likely not been detected yet since key operations are not
supposed to be performed on the main UI thread, however it was uncovered
in a similar application during other testing. This fix ensures the
ServiceConnection object's callbacks will be triggered from a separate
thread from the calling thread.

Bug: 196571032
Test: Apps that run key operations on the UI thread don't hang.
Change-Id: I630a0ef2560a8ebd962de54c65e3d6277133a1cb
Merged-In: I630a0ef2560a8ebd962de54c65e3d6277133a1cb
2021-08-17 06:43:46 +00:00
Xin Li
773a9dfba7 Merge sc-dev-plus-aosp-without-vendor@7634622
Merged-In: I661f5fb6b1f3f6ce4322fab8fa84a7ab364c65b1
Change-Id: I16482b494ff4821016aabbb646e495d616c630ac
2021-08-14 07:23:27 +00:00
Janis Danisevskis
7bdc12d5f3 Keystore 2.0 SPI: Fix contract between equals and hashCode
This fixes the contract between equals and hashCode in
AndroidKeystoreKey and AndroidKeystorePublicKey.

Bug: 196118021
Test: N/A
Change-Id: I3f7e6d72d53c7051c13daeb5aa6ce1abf4eb0cc5
2021-08-12 12:29:02 -07:00
Janis Danisevskis
f5985b0838 Keystore 2.0 SPI: Add EC_CURVE tag on key generation.
The KeyMint spec requires the specification of the EC_CURVE tag when
generating an EC key. This patch adds the correct curve tag parameter to
the parameter list.

Test: CtsVerifier Protected confirmation test.
Bug: 192908276
Merged-In: I2e7dd4868abda85d244e73592ff12d688f5c21fc
Change-Id: I2e7dd4868abda85d244e73592ff12d688f5c21fc
2021-07-08 10:00:22 -07:00
TreeHugger Robot
7f85119309 Merge "Keystore 2.0 SPI: Add EC_CURVE tag on key generation." into sc-dev am: 214d129500
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15225383

Change-Id: I8a65bc5a7724830ecb5a0df28c35c4f1fa806a0d
2021-07-08 16:32:51 +00:00
Janis Danisevskis
5a3c880534 Keystore 2.0 SPI: Add EC_CURVE tag on key generation.
The KeyMint spec requires the specification of the EC_CURVE tag when
generating an EC key. This patch adds the correct curve tag parameter to
the parameter list.

Test: CtsVerifier Protected confirmation test.
Bug: 192908276
Change-Id: I2e7dd4868abda85d244e73592ff12d688f5c21fc
2021-07-08 08:48:46 -07:00
Max Bires
40f4b669c1 Merge "Fixing the race condition in GenerateRkpKey" am: 5023e1fb96 am: 7fc084200f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1736160

Change-Id: I274163d45ee758a5a520c78dd82d0babba9a7d1d
2021-07-01 14:57:34 +00:00
Max Bires
5023e1fb96 Merge "Fixing the race condition in GenerateRkpKey" 2021-07-01 14:20:37 +00:00
Janis Danisevskis
84e082d3da Keystore 2.0: Renaming the vpnstore interface.
Renaming the vpnstore interface to legacykeystore.

Bug: 190229655
Test: TBD
Merged-In: Icd304ef621f0de52d6ebc415a0628d63f827fbcd
Change-Id: Icd304ef621f0de52d6ebc415a0628d63f827fbcd
2021-06-30 12:29:29 -07:00
Janis Danisevskis
191b206410 Keystore 2.0: Renaming the vpnstore interface.
Renaming the vpnstore interface to legacykeystore.

Bug: 191373871
Test: TBD
Change-Id: Icd304ef621f0de52d6ebc415a0628d63f827fbcd
2021-06-30 09:45:54 -07:00
Victor Chang
49a5bb208c Update the java doc of AndroidKeyStoreProvider#getKeyStoreOperationHandle to support Signature object
Bug: 191661889
Test: m droid
Merged-In: Ie65dcfe96f3bb00cc9af4d49e4e1d1f57bde438a
Change-Id: Ie65dcfe96f3bb00cc9af4d49e4e1d1f57bde438a
(cherry picked from commit 507a653a6e35fd3bf5b9a5927e4c17307593bcae)
2021-06-21 17:38:21 +01:00
Victor Chang
507a653a6e Update the java doc of AndroidKeyStoreProvider#getKeyStoreOperationHandle to support Signature object
Test: m droid
Change-Id: Ie65dcfe96f3bb00cc9af4d49e4e1d1f57bde438a
2021-06-16 15:57:44 +01:00
Max Bires
5e43390b9b Fixing the race condition in GenerateRkpKey
This file was written on the assumption that bindService was
synchronous, which it isn't. This change adds a CountDownLatch to force
the class to wait for the binding to finish. If the relevant key
generation service is not present on the system, then this
functionality will just silently be skipped over.

Bug: 190222116
Test: atest RemoteProvisionerUnitTests
Change-Id: Ie34997a08aa743642c66a20c4b756cd47bff4af1
Merged-In: Ie34997a08aa743642c66a20c4b756cd47bff4af1
2021-06-13 21:50:36 +00:00
Max Bires
17f9f3e8b5 Merge "Revert "Fixing the race condition in GenerateRkpKey"" 2021-06-09 20:35:23 +00:00
Max Bires
b2a11d35e5 Revert "Fixing the race condition in GenerateRkpKey"
This reverts commit 0f62195535139026d35e831ccf329f8204781430.

Reason for revert: Breaks non-RKP systems

Bug: 190222116
Change-Id: I7e31a3045caa7b8bb0e34c8d1e266c104a627324
Merged-In: I7e31a3045caa7b8bb0e34c8d1e266c104a627324
2021-06-09 20:21:41 +00:00
Max Bires
8092f01ce1 Merge "Revert "Fixing the race condition in GenerateRkpKey"" into sc-dev 2021-06-09 20:21:15 +00:00
Max Bires
56318a568f Revert "Fixing the race condition in GenerateRkpKey"
This reverts commit d05498b9d8d30ca69eaafe920c5915ee472058eb.

Reason for revert: Bugged on non-RKP systems.

Bug: 190222116
Change-Id: Ie7d17d4251c381c1bae6a76cd9b0246c551f8042
2021-06-09 19:54:48 +00:00