Commit graph

1019 commits

Author SHA1 Message Date
Pete Bentley
340b1bc382 Merge "Skip no-longer-supported signature/padding combinations." 2023-03-08 13:17:27 +00:00
Tri Vo
59473cad8b Merge "keystore2: Remove remote provisioning logic" 2023-03-07 22:19:08 +00:00
Pete Bentley
1f59474e62 Skip no-longer-supported signature/padding combinations.
Bug: 270297780
Test: atest keystore2_crypto_test
Change-Id: Ia47569e3ca1d78365b5e8f85c46e6e9da4b4fb18
2023-03-07 14:36:41 +00:00
Tri Vo
a1634bb643 keystore2: Remove remote provisioning logic
keystore2 will always be using RKPD instead.

Bug: 261214100
Test: m keystore2 keystore2_test
Change-Id: Ibd27a8ae7d502e0fab2f728aa49175d28a6780b0
2023-03-03 15:30:01 -08:00
Charisee
c3f67eab25 Change request for Rust v1.68.0
error: useless conversion to the same type: `std::ops::Range<i32>`
  --> system/security/keystore2/tests/keystore2_client_operation_tests.rs:47:5
   |
47 | /     (0..max_ops)
48 | |         .into_iter()
   | |____________________^ help: consider removing `.into_iter()`: `(0..max_ops)`

bug: 270756468
Test: test_compiler.py
Change-Id: Ib661ecaf1f30a1e165b6fb3bde4d0fc93758891e
2023-03-03 07:34:04 +00:00
Treehugger Robot
968539e9c7 Merge "Adding tests to update cert-chain or public key of the non existing keystore entry using updateSubcomponent API." 2023-02-28 16:33:38 +00:00
Treehugger Robot
f6ab3a152b Merge "Remove unused code in Keystore2's vintf library" 2023-02-28 14:19:16 +00:00
Treehugger Robot
8d2f97c705 Merge "Adding a test to list aliases of large number of Keystore entries with long aliases." 2023-02-28 13:17:11 +00:00
Pawan Wagh
467f8980bd Merge "Adding AIDL fuzzer for AuthorizationManager" 2023-02-21 18:41:45 +00:00
Eran Messeri
5e93cfa77c Remove unused code in Keystore2's vintf library
The methods get_hal_names and get_hal_names_and_versions were not used.
Remove them.

Bug: 249096262
Test: m keystore2
Change-Id: I9967286cfad86071a914d959385519890d1adb30
2023-02-21 15:04:21 +00:00
Rajesh Nyamagoud
2249b2d250 Adding tests to update cert-chain or public key of the non existing
keystore entry using `updateSubcomponent` API.

1. Try to update only the certificate-chain of the non existing
   asymmetric key, test should succeed in creating a new keystore
   entry with the given certificate-chain only.

2. Try to update only the public key of the non existing asymmetric
   key, test should fail to update non-existing key certificate with
   error response `KEY_NOT_FOUND`.

Bug: 267183713
Test: atest keystore2_client_tests
Change-Id: Iaf5c9b0e29eb59873493b330c0f1d36ec8337f88
2023-02-20 23:56:53 +00:00
Rajesh Nyamagoud
4eaf0616d4 Adding a test to list aliases of large number of Keystore entries with
long aliases.

Create 100 keystore entries with aliases of length 6000 chars and
list the aliases using `listEntries` API. Test should be able to
list all the Keystore entries aliases and match them with aliases
of the entries created by test. Test should successfully verify all
the aliases of Keystore entries it created.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I16d35dc1f053f8b60745e62185009397b987dfe7
2023-02-20 22:38:13 +00:00
Treehugger Robot
67d9a6e3a2 Merge "Adding key agreement [AGREE_KEY] tests." 2023-02-20 11:43:58 +00:00
Shaquille Johnson
4830a81a85 Merge "Update ks_err on Keystore security code" 2023-02-19 00:16:23 +00:00
Tri Vo
5ed5f7c915 Merge changes from topic "b/269460851"
* changes:
  keystore2: Fix timeout handling
  keystore2_test: Join all test threads
2023-02-16 21:00:14 +00:00
Tri Vo
0e5fe2c7a8 keystore2: Fix timeout handling
In earlier revisions of the code, RKPD client would wait indefinitely.
This model had an invariant guaranteeing that receiver end of the
oneshot channel is always present when sender is invoked.

With introduction of timeouts, this invariant no longer holds. The
receiver can time out and be cleaned up. This patch makes SafeSender
tolerate this scenario.

Also, attempt to cancelGetKey() if corresponding request for a key times
out.

Bug: 269460851
Test: keystore2_test
Change-Id: I33d80af52b5ab15c2113a140a8bd2beedfe2ff4f
2023-02-15 22:18:44 -08:00
Tri Vo
215f12e0e2 keystore2_test: Join all test threads
This catches bugs that could happen after main test thread completes.

Bug: 269460851
Test: keystore2_test
Change-Id: I0d723b04a95e83da8aaceb0748f5af0a9eab90e2
2023-02-15 16:23:43 -08:00
Treehugger Robot
1c55bace0f Merge "Make RKPD default" 2023-02-13 21:38:30 +00:00
Pawan Wagh
238f835120 Adding AIDL fuzzer for AuthorizationManager
Bug: 232439428
Test: m authorization_service_fuzzer && adb sync && adb shell /data/fuzz/arm64/authorization_service_fuzzer/authorization_service_fuzzer
Change-Id: I867dcb5da9dac98d6cb324dead3742ddd608506b
2023-02-11 01:15:11 +00:00
Shaquille Johnson
e8b152a05b Update ks_err on Keystore security code
Test: Run and tested using `atest keystore2_test` for Rust test and CTS test with `atest CtsKeystoreTestCases`
Change-Id: Id53c870260e9757227f6cb5d57787796f60fe9d5
2023-02-09 15:19:26 +00:00
Rajesh Nyamagoud
af05056d58 Adding key agreement [AGREE_KEY] tests.
1. Verify that key agreement works with curves `P_224, P_256, P_384 and
   P_521`. Test should generate KeyMint EC key with purpose `AGREE_KEY`
   and OpenSSL EC key with same curve as KeyMint key. Perform local ECDH
   between these two keys and verify that derived secrets are the same.

2. Verify that key agreement works with CURVE_25519 curve.
   Test should generate KeyMint EC-CURVE_25519 key with purpose
   `AGREE_KEY` and OpenSSL EC key with same curve as KeyMint key.
   Perform local ECDH between these two keys and verify that derived
   secrets are the same.

3. Verify that key agreement doesn't work when EC keys are using
   different curves. Generate a KeyMine EC key using P_256 curve and
   OpenSSL EC key using CURVE_25519. Try to perform a local ECDH between
   these keys and operation should fail with `INVALID_ARGUMENT` error
   code.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I3da7af09908d6828ad617c833469bbd786b09e8f
2023-02-07 01:57:33 +00:00
Seth Moore
484010a1e4 Handle errors codes from rkpd getKey operations
Now we'll get error codes bubbled up from rkpd (via the remote
provisioning system service). Convert those errors into meaningful
keystore errors so clients can act on them.

