blob: 66d36038a1f182bdfc2f475f6945d49e21825086 [file] [log] [blame]
Alice Wang33f4cae2023-09-05 09:27:39 +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//! This module contains functions related to the attestation of the
Alice Wang7b2ab942023-09-12 13:04:42 +000016//! service VM via the RKP (Remote Key Provisioning) server.
Alice Wang33f4cae2023-09-05 09:27:39 +000017
Alice Wang7b2ab942023-09-12 13:04:42 +000018use super::ec_key::EcKey;
Alice Wang33f4cae2023-09-05 09:27:39 +000019use alloc::vec::Vec;
Alice Wangd80e99e2023-09-15 13:26:01 +000020use core::result;
Alice Wang77639bf2023-09-21 06:57:12 +000021use diced_open_dice::DiceArtifacts;
Alice Wangd80e99e2023-09-15 13:26:01 +000022use service_vm_comm::{EcdsaP256KeyPair, GenerateCertificateRequestParams, RequestProcessingError};
23
24type Result<T> = result::Result<T, RequestProcessingError>;
Alice Wang33f4cae2023-09-05 09:27:39 +000025
Alice Wang77639bf2023-09-21 06:57:12 +000026pub(super) fn generate_ecdsa_p256_key_pair(
27 _dice_artifacts: &dyn DiceArtifacts,
28) -> Result<EcdsaP256KeyPair> {
Alice Wang7b2ab942023-09-12 13:04:42 +000029 let ec_key = EcKey::new_p256()?;
30
31 // TODO(b/279425980): Encrypt the private key in a key blob.
32 // Remove the printing of the private key.
33 log::debug!("Private key: {:?}", ec_key.private_key()?.as_slice());
34
35 // TODO(b/300068317): Build MACed public key.
Alice Wang33f4cae2023-09-05 09:27:39 +000036 let key_pair = EcdsaP256KeyPair { maced_public_key: Vec::new(), key_blob: Vec::new() };
37 Ok(key_pair)
38}
Alice Wang464e4732023-09-06 12:25:22 +000039
40pub(super) fn generate_certificate_request(
41 _params: GenerateCertificateRequestParams,
Alice Wang77639bf2023-09-21 06:57:12 +000042 _dice_artifacts: &dyn DiceArtifacts,
Alice Wang464e4732023-09-06 12:25:22 +000043) -> Result<Vec<u8>> {
44 // TODO(b/299256925): Generate the certificate request
45 Ok(Vec::new())
46}