Alice Wang | c2fec93 | 2023-02-23 16:24:02 +0000 | [diff] [blame] | 1 | // Copyright 2023, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! Handles the RKP (Remote Key Provisioning) VM and host communication. |
| 16 | //! The RKP VM will be recognized and attested by the RKP server periodically and |
| 17 | //! serves as a trusted platform to attest a client VM. |
| 18 | |
Alice Wang | f348260 | 2023-09-08 11:51:29 +0000 | [diff] [blame] | 19 | use android_hardware_security_rkp::aidl::android::hardware::security::keymint::MacedPublicKey::MacedPublicKey; |
Alice Wang | a448659 | 2023-09-05 08:25:59 +0000 | [diff] [blame] | 20 | use anyhow::{bail, Context, Result}; |
Alice Wang | bff017f | 2023-11-09 14:43:28 +0000 | [diff] [blame] | 21 | use service_vm_comm::{ |
| 22 | ClientVmAttestationParams, GenerateCertificateRequestParams, Request, Response, |
| 23 | }; |
Alice Wang | 5daec07 | 2024-03-15 15:31:17 +0000 | [diff] [blame] | 24 | use service_vm_manager::process_request; |
Alice Wang | c2fec93 | 2023-02-23 16:24:02 +0000 | [diff] [blame] | 25 | |
Alice Wang | bff017f | 2023-11-09 14:43:28 +0000 | [diff] [blame] | 26 | pub(crate) fn request_attestation( |
Alice Wang | 20b8ebc | 2023-11-17 09:54:47 +0000 | [diff] [blame] | 27 | csr: Vec<u8>, |
| 28 | remotely_provisioned_key_blob: Vec<u8>, |
| 29 | remotely_provisioned_cert: Vec<u8>, |
Alice Wang | bff017f | 2023-11-09 14:43:28 +0000 | [diff] [blame] | 30 | ) -> Result<Vec<u8>> { |
Alice Wang | 20b8ebc | 2023-11-17 09:54:47 +0000 | [diff] [blame] | 31 | let params = |
| 32 | ClientVmAttestationParams { csr, remotely_provisioned_key_blob, remotely_provisioned_cert }; |
Alice Wang | bff017f | 2023-11-09 14:43:28 +0000 | [diff] [blame] | 33 | let request = Request::RequestClientVmAttestation(params); |
Alice Wang | 5daec07 | 2024-03-15 15:31:17 +0000 | [diff] [blame] | 34 | match process_request(request).context("Failed to process request")? { |
Alice Wang | bff017f | 2023-11-09 14:43:28 +0000 | [diff] [blame] | 35 | Response::RequestClientVmAttestation(cert) => Ok(cert), |
Alice Wang | 1654e89 | 2024-02-21 15:43:57 +0000 | [diff] [blame] | 36 | other => bail!("Incorrect response type {other:?}"), |
Alice Wang | a448659 | 2023-09-05 08:25:59 +0000 | [diff] [blame] | 37 | } |
Alice Wang | c2fec93 | 2023-02-23 16:24:02 +0000 | [diff] [blame] | 38 | } |
Alice Wang | f348260 | 2023-09-08 11:51:29 +0000 | [diff] [blame] | 39 | |
Alice Wang | d80e99e | 2023-09-15 13:26:01 +0000 | [diff] [blame] | 40 | pub(crate) fn generate_ecdsa_p256_key_pair() -> Result<Response> { |
Alice Wang | f348260 | 2023-09-08 11:51:29 +0000 | [diff] [blame] | 41 | let request = Request::GenerateEcdsaP256KeyPair; |
Alice Wang | 5daec07 | 2024-03-15 15:31:17 +0000 | [diff] [blame] | 42 | process_request(request).context("Failed to process request") |
Alice Wang | f348260 | 2023-09-08 11:51:29 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | pub(crate) fn generate_certificate_request( |
| 46 | keys_to_sign: &[MacedPublicKey], |
| 47 | challenge: &[u8], |
Alice Wang | d80e99e | 2023-09-15 13:26:01 +0000 | [diff] [blame] | 48 | ) -> Result<Response> { |
Alice Wang | f348260 | 2023-09-08 11:51:29 +0000 | [diff] [blame] | 49 | let params = GenerateCertificateRequestParams { |
| 50 | keys_to_sign: keys_to_sign.iter().map(|v| v.macedKey.to_vec()).collect(), |
| 51 | challenge: challenge.to_vec(), |
| 52 | }; |
| 53 | let request = Request::GenerateCertificateRequest(params); |
| 54 | |
Alice Wang | 5daec07 | 2024-03-15 15:31:17 +0000 | [diff] [blame] | 55 | process_request(request).context("Failed to process request") |
Alice Wang | f348260 | 2023-09-08 11:51:29 +0000 | [diff] [blame] | 56 | } |