Commit graph

1037 commits

Author SHA1 Message Date
Seth Moore
373225c6c5 Merge "Include challenge in test_rkpd_attestation_key_upgrade" into main 2023-09-26 19:25:05 +00:00
Seth Moore
29fd461ceb Include challenge in test_rkpd_attestation_key_upgrade
KeyMint.generateKey requires a challenge to be passed when a key
blob is also passed. The test missed this, and was thus failing on
compliant HALs.

Bug: 301223273
Test: keystore2_test
Change-Id: Icf7a32683c85d87fddd7d05ba07a110bb4e38c79
2023-09-26 10:45:43 -07:00
Tri Vo
cd6fc7a578 Reuse error mapping logic for key operation metrics
Define SerializedError wire type for convenience and type safety. It
does not change the rules of how errors are downcasted to an i32.

Change operation outcome errors from Keymint ErrorCode to
SerializedError. This has an intended effect of binder errors being
reported to metrics as ResponseCode::SYSTEM_ERROR instead of
ErrorCode::UNKNOWN_ERROR.

Also update comments.

Bug: 298194325
Test: m
Change-Id: Ieff70245b776c38845c4f5142ab13d438ff79104
2023-09-19 16:28:37 -04:00
Devin Moore
a764eb9f45 Merge "keystore2 compat: stop crashing without hwservicemanager" into main 2023-09-06 17:33:15 +00:00
Tri Vo
0140d4b523 Merge "Updated to use shared library instead of static library." into main 2023-09-01 21:01:54 +00:00
Rajesh Nyamagoud
42276da855 Updated to use shared library instead of static library.
Removed `libkeymint_vts_test_utils` and its dependent libs from static
libs list and added only `libkeymint_vts_test_utils` in shared libs
list.

Test: m libkeystore2_test_utils; atest keystore2_client_tests; atest keystore2_test_utils_test;
atest keystore2_test
Bug: 194359114

Change-Id: Iab4b8c174af81a8c64a9f44fcd634d54f78773da
2023-09-01 16:50:01 +00:00
Tri Vo
8ace735b6e Merge "Remove IRPC error handling" into main 2023-08-31 22:18:06 +00:00
Devin Moore
bf520df50e keystore2 compat: stop crashing without hwservicemanager
New devices will no longer have hwservicemanager installed as part of
HIDL deprecation. So this service must not crash when it's not found.
From keystore2's perspective, this is the same as not having the HIDL
Keymaster HALs installed.

Test: remove hwservicemanager from
device/google/cuttlefish/shared/device.mk && launch_cvd
Bug: 298454031

Change-Id: I4c7cefd388936aff821cff572a8af1b6f69f82d1
2023-08-31 21:43:03 +00:00
Tri Vo
dc8d6c06bb Remove IRPC error handling
Keystore no longer talks to IRPC directly. Remove corresponding error
handling code.

Test: m
Change-Id: I47ce41a0f48a30b994b18e794b1dd94fdbf9aa52
2023-08-30 17:00:12 -04:00
Eran Messeri
19e80fc8a0 Merge "Re-structured keystore test-utils module." into main 2023-08-30 15:11:43 +00:00
Rajesh Nyamagoud
10f02e705a Re-structured keystore test-utils module.
- Created separate build file.
- Moved ffi-utils from keystore2-client-tests to test-utils.
- Updated calling apis.

Test: atest keystore2_client_tests; atest keystore2_test_utils_test;
atest keystore2_test
Bug: 194359114

Change-Id: Ia2404218b7d13a9ae43b3fc4e481899576d24e63
2023-08-29 17:03:35 +00:00
David Drysdale
e85523f34a keystore2: add more logging
Also remove benign logging when there are multiple strong
biometrics.

