Commit graph

1083 commits

Author SHA1 Message Date
Alice Wang
779c94e7f2 Merge "[rkpd] Move watchdog calls from rkpd_client to keystore2" into main 2023-11-08 21:41:34 +00:00
Eric Biggers
17e96a8797 Merge changes I26394509,I9d76a0ec,I88779273 into main
* changes:
  keystore2: link to android.security flags library
  keystore2: log super key creation
  keystore2: factor out create_super_key()
2023-11-08 18:42:45 +00:00
James Willcox
464c7d3d2b Merge "Use CLOCK_BOOTTIME for keystore2 auth token received time" into main 2023-11-08 18:12:42 +00:00
James Willcox
80f7be1516 Use CLOCK_BOOTTIME for keystore2 auth token received time
CLOCK_BOOTTIME is more correct because it includes time spent
while the device is suspended.

This also fixes an issue when comparing the times resulting from the
get_last_auth_time() API in the Java world, because we want to use
SystemClock.elapsedRealtime(), which uses CLOCK_BOOTTIME.

Bug: 309686873
Test: atest keystore2_client_tests
Change-Id: I89d71ccfcfe4f8b3495fede40ae26ad6fa2b0118
2023-11-08 17:13:49 +00:00
Alice Wang
4277d2e1ca [rkpd] Move watchdog calls from rkpd_client to keystore2
This cl moves watchdog calls to keystore2 to make rkpd_client
less dependent on keystore2, this allows us to make rkpd_client
an independent library more easily later.

Test: atest keystore2_test
Bug: 241428146
Change-Id: Ic3040ad65356aa7e25d38f36d453a258caf28403
2023-11-08 09:15:54 +00:00
Alice Wang
e66c3310cd [refactor] Split the message macro in a standalone library for reuse
This simplifies the task of creating an independent library of
rkpd_client later.

Test: atest keystore2_test
Bug: 241428146
Change-Id: Idddf37d14580e691fde5a494e54297465cb693b6
2023-11-07 13:47:54 +00:00
Alice Wang
bf6a693217 [rkpd] Move security level to RPC name conversion out of rkpd_client
This will facilitate the extraction of rkpd_client as a standalone
library later.

Test: atest keystore2_test
Bug: 241428146
Change-Id: Icff6f88f2c3cc3dc50dd126067ed5f10c8aa7b29
2023-11-07 13:27:54 +00:00
Alice Wang
83c6aefb5d [refactor] Split watchdog in a standalone library for reuse
This simplifies the task of creating an independent library of
rkpd_client later.

Test: atest keystore2_test
Bug: 241428146
Change-Id: I2834c9be9f5100d52829e6392f0dd48e7c76beb1
2023-11-07 10:30:26 +00:00
Charisee
78e844b86a Update needed for Rust v1.73.0
Remove redundancy
Bug: 303252546
Test: ./test_compiler.py --prebuilt-path dist/rust-dev.tar.xz  --target aosp_cf_x86_64_phone --image

Change-Id: Ia4366c2694c235f8931eea56d13548f08805952f
2023-11-06 20:41:19 +00:00
Orlando Arbildo
c0e1f3589b Merge "Adding 'static bound on binder Interface implementation" into main 2023-11-06 18:44:01 +00:00
Eric Biggers
698922b0a6 keystore2: link to android.security flags library
Make it possible for keystore2 to check android.security flags.

Bug: 296464083
Test: Build
Change-Id: I263945093ed9c76d914018b7ae24bf6151157c0c
2023-11-02 21:19:42 +00:00
Eric Biggers
6745f53b46 keystore2: log super key creation
Log an informational message when creating each of a user's super keys,
as these are significant events.

Bug: 296464083
Test: atest -p --include-subdirs system/security/keystore2
Flag: exempt, just adds a log message
Change-Id: I9d76a0ec06fae208412f4c6cf1b7dd739b023a61
2023-11-02 21:19:31 +00:00
Eric Biggers
456a3a6974 keystore2: factor out create_super_key()
Currently the UnlockedDeviceRequired super keys are created by
get_or_create_super_key(), while the AfterFirstUnlock super key is
created by separate code in init_user().  The super key creation code in
get_or_create_super_key() is generic enough to work for all super keys,
however.  This CL factors this code out into a new function
create_super_key(), which a later CL will use for the AfterFirstUnlock
super key.  No change in behavior.

