Skip to content

Commit 33c9a9e

Browse files
committed
chore: insecure mode feature flag
Signed-off-by: Richard Zak <[email protected]>
1 parent f552f0c commit 33c9a9e

File tree

6 files changed

+68
-62
lines changed

6 files changed

+68
-62
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ memoffset = { version = "0.7.1", default-features = false }
5050
rstest = { version = "0.15", default-features = false }
5151
testaso = { version = "0.1", default-features = false }
5252

53+
[features]
54+
default = []
55+
insecure = []
56+
5357
[profile.release]
5458
incremental = false
5559
codegen-units = 1

src/ext/kvm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl ExtVerifier for Kvm {
1919
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.6.1.4.1.58270.1.1");
2020
const ATT: bool = true;
2121

22-
fn verify(&self, _cri: &CertReqInfo<'_>, ext: &Extension<'_>, dbg: bool) -> Result<bool> {
22+
fn verify(&self, _cri: &CertReqInfo<'_>, ext: &Extension<'_>) -> Result<bool> {
2323
if ext.critical {
2424
return Err(anyhow!("kvm extension cannot be critical"));
2525
}
@@ -28,10 +28,10 @@ impl ExtVerifier for Kvm {
2828
return Err(anyhow!("invalid kvm extension"));
2929
}
3030

31-
if !dbg {
32-
return Err(anyhow!("steward not in debug mode"));
33-
}
31+
#[cfg(not(feature = "insecure"))]
32+
return Err(anyhow!("steward not in debug mode"));
3433

34+
#[cfg(feature = "insecure")]
3535
Ok(true)
3636
}
3737
}

src/ext/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ pub trait ExtVerifier {
2828
/// certificate. Returning `Ok(false)` will allow the certification request
2929
/// to continue, but this particular extension will not be included
3030
/// in the resulting certificate.
31-
fn verify(&self, cri: &CertReqInfo<'_>, ext: &Extension<'_>, dbg: bool) -> Result<bool>;
31+
fn verify(&self, cri: &CertReqInfo<'_>, ext: &Extension<'_>) -> Result<bool>;
3232
}

src/ext/sgx/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ use std::fmt::Debug;
1111

1212
use anyhow::{anyhow, Result};
1313
use const_oid::ObjectIdentifier;
14-
use der::{Decode, Encode};
14+
use der::Decode;
15+
#[cfg(not(feature = "insecure"))]
16+
use der::Encode;
17+
#[cfg(not(feature = "insecure"))]
1518
use sgx::parameters::{Attributes, MiscSelect};
19+
#[cfg(not(feature = "insecure"))]
1620
use sha2::{Digest, Sha256};
1721
use x509::{ext::Extension, request::CertReqInfo, Certificate, TbsCertificate};
1822

@@ -42,7 +46,7 @@ impl ExtVerifier for Sgx {
4246
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.6.1.4.1.58270.1.2");
4347
const ATT: bool = true;
4448

45-
fn verify(&self, cri: &CertReqInfo<'_>, ext: &Extension<'_>, dbg: bool) -> Result<bool> {
49+
fn verify(&self, cri: &CertReqInfo<'_>, ext: &Extension<'_>) -> Result<bool> {
4650
if ext.critical {
4751
return Err(anyhow!("sgx extension cannot be critical"));
4852
}
@@ -62,7 +66,8 @@ impl ExtVerifier for Sgx {
6266

6367
// Validate the report.
6468
let pck = self.trusted(&chain)?;
65-
let rpt = quote.verify(pck)?;
69+
#[cfg(feature = "insecure")]
70+
quote.verify(pck)?;
6671

6772
// Force certs to have the same key type as the PCK.
6873
//
@@ -82,7 +87,10 @@ impl ExtVerifier for Sgx {
8287
return Err(anyhow!("sgx pck algorithm mismatch"));
8388
}
8489

85-
if !dbg {
90+
#[cfg(not(feature = "insecure"))]
91+
{
92+
let rpt = quote.verify(pck)?;
93+
8694
// TODO: Validate that the certification request came from an SGX enclave.
8795
let hash = Sha256::digest(&cri.public_key.to_vec()?);
8896
if hash.as_slice() != &rpt.reportdata[..hash.as_slice().len()] {

src/ext/snp/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use der::asn1::UIntRef;
1313
use der::{Decode, Encode, Sequence};
1414
use flagset::{flags, FlagSet};
1515
use sec1::pkcs8::AlgorithmIdentifier;
16+
#[cfg(not(feature = "insecure"))]
1617
use sha2::Digest;
1718
use x509::ext::Extension;
1819
use x509::{request::CertReqInfo, Certificate};
@@ -241,7 +242,7 @@ impl ExtVerifier for Snp {
241242
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.6.1.4.1.58270.1.3");
242243
const ATT: bool = true;
243244

244-
fn verify(&self, cri: &CertReqInfo<'_>, ext: &Extension<'_>, dbg: bool) -> Result<bool> {
245+
fn verify(&self, cri: &CertReqInfo<'_>, ext: &Extension<'_>) -> Result<bool> {
245246
if ext.critical {
246247
return Err(anyhow!("snp extension cannot be critical"));
247248
}
@@ -372,7 +373,8 @@ impl ExtVerifier for Snp {
372373
}
373374
}
374375

375-
if !dbg {
376+
#[cfg(not(feature = "insecure"))]
377+
{
376378
// Validate that the certification request came from an SNP VM.
377379
let hash = sha2::Sha384::digest(&cri.public_key.to_vec()?);
378380
if hash.as_slice() != &report.body.report_data[..hash.as_slice().len()] {

0 commit comments

Comments
 (0)