Test: adb logcat on CF while adding/removing user/pwd
Change-Id: I777404d566990a4a604554133c0d87abba2200bc
2023-08-23 14:41:59 +01:00
Hasini Gunasinghe
7d690da73b Merge "Adding an OWNERS file as requested in b/288143537" into main 2023-08-18 21:45:07 +00:00
Tri Vo
dc4d64daff Merge "Generate certificates for importWrappedKey" into main 2023-08-18 18:37:47 +00:00
Tri Vo
3b0d703da8 Generate certificates for importWrappedKey
Bug: 291671113
Test: atest android.keystore.cts.ImportWrappedKeyTest
Change-Id: Ie195ac3931c4c79c738d583bfe272eb6a9314f8f
2023-08-17 13:57:01 -04:00
Treehugger Robot
e6dfdf59af Merge "keystore2_unsafe_fuzzer: Bug Fix" into main 2023-08-17 15:45:27 +00:00
James Farrell
2899721a5e Changes for Rust 1.72
Remove useless calls to vec!

Test: toolchain/android_rust/test_compiler.py
Bug: 295883071
Change-Id: Ie6cc07df6d27c522daf24f85d9fbaf673bdb413f
2023-08-17 04:37:05 +00:00
James Farrell
d77b97f0b6 Changes for Rust 1.72
Replace fold with try_fold

Bug: 295883071
Change-Id: I2b0b102d673f051ec52f6ba8caa6bd73030100b0
2023-08-15 20:03:38 +00:00
Shaquille Johnson
718036a8ad [Keystore]Fix abort unsafe check in keystore fuzz
Fuzzer finds issue when checking return message after response code
fails.

```
m -j$(nproc) keystore2_unsafe_fuzzer
adb sync data
adb shell /data/fuzz/${TARGET_ARCH}/keystore2_unsafe_fuzzer/keystore2_unsafe_fuzzer
```

Test: description
Bug: 292231203
Change-Id: I27bdcb91fa05a75239aeeb34d817e4f04387b41f
2023-08-10 15:16:43 +01:00
Treehugger Robot
b00c8ef0c5 Merge "Add safety comments." into main 2023-07-31 11:09:41 +00:00
Treehugger Robot
9c38948bc5 Merge "Add, standardise or temporarily opt out of safety comments for keystore2." into main 2023-07-28 10:20:42 +00:00
Andrew Walbran
a47698a88f Add, standardise or temporarily opt out of safety comments for keystore2.
These will soon be required by a lint.

Some functions were incorrectly marked as safe which were not actually
safe, so I've fixed those too.

Bug: 290018030
Test: m rust
Change-Id: I38df6a8162d430617f123ab1aace38b741458fce
2023-07-28 10:32:08 +01:00
Tri Vo
f814e4a24f Merge "Verify key characteristics of generated/imported keys." into main 2023-07-27 18:45:16 +00:00
Rajesh Nyamagoud
d0213ef0e6 Verify key characteristics of generated/imported keys.
Changes made in keystore2-client-tests to verify the key characteristics
of generated and imported keys.

Bug: 279721870
Test: atest keystore2_client_tests
Change-Id: I30c1fb2bdb1d69d321d356453d895db73347acde
2023-07-27 15:51:41 +00:00
Tri Vo
dbeb6aaa7d Merge "keystore: Fix ID rotation window" into main 2023-07-25 23:55:46 +00:00
Tri Vo
74997ed800 keystore: Fix ID rotation window
KeyMint spec requires unique ID rotation to happen every 30 days (or
more precisely 2592000000 milliseconds) starting at UNIX epoch time.

Keystore is also supposed to set the RESET_SINCE_ID_ROTATION to indicate
"whether the device has been factory reset since the last unique ID
rotation".

However, instead Keystore sets RESET_SINCE_ID_ROTATION if there has been
a factory reset in the last 30 days counting back from now, which is
different and will give one extra UNIQUE_ID value in a subsequent
period:

For example, if there's a factory reset (marked as :) in the 3rd period
(periods delimited by |), the first half of the 4th period will have
RESET_SINCE_ID_ROTATION set and get a different UNIQUE_ID value than it
should:

Want = |   A    |   B    | C : C2 |   D    | ...
Get  = |   A    |   B    | C : C2 | D2 : D | ...