Test: keystore2_tests
Test: RkpdAppIntegrationTests
Test: CtsKeystoreTestCases:android.keystore.cts.KeyStoreExceptionTest
Bug: 264888027
Change-Id: Ib574fe4da0443f32f95f8579c4a308d36fe4b46f
2023-02-06 10:31:54 -08:00
Tri Vo
3b89df9c2e Merge "keystore2_test: Enable stress test" 2023-02-04 03:25:57 +00:00
Tri Vo
fc1794914d Leave RKPD in a "good" state after tests
Test: keystore2_test
Change-Id: Ic3ed6f468065f56120305ca62ec93ac85bd5f892
2023-02-03 15:51:09 -08:00
Tri Vo
c29a65f02e keystore2_test: Enable stress test
Bug: 266607003
Test: keystore2_test
Change-Id: Id3667a181429a077eea493963aaa6d2e6d6c38ef
2023-02-03 14:32:50 -08:00
Eran Messeri
313890b173 Merge "Adding tests to validate below keystore2 service APIs - updateSubcomponent - getSecurityLevel" 2023-02-01 12:45:18 +00:00
Treehugger Robot
c55cb57adc Merge "Adding tests to validate deleteKey APIs." 2023-02-01 12:39:25 +00:00
Eran Messeri
ecbf8a4a6d Merge "Adding tests to verify grant and ungrant APIs." 2023-02-01 11:23:59 +00:00
Rajesh Nyamagoud
7ef5ec50f2 Adding tests to validate below keystore2 service APIs
- updateSubcomponent
 - getSecurityLevel

1. Generate asymmetric key and update its public certificate and
   certificate chain. Test should load the updated key and verify
   whether its certificate and cert-chain are updated successfully.

2. Try to update non-existing key's public cert and cert-chain. Test
   should fail to update with error response code `KEY_NOT_FOUND`.

3. Try to update the certificate in a grantee context which doesn't
   possess UPDATE access permission for the specified key. Test should
   fail to update with error response code `PERMISSION_DENIED`. Test
   should also verify that the gratee context which possess the `UPDATE`
   access permission should be able to update the certificate
   successfully.

4. Try to get `TRUSTED_ENVIRONMENT` security level instance. Test should
   successfully get the instance.

5. Try to get `SOFTWARE` security level instance. Test should fail with
   error response code `HARDWARE_TYPE_UNAVAILABLE`.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I92635c6c1fafde4e1cd4f5654f0164e45c145961
2023-02-01 02:10:23 +00:00
Rajesh Nyamagoud
8df4cc356d Adding tests to verify grant and ungrant APIs.
- Grant a key to the user with DELETE access. Vefify that grantee can
  delete the granted key successfully.

- Grant a key to the user. In grantee context try to grant this key to
  another user. Test should fail with `PERMISSION_DENIED` error
  response to grant a key to another user from grantee context for
  designated key.

- Try to grant a key to the user with `GRANT` access. Test should fail with
  `PERMISSION_DENIED` error response code. Keystore2 system must
  not allow `GRANT` permission to be granted.

- Try to grant a non-existing key to the user. Test should fail to grant
  a key with `KEY_NOT_FOUND` error response.

- Grant a key to the user and ungrant it before the grantee can use the
  granted key. In grantee context while trying to use the granted key
  `KEY_NOT_FOUND` error response is expected.

- Try to ungrant a non-existing key. Test should fail with
  `KEY_NOT_FOUND` error response.

- Grant a key to multiple users. All grantees should be able to access
  the key and use it for crypto operation.

- Grante a key to two users with GET_INFO|DELETE permissions. In one of
  the grantee contexts delete the key. In another grantee context when
  it tries to access the granted key, it should fail with
  `KEY_NOT_FOUND` error response.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I0bd6faeeaff2fa436413604dfbad67ea65dc8597
2023-02-01 01:31:38 +00:00
Tri Vo
654de1d0c9 Merge "keystore2: Add stress test for getting RKPD key" 2023-01-31 22:42:13 +00:00
Tri Vo
f02e4d6af2 Make RKPD default
Also, remove usage of
"persist.device_config.remote_key_provisioning_native.enable_rkpd".

Test: keystore2_test
Change-Id: I3e6673f1af45adf7f7075e61523621ac9377f414
2023-01-31 13:59:39 -08:00
Seth Moore
e5f44a081d Merge "Rename OUT_OF_KEYS -> OUT_OF_KEYS_TRANSIENT" 2023-01-30 17:11:37 +00:00
Tri Vo
ca8707344b Merge "keystore2: Add test for RKPD key upgrade" 2023-01-27 18:20:49 +00:00
Tri Vo
02f0fa46a5 keystore2: Add stress test for getting RKPD key
Bug: 266607003
Test: keystore2_test
Change-Id: Iaf73c26c6d5c9430e06b4c34ed720158f6b81f00
2023-01-26 15:40:44 -08:00
Tri Vo
30268daa50 keystore2: Add test for RKPD key upgrade
Also require root permisions so that the test can talk to KeyMint.

Test: keystore2_test
Change-Id: I265c2a05fdf0393adb81576e895009ed07dd2d46
2023-01-26 15:40:18 -08:00
Charisee Chiw
568c1e4356 Merge "Change requests for Rust update v1.66.0" 2023-01-26 23:26:49 +00:00
Tri Vo
229fe25f67 Merge "keystore2: Add timeout to RKPD get key call" 2023-01-25 17:58:42 +00:00
Charisee
03e0084a39 Change requests for Rust update v1.66.0
error: casting to the same type is unnecessary

Test: ./build.py --lto=thin
Bug: 263153841
Change-Id: Ibf820a90c36c46155d07176b3194b460904140c9
2023-01-25 01:49:59 +00:00
Tri Vo
437d014ae1 keystore2: Add timeout to RKPD get key call
Also replace libfutures with libtokio, as the former doesn't have
support for timeouts.

Bug: 264921138
Test: keystore2_test
Change-Id: I97c9749e93b2d001afe5d17bda8c665f884b0e05
2023-01-24 10:36:11 -08:00
Seth Moore
5dac386370 Use rkpd if the build flag is set
Add a second, read-only build flag indicating that rkpd is enabled.
This flag is not server controlled, and thus cannot be disabled.

Platforms, such as cuttlefish, are RKP only, and are using a new
version of keymint that is not compatible with the old
RemoteProvisioner. Therefore, we must ensure that the configuration
is fixed and cannot be turned off.

Bug: 266482839
Test: RemoteProvisionerUnitTests
Test: keystore2_client_tests
Test: RkpdAppUnitTests
Change-Id: Id61c704a8beca2ad7b5b9bee9433cc4e11964299
2023-01-24 09:10:49 -08:00
Seth Moore
d7ad856c18 Rename OUT_OF_KEYS -> OUT_OF_KEYS_TRANSIENT
More OUT_OF_KEYS errors are coming, and the old "OUT_OF_KEYS" is a
bucket for all transient errors. Rename the enum to better indicate
this.