Bug: 296464083
Test: atest -p --include-subdirs system/security/keystore2
Flag: exempt, mechanical refactoring
Change-Id: I88779273efef6cb925152381c07549e1f49daecf
2023-11-02 21:19:31 +00:00
James Willcox
d215da817a Add getLastAuthTime() to IKeystoreAuthorization
This returns the time (from CLOCK_MONOTONIC_RAW) that the specified user
last authenticated using the given authenticator.

Bug: 303839446
Test: atest keystore2_client_tests
Change-Id: Idd4c477365ffa556b7985d1d926dfa554680ff28
2023-10-31 20:30:50 +00:00
Treehugger Robot
449c3b2cec Merge "Adding tests using APPLICATION_DATA and APPLICATION_ID." into main 2023-10-31 18:22:42 +00:00
Orlando Arbildo
9ee036add7 Adding 'static bound on binder Interface implementation
Adding a 'static bound for a binder Interface Implementation.
This is now needed to allow new code used to cast a Binder
Native object back to the original object that implements the
Binder Interface.

Test: CI
Bug: 278780666
Change-Id: Ifa1ec4d4c6692d75ada6c58cb97e6c82b791be04
2023-10-31 00:15:22 +00:00
Shaquille Johnson
7e4cd0ade7 Add flag for deprecation of Legacy Keystore
Test: m keystore2
Bug: 307460850
Change-Id: Ib09449ad1a84c9f6dd455d8b14e1830788c86d49
2023-10-30 03:53:36 +00:00
Rajesh Nyamagoud
290dd7386f Adding tests using APPLICATION_DATA and APPLICATION_ID.
1. Generate a key with application-data and use the generated key to
   create an operation using the same application-data. Test should
   create an operation successfully.

2. Generate a key with application-data and use the generated key to
   create an operation using different application-data. Test should
   fail to create an operation with `INVALID_KEY_BLOB` error code.

3. Generate a key with application-id and use the generated key to
   create an operation using the same application-id. Test should
   create an operation successfully.

4. Generate a key with application-id and use the generated key to
   create an operation using different application-id. Test should
   fail to create an operation with `INVALID_KEY_BLOB` error code.

5. Generate an attestation key without app-id and app-data. Test should
   generate a new key with specifying app-id, app-data and using
   previously generated attestation key. Test should be able to generate
   a new key successfully.

6. Generate an attestation key with app-id and app-data. Test should try
   to generate an attested key using previously generated attestation
   key without specifying same app-id, app-data. Test should fail to
   generate a new key with an error code `INVALID_KEY_BLOB`. It is an
   oversight of the Keystore API that `APPLICATION_ID` and
   `APPLICATION_DATA` tags cannot be provided to generateKey for
   an attestation key that was generated with them.

Bug: 279721870
Test: atest keystore2_client_tests
Change-Id: I56fad4806c6d96c5994f4affdd7aa6620b1f1be8
2023-10-27 19:25:09 +00:00
Tri Vo
4e6dbef7f7 Add keystore2_client_tests to VTS
Bug: 194359114
Test: keystore2_client_tests
Change-Id: I74f29e8c42fd6fdca07a7999dfc2e5345ad45c09
2023-10-23 14:50:30 -04:00
Tri Vo
724e4e5660 Add keystore2_client_tests to TEST_MAPPING
Bug: 194359114
Test: keystore2_client_tests
Change-Id: Ia5f774cd797d1b4b4e343a5588833739ad4843ee
2023-10-23 14:50:25 -04:00
Eran Messeri
f692f42327 Merge "The INCLUDE_UNIQUE_ID parameter is not strictly expected to be in key authorizations." into main 2023-10-20 16:14:01 +00:00
Rajesh Nyamagoud
17a9261560 The INCLUDE_UNIQUE_ID parameter is not strictly expected to be in key authorizations.
Bug: 279721870
Test: atest keystore2_client_tests
Change-Id: Ic5724cf7ea2b6ad6d1f80e34524af777e5e0ea49
2023-10-19 17:29:12 +00:00
Eric Biggers
b1f641d7a5 keystore2: rename the ScreenLockBound superencryption keys and type
Rename the ScreenLockBound superencryption keys and superencryption type
to UnlockedDeviceRequired.  This avoids confusion about what "screen
lock bound" means and makes the terminology consistent with the
UnlockedDeviceRequired key parameter in the API.

