1*3f8e9d82SAndroid Build Coastguard Worker# Secretkeeper 2*3f8e9d82SAndroid Build Coastguard Worker 3*3f8e9d82SAndroid Build Coastguard WorkerSecretkeeper provides secure storage of secrets on behalf of other components in Android. 4*3f8e9d82SAndroid Build Coastguard WorkerIt is specified as [a HAL][secretkeeperhal] and must be implemented in an environment with 5*3f8e9d82SAndroid Build Coastguard Workerprivilege higher than any of its clients. Typically this will be a trusted execution environment 6*3f8e9d82SAndroid Build Coastguard Workersuch as ARM TrustZone. 7*3f8e9d82SAndroid Build Coastguard Worker 8*3f8e9d82SAndroid Build Coastguard WorkerThe core SecretManagement API is a [CBOR based protocol][secretmanagement_cddl] and can be used to 9*3f8e9d82SAndroid Build Coastguard Workerstore (& get) 32 bytes of secret data. Secretkeeper supports establishing a secure channel with 10*3f8e9d82SAndroid Build Coastguard Workerclients as well as deletion of some or all data. 11*3f8e9d82SAndroid Build Coastguard Worker 12*3f8e9d82SAndroid Build Coastguard Worker## AuthGraph key exchange 13*3f8e9d82SAndroid Build Coastguard Worker 14*3f8e9d82SAndroid Build Coastguard WorkerThe requests (from the client) & responses (from Secretkeeper) must be encrypted using symmetric 15*3f8e9d82SAndroid Build Coastguard Workerkeys agreed between the client & service. For this, Secretkeeper (& client) must implement the 16*3f8e9d82SAndroid Build Coastguard Worker[AuthGraph key exchange protocol][authgraphke] to establish a secure channel between them. 17*3f8e9d82SAndroid Build Coastguard Worker 18*3f8e9d82SAndroid Build Coastguard WorkerIn the key exchange protocol, the client acts as P1 (source) and Secretkeeper as P2 (sink). The 19*3f8e9d82SAndroid Build Coastguard Workerinterface returned by [getAuthGraphKe()][getauthgraphke] can be used to invoke methods on the sink. 20*3f8e9d82SAndroid Build Coastguard Worker 21*3f8e9d82SAndroid Build Coastguard Worker## Policy Gated Storage 22*3f8e9d82SAndroid Build Coastguard Worker 23*3f8e9d82SAndroid Build Coastguard WorkerThe storage layer of Secretkeeper, in addition to conventional storage, provides DICE 24*3f8e9d82SAndroid Build Coastguard Workerpolicy based access control. A client can restrict the access to its stored entry. 25*3f8e9d82SAndroid Build Coastguard Worker 26*3f8e9d82SAndroid Build Coastguard Worker### Storage 27*3f8e9d82SAndroid Build Coastguard Worker 28*3f8e9d82SAndroid Build Coastguard WorkerThe underlying storage of Secretkeeper should offer the following security guarantees: 29*3f8e9d82SAndroid Build Coastguard Worker 30*3f8e9d82SAndroid Build Coastguard Worker1. Confidentiality: No entity (of security privilege lower than Secretkeeper) should be able to get 31*3f8e9d82SAndroid Build Coastguard Worker a client's data in the clear. 32*3f8e9d82SAndroid Build Coastguard Worker2. Integrity: The data is protected against malicious Android OS tampering with database. i.e., if 33*3f8e9d82SAndroid Build Coastguard Worker Android (userspace & kernel) tampers with the client's secret, the Secretkeeper service must be 34*3f8e9d82SAndroid Build Coastguard Worker able to detect it & return an error when clients requests for their secrets. 35*3f8e9d82SAndroid Build Coastguard Worker **The integrity requirements also include rollback protection i.e., reverting the database 36*3f8e9d82SAndroid Build Coastguard Worker into an old state should be detected.** 37*3f8e9d82SAndroid Build Coastguard Worker3. Persistence: The data is persistent across device boot. 38*3f8e9d82SAndroid Build Coastguard Worker Note: Denial of service is not in scope. A malicious Android may be able to delete data. 39*3f8e9d82SAndroid Build Coastguard Worker In ideal situation, the data should be persistent. 40*3f8e9d82SAndroid Build Coastguard Worker 41*3f8e9d82SAndroid Build Coastguard Worker### Access control 42*3f8e9d82SAndroid Build Coastguard Worker 43*3f8e9d82SAndroid Build Coastguard WorkerSecretkeeper uses [DICE policy][DicePolicyCDDL] based access control. Each secret is associated 44*3f8e9d82SAndroid Build Coastguard Workerwith a sealing policy, which is a DICE policy. This is a required input while storing a secret. 45*3f8e9d82SAndroid Build Coastguard WorkerFurther access to this secret is restricted to clients whose DICE chain adheres to the 46*3f8e9d82SAndroid Build Coastguard Workercorresponding sealing policy. 47*3f8e9d82SAndroid Build Coastguard Worker 48*3f8e9d82SAndroid Build Coastguard Worker## Reference Implementation 49*3f8e9d82SAndroid Build Coastguard Worker 50*3f8e9d82SAndroid Build Coastguard WorkerAndroid provides a reference implementation of Secretkeeper as well as the required AuthGraph Key 51*3f8e9d82SAndroid Build Coastguard Workerexchange HAL. The implementation is modular and easily configurable. For example, 52*3f8e9d82SAndroid Build Coastguard Workerpartners can plug in their implementation of AES-GCM, RNG instead of using the BoringSSL 53*3f8e9d82SAndroid Build Coastguard Workerimplementations. 54*3f8e9d82SAndroid Build Coastguard Worker 55*3f8e9d82SAndroid Build Coastguard WorkerNavigating this project: 56*3f8e9d82SAndroid Build Coastguard Worker 57*3f8e9d82SAndroid Build Coastguard Worker1. [./core/][sk_core_dir]: Contains the reference implementation of Secretkeeper TA. 58*3f8e9d82SAndroid Build Coastguard Worker2. [./hal/][sk_hal_dir]: Contains the reference implementation of Secretkeeper HAL. 59*3f8e9d82SAndroid Build Coastguard Worker3. [./client/][sk_client_dir]: A client library for Secretkeeper, which can be used for managing 60*3f8e9d82SAndroid Build Coastguard Worker sessions with Secretkeeper, sending requests etc. 61*3f8e9d82SAndroid Build Coastguard Worker4. [./comm/][sk_comm_dir]: Secretkeeper is a CBOR heavy protocol, the Rust definition 62*3f8e9d82SAndroid Build Coastguard Worker of Requests/Response/Arguments/Errors is contained in this directory. 63*3f8e9d82SAndroid Build Coastguard Worker Additionally, Rust types for supporting the CBOR based communication between the TA and HAL is 64*3f8e9d82SAndroid Build Coastguard Worker also exported here. This is used by secretkeeper_core, secretkeeper_hal and secretkeeper_client. 65*3f8e9d82SAndroid Build Coastguard Worker5. [./dice_policy/][dice_policy_dir]: Contains code for building dice_policies as well 66*3f8e9d82SAndroid Build Coastguard Worker as well as matching them against Dice chain. As explained [here](#Policy-Gated-Storage), this 67*3f8e9d82SAndroid Build Coastguard Worker forms the foundation of Policy Gated Storage in Secretkeeper. 68*3f8e9d82SAndroid Build Coastguard Worker 69*3f8e9d82SAndroid Build Coastguard WorkerOutside this directory: 70*3f8e9d82SAndroid Build Coastguard Worker 71*3f8e9d82SAndroid Build Coastguard Worker1. Secretkeeper HAL Spec: [hardware/interfaces/security/secretkeeper/aidl/android/hardware/security/secretkeeper/ISecretkeeper.aidl][secretkeeperhal] 72*3f8e9d82SAndroid Build Coastguard Worker2. [Vendor Test Suite for Secretkeeper][secretkeeper_vts] 73*3f8e9d82SAndroid Build Coastguard Worker3. [HAL Integration for Trusty][sk_hal_trusty] 74*3f8e9d82SAndroid Build Coastguard Worker4. [TA Integration for Trusty][sk_ta_trusty] 75*3f8e9d82SAndroid Build Coastguard Worker5. [Command line test tool for interacting with Secretkeeper][secretkeeper_cli] 76*3f8e9d82SAndroid Build Coastguard Worker6. [AuthGraph HAL Spec & Test Suite][authgraphhal_dir] 77*3f8e9d82SAndroid Build Coastguard Worker7. AuthGraph Reference implementation: [system/authgraph/][authgraph_ref] 78*3f8e9d82SAndroid Build Coastguard Worker 79*3f8e9d82SAndroid Build Coastguard Worker[sk_core_dir]: https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/core/ 80*3f8e9d82SAndroid Build Coastguard Worker[sk_hal_dir]: https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/hal/ 81*3f8e9d82SAndroid Build Coastguard Worker[sk_client_dir]: https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/client/ 82*3f8e9d82SAndroid Build Coastguard Worker[sk_comm_dir]: https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/comm/ 83*3f8e9d82SAndroid Build Coastguard Worker[dice_policy_dir]: https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/dice_policy/ 84*3f8e9d82SAndroid Build Coastguard Worker[secretkeeper_vts]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/secretkeeper/aidl/vts/secretkeeper_test_client.rs 85*3f8e9d82SAndroid Build Coastguard Worker[sk_hal_trusty]: https://cs.android.com/android/platform/superproject/main/+/main:system/core/trusty/secretkeeper/src/hal_main.rs 86*3f8e9d82SAndroid Build Coastguard Worker[sk_ta_trusty]: https://android.googlesource.com/trusty/app/secretkeeper/+/refs/heads/master/lib.rs 87*3f8e9d82SAndroid Build Coastguard Worker[secretkeeper_cli]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/secretkeeper/aidl/vts/secretkeeper_cli.rs 88*3f8e9d82SAndroid Build Coastguard Worker[authgraphhal_dir]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/authgraph/aidl/ 89*3f8e9d82SAndroid Build Coastguard Worker[authgraph_ref]: https://cs.android.com/android/platform/superproject/main/+/main:system/authgraph/ 90*3f8e9d82SAndroid Build Coastguard Worker 91*3f8e9d82SAndroid Build Coastguard Worker### Porting to a Device 92*3f8e9d82SAndroid Build Coastguard Worker 93*3f8e9d82SAndroid Build Coastguard WorkerTo use the Rust reference implementation on an Android device, device-specific implementations of 94*3f8e9d82SAndroid Build Coastguard Workervarious abstractions must be provided. This section describes the different areas of functionality 95*3f8e9d82SAndroid Build Coastguard Workerthat are required. 96*3f8e9d82SAndroid Build Coastguard Worker 97*3f8e9d82SAndroid Build Coastguard Worker#### Rust Toolchain and Heap Allocator 98*3f8e9d82SAndroid Build Coastguard Worker 99*3f8e9d82SAndroid Build Coastguard WorkerUsing the reference implementation requires a Rust toolchain that can target the secure environment. 100*3f8e9d82SAndroid Build Coastguard WorkerThis toolchain (and any associated system libraries) must also support heap allocation (or an 101*3f8e9d82SAndroid Build Coastguard Workerapproximation thereof) via the [`alloc` sysroot crate](https://doc.rust-lang.org/alloc/). 102*3f8e9d82SAndroid Build Coastguard Worker 103*3f8e9d82SAndroid Build Coastguard WorkerIf the BoringSSL-based implementation of cryptographic functionality is used (see below), then some 104*3f8e9d82SAndroid Build Coastguard Workerparts of the Rust `std` library must also be provided, in order to support the compilation of the 105*3f8e9d82SAndroid Build Coastguard Worker[`openssl`](https://docs.rs/openssl) wrapper crate. 106*3f8e9d82SAndroid Build Coastguard Worker 107*3f8e9d82SAndroid Build Coastguard Worker**Checklist:** 108*3f8e9d82SAndroid Build Coastguard Worker 109*3f8e9d82SAndroid Build Coastguard Worker- [ ] Rust toolchain that targets secure environment. 110*3f8e9d82SAndroid Build Coastguard Worker- [ ] Heap allocation support via `alloc`. 111*3f8e9d82SAndroid Build Coastguard Worker 112*3f8e9d82SAndroid Build Coastguard Worker#### HAL Service 113*3f8e9d82SAndroid Build Coastguard Worker 114*3f8e9d82SAndroid Build Coastguard WorkerSecretkeeper appears as a HAL service in userspace, and so an executable that registers for and 115*3f8e9d82SAndroid Build Coastguard Workerservices the Secretkeeper HAL must be provided. 116*3f8e9d82SAndroid Build Coastguard Worker 117*3f8e9d82SAndroid Build Coastguard WorkerThe implementation of this service is mostly provided by the [`secretkeeper_hal` crate][sk_hal_dir] 118*3f8e9d82SAndroid Build Coastguard Worker(and by the associated [`authgraph_hal` 119*3f8e9d82SAndroid Build Coastguard Workercrate](https://cs.android.com/android/platform/superproject/main/+/main:system/authgraph/hal/)), 120*3f8e9d82SAndroid Build Coastguard Workerbut a driver program must be provided that: 121*3f8e9d82SAndroid Build Coastguard Worker 122*3f8e9d82SAndroid Build Coastguard Worker- Performs start-of-day administration (e.g. logging setup, panic handler setup). 123*3f8e9d82SAndroid Build Coastguard Worker- Creates communication channels to the Secretkeeper TA. 124*3f8e9d82SAndroid Build Coastguard Worker- Registers for the Secretkeeper HAL service. 125*3f8e9d82SAndroid Build Coastguard Worker- Starts a thread pool to service requests. 126*3f8e9d82SAndroid Build Coastguard Worker 127*3f8e9d82SAndroid Build Coastguard WorkerThe Secretkeeper HAL service (which runs in userspace) must communicate with the Secretkeeper TA 128*3f8e9d82SAndroid Build Coastguard Worker(which runs in the secure environment). The reference implementation assumes the existence of two 129*3f8e9d82SAndroid Build Coastguard Workerreliable, message-oriented, bi-directional communication channels for this (one for Secretkeeper, 130*3f8e9d82SAndroid Build Coastguard Workerone for AuthGraph), as encapsulated in the `authgraph_hal::channel::SerializedChannel` trait. 131*3f8e9d82SAndroid Build Coastguard Worker 132*3f8e9d82SAndroid Build Coastguard WorkerThis trait has a single method `execute()`, which takes as input a request message (as bytes), and 133*3f8e9d82SAndroid Build Coastguard Workerreturns a response message (as bytes) or an error. 134*3f8e9d82SAndroid Build Coastguard Worker 135*3f8e9d82SAndroid Build Coastguard WorkerTwo instances of this trait must be provided to the `secretkeeper_hal::SecretkeeperService` type, 136*3f8e9d82SAndroid Build Coastguard Workerwhich allows it to service Binder requests by forwarding the requests to the TA as request/response 137*3f8e9d82SAndroid Build Coastguard Workerpairs. 138*3f8e9d82SAndroid Build Coastguard Worker 139*3f8e9d82SAndroid Build Coastguard Worker**Checklist:** 140*3f8e9d82SAndroid Build Coastguard Worker 141*3f8e9d82SAndroid Build Coastguard Worker- [ ] Implementation of HAL service, which registers the Secretkeeper HAL service with Binder. 142*3f8e9d82SAndroid Build Coastguard Worker- [ ] SELinux policy for the HAL service. 143*3f8e9d82SAndroid Build Coastguard Worker- [ ] `init.rc` configuration for the HAL service. 144*3f8e9d82SAndroid Build Coastguard Worker- [ ] Implementation of `SerializedChannel` trait, for reliable HAL <-> TA communication. 145*3f8e9d82SAndroid Build Coastguard Worker 146*3f8e9d82SAndroid Build Coastguard WorkerThe [Trusty implementation of the Secretkeeper 147*3f8e9d82SAndroid Build Coastguard WorkerHAL](https://cs.android.com/android/platform/superproject/+/main:system/core/trusty/secretkeeper/src/hal_main.rs) 148*3f8e9d82SAndroid Build Coastguard Workerprovides an example of all of the above. 149*3f8e9d82SAndroid Build Coastguard Worker 150*3f8e9d82SAndroid Build Coastguard Worker#### TA Driver 151*3f8e9d82SAndroid Build Coastguard Worker 152*3f8e9d82SAndroid Build Coastguard WorkerThe `secretkeeper_core::ta` module provides the majority of the implementation of the Secretkeeper 153*3f8e9d82SAndroid Build Coastguard WorkerTA, but needs a driver program that: 154*3f8e9d82SAndroid Build Coastguard Worker 155*3f8e9d82SAndroid Build Coastguard Worker- Performs start-of-day administration (e.g. logging setup). 156*3f8e9d82SAndroid Build Coastguard Worker- Creates an `authgraph_core::ta::AuthGraphTa` instance. 157*3f8e9d82SAndroid Build Coastguard Worker- Creates a `secretkeeper_core_ta::SecretkeeperTa` instance. 158*3f8e9d82SAndroid Build Coastguard Worker- Configures the pair of communication channels that communicate with the HAL service (one for 159*3f8e9d82SAndroid Build Coastguard Worker Secretkeeper, one for AuthGraph). 160*3f8e9d82SAndroid Build Coastguard Worker- Configures the communication channel with the bootloader, which is required so that the current 161*3f8e9d82SAndroid Build Coastguard Worker Secretkeeper identity information can be retrieved at start-of-day. 162*3f8e9d82SAndroid Build Coastguard Worker- Holds the main loop that: 163*3f8e9d82SAndroid Build Coastguard Worker - reads request messages from the channel(s) 164*3f8e9d82SAndroid Build Coastguard Worker - passes request messages to `SecretkeeperTa::process()` or `AuthGraphTa::process()`, receiving 165*3f8e9d82SAndroid Build Coastguard Worker a response 166*3f8e9d82SAndroid Build Coastguard Worker - writes response messages back to the relevant channel. 167*3f8e9d82SAndroid Build Coastguard Worker 168*3f8e9d82SAndroid Build Coastguard Worker**Checklist:** 169*3f8e9d82SAndroid Build Coastguard Worker 170*3f8e9d82SAndroid Build Coastguard Worker- [ ] Implementation of `main` equivalent for TA, handling scheduling of incoming requests. 171*3f8e9d82SAndroid Build Coastguard Worker- [ ] Implementation of communication channels between HAL service and TA. 172*3f8e9d82SAndroid Build Coastguard Worker- [ ] Implementation of communication channel between bootloader and TA. 173*3f8e9d82SAndroid Build Coastguard Worker 174*3f8e9d82SAndroid Build Coastguard WorkerThe [Trusty implementation of the Secretkeeper 175*3f8e9d82SAndroid Build Coastguard WorkerTA](https://android.googlesource.com/trusty/app/secretkeeper/+/refs/heads/main/lib.rs) 176*3f8e9d82SAndroid Build Coastguard Workerprovides an example of all of the above. 177*3f8e9d82SAndroid Build Coastguard Worker 178*3f8e9d82SAndroid Build Coastguard Worker#### Bootloader 179*3f8e9d82SAndroid Build Coastguard Worker 180*3f8e9d82SAndroid Build Coastguard WorkerIf Secretkeeper is used to store secrets on behalf of protected virtual machines (pVMs), then the 181*3f8e9d82SAndroid Build Coastguard Workerbootloader is required to retrieve the identity of Secretkeeper (expressed as a public key) at boot 182*3f8e9d82SAndroid Build Coastguard Workertime so that the identity can be (securely) provided to pVM instances, as described 183*3f8e9d82SAndroid Build Coastguard Worker[below](#secretkeeper-public-key). The bootloader should use the 184*3f8e9d82SAndroid Build Coastguard Worker[`secretkeeper_core::ta::bootloader::GetIdentityKey` 185*3f8e9d82SAndroid Build Coastguard Workermessage](https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/core/src/ta/bootloader.rs?q=GetIdentityKey) 186*3f8e9d82SAndroid Build Coastguard Workerto do this. 187*3f8e9d82SAndroid Build Coastguard Worker 188*3f8e9d82SAndroid Build Coastguard Worker**Checklist:** 189*3f8e9d82SAndroid Build Coastguard Worker 190*3f8e9d82SAndroid Build Coastguard Worker- [ ] Implementation of communication channel from bootloader to TA. 191*3f8e9d82SAndroid Build Coastguard Worker- [ ] Send `GetIdentityKey` request at boot time. 192*3f8e9d82SAndroid Build Coastguard Worker- [ ] Populate the relevant device tree property. 193*3f8e9d82SAndroid Build Coastguard Worker 194*3f8e9d82SAndroid Build Coastguard Worker#### Cryptographic Abstractions 195*3f8e9d82SAndroid Build Coastguard Worker 196*3f8e9d82SAndroid Build Coastguard WorkerThe Secretkeeper TA requires implementations for low-level cryptographic primitives to be provided, 197*3f8e9d82SAndroid Build Coastguard Workerin the form of implementations of the various Rust traits held in 198*3f8e9d82SAndroid Build Coastguard Worker[`authgraph_core::traits`](https://cs.android.com/android/platform/superproject/main/+/main:system/authgraph/core/src/traits.rs). 199*3f8e9d82SAndroid Build Coastguard Worker 200*3f8e9d82SAndroid Build Coastguard WorkerNote that some of these traits include methods that have default implementations, which means that 201*3f8e9d82SAndroid Build Coastguard Workeran external implementation is not required (but can be provided if desired). 202*3f8e9d82SAndroid Build Coastguard Worker 203*3f8e9d82SAndroid Build Coastguard Worker**Checklist:** 204*3f8e9d82SAndroid Build Coastguard Worker 205*3f8e9d82SAndroid Build Coastguard Worker- [ ] RNG implementation. 206*3f8e9d82SAndroid Build Coastguard Worker- [ ] AES-GCM implementation. 207*3f8e9d82SAndroid Build Coastguard Worker- [ ] HMAC implementation. 208*3f8e9d82SAndroid Build Coastguard Worker- [ ] ECDH implementation with P-256. 209*3f8e9d82SAndroid Build Coastguard Worker- [ ] ECDSA implementation (P-256, P-384, Ed25519). 210*3f8e9d82SAndroid Build Coastguard Worker 211*3f8e9d82SAndroid Build Coastguard WorkerBoringSSL-based implementations are 212*3f8e9d82SAndroid Build Coastguard Worker[available](https://cs.android.com/android/platform/superproject/main/+/main:system/authgraph/boringssl/src/lib.rs) 213*3f8e9d82SAndroid Build Coastguard Workerfor all of the above. 214*3f8e9d82SAndroid Build Coastguard Worker 215*3f8e9d82SAndroid Build Coastguard Worker#### Device-Specific Abstractions 216*3f8e9d82SAndroid Build Coastguard Worker 217*3f8e9d82SAndroid Build Coastguard WorkerThe Secretkeeper requires an implementation of the [`secretkeeper_core::store::KeyValueStore` 218*3f8e9d82SAndroid Build Coastguard Workertrait](https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/core/src/store.rs?q=%22trait%20KeyValueStore%22) 219*3f8e9d82SAndroid Build Coastguard Workerthat abstracts away access to secure storage. 220*3f8e9d82SAndroid Build Coastguard Worker 221*3f8e9d82SAndroid Build Coastguard WorkerThe Trusty implementation of the Secretkeeper TA includes an [example 222*3f8e9d82SAndroid Build Coastguard Workerimplementation](https://android.googlesource.com/trusty/app/secretkeeper/+/refs/heads/main/store.rs). 223*3f8e9d82SAndroid Build Coastguard Worker 224*3f8e9d82SAndroid Build Coastguard Worker**Checklist:** 225*3f8e9d82SAndroid Build Coastguard Worker 226*3f8e9d82SAndroid Build Coastguard Worker- [ ] `KeyValueStore` implementation. 227*3f8e9d82SAndroid Build Coastguard Worker 228*3f8e9d82SAndroid Build Coastguard Worker## Example usage: Rollback protected secrets of Microdroid based pVMs 229*3f8e9d82SAndroid Build Coastguard Worker 230*3f8e9d82SAndroid Build Coastguard WorkerMicrodroid instances use Secretkeeper to store their secrets while protecting against the Rollback 231*3f8e9d82SAndroid Build Coastguard Workerattacks on the boot images & packages. Such secrets (and data protected by the secrets) are 232*3f8e9d82SAndroid Build Coastguard Workeraccessible on updates but not on downgrades of boot images and apks. 233*3f8e9d82SAndroid Build Coastguard Worker 234*3f8e9d82SAndroid Build Coastguard Worker[authgraphke]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/authgraph/aidl/android/hardware/security/authgraph/IAuthGraphKeyExchange.aidl 235*3f8e9d82SAndroid Build Coastguard Worker[getauthgraphke]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/secretkeeper/aidl/android/hardware/security/secretkeeper/ISecretkeeper.aidl?q=getAuthGraphKe 236*3f8e9d82SAndroid Build Coastguard Worker[secretkeeperhal]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/secretkeeper/aidl/android/hardware/security/secretkeeper/ISecretkeeper.aidl 237*3f8e9d82SAndroid Build Coastguard Worker[secretmanagement_cddl]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/secretkeeper/aidl/android/hardware/security/secretkeeper/SecretManagement.cddl 238*3f8e9d82SAndroid Build Coastguard Worker[DicePolicyCDDL]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/authgraph/aidl/android/hardware/security/authgraph/DicePolicy.cddl 239*3f8e9d82SAndroid Build Coastguard Worker 240*3f8e9d82SAndroid Build Coastguard Worker### Secretkeeper public key 241*3f8e9d82SAndroid Build Coastguard Worker 242*3f8e9d82SAndroid Build Coastguard WorkerAs described [above](#authgraph-key-exchange), Microdroid as a Secretkeeper 243*3f8e9d82SAndroid Build Coastguard Workerclient establishes a secure channel with the Secretkeeper implementation using 244*3f8e9d82SAndroid Build Coastguard Workerthe AuthGraph key exchange protocol. As part of this Microdroid needs to verify 245*3f8e9d82SAndroid Build Coastguard Workerthat it is communicating with the real Secretkeeper. 246*3f8e9d82SAndroid Build Coastguard Worker 247*3f8e9d82SAndroid Build Coastguard WorkerTo achieve this the Secretkeeper implementation should generate a per-boot key 248*3f8e9d82SAndroid Build Coastguard Workerpair and use that as its identity in the AuthGraph protocol. The public key from 249*3f8e9d82SAndroid Build Coastguard Workerthe pair then needs to be securely communicated to the Microdroid VM which uses 250*3f8e9d82SAndroid Build Coastguard Workerit to verify the identity of Secretkeeper. 251*3f8e9d82SAndroid Build Coastguard Worker 252*3f8e9d82SAndroid Build Coastguard WorkerThe public key is transported as a CBOR-encoded COSE_key, as a PubKeyEd25519 / 253*3f8e9d82SAndroid Build Coastguard WorkerPubKeyECDSA256 / PubKeyECDSA384 as defined in 254*3f8e9d82SAndroid Build Coastguard Worker[generateCertificateRequestV2.cddl][pubkeycddl]. 255*3f8e9d82SAndroid Build Coastguard Worker 256*3f8e9d82SAndroid Build Coastguard WorkerMicrodroid expects the public key to be present in the Linux device tree as the 257*3f8e9d82SAndroid Build Coastguard Workervalue of the `secretkeeper_public_key` property of the `/avf` node - exposed to 258*3f8e9d82SAndroid Build Coastguard Workeruserspace at `/proc/device-tree/avf/secretkeeper_public_key`. 259*3f8e9d82SAndroid Build Coastguard Worker 260*3f8e9d82SAndroid Build Coastguard WorkerWhen a protected VM is started, AVF populates this property in the VM DT `/avf` 261*3f8e9d82SAndroid Build Coastguard Workernode by querying `ISecretekeeper::getSecretkeeperIdentity`. pvmfw verifies that 262*3f8e9d82SAndroid Build Coastguard Workerthe value is correct using the VM reference DT that is included in the pvmfw 263*3f8e9d82SAndroid Build Coastguard Worker[configuration data][pvmfwconfig]. 264*3f8e9d82SAndroid Build Coastguard Worker 265*3f8e9d82SAndroid Build Coastguard WorkerThe [Android bootloader][androidbootloader] should request the public key from 266*3f8e9d82SAndroid Build Coastguard Workerthe Secretkeeper implementation at boot time and populate it in both the host 267*3f8e9d82SAndroid Build Coastguard WorkerAndroid DT and the VM Reference DT for pvmfw. 268*3f8e9d82SAndroid Build Coastguard Worker 269*3f8e9d82SAndroid Build Coastguard WorkerThe reference code for Secretkeeper defines a protocol that can be used by the 270*3f8e9d82SAndroid Build Coastguard Workerbootloader to retrieve the public key; see 271*3f8e9d82SAndroid Build Coastguard Worker[core/src/ta/bootloader.rs][skbootloader]. 272*3f8e9d82SAndroid Build Coastguard Worker 273*3f8e9d82SAndroid Build Coastguard Worker[pubkeycddl]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/security/rkp/aidl/android/hardware/security/keymint/generateCertificateRequestV2.cddl;l=143 274*3f8e9d82SAndroid Build Coastguard Worker[pvmfwconfig]: https://android.googlesource.com/platform/packages/modules/Virtualization/+/refs/heads/main/pvmfw/README.md#configuration-data-format 275*3f8e9d82SAndroid Build Coastguard Worker[androidbootloader]: https://source.android.com/docs/core/architecture/bootloader 276*3f8e9d82SAndroid Build Coastguard Worker[skbootloader]: https://cs.android.com/android/platform/superproject/main/+/main:system/secretkeeper/core/src/ta/bootloader.rs 277