Alice Wang | 33f4cae | 2023-09-05 09:27:39 +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 | //! This module contains functions related to the attestation of the |
Alice Wang | 7b2ab94 | 2023-09-12 13:04:42 +0000 | [diff] [blame] | 16 | //! service VM via the RKP (Remote Key Provisioning) server. |
Alice Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 17 | |
Alice Wang | 7b2ab94 | 2023-09-12 13:04:42 +0000 | [diff] [blame] | 18 | use super::ec_key::EcKey; |
Alice Wang | a78d3f0 | 2023-09-13 12:39:16 +0000 | [diff] [blame^] | 19 | use super::pub_key::build_maced_public_key; |
Alice Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 20 | use alloc::vec::Vec; |
Alice Wang | d80e99e | 2023-09-15 13:26:01 +0000 | [diff] [blame] | 21 | use core::result; |
Alice Wang | 77639bf | 2023-09-21 06:57:12 +0000 | [diff] [blame] | 22 | use diced_open_dice::DiceArtifacts; |
Alice Wang | d80e99e | 2023-09-15 13:26:01 +0000 | [diff] [blame] | 23 | use service_vm_comm::{EcdsaP256KeyPair, GenerateCertificateRequestParams, RequestProcessingError}; |
| 24 | |
| 25 | type Result<T> = result::Result<T, RequestProcessingError>; |
Alice Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 26 | |
Alice Wang | 77639bf | 2023-09-21 06:57:12 +0000 | [diff] [blame] | 27 | pub(super) fn generate_ecdsa_p256_key_pair( |
| 28 | _dice_artifacts: &dyn DiceArtifacts, |
| 29 | ) -> Result<EcdsaP256KeyPair> { |
Alice Wang | a78d3f0 | 2023-09-13 12:39:16 +0000 | [diff] [blame^] | 30 | let hmac_key = []; |
Alice Wang | 7b2ab94 | 2023-09-12 13:04:42 +0000 | [diff] [blame] | 31 | let ec_key = EcKey::new_p256()?; |
Alice Wang | a78d3f0 | 2023-09-13 12:39:16 +0000 | [diff] [blame^] | 32 | let maced_public_key = build_maced_public_key(ec_key.cose_public_key()?, &hmac_key)?; |
Alice Wang | 7b2ab94 | 2023-09-12 13:04:42 +0000 | [diff] [blame] | 33 | |
| 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 Wang | a78d3f0 | 2023-09-13 12:39:16 +0000 | [diff] [blame^] | 38 | let key_pair = EcdsaP256KeyPair { maced_public_key, key_blob: Vec::new() }; |
Alice Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 39 | Ok(key_pair) |
| 40 | } |
Alice Wang | 464e473 | 2023-09-06 12:25:22 +0000 | [diff] [blame] | 41 | |
| 42 | pub(super) fn generate_certificate_request( |
| 43 | _params: GenerateCertificateRequestParams, |
Alice Wang | 77639bf | 2023-09-21 06:57:12 +0000 | [diff] [blame] | 44 | _dice_artifacts: &dyn DiceArtifacts, |
Alice Wang | 464e473 | 2023-09-06 12:25:22 +0000 | [diff] [blame] | 45 | ) -> Result<Vec<u8>> { |
| 46 | // TODO(b/299256925): Generate the certificate request |
| 47 | Ok(Vec::new()) |
| 48 | } |