Bug: 296464083
Test: atest -p --include-subdirs system/security/keystore2
Test: atest CtsKeystoreTestCases
Flag: exempt, mechanical refactoring and comment changes
Change-Id: I98f7716d05c06f8c6db0f3eb616fb6e780407c2d
2023-10-18 01:54:18 +00:00
Eric Biggers
673d34addb keystore2: rename the LskfBound superencryption key and type
Rename the LskfBound superencryption key and superencryption type (also
known as per-boot) to AfterFirstUnlock.

This makes it much clearer what the protection of this key is.  This
includes avoiding the misleading use of "LSKF"; the secret that's
actually relevant is the user's synthetic password, which is most
commonly unlocked with the LSKF but can potentially be unlocked in other
ways.  This is also helpful for the planned change to make the user's
super keys exist even while the user doesn't have an LSKF.

Bug: 296464083
Test: atest -p --include-subdirs system/security/keystore2
Test: atest CtsKeystoreTestCases
Flag: exempt, mechanical refactoring and comment changes
Change-Id: I9b16934f37222fef2bf01830f521928ef2c1853a
2023-10-18 01:54:18 +00:00
Eric Biggers
1386937eca keystore2: rename values of UserState enum
Rename UserState::LskfLocked to UserState::BeforeFirstUnlock, and
rename UserState::LskfUnlocked to UserState::AfterFirstUnlock.

This makes it much clearer what these states are.  This includes
avoiding the misleading use of "LSKF"; the secret that's actually
relevant is the user's synthetic password, which is most commonly
unlocked with the LSKF but can potentially be unlocked in other ways.
This is also helpful for the planned change to make the user's super
keys exist even while the user doesn't have an LSKF.

Bug: 296464083
Test: atest -p --include-subdirs system/security/keystore2
Test: atest CtsKeystoreTestCases
Flag: exempt, mechanical refactoring and comment changes
Change-Id: I78f15e2165876951c98e22e577fc4c92a3602b3b
2023-10-18 01:54:18 +00:00
Treehugger Robot
7eea1e3c1c Merge "Update needed for Rust v1.73.0" into main 2023-10-17 16:33:52 +00:00
David Drysdale
abdfe3a53e Merge "Add utilities to deal with software keyblobs" into main 2023-10-17 06:44:29 +00:00
Treehugger Robot
e79fe80acf Merge changes Ic7857267,I2bf53018 into main
* changes:
  Adding tests to check unique id attestation.
  Changes are made in keystore-client-tests to verify CREATION_DATETIME, ATTESTATION_CHALLENGE and ATTESTATION_APPLICATION_ID.
2023-10-16 17:20:52 +00:00
Eric Biggers
b6d1dfbe0b Merge "Remove IKeystoreMaintenance#getState()" into main 2023-10-16 16:26:56 +00:00
Charisee
6fff58e850 Update needed for Rust v1.73.0
Bug: 303252546
Test: ./test_compiler.py --prebuilt-path dist/rust-dev.tar.xz  --target aosp_cf_x86_64_phone --image
Change-Id: Icbe8740b2bff6bf35fd18cdaee1518af5a11a348
2023-10-14 21:11:03 +00:00
Treehugger Robot
df6fe6d17d Merge "Adding tests using MAX_USES_PER_BOOT, EARLY_BOOT_ONLY, BOOTLOADER_ONLY and USAGE_COUNT_LIMIT" into main 2023-10-13 10:56:03 +00:00
David Drysdale
c0ed986a8d Add utilities to deal with software keyblobs
Add code (adapted from system/keymint/common/src/keyblob/legacy.rs)
which parses keyblobs in the format produced by the previous C++
reference implementation of KeyMint.