Bug: 289774200
Test: keystore2_test
Change-Id: I156de902931915cd1ae7ad2eba63fd0276f15ae0
2023-07-25 16:40:31 -04:00
Andrew Walbran
7036c2b48c Fix soundness issue in keystore2.
Sync was incorrectly implemented for AuthRequest, allowing simultaneous
access to a Receiver from multiple threads despite it not being
threadsafe. Use a Mutex instead to do this safely.

Bug: 290018030
Test: m rust
Change-Id: I6f43f13d5f36bdbafc9bd910a1ebadbb1366009d
2023-07-25 17:04:45 +01:00
Andrew Walbran
094a9c4e17 Add safety comments.
These will soon be required by a lint.

Bug: 290018030
Test: m libkeystore2_apc_compat-rust
Change-Id: Ic7e4e62e52d3361af9a275443bf097282a84f034
2023-07-18 15:31:38 +01:00
Chris Wailes
53a22af8e1 Fix errors from rustc 1.71.0
Bug: 288268986
Test: m rust
Change-Id: If972c3856297978663642c60d162fcc504eb659d
2023-07-12 17:02:47 -07:00
Devendra Singhi
c08a5ae0a0 keystore2_unsafe_fuzzer: Bug Fix
Remove get_declared_instances API as it is not a part of the target module - libkeystore2

Bug: 287588482
Test: ./keystore2_unsafe_fuzzer clusterfuzz-testcase-minimized-keystore2_unsafe_fuzzer-5127790852636672

Change-Id: I7513955783f4877496f721f52b92970887bbad41
2023-07-10 13:30:58 +05:30
Hasini Gunasinghe
eae69a6271 Adding an OWNERS file as requested in b/288143537
This is just a copy of the OWNERS file in the parent directory with
only the members of the AHWS team filtered in, in the same order as the
parent file, except that eranm@ is added at the top of the list as
per go/atos-user-guide which says: First Owner in the OWNERS file should
be the person to triage the issues.

Bug: 288143537
Test: N/A
Change-Id: Ia9bb4773cb494e793ae3b4f0b18ebd90641051e2
2023-06-30 21:42:52 +00:00
Matthew Maurer
91a9763c5f Bindgen 0.65.1 no longer supports size_t-is-usize
The flag has been a default, and now is not accepted.

Test: Treehugger, m rust
Bug: 279198502
Bug: 276464273
Change-Id: I71ebcdbd3606c5dc55bf3454acfba9cc55ad85dd
2023-06-26 22:38:57 +00:00
Rajesh Nyamagoud
a42dee61ce Added tests to attest keys with attestation id.
- Generate an RSA/EC attested keys with attestation of the device's
  identifiers. Test should succeed in generatating a attested key with
  attestation of device identifier. Test might fail on devices which
  doesn't support device id attestation with error response code
  `CANNOT_ATTEST_IDS or INVALID_TAG`.

- Try to generate an attested key with attestation of invalid device's
  identifiers. Test should fail with error response `CANNOT_ATTEST_IDS`

- Test to make sure `CANNOT_ATTEST_IDS` error code is returned while
  trying to generate a key on a device which doesn't support
  `FEATURE_DEVICE_ID_ATTESTATION`.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: Ib57c58d3ea89279eb69db342c3343b8d99ddc639
2023-06-20 19:07:27 +00:00
David Drysdale
cdeb7302af Merge "keystore: log receipt of auth tokens" 2023-06-16 05:22:30 +00:00
Marcin Radomski
402750dae1 Merge "audit_log.rs: handle Results in LogContext handling" 2023-06-15 14:29:35 +00:00
David Drysdale
bf2d72f6e4 keystore: log receipt of auth tokens
Various recent bugs would have been easier to investigate if the auth
tokens received by keystore were logged.