Also rename OUT_OF_KEYS_REQUIRES_UPGRADE to
OUT_OF_KEYS_REQUIRES_SECURITY_PATCH. This better indicates that
system is potentially vulnerable (rather than simply running old code).

Test: keystore2_test
Change-Id: I1f2d803529c3e43592536016a9261e2294b42bb5
2023-01-24 08:45:47 -08:00
Eran Messeri
4c6a596077 Merge "Limit the number of key descriptors sent back" 2023-01-24 16:24:36 +00:00
Eran Messeri
6e1213f5f5 Limit the number of key descriptors sent back
In case the number of key descriptors and their content exceeds the
binder transaction size limit, only return a subset that does fit.

This is a temporary fix - long-term fix is to introduce new API that
lets the caller specify the range of aliases to be fetched.

Bug: 222287335
Test: Manual: Generate 100 keys with a 6k characters name each.
Change-Id: I5e8543a25dd9f1bb504fbc23f35779da0a0153b0
2023-01-24 14:23:25 +00:00
Tri Vo
a529b14ee3 Merge changes I2f3003a7,I0f66cb6a
* changes:
  keystore2: Test case for storing upgraded RKPD key
  Use separate RKPD key IDs in test cases
2023-01-23 22:35:33 +00:00
Tri Vo
bac3b5273a keystore2: Test case for storing upgraded RKPD key
Bug: 261214100
Test: keystore2_test
Change-Id: I2f3003a73b41330f2973ff1503b642a2cb0c6118
2023-01-23 13:10:24 -08:00
Tri Vo
4b1cd82404 Use separate RKPD key IDs in test cases
This avoids races between test cases for RKPD keys.

Test: keystore2_test
Change-Id: I0f66cb6a2d2b99dfeffb812233eb33d4112b9aaf
2023-01-23 13:09:56 -08:00
Dave McCloskey
435b8f8dff Update the documentation for onLockScreenEvent to be more comprehensive.
Change-Id: Ia66c14a1d03ace0d8be075af3bc5c6673bba09b1
2023-01-19 22:58:44 +00:00
Treehugger Robot
1cd35f0006 Merge "Import macro directly rather than using #[macro_use]." 2023-01-19 13:22:05 +00:00
Andrew Walbran
870a01a9b2 Import macro directly rather than using #[macro_use].
`extern crate` makes it harder to keep track of dependencies, so we
prefer to import macros explicitly instead.

Bug: 261037227
Test: m keystore2_unsafe_fuzzer
Change-Id: I0ec95e9343a05c8f61c2cdca3ba601bae97c9187
2023-01-19 11:30:49 +00:00
Treehugger Robot
a09b2e109a Merge "Revert "Disable cert validation in tests until b/263254184 is fixed"" 2023-01-19 02:29:11 +00:00
Rajesh Nyamagoud
e159fccc1d Adding tests to validate deleteKey APIs.
- Generate a key and delete it using keystore2 service `deleteKey` API.
  Test should delete the key successfully.

- Try to delete a non-existing key with keystore2 service `deleteKey`
  API. Test should fail to delete a key with an error response code
  `KEY_NOT_FOUND`.

- Try to delete a key with domain `BLOB` using keystore2 service
  `deleteKey` API. Test should fail to delete a key with an error code
  `INVALID_ARGUMENT`.

- Generate a key with domain `BLOB`. Delete the generated key using
  underlying security level `deleteKey` API. Test should successfully
  delete key blob.

- Try to delete a key with domain `BLOB` without providing key-blob.
  Test should fail to delete a key with an error code
  `INVALID_ARGUMENT`.

- Try to delete a key with domain `APP` using underlying security level
  `deleteKey` API. Test should fail to delete with an error code
  `INVALID_ARGUMENT`.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I8233ef79b33daff868ad9767903169dc21f4906e
2023-01-18 00:43:30 +00:00
Greg Kaiser
ac300b50f3 Merge "Replaced size_t by int to handle the errors." 2023-01-17 20:35:25 +00:00
David Drysdale
f5a15eeec4 Merge "Make keystore2 unit tests less brittle" 2023-01-16 05:42:21 +00:00
Daniel Angell
69ad6cdad1 Revert "Disable cert validation in tests until b/263254184 is fixed"
This reverts commit c16d6cd77f.

Reason for revert: Root cause has been resolved

Change-Id: Ief83cceb607fa72ca4602588e18d3d06779d027c
2023-01-13 21:23:27 +00:00
Seth Moore
613a1fd729 Clean up rkpd client in keystore2
1. Remove helper functions for binders. Just do the work in the binder
   function (reducing layers).
2. Stop returning Result from new_native_binder. Those functions have
   no failure paths.
3. Add some debug logs

Test: keytore2_test
Change-Id: I99aeeefec1e39891a124e1eb02f5a19f7188ca76
2023-01-13 00:13:48 +00:00
Rajesh Nyamagoud
cebd79d55b Replaced size_t by int to handle the errors.
Bug: 194359114
Test: atest keystore2_client_tests
Change-Id: Ibb1215322a50400d493f875a6e427af8f0d29818
2023-01-12 16:22:00 +00:00
David Drysdale
38f2ca31cf Make keystore2 unit tests less brittle
- Don't specify a BlockMode for RSA operations.
- Don't set ATTESTATION_APPLICATION_ID from the client; keystore will
  fill this in itself whenever an ATTESTATION_CHALLENGE is present.
- Rename `has_trusty_keymint` to `has_default_keymint`, as it has
  nothing to do with Trusty.
- Allow wider ranges of error codes.

Bug: 197891150
Test: keystore2_client_tests
Change-Id: I17d4eff724c554cbd89dfcc0a4e3ec7beb4e08db
2023-01-12 12:56:03 +00:00
Seth Moore
f896d36baa Fix hanging unit test
Since these tests perform actual binder interactions with rkpd, we
need to spin up the binder thread pool so that the callbacks have
a thread to run on.

Test: keystore2_test
Change-Id: If0f67661f915798722d2bf7f9c5072887048cae8
2023-01-11 10:44:06 -08:00
Seth Moore
a55428ecf8 The RKPD store upgraded key interface is now async
Update keystore2 to pass a callback for receiving success/failure from
the storeUpgradedKeyAsync API.

Test: keystore2_test
Bug: 262748535
Change-Id: Ifbae48b697267d05baa83d7d1e42569c7db694b5
2023-01-10 13:07:54 -08:00
Seth Moore
a882c96d61 Create helper type for oneshot::Sender
Move boilerplate for the sender code into a helper type. This moves
all the mutex unwrapping and optional checking into one spot, cleaning
up the call sites.

Test: keystore2_test
Change-Id: I517e091047d11d4ecca73026e5ee288878658fa3
2023-01-10 12:48:01 -08:00
Eran Messeri
6e0f462354 Merge "Tests to verify importWrappedKey functionality." 2023-01-09 17:00:32 +00:00
Treehugger Robot
f3c7e05d60 Merge "Disable cert validation in tests until b/263254184 is fixed" 2023-01-05 17:00:36 +00:00
Rajesh Nyamagoud
c946cc419c Tests to verify importWrappedKey functionality.
- Build ASN.1 DER-encoded wrapped key material `SecureKeyWrapper`.
  Import the wrapped key material. Test should create DER-encoded
  wrapped key material and import the secure key successfully.
  Imported key should be used perform crypto operation successfully.

