blob: bb05edd1a6c976eb2701aaab0c11040ffd0297cb [file] [log] [blame]
Alice Wangc2fec932023-02-23 16:24:02 +00001// 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 Wangc206b9b2023-08-28 14:13:51 +000019use crate::service_vm;
20use anyhow::{anyhow, Result};
Alice Wangc2fec932023-02-23 16:24:02 +000021use log::info;
Alice Wangc2fec932023-02-23 16:24:02 +000022use std::time::Duration;
Alice Wangc2fec932023-02-23 16:24:02 +000023
Alice Wangc206b9b2023-08-28 14:13:51 +000024pub(crate) fn request_certificate(csr: &[u8]) -> Result<Vec<u8>> {
25 let vm = service_vm::start()?;
Alice Wangc2fec932023-02-23 16:24:02 +000026
27 // TODO(b/274441673): The host can send the CSR to the RKP VM for attestation.
28 // Wait for VM to finish.
29 vm.wait_for_death_with_timeout(Duration::from_secs(10))
30 .ok_or_else(|| anyhow!("Timed out waiting for VM exit"))?;
31
32 info!("service_vm: Finished getting the certificate");
33 Ok([b"Return: ", csr].concat())
34}