Test: adb logcat while lock/unlock
Bug: 285328437
Bug: 284802403
Change-Id: Ia955d344a2bb47820c0616cc1b9784f5fcbecb0a
2023-06-15 13:38:36 +01:00
Marcin Radomski
b948e92b70 audit_log.rs: handle Results in LogContext handling
The Rust liblog_event_list API used to silently ignore any errors
reported by liblog. aosp/2617613 attempts to make the operations
propagate the failure instead.

Note that this introduces a subtle behavior change: when *creating the
log record* fails, the API with Results does not allow submitting a
partially constructed log. Otherwise, the result of the write operation
is ignored as it was before.

Bug: 282691103
Test: m
Test: atest keystore2_test
Change-Id: I7c43100149b4ca831050af0a9229b95d2f7f8392
2023-06-14 13:44:04 +00:00
Treehugger Robot
96947c9d89 Merge "Adding tests to verify EVP_PKEY_from_keystore2 API [Keystore2-engine]." 2023-06-09 17:23:00 +00:00
Treehugger Robot
1600dc1a47 Merge "Fix keystore2 crash counting" 2023-06-05 16:43:23 +00:00
Nathan Huckleberry
efb59be97a Merge changes from topic "super-key-cleanups"
* changes:
  Add tests for super_key.rs
  Simplify control flow for user unlocking.
  Remove unlock_user_key function
  Separate logic for user reset, remove, and init
  Separate hybrid key logic into a helper function.
  Make super_encrypt_on_key_init inline
2023-06-05 16:24:38 +00:00
Eric Biggers
9f9ab18bc6 Fix keystore2 crash counting
https://r.android.com/1971319 changed the return type of
rustutils::system_properties::read() from Result<String> to
Result<Option<String>>.  But, read_keystore_crash_count() was not
correctly updated to handle the Ok(None) case.  Consequently, the case
of "property doesn't exist" started being considered an error, and the
code intended to handle this case stopped being executed.  Fix this by
correctly handling the return value.

Bug: 284163087
Test: Verified that the read_keystore_crash_count() error message is no
      longer present in logcat at boot time, and
      'getprop keystore.crash_count' shows 0.
Change-Id: I4b9ff16cba9e7500623dab7c3bc888cba0daf997
2023-06-01 02:30:28 +00:00
Nathan Huckleberry
95dca01f5f Add tests for super_key.rs
The new tests are focused on unlocking, resetting and removing a user.
The tests verify that keys are deleted when necessary and that the user
state transitions properly.

Bug: 280502317
Test: atest keystore2_test on cuttlefish
Change-Id: Idae5d99fb289045bb277ba6c93ab62cfd9aed6fb
2023-05-31 19:51:26 +00:00
Nathan Huckleberry
7dfe818bb2 Simplify control flow for user unlocking.
Keystore2 super key handling is being refactored in preparation for
Unlocked-Only Storage.

Currently, super_key.rs exposes two functions to authorization.rs for
key unlocking:
- unlock_screen_lock_bound_key
- unlock_and_get_user_state

This change simplifies the key_unlocking logic to a single function,
unlock_user. This new function handles all of the unlocking logic and
functions more like a state machine than the previous code.

This change mainly improves readability. It tries not to change
functionality.

Bug: 280502317
Bug: 277798192
Test: Wiped device. Setup user with PIN. Ensured unlock works. Remove
    PIN. Ensured unlock works. Added pin and biometric. Ensured unlock
    works.  Rebooted device. Ensured unlock works.
Change-Id: Ib9a3e907cd40d34c5ecf2a869a65e403deda0254
2023-05-31 19:51:26 +00:00
Nathan Huckleberry
1afc660952 Remove unlock_user_key function
Keystore2 super key handling is being refactored in preparation for
Unlocked-Only Storage.

This function is dead code. It has no callers.

Bug: 280502317
Bug: 277798192
Test: Wiped device. Setup user with PIN. Ensured unlock works. Remove
    PIN. Ensured unlock works. Added pin and biometric. Ensured unlock
    works.  Rebooted device. Ensured unlock works.
