Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/certs/sev/sev/cert/v1/sig/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ impl TryFrom<&[u8]> for Signature {
}
}

#[cfg(feature = "openssl")]
impl TryFrom<&Array<u8, 144>> for ecdsa::EcdsaSig {
type Error = Error;

#[inline]
fn try_from(value: &Array<u8, 144>) -> Result<Self> {
let arr: &[u8] = value.as_ref();
let r = bn::BigNum::from_le(&arr[..SIG_PIECE_SIZE])?;
let s = bn::BigNum::from_le(&arr[SIG_PIECE_SIZE..])?;
Ok(ecdsa::EcdsaSig::from_private_components(r, s)?)
}
}

#[cfg(feature = "openssl")]
impl TryFrom<&Signature> for ecdsa::EcdsaSig {
type Error = Error;
Expand Down
23 changes: 16 additions & 7 deletions src/firmware/host/types/sev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::certs::sev::{
};

#[cfg(feature = "openssl")]
use openssl::{ec::EcKey, ecdsa::EcdsaSig, pkey::Public};
use openssl::{ec::EcKey, ecdsa::EcdsaSig, pkey::Public, sha::Sha256};

use crate::util::{TypeLoad, TypeSave};

use crate::certs::sev::sev::EcdsaSignature;
use crate::util::array::Array;
use serde::{Deserialize, Serialize};

use std::{
Expand Down Expand Up @@ -119,7 +119,7 @@ pub struct LegacyAttestationReport {
/// 128-bit Nonce from the Command Buffer.
pub mnonce: [u8; MNONCE_SIZE], // 0x00
/// SHA-256 digest of launched guest.
pub launch_digest: [u8; POLICY_SIZE], // 0x10
pub launch_digest: [u8; DIGEST_SIZE], // 0x10
/// Policy guest was launched with.
pub policy: u32, // 0x30
/// Key usage of SIG1 signing key.
Expand All @@ -129,7 +129,7 @@ pub struct LegacyAttestationReport {
/// Reserved
_reserved_0: u32, // 0x3C
/// Signature of the report.
pub signature: EcdsaSignature,
pub signature: Array<u8, 144>, // 0x40 - 0xCF
}

impl LegacyAttestationReport {
Expand All @@ -153,8 +153,17 @@ impl Verifiable for (&Certificate, &LegacyAttestationReport) {

let sig: EcdsaSig = (&self.1.signature).try_into()?;

sig.verify(&self.1.measurable_bytes(), pub_key)?;

Ok(())
let mut hasher = Sha256::new();
hasher.update(&self.1.measurable_bytes());
let base_digest = hasher.finish();

let signed = sig.verify(&base_digest, pub_key)?;
match signed {
true => Ok(()),
false => Err(std::io::Error::new(
std::io::ErrorKind::Other,
"PEK does not sign the attestation report",
)),
}
}
}