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 | a448659 | 2023-09-05 08:25:59 +0000 | [diff] [blame] | 19 | use anyhow::{bail, Context, Result}; |
| 20 | use service_vm_comm::{Request, Response}; |
Alice Wang | 734801c | 2023-09-05 11:46:50 +0000 | [diff] [blame] | 21 | use service_vm_manager::ServiceVm; |
Alice Wang | c2fec93 | 2023-02-23 16:24:02 +0000 | [diff] [blame] | 22 | |
Alice Wang | c206b9b | 2023-08-28 14:13:51 +0000 | [diff] [blame] | 23 | pub(crate) fn request_certificate(csr: &[u8]) -> Result<Vec<u8>> { |
Alice Wang | a448659 | 2023-09-05 08:25:59 +0000 | [diff] [blame] | 24 | let mut vm = ServiceVm::start()?; |
Alice Wang | c2fec93 | 2023-02-23 16:24:02 +0000 | [diff] [blame] | 25 | |
Alice Wang | a448659 | 2023-09-05 08:25:59 +0000 | [diff] [blame] | 26 | // TODO(b/271275206): Send the correct request type with client VM's |
| 27 | // information to be attested. |
| 28 | let request = Request::Reverse(csr.to_vec()); |
Alice Wang | fbdc85b | 2023-09-07 12:56:46 +0000 | [diff] [blame] | 29 | match vm.process_request(request).context("Failed to process request")? { |
Alice Wang | a448659 | 2023-09-05 08:25:59 +0000 | [diff] [blame] | 30 | Response::Reverse(cert) => Ok(cert), |
| 31 | _ => bail!("Incorrect response type"), |
| 32 | } |
Alice Wang | c2fec93 | 2023-02-23 16:24:02 +0000 | [diff] [blame] | 33 | } |