- Build ASN.1 DER-encoded wrapped key material `SecureKeyWrapper` with
  invalid AAD. Try to import the wrapped key material. Test should
  create DER-encoded wrapped key material. Test should fail to import
  the secure key with error code `VERIFICATION_FAILED`.

- Import wrapped AES key and use it for crypto operations. Test should
  import wrapped key and  user it for performing crypto operations
  successfully.

- Import a key wihtout WRAP_KEY purpose and try to use it as wrapping
  key while importing wrapped key. Test should fail to import wrapped
  key with an error code `INCOMPATIBLE_PURPOSE`.

- Try to import wrapped key using non-existing wrapping key in Android
  keystore. Test should fail to import wrapped key with an error code
  `KEY_NOT_FOUND`.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ic9ed03b6f945bd41c4873f97a84c1658c284e918
2023-01-04 22:42:18 +00:00
Seth Moore
c16d6cd77f Disable cert validation in tests until b/263254184 is fixed
Test: Presubmit
Bug: 263254184
Change-Id: I157718ec8ae5bbc2e8fd5e4a61b252ed964b4e74
2023-01-04 12:02:38 -08:00
Treehugger Robot
26d4222e92 Merge "Remove use of size_t in Rust code" 2023-01-04 00:28:05 +00:00
Tri Vo
b5e43d19b6 keystore2: Support for RKPD attestation keys
Bug: 261214100
Test: TODO
Change-Id: I2234fb01179aec212811b864d68e5f94772c2538
2022-12-22 01:01:27 -08:00
Tri Vo
e8f0444d59 keystore2: Add utils to fetch keys from RKPD
Bug: 261214100
Test: keystore2_test
Change-Id: I87ec83dd700b4e3e24c65ce0650cd5643000a390
2022-12-22 01:01:18 -08:00
Jeff Vander Stoep
76c0f2874b Remove use of size_t in Rust code
Needed to upgrade bindgen from 0.59.0 to 0.63.0. Resolves the
following errors:

//#[path = "../../../src/options.rs"]
//mod options;

error[E0432]: unresolved import `keystore2_apc_compat_bindgen::size_t`
  --> system/security/keystore2/apc_compat/apc_compat.rs:22:82
   |
22 |     abortUserConfirmation, closeUserConfirmationService, promptUserConfirmation, size_t,
   |
      ^^^^^^ no `size_t` in the root

error[E0412]: cannot find type `size_t` in this scope
  --> system/security/keystore2/apc_compat/apc_compat.rs:79:23
   |
79 |     tbs_message_size: size_t,
   |                       ^^^^^^ not found in this scope

error[E0412]: cannot find type `size_t` in this scope
  --> system/security/keystore2/apc_compat/apc_compat.rs:81:30
   |
81 |     confirmation_token_size: size_t,
   |                              ^^^^^^ not found in this scope

error[E0412]: cannot find type `size_t` in this scope
   --> system/security/keystore2/apc_compat/apc_compat.rs:181:37
    |
181 |                 extra_data.len() as size_t,
    |                                     ^^^^^^ not found in this scope

Test: Treehugger
Change-Id: I848f481627f3c14caa6252eee6b5dd40d2f58eed
2022-12-07 11:57:25 +01:00
Seth Moore
003e381103 Merge "Revert "Keystore 2.0 km_compat: Cuttlefish does not return a vendor patch level."" 2022-12-06 21:52:06 +00:00
Shaquille Johnson
615ee36224 Add java_defaults to Android.bp and update default
This makes a java defaults and catches a few
places where the files were not updated
to use the default latest library version

Test: Run and tested using `atest keystore2_test` for Rust test and CTS test with `atest CtsKeystoreTestCases`
Change-Id: I2b67e482f341405e2aa23d53535e8b3d0b41cfab
2022-12-06 17:45:42 +00:00
Eran Messeri
637259c81f ID attestation: Pass 2nd IMEI to KeyMint
Pass the 2nd IMEI tag, if provided, to KeyMint.

Bug: 244732345
Test: atest android.keystore.cts.DeviceOwnerKeyManagementTest
Change-Id: I52aea1ba59c4337ba0003784abfc178ab0efee55
2022-12-05 13:18:01 +00:00
Treehugger Robot
4d6fb44a08 Merge "Add log message when keystore can't find IRPC" 2022-12-01 20:33:42 +00:00
Seth Moore
4685db34ff Add log message when keystore can't find IRPC
On older devices, keystore will not publish the remoteprovisioning
service. Add a log message so it's obvious when this happens instead
of silently swallowing errors.

Test: local build + logcat
Change-Id: Ic15f4574da86031a56f6d7c8a8339d364d9cc7b9
2022-12-01 10:04:09 -08:00
Shaquille Johnson
aec2eca4ca Update logs to use ks_err in rust code
Test: Run and tested using `atest keystore2_test` for Rust test and CTS test with `atest CtsKeystoreTestCases`
Change-Id: Ic8e62f1c5d19c6203945fefeb18b066bf8a32ed7
2022-11-30 17:52:38 +00:00
Chris Wailes
dabb6fe865 Fix warnings from rustc 1.65.0
Bug: 250026064
Test: m rust
Change-Id: I90d1ecde006d16967879cec4138e804ad246698d
2022-11-16 16:07:59 -08:00
Eran Messeri
7002b154de Merge "Route ECDH key import requests to Soft-KeyMint." 2022-11-15 14:49:00 +00:00
Seth Moore
cd6e918fbd Add dependencies on newly-split RKP HAL
Bug: 254112961
Test: vts_treble_vintf_vendor_test
Merged-In: I5506757aaebdf37d42bf7ac0a68e83f2d3c12049
Change-Id: I5506757aaebdf37d42bf7ac0a68e83f2d3c12049
2022-11-09 10:52:39 -08:00
Seth Moore
4c0d4b0a8c Add case for new "second IMEI" key tag
Bug: 244732345
Test: android.keystore.cts.DeviceOwnerKeyManagementTest
Merged-In: I243f83fb56a2397ec2e223bab10751417b49aed9
Change-Id: I243f83fb56a2397ec2e223bab10751417b49aed9
2022-11-09 10:52:32 -08:00
Eran Messeri
44e3fc2b3f Merge "Tests to verify importKey with Asymmetric and symmetric keys." 2022-11-04 15:59:14 +00:00
Rajesh Nyamagoud
2a285631e1 Route ECDH key import requests to Soft-KeyMint.
Since KeyMaster doesn't support ECDH, route all key ECDH key import
requests to Soft-KeyMint.

Bug: 216434270
Test: atest
CtsKeystoreWycheproofTestCases:com.google.security.wycheproof.JsonEcdhTest;
atest CtsKeystoreTestCases:android.keystore.cts.KeyAgreementTest#testGenerateSecret_withImportedKey

