From c00f7665dbba08afa7f9dec7a6248af4bd62a180 Mon Sep 17 00:00:00 2001 From: Carl Lundin Date: Wed, 18 Dec 2024 11:38:09 -0800 Subject: [PATCH] Remove Symmetric signing. --- Cargo.lock | 1 - crypto/Cargo.toml | 3 +- crypto/src/lib.rs | 18 ---- crypto/src/openssl.rs | 24 +---- crypto/src/rustcrypto.rs | 28 +----- crypto/src/signer.rs | 3 - dpe/Cargo.toml | 1 - dpe/src/commands/certify_key.rs | 2 - dpe/src/commands/derive_context.rs | 2 +- dpe/src/commands/sign.rs | 139 ++------------------------ dpe/src/response.rs | 2 +- dpe/src/support.rs | 18 +--- simulator/src/main.rs | 5 - verification/client/abi.go | 8 +- verification/client/client.go | 6 +- verification/sim/transport.go | 3 - verification/testing/negativeCases.go | 8 -- verification/testing/sign.go | 69 +------------ verification/testing/simulator.go | 9 +- verification/testing/tpm.go | 2 +- verification/testing/verification.go | 6 -- 21 files changed, 25 insertions(+), 332 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c3751f9..9c642681 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,7 +296,6 @@ dependencies = [ "caliptra-cfi-lib-git", "ecdsa", "hkdf", - "hmac", "openssl", "p256", "p384", diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index e14f71e8..9af37bbc 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [features] openssl = ["dep:openssl", "dep:hkdf", "dep:sha2"] -rustcrypto = ["dep:hkdf", "dep:hmac", "dep:p256", "dep:p384", "dep:rand", "dep:sha2", "dep:base64ct", "dep:ecdsa", "dep:sec1"] +rustcrypto = ["dep:hkdf", "dep:p256", "dep:p384", "dep:rand", "dep:sha2", "dep:base64ct", "dep:ecdsa", "dep:sec1"] deterministic_rand = ["dep:rand"] no-cfi = [] @@ -17,7 +17,6 @@ caliptra-cfi-lib-git = { workspace = true, default-features = false, features = caliptra-cfi-derive-git.workspace = true ecdsa = { version = "0.16.9", optional = true, features = ["pem"]} hkdf = { version = "0.12.3", optional = true } -hmac = {version="0.12.1", optional = true} openssl = {workspace = true, optional = true} p256 = {version= "0.13.2", optional = true} p384 = {version= "0.13.0", optional = true} diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index cb9aee03..33d9b348 100644 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -240,24 +240,6 @@ pub trait Crypto { priv_key: &Self::PrivKey, pub_key: &EcdsaPub, ) -> Result; - - /// Sign `digest` with a derived HMAC key from the CDI. - /// - /// # Arguments - /// - /// * `algs` - Which length of algorithms to use. - /// * `cdi` - CDI from which to derive the signing key - /// * `label` - Caller-supplied label to use in symmetric key derivation - /// * `info` - Caller-supplied info string to use in symmetric key derivation - /// * `digest` - Digest of data to be signed. - fn hmac_sign_with_derived( - &mut self, - algs: AlgLen, - cdi: &Self::Cdi, - label: &[u8], - info: &[u8], - digest: &Digest, - ) -> Result; } #[cfg(test)] mod tests { diff --git a/crypto/src/openssl.rs b/crypto/src/openssl.rs index 29d27fae..f1bba622 100644 --- a/crypto/src/openssl.rs +++ b/crypto/src/openssl.rs @@ -1,6 +1,6 @@ // Licensed under the Apache-2.0 license -use crate::{hkdf::*, AlgLen, Crypto, CryptoBuf, CryptoError, Digest, EcdsaPub, Hasher, HmacSig}; +use crate::{hkdf::*, AlgLen, Crypto, CryptoBuf, CryptoError, Digest, EcdsaPub, Hasher}; #[cfg(not(feature = "no-cfi"))] use caliptra_cfi_derive_git::cfi_impl_fn; use openssl::{ @@ -10,8 +10,7 @@ use openssl::{ error::ErrorStack, hash::MessageDigest, nid::Nid, - pkey::{PKey, Private}, - sign::Signer, + pkey::Private, }; #[cfg(feature = "deterministic_rand")] use rand::{rngs::StdRng, RngCore, SeedableRng}; @@ -205,23 +204,4 @@ impl Crypto for OpensslCrypto { Ok(super::EcdsaSig { r, s }) } - - fn hmac_sign_with_derived( - &mut self, - algs: AlgLen, - cdi: &Self::Cdi, - label: &[u8], - info: &[u8], - digest: &Digest, - ) -> Result { - let (symmetric_key, _) = self.derive_key_pair(algs, cdi, label, info)?; - let hmac_key = PKey::hmac(symmetric_key.bytes()).unwrap(); - - let sha_size = Self::get_digest(algs); - let mut signer = Signer::new(sha_size, &hmac_key).unwrap(); - signer.update(digest.bytes()).unwrap(); - let hmac = signer.sign_to_vec().unwrap(); - - Ok(HmacSig::new(&hmac).unwrap()) - } } diff --git a/crypto/src/rustcrypto.rs b/crypto/src/rustcrypto.rs index 51610607..5a691032 100644 --- a/crypto/src/rustcrypto.rs +++ b/crypto/src/rustcrypto.rs @@ -1,11 +1,8 @@ // Licensed under the Apache-2.0 license -use crate::{ - hkdf::*, AlgLen, Crypto, CryptoBuf, CryptoError, Digest, EcdsaPub, EcdsaSig, Hasher, HmacSig, -}; +use crate::{hkdf::*, AlgLen, Crypto, CryptoBuf, CryptoError, Digest, EcdsaPub, EcdsaSig, Hasher}; use core::ops::Deref; use ecdsa::{signature::hazmat::PrehashSigner, Signature}; -use hmac::{Hmac, Mac}; use p256::NistP256; use p384::NistP384; use rand::{rngs::StdRng, RngCore, SeedableRng}; @@ -174,27 +171,4 @@ impl Crypto for RustCryptoImpl { } } } - - fn hmac_sign_with_derived( - &mut self, - algs: AlgLen, - cdi: &Self::Cdi, - label: &[u8], - info: &[u8], - digest: &Digest, - ) -> Result { - let (symmetric_key, _) = self.derive_key_pair(algs, cdi, label, info)?; - match algs { - AlgLen::Bit256 => { - let mut hmac = Hmac::::new_from_slice(symmetric_key.bytes()).unwrap(); - Mac::update(&mut hmac, digest.bytes()); - HmacSig::new(hmac.finalize().into_bytes().as_slice()) - } - AlgLen::Bit384 => { - let mut hmac = Hmac::::new_from_slice(symmetric_key.bytes()).unwrap(); - Mac::update(&mut hmac, digest.bytes()); - HmacSig::new(hmac.finalize().into_bytes().as_slice()) - } - } - } } diff --git a/crypto/src/signer.rs b/crypto/src/signer.rs index 139ad093..c09191c8 100644 --- a/crypto/src/signer.rs +++ b/crypto/src/signer.rs @@ -26,9 +26,6 @@ impl EcdsaPub { } } -/// An HMAC Signature -pub type HmacSig = CryptoBuf; - /// A common base struct that can be used for all digests, signatures, and keys. #[derive(Debug, PartialEq, Eq, ZeroizeOnDrop)] pub struct CryptoBuf(ArrayVec); diff --git a/dpe/Cargo.toml b/dpe/Cargo.toml index 0329a1e4..57f287f5 100644 --- a/dpe/Cargo.toml +++ b/dpe/Cargo.toml @@ -17,7 +17,6 @@ disable_auto_init = [] disable_rotate_context = [] disable_x509 = [] disable_csr = [] -disable_is_symmetric = [] disable_internal_info = [] disable_internal_dice = [] disable_retain_parent_context = [] diff --git a/dpe/src/commands/certify_key.rs b/dpe/src/commands/certify_key.rs index 9cc0a4c6..5b217ed2 100644 --- a/dpe/src/commands/certify_key.rs +++ b/dpe/src/commands/certify_key.rs @@ -298,7 +298,6 @@ mod tests { dpe_instance::tests::{TestTypes, SIMULATION_HANDLE, TEST_LOCALITIES}, support::Support, x509::tests::TcbInfo, - DpeProfile, }; use caliptra_cfi_lib_git::CfiCounter; use cms::{ @@ -311,7 +310,6 @@ mod tests { bn::BigNum, ec::{EcGroup, EcKey}, ecdsa::EcdsaSig, - hash::{Hasher, MessageDigest}, nid::*, }; use platform::default::DefaultPlatform; diff --git a/dpe/src/commands/derive_context.rs b/dpe/src/commands/derive_context.rs index 5dc9e356..39acc8d6 100644 --- a/dpe/src/commands/derive_context.rs +++ b/dpe/src/commands/derive_context.rs @@ -678,7 +678,7 @@ mod tests { Ok(Response::Sign(resp)) => ( resp.new_context_handle, EcdsaSig::from_private_components( - BigNum::from_slice(&resp.sig_r_or_hmac).unwrap(), + BigNum::from_slice(&resp.sig_r).unwrap(), BigNum::from_slice(&resp.sig_s).unwrap(), ) .unwrap(), diff --git a/dpe/src/commands/sign.rs b/dpe/src/commands/sign.rs index 574322e0..cca0e2e4 100644 --- a/dpe/src/commands/sign.rs +++ b/dpe/src/commands/sign.rs @@ -14,8 +14,6 @@ use caliptra_cfi_lib_git::cfi_launder; use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq, cfi_assert_ne}; use cfg_if::cfg_if; use crypto::{Crypto, Digest, EcdsaSig}; -#[cfg(not(feature = "disable_is_symmetric"))] -use crypto::{CryptoBuf, HmacSig}; #[repr(C)] #[derive( @@ -30,9 +28,7 @@ use crypto::{CryptoBuf, HmacSig}; pub struct SignFlags(u32); bitflags! { - impl SignFlags: u32 { - const IS_SYMMETRIC = 1u32 << 30; - } + impl SignFlags: u32 {} } #[repr(C)] @@ -53,10 +49,6 @@ pub struct SignCmd { } impl SignCmd { - const fn uses_symmetric(&self) -> bool { - self.flags.contains(SignFlags::IS_SYMMETRIC) - } - /// Signs `digest` using ECDSA /// /// # Arguments @@ -94,40 +86,6 @@ impl SignCmd { Ok(sig) } - - /// Signs `digest` using an HMAC - /// - /// # Arguments - /// - /// * `dpe` - DPE instance - /// * `env` - DPE environment containing Crypto and Platform implementations - /// * `idx` - The index of the context where the measurement hash is computed from - /// * `digest` - The data to be signed - #[cfg_attr(not(feature = "no-cfi"), cfi_impl_fn)] - #[cfg(not(feature = "disable_is_symmetric"))] - fn hmac_sign( - &self, - dpe: &mut DpeInstance, - env: &mut DpeEnv, - idx: usize, - digest: &Digest, - ) -> Result { - let algs = DPE_PROFILE.alg_len(); - let cdi_digest = dpe.compute_measurement_hash(env, idx)?; - let cdi = env - .crypto - .derive_cdi(DPE_PROFILE.alg_len(), &cdi_digest, b"DPE"); - if cfi_launder(cdi.is_ok()) { - #[cfg(not(feature = "no-cfi"))] - cfi_assert!(cdi.is_ok()); - } else { - #[cfg(not(feature = "no-cfi"))] - cfi_assert!(cdi.is_err()); - } - Ok(env - .crypto - .hmac_sign_with_derived(algs, &cdi?, &self.label, b"HMAC", digest)?) - } } impl CommandExecution for SignCmd { @@ -138,11 +96,6 @@ impl CommandExecution for SignCmd { env: &mut DpeEnv, locality: u32, ) -> Result { - // Make sure the operation is supported. - if !dpe.support.is_symmetric() && self.uses_symmetric() { - return Err(DpeErrorCode::ArgumentNotSupported); - } - let idx = dpe.get_active_context_pos(&self.handle, locality)?; let context = &dpe.contexts[idx]; @@ -152,29 +105,14 @@ impl CommandExecution for SignCmd { cfg_if! { if #[cfg(not(feature = "no-cfi"))] { - cfi_assert!(dpe.support.is_symmetric() || !self.uses_symmetric()); cfi_assert_ne(context.context_type, ContextType::Simulation); } } let digest = Digest::new(&self.digest)?; - let EcdsaSig { r, s } = if !self.uses_symmetric() { - self.ecdsa_sign(dpe, env, idx, &digest)? - } else { - cfg_if! { - if #[cfg(not(feature = "disable_is_symmetric"))] { - let algs = DPE_PROFILE.alg_len(); - let r = self.hmac_sign(dpe, env, idx, &digest)?; - let s = CryptoBuf::default(algs); - EcdsaSig { r, s } - } - else { - Err(DpeErrorCode::ArgumentNotSupported)? - } - } - }; + let EcdsaSig { r, s } = self.ecdsa_sign(dpe, env, idx, &digest)?; - let sig_r_or_hmac: [u8; DPE_PROFILE.get_ecc_int_size()] = r + let sig_r: [u8; DPE_PROFILE.get_ecc_int_size()] = r .bytes() .try_into() .map_err(|_| DpeErrorCode::InternalError)?; @@ -189,7 +127,7 @@ impl CommandExecution for SignCmd { Ok(Response::Sign(SignResp { new_context_handle: dpe.contexts[idx].handle, - sig_r_or_hmac, + sig_r, sig_s, resp_hdr: ResponseHdr::new(DpeErrorCode::NoError), })) @@ -208,7 +146,7 @@ mod tests { Command, CommandHdr, DeriveContextCmd, InitCtxCmd, }, dpe_instance::tests::{TestTypes, RANDOM_HANDLE, SIMULATION_HANDLE, TEST_LOCALITIES}, - support::{test::SUPPORT, Support}, + support::test::SUPPORT, }; use caliptra_cfi_lib_git::CfiCounter; use crypto::OpensslCrypto; @@ -235,24 +173,6 @@ mod tests { ); } - #[test] - fn test_uses_symmetric() { - CfiCounter::reset_for_test(); - // No flags set. - assert!(!SignCmd { - flags: SignFlags::empty(), - ..TEST_SIGN_CMD - } - .uses_symmetric()); - - // Just is-symmetric flag set. - assert!(SignCmd { - flags: SignFlags::IS_SYMMETRIC, - ..TEST_SIGN_CMD - } - .uses_symmetric()); - } - #[test] fn test_bad_command_inputs() { CfiCounter::reset_for_test(); @@ -262,18 +182,6 @@ mod tests { }; let mut dpe = DpeInstance::new(&mut env, SUPPORT).unwrap(); - // Bad argument - assert_eq!( - Err(DpeErrorCode::ArgumentNotSupported), - SignCmd { - handle: ContextHandle([0xff; ContextHandle::SIZE]), - label: TEST_LABEL, - flags: SignFlags::IS_SYMMETRIC, - digest: TEST_DIGEST - } - .execute(&mut dpe, &mut env, TEST_LOCALITIES[0]) - ); - // Bad handle. assert_eq!( Err(DpeErrorCode::InvalidHandle), @@ -354,7 +262,7 @@ mod tests { }; EcdsaSig::from_private_components( - BigNum::from_slice(&resp.sig_r_or_hmac).unwrap(), + BigNum::from_slice(&resp.sig_r).unwrap(), BigNum::from_slice(&resp.sig_s).unwrap(), ) .unwrap() @@ -379,39 +287,4 @@ mod tests { assert!(sig.verify(&TEST_DIGEST, &ec_pub_key).unwrap()); } - - #[test] - fn test_symmetric() { - CfiCounter::reset_for_test(); - let mut env = DpeEnv:: { - crypto: OpensslCrypto::new(), - platform: DefaultPlatform, - }; - let mut dpe = - DpeInstance::new(&mut env, Support::AUTO_INIT | Support::IS_SYMMETRIC).unwrap(); - - let cmd = SignCmd { - handle: ContextHandle::default(), - label: TEST_LABEL, - flags: SignFlags::IS_SYMMETRIC, - digest: TEST_DIGEST, - }; - let resp = match cmd.execute(&mut dpe, &mut env, TEST_LOCALITIES[0]).unwrap() { - Response::Sign(resp) => resp, - _ => panic!("Incorrect response type"), - }; - - let idx = dpe - .get_active_context_pos(&ContextHandle::default(), TEST_LOCALITIES[0]) - .unwrap(); - // Check that r is equal to the HMAC over the digest - assert_eq!( - resp.sig_r_or_hmac, - cmd.hmac_sign(&mut dpe, &mut env, idx, &Digest::new(&TEST_DIGEST).unwrap(),) - .unwrap() - .bytes() - ); - // Check that s is a buffer of all 0s - assert!(&resp.sig_s.iter().all(|&b| b == 0x0)); - } } diff --git a/dpe/src/response.rs b/dpe/src/response.rs index 22d042ed..18c1f533 100644 --- a/dpe/src/response.rs +++ b/dpe/src/response.rs @@ -173,7 +173,7 @@ pub struct CertifyKeyResp { pub struct SignResp { pub resp_hdr: ResponseHdr, pub new_context_handle: ContextHandle, - pub sig_r_or_hmac: [u8; DPE_PROFILE.get_ecc_int_size()], + pub sig_r: [u8; DPE_PROFILE.get_ecc_int_size()], pub sig_s: [u8; DPE_PROFILE.get_ecc_int_size()], } diff --git a/dpe/src/support.rs b/dpe/src/support.rs index 938f9881..d5f75220 100644 --- a/dpe/src/support.rs +++ b/dpe/src/support.rs @@ -15,7 +15,6 @@ bitflags! { const ROTATE_CONTEXT = 1u32 << 27; const X509 = 1u32 << 26; const CSR = 1u32 << 25; - const IS_SYMMETRIC = 1u32 << 24; const INTERNAL_INFO = 1u32 << 22; const INTERNAL_DICE = 1u32 << 21; const RETAIN_PARENT_CONTEXT = 1u32 << 19; @@ -41,9 +40,6 @@ impl Support { pub fn csr(&self) -> bool { self.contains(Support::CSR) } - pub fn is_symmetric(&self) -> bool { - self.contains(Support::IS_SYMMETRIC) - } pub fn internal_info(&self) -> bool { self.contains(Support::INTERNAL_INFO) } @@ -82,10 +78,6 @@ impl Support { { support.insert(Support::CSR); } - #[cfg(feature = "disable_is_symmetric")] - { - support.insert(Support::IS_SYMMETRIC); - } #[cfg(feature = "disable_internal_info")] { support.insert(Support::INTERNAL_INFO); @@ -135,9 +127,6 @@ pub mod test { // Supports certify csr. let flags = Support::CSR.bits(); assert_eq!(flags, 1 << 25); - // Supports is symmetric. - let flags = Support::IS_SYMMETRIC.bits(); - assert_eq!(flags, 1 << 24); // Supports internal info. let flags = Support::INTERNAL_INFO.bits(); assert_eq!(flags, 1 << 22); @@ -157,10 +146,8 @@ pub mod test { flags, (1 << 31) | (1 << 29) | (1 << 27) | (1 << 25) | (1 << 21) ); - let flags = - (Support::RECURSIVE | Support::X509 | Support::IS_SYMMETRIC | Support::INTERNAL_INFO) - .bits(); - assert_eq!(flags, (1 << 30) | (1 << 26) | (1 << 24) | (1 << 22)); + let flags = (Support::RECURSIVE | Support::X509 | Support::INTERNAL_INFO).bits(); + assert_eq!(flags, (1 << 30) | (1 << 26) | (1 << 22)); // Supports everything. let flags = Support::all().bits(); assert_eq!( @@ -171,7 +158,6 @@ pub mod test { | (1 << 27) | (1 << 26) | (1 << 25) - | (1 << 24) | (1 << 22) | (1 << 21) | (1 << 19) diff --git a/simulator/src/main.rs b/simulator/src/main.rs index 851a48cf..36120dc0 100644 --- a/simulator/src/main.rs +++ b/simulator/src/main.rs @@ -100,10 +100,6 @@ struct Args { #[arg(long)] supports_csr: bool, - /// Supports symmetric derivation. - #[arg(long)] - supports_is_symmetric: bool, - /// Supports the INTERNAL_INPUT_INFO extension to DeriveContext #[arg(long)] supports_internal_info: bool, @@ -155,7 +151,6 @@ fn main() -> std::io::Result<()> { support.set(Support::ROTATE_CONTEXT, args.supports_rotate_context); support.set(Support::INTERNAL_DICE, args.supports_internal_dice); support.set(Support::INTERNAL_INFO, args.supports_internal_info); - support.set(Support::IS_SYMMETRIC, args.supports_is_symmetric); support.set( Support::RETAIN_PARENT_CONTEXT, args.supports_retain_parent_context, diff --git a/verification/client/abi.go b/verification/client/abi.go index 2707734e..2ba12073 100644 --- a/verification/client/abi.go +++ b/verification/client/abi.go @@ -259,7 +259,7 @@ type SignReq[Digest DigestAlgorithm] struct { // SignResp is the output response from Sign type SignResp[Digest DigestAlgorithm] struct { NewContextHandle ContextHandle - HmacOrSignatureR Digest + SignatureR Digest SignatureS Digest } @@ -694,9 +694,9 @@ func (c *DPEABI[_, Digest, _]) Sign(handle *ContextHandle, label []byte, flags S } signedResp := &DPESignedHash{ - Handle: resp.NewContextHandle, - HmacOrSignatureR: resp.HmacOrSignatureR.Bytes(), - SignatureS: resp.SignatureS.Bytes(), + Handle: resp.NewContextHandle, + SignatureR: resp.SignatureR.Bytes(), + SignatureS: resp.SignatureS.Bytes(), } return signedResp, nil diff --git a/verification/client/client.go b/verification/client/client.go index 260b1fa6..1a4cb617 100644 --- a/verification/client/client.go +++ b/verification/client/client.go @@ -41,9 +41,9 @@ type DPETCI struct { // DPESignedHash is the response from DPE Sign type DPESignedHash struct { - Handle ContextHandle - HmacOrSignatureR []byte - SignatureS []byte + Handle ContextHandle + SignatureR []byte + SignatureS []byte } // DPEClient is a generic interface to a DPE instance diff --git a/verification/sim/transport.go b/verification/sim/transport.go index c08cc42b..19518b7a 100644 --- a/verification/sim/transport.go +++ b/verification/sim/transport.go @@ -73,9 +73,6 @@ func (s *DpeSimulator) PowerOn() error { if s.supports.Csr { args = append(args, "--supports-csr") } - if s.supports.IsSymmetric { - args = append(args, "--supports-is-symmetric") - } if s.supports.InternalInfo { args = append(args, "--supports-internal-info") } diff --git a/verification/testing/negativeCases.go b/verification/testing/negativeCases.go index 5d9d5422..245f06ca 100644 --- a/verification/testing/negativeCases.go +++ b/verification/testing/negativeCases.go @@ -146,7 +146,6 @@ func TestUnsupportedCommand(d client.TestDPEInstance, c client.DPEClient, t *tes // IsCA : Allows caller to request the key cert of CA // Csr : Allows caller to request the key cert in CSR format // X509 : Allows caller to request the key cert in X509 format -// IsSymmetric : Allows caller to request for symmetric signing // InternalInfo : Allows caller to derive child context with InternalInfo // InternalDice : Allows caller to derive child context with InternalDice func TestUnsupportedCommandFlag(d client.TestDPEInstance, c client.DPEClient, t *testing.T) { @@ -179,13 +178,6 @@ func TestUnsupportedCommandFlag(d client.TestDPEInstance, c client.DPEClient, t t.Errorf("[ERROR]: Incorrect error type. X509 format is not supported by DPE, CertifyKey should return %q, but returned %q", client.StatusArgumentNotSupported, err) } - // Check whether error is returned since symmetric signing is unsupported by DPE profile - if _, err := c.Sign(handle, make([]byte, digestLen), client.SignFlags(client.IsSymmetric), make([]byte, digestLen)); err == nil { - t.Errorf("[ERROR]: Symmetric signing is not supported by DPE, Sign should return %q, but returned no error", client.StatusInvalidArgument) - } else if !errors.Is(err, client.StatusArgumentNotSupported) { - t.Errorf("[ERROR]: Incorrect error type. Symmetric signing is not supported by DPE, Sign should return %q, but returned %q", client.StatusInvalidArgument, err) - } - // Check whether error is returned since InternalInfo usage is unsupported by DPE profile if _, err := c.DeriveContext(handle, make([]byte, digestLen), client.DeriveContextFlags(client.InternalInputInfo), 0, 0); err == nil { t.Errorf("[ERROR]:InternalInfo is not supported by DPE, DeriveContext should return %q, but returned no error", client.StatusArgumentNotSupported) diff --git a/verification/testing/sign.go b/verification/testing/sign.go index 7f4c0e4d..b4abc041 100644 --- a/verification/testing/sign.go +++ b/verification/testing/sign.go @@ -3,7 +3,6 @@ package verification import ( - "bytes" "crypto/ecdsa" "crypto/elliptic" "crypto/x509" @@ -17,8 +16,6 @@ import ( // TestAsymmetricSigning obtains and validates signature of asymmetric signing. // Check whether the digital signature returned by Sign command can be verified // using public key in signing key certificate returned by CertifyKey command. -// Inspite of the DPE profile supporting symmetric key, for symmetric signing it must be enabled -// explicitly in Sign command flags. Else asymmetric signing is used as default. func TestAsymmetricSigning(d client.TestDPEInstance, c client.DPEClient, t *testing.T) { useSimulation := false handle := getInitialContextHandle(d, c, t, useSimulation) @@ -73,7 +70,7 @@ func TestAsymmetricSigning(d client.TestDPEInstance, c client.DPEClient, t *test publicKey := ecdsa.PublicKey{Curve: ec, X: x, Y: y} // Build Signature from bytes - r := new(big.Int).SetBytes(signResp.HmacOrSignatureR) + r := new(big.Int).SetBytes(signResp.SignatureR) s := new(big.Int).SetBytes(signResp.SignatureS) // Verify Signature @@ -100,73 +97,9 @@ func TestSignSimulation(d client.TestDPEInstance, c client.DPEClient, t *testing digestLen := profile.GetDigestSize() - if _, err := c.Sign(handle, make([]byte, digestLen), client.SignFlags(client.IsSymmetric), make([]byte, digestLen)); err == nil { - t.Fatalf("[FATAL]: Should return %q, but returned no error", client.StatusInvalidArgument) - } else if !errors.Is(err, client.StatusInvalidArgument) { - t.Fatalf("[FATAL]: Incorrect error type. Should return %q, but returned %q", client.StatusInvalidArgument, err) - } - if _, err := c.Sign(handle, make([]byte, digestLen), client.SignFlags(0), make([]byte, digestLen)); err == nil { t.Fatalf("[FATAL]: Should return %q, but returned no error", client.StatusInvalidArgument) } else if !errors.Is(err, client.StatusInvalidArgument) { t.Fatalf("[FATAL]: Incorrect error type. Should return %q, but returned %q", client.StatusInvalidArgument, err) } } - -// TestSymmetricSigning obtains HMAC (symmetric signature) generated and compares for varying label inputs. -// Signature created is deterministic and depends on label passed to command. -// This is because label is used by DPE in symmetric key derivation. -// Invoking Sign command multiple times with same label and same content (TBS) should return same signature -// but it should return different signatures for different labels despite having the same content (To Be Signed content). -func TestSymmetricSigning(d client.TestDPEInstance, c client.DPEClient, t *testing.T) { - useSimulation := false - handle := getInitialContextHandle(d, c, t, useSimulation) - - // Get digest size - profile, err := client.GetTransportProfile(d) - if err != nil { - t.Fatalf("Could not get profile: %v", err) - } - - digestLen := profile.GetDigestSize() - label := make([]byte, digestLen) - for i := range label { - label[i] = byte(i) - } - - tbs := make([]byte, digestLen) - for i := range tbs { - tbs[i] = byte(i) - } - - signedData, err := c.Sign(handle, label, client.SignFlags(client.IsSymmetric), tbs) - if err != nil { - t.Fatalf("[FATAL]: Error while signing %v", err) - } - - // Rerun with same label and compare signature emitted. - signedDataWithSameLabel, err := c.Sign(handle, label, client.SignFlags(client.IsSymmetric), tbs) - if err != nil { - t.Fatalf("[FATAL]: Error while signing %v", err) - } - - // Symmetric sign only populates HmacOrSignatureR. SignatureS is all zeroes. - if !bytes.Equal(signedDataWithSameLabel.HmacOrSignatureR, signedData.HmacOrSignatureR) { - t.Errorf("[ERROR]: Signature varies for same label, want %v but got %v", signedData.HmacOrSignatureR, signedDataWithSameLabel.HmacOrSignatureR) - } - - // Rerun with different label, signature must change this time - newLabel := make([]byte, digestLen) - for i := range newLabel { - newLabel[i] = byte(0) - } - - signedDataWithDiffLabel, err := c.Sign(handle, newLabel, client.SignFlags(client.IsSymmetric), tbs) - if err != nil { - t.Fatalf("[FATAL]: Error while signing %v", err) - } - - if bytes.Equal(signedDataWithDiffLabel.HmacOrSignatureR, signedData.HmacOrSignatureR) { - t.Errorf("[ERROR]: Signature must vary for different label despite having same toBeSigned content, want new signature but got old %v", signedData.HmacOrSignatureR) - } -} diff --git a/verification/testing/simulator.go b/verification/testing/simulator.go index 6282bf92..44b1a35e 100644 --- a/verification/testing/simulator.go +++ b/verification/testing/simulator.go @@ -42,7 +42,7 @@ func GetSimulatorTargets() []TestTarget { }, { "DefaultSupport", - getTestTarget([]string{"AutoInit", "Simulation", "X509", "Csr", "IsCA", "RotateContext", "Recursive", "IsSymmetric", "RetainParentContext"}), + getTestTarget([]string{"AutoInit", "Simulation", "X509", "Csr", "IsCA", "RotateContext", "Recursive", "RetainParentContext"}), AllTestCases, }, { @@ -75,11 +75,6 @@ func GetSimulatorTargets() []TestTarget { getTestTarget([]string{"Csr"}), []TestCase{GetProfileTestCase}, }, - { - "GetProfile_Symmetric", - getTestTarget([]string{"IsSymmetric"}), - []TestCase{GetProfileTestCase}, - }, { "GetProfile_InternalInfo", getTestTarget([]string{"InternalInfo"}), @@ -112,7 +107,7 @@ func GetSimulatorTargets() []TestTarget { }, { "GetProfile_All", - getTestTarget([]string{"Simulation", "Recursive", "AutoInit", "RotateContext", "X509", "Csr", "IsSymmetric", "InternalInfo", "InternalDice", "IsCA"}), + getTestTarget([]string{"Simulation", "Recursive", "AutoInit", "RotateContext", "X509", "Csr", "InternalInfo", "InternalDice", "IsCA"}), []TestCase{GetProfileTestCase}, }, { diff --git a/verification/testing/tpm.go b/verification/testing/tpm.go index 323b374a..667a1396 100644 --- a/verification/testing/tpm.go +++ b/verification/testing/tpm.go @@ -130,7 +130,7 @@ func TestTpmPolicySigning(d dpe.TestDPEInstance, c dpe.DPEClient, t *testing.T) pkh := loadPubKey(t, pubKey, tpm, alg, ec) // Get encoded signature from TPM - r := new(big.Int).SetBytes(signResp.HmacOrSignatureR) + r := new(big.Int).SetBytes(signResp.SignatureR) s := new(big.Int).SetBytes(signResp.SignatureS) encodedSignature := getEncodedSignature(t, r, s, alg) diff --git a/verification/testing/verification.go b/verification/testing/verification.go index 1893baee..65ee6dcb 100644 --- a/verification/testing/verification.go +++ b/verification/testing/verification.go @@ -97,11 +97,6 @@ var SignAsymmetricTestCase = TestCase{ "Sign", TestAsymmetricSigning, []string{"AutoInit", "X509"}, } -// SignSymmetricTestCase tests Sign with is-symmetric = true -var SignSymmetricTestCase = TestCase{ - "SignSymmetric", TestSymmetricSigning, []string{"AutoInit", "IsSymmetric"}, -} - // SignSimulationTestCase tests Sign with Simulation contexts var SignSimulationTestCase = TestCase{ "SignSimulation", TestSignSimulation, []string{"Simulation"}, @@ -162,7 +157,6 @@ var AllTestCases = []TestCase{ RotateContextTestCase, RotateContextSimulationTestCase, SignAsymmetricTestCase, - SignSymmetricTestCase, SignSimulationTestCase, GetProfileTestCase, InitializeContextTestCase,