Change-Id: I4c7791f6944afb621afb2d67f4b7b7d4690ddd78
2023-05-31 19:51:26 +00:00
Nathan Huckleberry
204a044209 Separate logic for user reset, remove, and init
Keystore2 super key handling is being refactored in preparation for
Unlocked-Only Storage.

This does not change the behavior of keystore2. It is a readability
change.

Currently, super_key.rs exposes one function for resetting, removing,
and initializing users:
- reset_or_init_user_and_get_user_state

This change breaks this function into smaller parts:
- reset_user
- init_user
- remove_user
- get_user_state

This simplifies the code in super_key.rs and allows it to act more like
a state machine.

Bug: 280502317
Bug: 277798192
Test: Wiped device. Setup user with PIN. Ensured unlock works. Remove
    PIN. Ensured unlock works. Added pin and biometric. Ensured unlock
    works.  Rebooted device. Ensured unlock works.
Change-Id: I4e27b41a76a8b45ca2bae6daabe51f2a985c2efe
2023-05-31 19:51:21 +00:00
Nathan Huckleberry
f9494d172b Separate hybrid key logic into a helper function.
Keystore2 super key handling is being refactored in preparation for
Unlocked-Only Storage.

This code is complicated and should be moved to its own function.

Bug: 280502317
Bug: 277798192
Test: Wiped device. Setup user with PIN. Ensured unlock works. Remove
    PIN. Ensured unlock works. Added pin and biometric. Ensured unlock
    works.  Rebooted device. Ensured unlock works.
Change-Id: I0602a8229cdd149d4f9b42a96f446d2a17df1321
2023-05-31 17:13:23 +00:00
Nathan Huckleberry
a405d0efb5 Make super_encrypt_on_key_init inline
Keystore2 super key handling is being refactored in preparation for
Unlocked-Only Storage.

There's no reason to separate this function.  It doesn't handle any
complicated logic and makes control flow more difficult to understand.

Bug: 280502317
Bug: 277798192
Test: Wiped device. Setup user with PIN. Ensured unlock works. Remove
    PIN. Ensured unlock works. Added pin and biometric. Ensured unlock
    works.  Rebooted device. Ensured unlock works.
Change-Id: Iafd31ae79a722910effaba98ac216d5b912dd348
2023-05-31 17:13:17 +00:00
Andrew Walbran
78abb1e0e2 Update for rusqlite 0.29.0.
Test: atest keystore2_test_utils_test keystore2_test
Change-Id: Ib613f9e11523f16060e4fb473b849203ff26ee2d
2023-05-30 16:20:56 +00:00
Rajesh Nyamagoud
28abde6189 Adding tests to verify EVP_PKEY_from_keystore2 API [Keystore2-engine].
1. Generate RSA key and grant it to a user. In user context load the
   key using `EVP_PKEY_from_keystore` and perform sign and verify
   opeearions.
   [keystore2_perofrm_crypto_op_using_keystore2_engine_rsa_key_success]

2. Generate EC key and grant it to a user. In user context load the
   key using `EVP_PKEY_from_keystore` and perform sign and verify
   operations.
   [keystore2_perofrm_crypto_op_using_keystore2_engine_ec_key_success]

3. Generate RSA key and grant it to a user. Re-encode the certificate
   as PEM and update the certificate using `updateSubcomponents`.
   In user context load the key using `EVP_PKEY_from_keystore` and
   perform sign and verify operations.

Bug: 201343811
Test: atest keystore2_client_tests
Change-Id: I7dafd598f4198e11103cd11695b2f67636f24755
2023-05-23 19:28:24 +00:00
Treehugger Robot
4123d9853c Merge "Adding tests to verify getNumberOfEntries and listEntriesBatched." 2023-05-23 16:11:49 +00:00
Andrew Walbran
3137bf9d43 Use macro explicitly rather than using #[macro_use].
This makes it more clear where it comes from.