Change-Id: Ia4da2b319e2fc2b4fc6cceab7c3b66c6713dc3a0
2022-11-03 19:31:27 +00:00
Shaquille Johnson
32bd2673a9 Changed RP logs to only error when RKP only
This error occurs when there are no attestation keys to give
and is not a true error. In meeting it was decided that the
RKP keys being empty is fine and the only time to warn when
we are on an RKP only device.

Test: Run and tested using `atest keystore2_test` for Rust test and CTS test with `atest CtsKeystoreTestCases`
Bug: 241924261
Change-Id: I234493522ac59babad1a5dd315d7070eab9da3b9
2022-10-31 19:38:21 +00:00
Rajesh Nyamagoud
b8402b6d91 Tests to verify importKey with Asymmetric and symmetric keys.
- Test to import a RSA key and validate imported key parameters.
  Perform an operation using imported key. Test should be able to
  import the key and complete the operation successfully.

- Test to import a RSA key without specifying key size and public
  expenent. Determine key-size and public exponent from key material.
  Validate imported key parameters. Perform an operation using imported
  key. Test should be able to import the key and complete the operation
  successfully.

- Test to import a RSA key with incorrect key-size as import key
  parameter. Test should fail to import a key with an error code
  `IMPORT_PARAMETER_MISMATCH`.

- Test to import a RSA key with incorrect public exponent as import key
  parameter. Test should fail to import a key with an error code
  `IMPORT_PARAMETER_MISMATCH`.

- Test to import a RSA key with multiple pursposes [SIGN and ATTEST_KEY]
  as import key parameters. Test should fail to import a key with an
  error code `INCOMPATIBLE_PURPOSE`.

- Test to import a EC key without specifying curve. Determine ec-curve
  from key material. Validate imported key parameters. Perform an
  operation using imported key. Test should be able to import the key
  and complete the operation successfully.

- Test to import a EC key with incorrect ec-curve as import key
  parameter. Test should fail to import a key with an error code
  `IMPORT_PARAMETER_MISMATCH`.

- Test to import a AES, 3DES and HMAC keys. Validate imported keys
  parameters. Perform operations using imported keys. Test should
  be able to import the key and complete the operation successfully.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ib90c05b93929b8b0e1d4cb9542f5b8493a116c39
2022-10-28 01:33:16 +00:00
Rajesh Nyamagoud
2d532d9b3d Updated to return INVALID_ARGUMENT response code instead of
`SYSTEM_ERROR` while loading attest key.

While loading attest-key if it fails to find its blob or cert
then `INVALID_ARGUMENT` error reponse is returned instead of
`SYSTEM_ERROR`.
Bug: 254703846
Test: atest CtsKeystoreTestCases; atest keystore2_client_tests

Change-Id: Ie0d75c3bd99057b4c775e9c8f9dd91385cd6db81
2022-10-21 19:28:46 +00:00
Rajesh Nyamagoud
4d48337ffd Added tests using attest keys for signing RSA and EC keys.
- Generate EC/RSA attestation keys and use it for signing RSA and EC
  keys. Test should be able to use the attest keys for signing the
  generated keys successfully.

- Generate EC-CURVE_25519 attestation key and use it for signing RSA
  key. Test should be able to generate RSA key with EC-CURVE_25519 key
  as attestation key.

- Generate an asymmetric key which doesn't possess ATTEST_KEY purpose.
  Use this key for attesting asymmetric key. It should fail to generate
  key with incompatible purpose error.

- Generate a symmetric key. Try to use this symmetric key as attestation
  key while generating asymmetric key. It should fail to generate a key
  with system error.

- Try to generate symmetric key with valid attestation key,
  attstation-challenge and attestation-app-id. Test should generate a
  key without attestation record.

- Try to generate RSA/EC attestation keys with multiple purpose. Test
  should fail to generate keys with incompatible purpose error code.

- Generate an attestation key and try to use it for signing a key
  without providing attestation challenge. Test should fail with missing
  attestation challenge error.

Note: These tests are executed on devices where
`android.hardware.keystore.app_attest_key` feature is enabled, otherwise
tests are skipped.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I4228dc5fe5e207995472c3425d5f2696ef95249f
2022-10-20 16:09:02 +00:00
Shaquille Johnson
fd317c72d9 Merge "Changing code to have better error logging" 2022-10-20 15:20:33 +00:00
Tri Vo
4158567f46 Bump KM AIDL API to version 3
Test: m
Change-Id: If52436b0768557522e459ee0049e5cb4fcbf00cd
2022-10-18 12:21:55 -07:00
Shaquille Johnson
9da2e1cd3d Changing code to have better error logging
This changes the error logs to show the file and line number instead of
naming a specific a function where the error originated. In some cases
the function name is kept where it made sense for readibility of the
logs.

Test: Run and tested using `atest keystore2_test` for Rust test and CTS test with `atest CtsKeystoreTestCases`
Bug: 241924261
Change-Id: I2ea970dd83e18033506555f2726c716626697cdf
2022-10-18 15:08:41 +00:00
Tri Vo
113a1c95fb keystore2_test: Update to IRPC v3
Bug: 235265072
Test: m keystore2_test
Change-Id: Id9e9196670e2e18c9d5f509d444c41eafbfc47eb
2022-10-17 15:02:51 -07:00
Treehugger Robot
d45bc5b0bd Merge "Changes made in keystore2_client_tests to avoid test timeout issues." 2022-10-13 12:01:14 +00:00
Shaquille Johnson
1f1d5152b1 Update the Rust test to reflect the new Debug
Debug implementation was changed in https://android-review.googlesource.com/c/platform/frameworks/native/+/2239178.
This changes how enums made with declare_binder_enum are displayed by default. The updated strings print the Debug
implementation for the enum and check the values against that.

Test: Tested using `atest keystore2_test`
Bug: 252968848
Change-Id: I86a124432f83116b87c9b40c023851fac4030fb8
2022-10-11 14:44:35 +01:00
Rajesh Nyamagoud
c7d064d59f Changes made in keystore2_client_tests to avoid test timeout issues.
Added macros to generate test code for RSA and EC keys use cases.
Test cases are split to run them in distict test cases to avoid
timeout issues. Limiting RSA and EC each test cases to generate only
one key and perform an operation.

Bug: 242356276
Test: atest keystore2_client_tests
Change-Id: I2841734f329afb0005727da26cc5b9ff532b9e73
2022-10-05 18:57:51 +00:00
Rajesh Nyamagoud
dc4b612793 Changes to adapt ConfirmationUi AIDL interface.
apc_compat module updated to support confirmationui AIDL service without
altering the existing behavior with HIDL service. Higher precedence is
given to AIDL service.

