Skip to content

Commit 675a026

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

File tree

5 files changed

+74
-70
lines changed

5 files changed

+74
-70
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ rstest = { version = "0.16", default-features = false }
4646
sgx = { version = "0.6.0", default-features = false }
4747
testaso = { version = "0.1", default-features = false }
4848

49+
[features]
50+
default = []
51+
insecure = []
52+
4953
[profile.release]
5054
incremental = false
5155
codegen-units = 1

crates/sgx_validation/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ use std::fmt::Debug;
1212
use crate::config::Config;
1313
use anyhow::{bail, ensure, Result};
1414
use cryptography::const_oid::ObjectIdentifier;
15+
#[cfg(not(feature = "insecure"))]
1516
use cryptography::sha2::{Digest, Sha256};
1617
use cryptography::x509::{ext::Extension, request::CertReqInfo, Certificate, TbsCertificate};
17-
use der::{Decode, Encode};
18+
use der::Decode;
19+
#[cfg(not(feature = "insecure"))]
20+
use der::Encode;
1821

1922
#[derive(Clone, Debug)]
2023
pub struct Sgx([Certificate<'static>; 1]);
@@ -44,7 +47,6 @@ impl Sgx {
4447
cri: &CertReqInfo<'_>,
4548
ext: &Extension<'_>,
4649
config: Option<&Config>,
47-
dbg: bool,
4850
) -> Result<bool> {
4951
ensure!(!ext.critical, "sgx extension cannot be critical");
5052

@@ -82,7 +84,8 @@ impl Sgx {
8284
"sgx pck algorithm mismatch"
8385
);
8486

85-
if !dbg {
87+
#[cfg(not(feature = "insecure"))]
88+
{
8689
// Validate that the certification request came from an SGX enclave.
8790
let hash = Sha256::digest(cri.public_key.to_vec()?);
8891
ensure!(

crates/snp_validation/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use cryptography::const_oid::db::rfc5912::ECDSA_WITH_SHA_384;
1212
use cryptography::const_oid::ObjectIdentifier;
1313
use cryptography::ext::TbsCertificateExt;
1414
use cryptography::sec1::pkcs8::AlgorithmIdentifier;
15-
use cryptography::sha2::{Digest, Sha384};
15+
#[cfg(not(feature = "insecure"))]
16+
use cryptography::sha2::Digest;
17+
use cryptography::sha2::Sha384;
1618
use cryptography::x509::ext::Extension;
1719
use cryptography::x509::{request::CertReqInfo, Certificate};
1820
use cryptography::x509::{PkiPath, TbsCertificate};
@@ -258,7 +260,6 @@ impl Snp {
258260
cri: &CertReqInfo<'_>,
259261
ext: &Extension<'_>,
260262
config: Option<&Config>,
261-
dbg: bool,
262263
) -> Result<bool> {
263264
ensure!(!ext.critical, "snp extension cannot be critical");
264265

@@ -382,7 +383,8 @@ impl Snp {
382383

383384
ensure!(report.body.vmpl == 0, "snp report vmpl field invalid value");
384385

385-
if !dbg {
386+
#[cfg(not(feature = "insecure"))]
387+
{
386388
// Validate that the certification request came from an SNP VM.
387389
let hash = Sha384::digest(cri.public_key.to_vec()?);
388390
ensure!(

src/kvm.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ impl Kvm {
1717
pub(crate) const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.6.1.4.1.58270.1.1");
1818
pub(crate) const ATT: bool = true;
1919

20-
pub(crate) fn verify(
21-
&self,
22-
_cri: &CertReqInfo<'_>,
23-
ext: &Extension<'_>,
24-
dbg: bool,
25-
) -> Result<bool> {
20+
pub(crate) fn verify(&self, _cri: &CertReqInfo<'_>, ext: &Extension<'_>) -> Result<bool> {
2621
if ext.critical {
2722
return Err(anyhow!("kvm extension cannot be critical"));
2823
}
@@ -31,10 +26,10 @@ impl Kvm {
3126
return Err(anyhow!("invalid kvm extension"));
3227
}
3328

34-
if !dbg {
35-
return Err(anyhow!("steward not in debug mode"));
36-
}
29+
#[cfg(not(feature = "insecure"))]
30+
return Err(anyhow!("steward not in debug mode"));
3731

32+
#[cfg(feature = "insecure")]
3833
Ok(true)
3934
}
4035
}

0 commit comments

Comments
 (0)