Bug: 261037227
Test: m authorization_service_fuzzer
Change-Id: Ifc68ccf8e40fe262f8c823a1d1bd6ebd1700454b
2023-05-17 13:53:30 +00:00
Tri Vo
6ff734224e Merge "keystore: Remove dead code" 2023-05-12 19:56:21 +00:00
Tri Vo
0346bbe540 keystore: Remove dead code
Attestation keys are now managed by RKPD. Remove support for attestation
keys in keystore DB.

Test: keystore2_test
Change-Id: Iad7d9297701364eba44bcc60b564c7c7e12b9aea
2023-05-12 14:19:39 -04:00
Andrew Walbran
48fa970f91 Update for PropertyWatcher API change.
Bug: 270142874
Test: atest keystore2_test
Change-Id: I890666b8afff37135933c4ededecf8f4741ee3ca
2023-05-10 15:19:30 +00:00
Rajesh Nyamagoud
6a82349afb Adding tests to verify getNumberOfEntries and listEntriesBatched.
1. Try to list large number of aliases such that aliases list would
   exceed the binder transaction size limit. Test should successfully
   list the aliases using `listEntriesBatched` API.

2. Import keys from multiple processes having same user context. Try to
   list the aliases in all the processes with and without providing
   `startingPastAlias`. Test should list aliases using
   `listEntriesBatched` in all the processes using any of the alias as
   `startingPastAlias` and match with expected list of aliases. Test
   should also list all the aliases without providing
   `startingPastAlias`.

3. Try to list aliases with empty keystore using `listEntriesBatched`
   API. Test should successfully query the Keystore for aliases and
   vrify that keystore is empty.

4. Test to list aliases using domain as SELINUX using
   `listEntriesBatched` API.

5. Import multiple number of keys in an app context and try to list the
   aliases using imported keys aliases as `startingPastAlias` and verify
   the retrived the list of aliases matches the expected list of alises
   in all the cases.

6.  Try to list the key entries with domain SELINUX from user context
    where user doesn't possesses `GET_INFO` permission for specified
    namespace. Test should fail to list key entries with error response
    code `PERMISSION_DENIED`.

7. Try to list key entries with domain BLOB. Test should fail with error
   response code `INVALID_ARGUMENT`.

8.  Try to get the total number of keystore entries with domain SELINUX
    from user context where user doesn't possesses `GET_INFO` permission
    for specified namespace. Test should fail to get the count with
    error response code `PERMISSION_DENIED`.

9. Try to get the count of total number of entries in keystore with
   domain BLOB. Test should fail with error response code
   `INVALID_ARGUMENT`.

Bug: 194359114
Test: atest keystore2_client_test
Change-Id: I7dd52230cd602a1ae33e3f9f2a22d2dd2c447df7
2023-05-09 17:54:45 +00:00
Shaquille Johnson
f20c0ddd09 Merge "Use binder to get AIDL descriptor in Rust" 2023-04-27 15:45:36 +00:00
Shaquille Johnson
df83fb71d4 Use binder to get AIDL descriptor in Rust
Using the binder object we can directly get names of interfaces
rather than hardcoding the strings. This allows for lookup to be easier.

Test: atest keystore2_test and atest CtsKeystoreTestCases
Bug: 249096262
Change-Id: I74bc696b860e2c08286b1d5175378e8d44728858
2023-04-27 12:21:52 +00:00
Shaquille Johnson
bbbe5d5441 Edit hidl instances to remove vintf
This uses the getAllHalInstanceNames method to replace calls
to vintf and return the hal names to the code. Other callers
to this function will not need to change their inputs.

Test: atest keystore2_test && atest CtsKeystoreTestCases
Bug: 249096262
Change-Id: If23cf8ca4b9d1c8cb3675964475066728bfe789f
2023-04-27 12:21:22 +00:00
David Drysdale
bf00b4af0a Ensure RSA_OAEP_MGF_DIGEST tags are returned
Test: CtsKeystorePerformanceTestCases with printf debugging
Bug: 278157584
Change-Id: I39a286fece2fa2e3637bb41e127bb79034434af1
2023-04-24 18:17:34 +01:00
Shaquille Johnson
8d67b75bc1 Connects to Keymint and gets version number
Fix for regression in aosp/2453685, this gets the
version of keymint that is on the device.

