blob: 9b3e569b72e43f3d3543535e6452cd3d45b88040 [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 Wangff5592d2023-09-13 15:27:39 +000019use super::pub_key::{build_maced_public_key, validate_public_key};
Alice Wang33f4cae2023-09-05 09:27:39 +000020use alloc::vec::Vec;
Alice Wangd80e99e2023-09-15 13:26:01 +000021use core::result;
Alice Wang77639bf2023-09-21 06:57:12 +000022use diced_open_dice::DiceArtifacts;
Alice Wangd80e99e2023-09-15 13:26:01 +000023use service_vm_comm::{EcdsaP256KeyPair, GenerateCertificateRequestParams, RequestProcessingError};
24
25type Result<T> = result::Result<T, RequestProcessingError>;
Alice Wang33f4cae2023-09-05 09:27:39 +000026
Alice Wang77639bf2023-09-21 06:57:12 +000027pub(super) fn generate_ecdsa_p256_key_pair(
28 _dice_artifacts: &dyn DiceArtifacts,
29) -> Result<EcdsaP256KeyPair> {
Alice Wanga78d3f02023-09-13 12:39:16 +000030 let hmac_key = [];
Alice Wang7b2ab942023-09-12 13:04:42 +000031 let ec_key = EcKey::new_p256()?;
Alice Wanga78d3f02023-09-13 12:39:16 +000032 let maced_public_key = build_maced_public_key(ec_key.cose_public_key()?, &hmac_key)?;
Alice Wang7b2ab942023-09-12 13:04:42 +000033
34 // TODO(b/279425980): Encrypt the private key in a key blob.
35 // Remove the printing of the private key.
36 log::debug!("Private key: {:?}", ec_key.private_key()?.as_slice());
37
Alice Wanga78d3f02023-09-13 12:39:16 +000038 let key_pair = EcdsaP256KeyPair { maced_public_key, key_blob: Vec::new() };
Alice Wang33f4cae2023-09-05 09:27:39 +000039 Ok(key_pair)
40}
Alice Wang464e4732023-09-06 12:25:22 +000041
42pub(super) fn generate_certificate_request(
Alice Wangff5592d2023-09-13 15:27:39 +000043 params: GenerateCertificateRequestParams,
Alice Wang77639bf2023-09-21 06:57:12 +000044 _dice_artifacts: &dyn DiceArtifacts,
Alice Wang464e4732023-09-06 12:25:22 +000045) -> Result<Vec<u8>> {
Alice Wangff5592d2023-09-13 15:27:39 +000046 // TODO(b/300590857): Derive the HMAC key from the DICE sealing CDI.
47 let hmac_key = [];
48 for key_to_sign in params.keys_to_sign {
49 validate_public_key(&key_to_sign, &hmac_key)?;
50 }
Alice Wang464e4732023-09-06 12:25:22 +000051 // TODO(b/299256925): Generate the certificate request
52 Ok(Vec::new())
53}