Bug: b/205760172
Test: Run confirmation UI test using CTS Verifier
Change-Id: I0fac9b3a7ea0d4d63cb76111ccd95d52b10a047e
2022-09-29 18:02:05 +00:00
Shaquille Johnson
f0606d4b2d Merge "Run rustfmt and add rustfmt.toml to directory" 2022-09-20 09:14:08 +00:00
Shaquille Johnson
04a34cf10a Run rustfmt and add rustfmt.toml to directory
Runs the formatting command and adds a directory formatter
to the keystore2 for standardized directory formatting.

Test: Formatting change
Change-Id: I56230f57dcfd3e48c7c9e39e1362bb67ebc7862e
2022-09-19 11:23:31 +00:00
Charisee
28e6f0b066 Change request for Rust v1.64.0
note from clippy: https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain

Please check change for correctness.

bug: 243420629
Test: test_compiler.py
Change-Id: If64daae01c3bf6d83b80f624c1f5603fae171a2d
2022-09-15 23:49:23 +00:00
Tri Vo
735f9cb643 Use latest Keystore2 AIDL API
Test: m
Change-Id: I19510de8dcf384fc30bb8d2b1bf9116de5bd7eb1
2022-09-06 17:27:28 -07:00
Tri Vo
a99ac4e96e Merge "Use latest KM AIDL API" 2022-09-06 20:58:36 +00:00
Tri Vo
d4f0a180dc Use latest KM AIDL API
Test: m keystore2_legacy_blobs_test
Change-Id: Ia76f720ffdacdfe8496e716890df50586e67753e
2022-09-02 18:03:05 -07:00
Eran Messeri
6d9481b7f0 Merge "Run rustfmt on directory" 2022-09-02 14:25:29 +00:00
Shaquille Johnson
bcab601c03 Run rustfmt on directory
Runs rustfmt on keystore2 to standardize formatting changes.

Test: Formatting change so no test needed
Change-Id: I24208f8fe91e6b15108eef0ff5264a3f086497e4
2022-09-02 13:17:54 +00:00
Treehugger Robot
ffcc8fd2ef Merge "Added HMAC key generation tests." 2022-09-02 11:14:01 +00:00
Treehugger Robot
5af917188a Merge "Adding a test to simulate OPERATION_BUSY error from keystore." 2022-09-02 10:00:04 +00:00
Rajesh Nyamagoud
01d4cde74a Adding a test to simulate OPERATION_BUSY error from keystore.
The test tries to create a race condition: It creates an operation
and starts two threads, each trying to use the operation repeatedly
until it gets  `OPERATION_BUSY`  or finishes successfully.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ib3549d6bcad4e24bf621960f0f399481bf2da7c7
2022-08-31 18:27:03 +00:00
Rajesh Nyamagoud
4c6193c217 Added HMAC key generation tests.
- Generate HMAC keys with digest modes [SHA1, SHA_2_224, SHA_2_256,
  SHA_2_384, SHA_2_512], should be able to create operations using
  generated keys successfully.

- Try to generate HAMC keys with key size in the range 0..513. For
  invalid key size, key generation should fail with an error code
  `UNSUPPORTED_KEY_SIZE`.

- Generate HMAC keys with min-mac-lengths in the range 0..257. For
  invalid min-mac-length, key generation should fail with an error
  code `UNSUPPORTED_MIN_MAC_LENGTH`.

- Try to generate HMAC key with multiple digest modes, key generation
  should fail with an error code `UNSUPPORTED_DIGEST`.

- Try to generate HMAC key without providing digest mode, key
  generation should fail with an error code `UNSUPPORTED_DIGEST`.

- Try to generate HMAC key with digest mode `NONE`, key
  generation should fail with an error code `UNSUPPORTED_DIGEST`.

- Generate HMAC key with min-mac-length of 128 bits and digests
  [SHA1, SHA-2-224], try to create operations with mac-len greater than
  digest lengths. Test should fail to create an operation with an error
  code `UNSUPPORTED_MAC_LENGTH`.

- Generate HMAC key with min-mac-length of 128 bits and digests
  [SHA1, SHA-2-224], try to create operations with mac-len less than
  min-mac-length. Test should fail to create an operation with an error
  code `INVALID_MAC_LENGTH`.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I594c9718b0f6a67f2655faca4bf100abf2ced3a3
2022-08-31 18:22:08 +00:00
Ryan Prichard
9cf7f66c51 Add missing assert.h and functional includes
Bug: http://b/175635923
Test: treehugger
Change-Id: Ib062da6888e560fed3abd389dad3dfbf4cb4f3fa
2022-08-30 17:35:03 -07:00
Paul Crowley
f71fe8a1e5 Use ro.keystore.boot_level_key.strategy
Choose the strategy for generating the boot level  key from a property,
if present, instead of looking at KM versions.

Bug: 241241178
Test: set property on Cuttlefish, check logs for strategy used.
Change-Id: I2c7a6fb2c6471ab4a7cb7f650791930f41068bfa
2022-08-24 10:03:46 -07:00
Paul Crowley
e1e1723781 Refactor L0 key handling ahead of fix
Bug: 241241178
Test: treehugger
Change-Id: I3b9c6dcda0a9b8d57d6d4e8be8f9eddf59d3b89f
2022-08-24 10:03:46 -07:00
Treehugger Robot
65f8bf69c5 Merge "Added keystore2_unsafe_fuzzer" 2022-08-22 05:42:53 +00:00
Treehugger Robot
767a2e3f7f Merge "Update source for Rust 1.63.0" am: e3973b49eb
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2184738

Change-Id: I1e3bc3bbb2b22475d103f8944a2fdd85363da811
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-12 19:40:58 +00:00
Treehugger Robot
e3973b49eb Merge "Update source for Rust 1.63.0" 2022-08-12 19:13:34 +00:00
Chris Wailes
263de9f8d7 Update source for Rust 1.63.0
Test: m rust
Bug: 241303140
Change-Id: I3b4d8c1c3101941258e366279bfd2a4a3ab1b948
2022-08-12 10:36:10 -07:00
Eran Messeri
f73b2d0470 Merge "Updated listEntries API response code with invalid domain field." am: 6ec53e3489
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2166105

Change-Id: I85422389dfa79e167cd1258dfa4ef5fba5565104
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-12 14:09:57 +00:00
Eran Messeri
6ec53e3489 Merge "Updated listEntries API response code with invalid domain field." 2022-08-12 13:20:09 +00:00
Treehugger Robot
af75992ff6 Merge "Added tests using 3DES algorithm." am: 99fe2aeaec
Original change: https://android-review.googlesource.com/c/platform/system/security/+/1967149

Change-Id: I1d3622e893b7f99d6aa058b6d172d461d32660e3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-12 11:34:28 +00:00
Rajesh Nyamagoud
c3523bacff Added tests using 3DES algorithm.
- Generate 3DES keys with block modes [ECB, CBC] and padding modes
  [NONE, PKCS7]. Should be able to create operations successfully
  with these generated keys.