Bug: 283077822
Bug: 296403357
Test: tested with ARC upgrade, see b/296403357
Change-Id: I519eed0ac968d5c2595f95609ffadede5d2d2677
2023-10-12 09:27:49 +01:00
David Drysdale
cc5143e2b1 Merge changes I8539455e,I14f0d535 into main
* changes:
  Cope with Keymaster->KeyMint device upgrade
  Commonize upgrade_keyblob_if_required_with
2023-10-11 10:50:21 +00:00
David Drysdale
5accbaa18a Cope with Keymaster->KeyMint device upgrade
When handling keyblob upgrade required, also watch out for an invalid
keyblob error that might indicate that a key used to be a
km_compat-wrapped Keymaster key.

In this situation, try stripping off the km_compat prefix and
attempt upgrade of the inner keyblob data instead.

Bug: 251426862
Bug: 283077822
Bug: 296403357
Test: tested with ARC upgrade, see b/296403357
Change-Id: I8539455e33ab2e1c97f26174476ee9d616269e74
2023-10-10 07:04:50 +01:00
Eric Biggers
2f9498af06 Remove IKeystoreMaintenance#getState()
IKeystoreMaintenance#getState() is no longer called, so remove it along
with the enum value for the GetState permission.

Bug: 296464083
Test: atest -p --include-subdirs system/security/keystore2
Change-Id: I9ec6cca78cd1eb899ac7adfc99fc5eee41dc7e44
2023-10-09 23:16:05 +00:00
Rajesh Nyamagoud
f408c28c0e Adding tests to check unique id attestation.
Bug: 279721870
Test: atest keystore2_client_tests
Change-Id: Ic7857267345035ad0d92d8176d34cfe3e64e5c62
2023-10-09 21:59:43 +00:00
Rajesh Nyamagoud
5f6db2f442 Changes are made in keystore-client-tests to verify CREATION_DATETIME,
ATTESTATION_CHALLENGE and ATTESTATION_APPLICATION_ID.

Bug: 279721870
Test: atest keystore2_client_tests
Change-Id: I2bf530189e41ede27763ef696ff9a126c4110e24
2023-10-09 21:51:19 +00:00
Rajesh Nyamagoud
f436a9326c Adding tests using MAX_USES_PER_BOOT, EARLY_BOOT_ONLY, BOOTLOADER_ONLY and USAGE_COUNT_LIMIT
1. Generate a key with `BOOTLOADER_ONLY` tag. Test should successfully
   generate a key and verify the key characteristics. Test should fail
   with error code `INVALID_KEY_BLOB` during creation of an operation
   using this key.

2. Generate a key with `EARLY_BOOT_ONLY` tag. Test should successfully
   generate a key and verify the key characteristics. Test should fail
   with error code `EARLY_BOOT_ENDED` during creation of an operation
   using this key.

3. Generate a key with `MAX_USES_PER_BOOT` tag. Test should successfully
   generate a key and verify the key characteristics. Test should be
   able to use the key successfully `MAX_USES_COUNT` times. After
   exceeding key usage `MAX_USES_COUNT` times subsequent attempts to use
   the key in test should fail with error code `MAX_OPS_EXCEEDED`.

4. Generate a key with `USAGE_COUNT_LIMIT` tag. Test should successfully
   generate a key and verify the key characteristics. Test should be
   able to use the key successfully `MAX_USES_COUNT` times. After
   exceeding key usage `MAX_USES_COUNT` times subsequent attempts to use
   the key in test should fail with error code `KEY_NOT_FOUND`. Test
   should also check attest record for attested keys that
   `USAGE_COUNT_LIMIT` is included in attest record.

Bug: 279721870
Test: atest keystore2_client_tests
Change-Id: I205964b571d92dc0fcbd11b1f6d45bc3aea7c050
2023-10-09 21:44:48 +00:00
Rajesh Nyamagoud
75dfa0c2ec Adding tests using tags ACTIVE_DATETIME, ORIGINATION_EXPIRE_DATETIME,
USAGE_EXPIRE_DATETIME.