Test: atest keystore2_test
Bug: 275589241 276396649
Change-Id: I2afe1472a0a4e3c4f81379c589833285bb228811
2023-04-12 10:48:48 +01:00
Seth Moore
1904440782 Remove dead stats interface for getting some atoms from keystore
The RkpPoolStats atom has been moved from keystore2 into rkpd, so
we no longer need to query it from keystore2.

Bug: 268247931
Test: presubmit
Change-Id: I285011ed29183e3008310be248ddeb8b9668ac01
2023-03-31 15:05:17 -07:00
Eran Messeri
4ec7585ff8 Merge "Keystore2: Batching listing of key entries" 2023-03-27 10:18:00 +00:00
Eran Messeri
24f3197c7f Keystore2: Batching listing of key entries
Support for listing key entries in batches, so that a large number of
key entries, or entries with long key aliases, could be listed.

The list of key descriptors (which contain the key alias) is returned
to JCA from Keystore2 service via the Binder interface.
The size of a single Binder transaction is limited. Thus, we have run
into http://b/222287335 , where an app can create too many Keystore2
keys than can be returned in a single Binder transaction. Effectively,
this prevents the app from listing the keys it generated at all.

This is solved by adding a method to the Keystore2 interface for
obtaining all the key descriptors whose alias is past a given value
(with the intention that this value is the last key alias from the
previous batch). Keystore2 already limits the number of entries
returned to a number estimated to fit under the Binder transaction size
limit. Together, this enables callers to receive the list of key
descriptors in batches.

Additionally, add a method to Keystore2 to return the total number of
key entries by querying the DB for the number of rows, rather than count
the number of entries returned (which may be truncated).

Bug: 222287335
Test: atest KeystoreTests
Test: atest CtsKeystoreTestCases:android.keystore.cts.AndroidKeyStoreTest
Test: atest keystore2_test
Change-Id: I4a8efef2303beadd2cf6db992833d87bf58d7aec
2023-03-21 09:35:33 +00:00
Tri Vo
128453ec87 Revert^2 "Remove android.security.remoteprovisioning interfaces"
These interfaces are deprecated and replaced by
android.security.rkp_aidl ones.

Bug: 273325840
Change-Id: I6f561d7c332fc3cc5921453b5bd5938154b700d0
Test: m
2023-03-20 19:38:04 +00:00
Ioana Alexandru
8c8feac745 Revert "Remove android.security.remoteprovisioning interfaces"
This reverts commit 9fad346811.

Reason for revert: DroidMonitor-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?branch=git_udc-d1-dev-plus-aosp-without-vendor&target=errorprone&lkgb=9769185&lkbb=9776170&fkbb=9771476, bug b/274209879

Change-Id: I210c4a47d76864c3c212b907eb875ef363c3beab
2023-03-20 17:08:20 +00:00
Tri Vo
9fad346811 Remove android.security.remoteprovisioning interfaces
These interfaces are deprecated and replaced by
android.security.rkp_aidl ones.

Bug: 273325840
Test: m
Change-Id: I888ded721341ab6e6e89fe236c8fb0f7e6122b74
2023-03-13 15:34:01 -07:00
Chris Wailes
bac435591f Remove usage of slice_internals feature
This CL replaces the usage of the core::slice::memchr function with
calls to std::iter::position.

Test: m keystore2_unsafe_fuzzer
Test: TH
Bug: 267698452
Change-Id: I33cab09176d0ff02ce092e240e887ece98728915
2023-03-08 10:21:06 -08:00
Shaquille Johnson
d4443c6fd4 Remove vintf aidl and replace with binder
Aidl Instances can be gotten from the binder with
get_declared_instances.

Test: m keystore2 && m keystore2_unsafe_fuzzer
Change-Id: I36b4bdb8de6dd8abedf50d2026d1d841ce27c55d
2023-03-08 13:46:19 +00:00
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