- Try to generate a key and create an operation with invalid inputs, it
  should fail with proper error codes
  - with unsupported key size
  - with unsupported padding mode
  - with padding mode NONE and input text whose length isn't a
    multiple of the DES block size
  - with unsupported blockmode

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ida98fd2e6f9b7ba84b8beba9ea979d5aeb2240ee
2022-08-12 02:09:46 +00:00
Rajesh Nyamagoud
16198a3ca9 Updated listEntries API response code with invalid domain field.
Updated to return `INVALID_ARGUMENT` instead of `PERMISSION_DENIED`
response code when domain is other than `APP` or `SELINUX`.

Added tests to validate `listEntries` API with valid domains `APP and
SELINUX` and invalid domains like `BLOB`.

Bug: 239719010
Test: atest CtsKeystoreTestCases; atest keystore2_client_tests;
Change-Id: I7d10c13342ca5719682e371e428fa42f992ba07d
2022-08-12 00:03:57 +00:00
Treehugger Robot
727b510c18 Merge "Restructured keystore2 client tests." am: a00741ceb6
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2176242

Change-Id: Ic950a2695f904ac436817fea368779a30e14fc34
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-10 17:16:45 +00:00
Rajesh Nyamagoud
609846ad49 Restructured keystore2 client tests.
Separated out the tests based on functionalities and created a separate
modules without modifying the existing test cases.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ifc93b3ce69817469d1d5f01844c623f5209e2b62
2022-08-04 23:52:30 +00:00
Devendra Singhi
31863b1ab5 Added keystore2_unsafe_fuzzer
Test: ./keystore2_unsafe_fuzzer
Bug: 240524901

Change-Id: Ibb6d2c649f982bc1b5fc8d4a259087e53bac79aa
2022-08-04 14:33:29 +05:30
Treehugger Robot
3615d1fe47 Merge changes Ibf1b8460,I16843932 am: 32cf305fc5
Original change: https://android-review.googlesource.com/c/platform/system/security/+/1941336

Change-Id: I19df4d4b5221e399010b9cab337834005e6fa5da
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-03 17:40:04 +00:00
Treehugger Robot
32cf305fc5 Merge changes Ibf1b8460,I16843932
* changes:
  Adding tests using AES algorithm.
  Adding generate key tests using RSA algorithm.
2022-08-03 17:32:48 +00:00
Rajesh Nyamagoud
4740993bf1 Adding tests using AES algorithm.
- Generate AES keys with block modes [ECB, CBC] and padding modes [NONE,
  PKCS7]. Should be able to create operations successfully with these
  generated keys.

- Generate AES keys with block modes [CTR, GCM] and padding modes [NONE,
  PKCS7]. Should be able to create operations successfully with padding
  mode NONE. With PKCS7 padding mode creation of an operation should
  fail with incompatible padding mode.

- Try to generate a key and create an operation with invalid inputs, it
  should fail with proper error codes.
  - with unsupported key size
  - with GCM block mode without providing min-mac-length
  - with multiple block modes
  - with multiple padding modes
  - with incompatible padding modes
  - with incompatible block modes
  - with missing mac-length
  - with invalid mac-length
  - with unsupported mac-length
  - With AES-CBC-PKCS7 key without `CALLER_NONCE` authorization, Try to
    set nonce while creating an operation.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ibf1b8460317b4c99d9060d5889c8b3778a80ca5b
2022-07-22 18:58:41 +00:00
Rajesh Nyamagoud
11912eaf78 Adding generate key tests using RSA algorithm.
- Generate RSA signing keys with combinations of digest modes [NONE,
  MD5, SHA1, SHA_2_224, SHA_2_256, SHA_2_384, SHA_2_512] and padding
  modes [NONE, RSA_PKCS1_1_5_SIGN, RSA_PSS]. Should be able to
  create operations using these keys except in below cases.
   - when padding mode is RSA_PSS and digest mode is NONE
   - when padding mode is NONE and digest is other than NONE.

- Generate RSA encrypt/decrypt keys with OAEP padding mode, combinations
  of digests [MD5, SHA1, SHA_2_224, SHA_2_256, SHA_2_384, SHA_2_512] and
  mgf-digests [MD5, SHA1, SHA_2_224, SHA_2_256, SHA_2_384, SHA_2_512].
  Should be able to create operations with these generated keys
  successfully.

- Generate RSA encrypt/decrypt keys with combinations of padding modes
  [NONE, RSA_PKCS1_1_5_ENCRYPT, RSA_OAEP], digests [NONE, MD5, SHA1,
  SHA_2_224, SHA_2_256, SHA_2_384, SHA_2_512]. Should be able to create
  operations with these generated keys successfully except in below case
   - with padding mode RSA_OAEP and digest mode NONE an error is
     expected.

- Generate RSA encrypt/decrypt keys with padding modes [NONE,
  RSA_PKCS1_1_5_ENCRYPT, RSA_OAEP] and without digests. Should be able
  to create operations with these generated keys successfully.

- Generate RSA keys without padding modes and digest modes. Creation of
  an operation should fail with unsupported padding mode error.

- Tests to validate failure of generating RSA keys with incompatible
  purpose, unsupported purpose, unsupported padding mode, unsupported
  digest and unsupported key sizes.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I16843932cc170d0e820208f558587aacf13b9272
2022-07-22 17:54:16 +00:00
Andrew Scull
9cb85479f3 Merge "Allow virt APEX to use diced and open_dice_cbor" am: af43ae73f9
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2151395

Change-Id: I6c44929e72db1bf1d65cfcfa43d9bbcd20d08f89
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-19 09:51:20 +00:00
Andrew Scull
af43ae73f9 Merge "Allow virt APEX to use diced and open_dice_cbor" 2022-07-19 09:27:41 +00:00
Vikram Gaur
6d4c60eaaa Merge "Support upgrade key for software-emulated keys." am: 65467fba1f
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2155233

Change-Id: I231789a61c60244bb925a53e90bc7a82d1284135
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-18 21:32:17 +00:00
Vikram Gaur
65467fba1f Merge "Support upgrade key for software-emulated keys." 2022-07-18 21:11:36 +00:00
Eran Messeri
794cf95437 Merge "Adding tests using Domain::KEY_ID." am: 75aa039b3d
Original change: https://android-review.googlesource.com/c/platform/system/security/+/1924617

Change-Id: I3843abf5ab1d0d0c284593486d1c0217a88618a5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-18 11:38:32 +00:00
Eran Messeri
75aa039b3d Merge "Adding tests using Domain::KEY_ID." 2022-07-18 11:11:16 +00:00
Vikram Gaur
856b1cdc9c Support upgrade key for software-emulated keys.
Currently software-emulated keys do not have any update mechanism. Any
software key that is created in previous versions cannot be used once
the device is upgraded. With this change, keys now can be upgraded and
used by the latest keystore.

Change-Id: Ic791baeedd7775df7eafca405440e645b19ec2bc
Test: TreeHugger
Fixes: 223376764
2022-07-17 23:53:20 +00:00
Rajesh Nyamagoud
54f6590f60 Adding tests using Domain::KEY_ID.
- Test to verify that Domain::KEY_ID is not allowed for generating
   a key. Try to generate a key with domain as KEY_ID and expect an
   error.

 - Test to find key entry with domain as KEY_ID.
   Generate a key and load it with domain as KEY_ID. Test should be
   able to create an operation using the key loaded with domain as
   KEY_ID.

 - Generate a key with an alias. Generate another key and bind it with
   same alias. Verify that originally generated key no longer exists
   and report an error if we try to use it.

 - Generate a key with an alias. Load the generated key with domain
   KEY_ID. Generate another key and bind it with same alias. Verify
   that originally loaded key no longer exists and report an error
   if we try to use it.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ibfe237181311decf5f6f00dc222d5cd124e4ac11