1. Tests will generate a key with current date and time set to
   active-datetime and verify the key characteristics. Test will use
   this key to create a sign operation successfully.

2. Test will generate a key with future date set to active-datetime and
   verify the key characteristics. Test will fail with error code
   `KEY_NOT_YET_VALID` while creating an operation using generated key.

3. Tests will generate a key with future date and time set to
   origination-expire-datetime and verify the key characteristics. Test
   will use this key to create a sign operation successfully.

4. Test will generate a key with current date and time set to
   origination-expire-datetime and verify the key characteristics. Test
   will fail with error code `KEY_EXPIRED` while creating an operation
   using generated key.

5. Tests will generate a key with future date and time set to
   usage-expire-datetime and verify the key characteristics. Test
   will use this key to successfully verify the signature created using
   this key.

6. Tests will generate a key with current date and time set to
   usage-expire-datetime and verify the key characteristics. Test
   will fail with error code `KEY_EXPIRED` while verifying the signature
   created using this key.

7. Test will generate a AES key with future date and time set to
   usage-expire-datetime and verify the key characteristics. Test
   will perform encrypt and decrypt operations using this generated key
   successfully.

8. Test will generate a AES key with current date and time set to
   usage-expire-datetime and verify the key characteristics. Test
   will fail with error code `KEY_EXPIRED` while creating Decrypt
   operation using generated key.

Bug: 279721870
Test: atest keystore2_client_tests
Change-Id: I8a0865a6256a6da133e95d0ee8250ba67359a2a2
2023-10-09 21:10:00 +00:00
Eric Biggers
3363996eaf Merge "IKeystoreMaintenance.aidl: document permissions correctly" into main 2023-10-09 16:41:43 +00:00
David Drysdale
96db425969 Commonize upgrade_keyblob_if_required_with
Bug: 251426862
Bug: 283077822
Bug: 296403357
Test: tested with ARC upgrade, see b/296403357
Change-Id: I14f0d53585c97da2ebdbd53aafa18c4d8b778e17
2023-10-09 10:07:26 +01:00
Rajesh Nyamagoud
19fe29adb3 Removed dependency on libkeymint_vts_test_utils.
Test: mmm system/security/keystore2/test_utils/; mmm system/security/keystore2/tests;
atest keystore2_client_tests; atest keystore2_test_utils_test; atest keystore2_test; atest keystore2_legacy_blobs_test;
Bug: 194359114

Change-Id: I2e17697c8ea54b1c38e128b32b4d30f1214c51fc
2023-10-06 23:15:21 +00:00
Eric Biggers
37e72923ce IKeystoreMaintenance.aidl: document permissions correctly
Test: N/A
Change-Id: Ia31dd277e17d32b857d1dd0fe58b8903c6ad2679
2023-10-06 21:42:06 +00:00
Shaquille Johnson
7f5a815ac4 Use pragma WAL in db connections
WAL mode allows db connections to open when the disk
is full. This is done in the current and legacy db and
tested manually by the commandline.

Testing: Filled a file with empty values until it took up all the space on the disk then accessed the database. This was not possible with this mode disabled but was once I enabled it on a new flash

Bug: 191777960
Test: atest keystore2_test and atest CtsKeystoreTestCases, filled real device to full and tested
Change-Id: Ic1a45fd635168061a6c5489a42a67cb59d3ddc6a
2023-10-03 11:39:28 +00:00
Shaquille Johnson
bce0cac39f Remove java generated files
Remove improper import and make the flag a constant
with the read only option

Bug: 191777960
Test: m keystore2
Change-Id: I34bd2d0d891686c93a167456e8d50eec75374244
2023-09-27 22:28:05 +01:00
Shaquille Johnson
6a751993d5 Add aconfig flags for rust keystore2
Test: m keystore2
Change-Id: I0bdd3d34a4e78500b266b8aac321ff1e2903dffb
2023-09-27 17:08:42 +01:00
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