2022-07-15 15:00:16 +00:00
Andrew Scull
f4a6e2842d Allow virt APEX to use diced and open_dice_cbor
Microdroid payloads use diced to access their secrets and BCCs. The
open_dice_cbor then gives them safe rust bindings to open-dice to
process them. There's a dependency on ZVec which pulls in
libkeystore2_crypto.

Test: build, TH
Change-Id: I402a9a416d7b0e0eed2e268495b148e5669e5c52
2022-07-12 15:27:00 +00:00
Treehugger Robot
356277b1d0 Merge "Extend attestation key expiration buffer to 12 hours" am: b075b8e4a1
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2147406

Change-Id: Ieeeabab95f50b47ce607dadeae5982833d7d3613
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 21:46:35 +00:00
Treehugger Robot
b075b8e4a1 Merge "Extend attestation key expiration buffer to 12 hours" 2022-07-07 21:32:38 +00:00
Seth Moore
056106fce4 Extend attestation key expiration buffer to 12 hours
This buffer time is how far into the future keystore looks to mark
a key as "old" and needing deletion.

The old buffer time was only 20 seconds, which may not even be enough
for very slow network (where round trips and retries could take
minutes).

Test: keystore2_test
Change-Id: I27869458ec66e546b42fe344bbdffd32881c84e7
2022-07-07 09:53:51 -07:00
Eran Messeri
201f14ce45 Merge "Updated to return INVALID_ARGUMENT on generateKey with invalid domain field." am: 47fce38faa
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2106689

Change-Id: Ie49808093ad5f251055a8dfcb9a2bb50dddcba0e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 11:32:23 +00:00
Rajesh Nyamagoud
caee93eb89 Updated to return INVALID_ARGUMENT on generateKey with invalid domain field.
Bug: 211005249
Test: atest keystore2_client_tests
Change-Id: I1c2a8f66f2e3a6897d5a2bf48b65fb97bcf9903b
2022-07-06 14:43:29 +00:00
Eran Messeri
f57fec002f Merge "Adding generateKey tests with EC key algorithm." am: 28f5a40002
Original change: https://android-review.googlesource.com/c/platform/system/security/+/1920127

Change-Id: I66bb058ce6b1fe73904305a01256caea19462045
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-05 15:47:22 +00:00
Eran Messeri
28f5a40002 Merge "Adding generateKey tests with EC key algorithm." 2022-07-05 15:23:48 +00:00
Rajesh Nyamagoud
a7766455e9 Adding generateKey tests with EC key algorithm.
Test 1: Should fail to generate a key with domain not listed
        in keystore2::Domain.
Test 2: Should fail to generate a EC key without providing curve.
Test 3: Should fail to generate a EC key with 25519 curve having
        sign and agree_key purposes.
Test 4: Generate a EC keys with `NONE, MD5, SHA1, SHA-2 224,
        SHA-2 256, SHA-2 384 and SHA-2 512` digest modes and P_224,
	P_256, P_384, P_521 ec curves combinations. Should be able
	to create operations with these keys successfully for all
	digest modes except NONE and MD5.
Test 5: Generate a EC key with curve CURVE_25519 and digest mode NONE.
	Should be able to create an operation with digest mode NONE.
Test 6: Generate a EC keys with curve CURVE_25519 and digest modes
        `MD5, SHA1, SHA-2 224, SHA-2 256, SHA-2 384 and SHA-2 512`
	combinations. Creation of an operation should fail with
	unsupported digest error.
Test 7: Should fail to create an operation with incompatible digest
        mode in key authorizations.
Test 8: Test for key owner validation. Generate a key in one user and
        try to use it in another user context where it should fail to
	load the key as it doesn't own the key generated by prior user.
Test 9: Generate a key with Domain::BLOB. Verify that key descriptor
        holds the key blob. Try to use this key to perform an operation
	successfully.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I8b923cfdd9dbd50d1ebaab03560e9378ede7cdee
2022-07-01 16:24:41 +00:00
Treehugger Robot
30a630eaf8 Merge "Update for Rust v1.62.0" am: b304d464ef
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2143072

Change-Id: I4b7feea0880ed6c3ed2c8fffcaf77fdffb713285
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 06:11:58 +00:00
Treehugger Robot
b304d464ef Merge "Update for Rust v1.62.0" 2022-07-01 05:53:18 +00:00
Charisee
9761d85cbb Update for Rust v1.62.0
See https://rust-lang.github.io/rust-clippy/master/index.html#is_digit_ascii_radix
Test: run test_compiler.py

Bug: 236723597
Change-Id: I98230b7584bfda1cb0119aca92e8068dfb588429
2022-07-01 01:49:12 +00:00
Eran Messeri
fcee89c861 Merge "Test keystore grant with invalid access vector values." am: 7293ffc837
Original change: https://android-review.googlesource.com/c/platform/system/security/+/2129785

Change-Id: I410731246ffcaa818bc90fb22c5fd535d79d51da
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-30 10:22:57 +00:00
Eran Messeri
7293ffc837 Merge "Test keystore grant with invalid access vector values." 2022-06-30 09:16:06 +00:00
Xin Li
ae7b082370 Merge tm-dev-plus-aosp-without-vendor@8763363
Bug: 236760014
Merged-In: Ib81fb65570a4e9eb7e7b051f9791071ee78dc02f
Change-Id: Ic18cb2c00c503dae6b663c8895106bb039a73f73
2022-06-27 23:40:17 +00:00
Charisee Chiw
593b919baa Merge "Update for Rust v1.62.0" 2022-06-27 20:37:10 +00:00
Charisee
b48992e50e Update for Rust v1.62.0
Code triggered an error. See https://rust-lang.github.io/rust-clippy/master/index.html#map_identity

Please check for correctness

Test: Ran test_compiler.py
Bug: 236723597
Change-Id: I4f4119f4d9fab5baa58b60a1de3c6e8210df1432
2022-06-27 20:35:41 +00:00
Rajesh Nyamagoud
7fe5592037 Test keystore grant with invalid access vector values.
- Test to verify grant API with invalid access vector, it is expected to
  fail with proper error code.

- Test to verify grant API with empty access vector, it is expected to
  succeed granting a key with empty access vector. In grantee context
  while trying to use this key permission denied error is expected.

- Test to verify grant API with valid access vector, it is expected to
  successfully grant a key. Grantee should be able access the key and
  use it according to granted key permissions.

Bug: 236253306
Test: atest keystore2_client_tests
Change-Id: I20dc31b0e4f888f2bf740f84e3bb7b0e97a1bb52
2022-06-27 15:25:03 +00:00