Skip to content

Commit 085f152

Browse files
committed
Merge pull-request #514
2 parents 1edc254 + a8acf6d commit 085f152

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

src/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exclude = [
1818
"qos_enclave",
1919
"qos_p256/fuzz",
2020
"qos_crypto/fuzz",
21+
"qos_nsm/fuzz",
2122
]
2223
# We need this to avoid issues with the mock feature uinintentionally being
2324
# enabled just because some tests need it.

src/qos_nsm/fuzz/Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
name = "qos_nsm_fuzz"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2021"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
libfuzzer-sys = "0.4"
12+
13+
qos_hex = { path = "../../qos_hex" }
14+
15+
# we need some of the mock code features
16+
qos_nsm = { path = "../", features = ["mock"] }
17+
18+
19+
# Prevent this from interfering with workspaces
20+
[workspace]
21+
members = ["."]
22+
23+
[profile.release]
24+
# enable arithmetic checks at runtime
25+
overflow-check = 1
26+
27+
[[bin]]
28+
name = "1_attestation_doc_from_der"
29+
path = "fuzz_targets/1_attestation_doc_from_der.rs"
30+
test = false
31+
doc = false
32+
bench = false
33+
34+
[[bin]]
35+
name = "2_verify_attestation_doc_against_user_input"
36+
path = "fuzz_targets/2_verify_attestation_doc_against_user_input.rs"
37+
test = false
38+
doc = false
39+
bench = false

src/qos_nsm/fuzz/IDEAS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Fuzzing Ideas
2+
3+
Special parameter requirements:
4+
* Valid inputs for attestation doc related testing harnesses can be fairly large. For example, src/static/mock_attestation_doc is over 5KB in size. Therefore a relatively large `-min_len=` length parameter value such as `-min_len=6000` is needed during fuzzing.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![no_main]
2+
3+
use libfuzzer_sys::fuzz_target;
4+
5+
use qos_nsm::nitro::{attestation_doc_from_der, cert_from_pem};
6+
// working root cert, use as example
7+
use qos_nsm::nitro::AWS_ROOT_CERT_PEM;
8+
// this is just an example timestamp
9+
use qos_nsm::mock::MOCK_SECONDS_SINCE_EPOCH;
10+
11+
fuzz_target!(|data: &[u8]| {
12+
let root_cert = cert_from_pem(AWS_ROOT_CERT_PEM).unwrap();
13+
// test attestation conversion function
14+
// this includes verification of signatures, and is unlikely to succeed
15+
// unless on variants of a validly signed doc
16+
let attestation_result = attestation_doc_from_der(
17+
data,
18+
&root_cert[..],
19+
MOCK_SECONDS_SINCE_EPOCH,
20+
);
21+
22+
match attestation_result {
23+
Err(_) => {}
24+
Ok(_reconstructed) => {
25+
// debug print, signals how often this path is hit, remove later
26+
println!("succeeded parsing, data length: {}", data.len());
27+
}
28+
}
29+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![no_main]
2+
3+
use libfuzzer_sys::fuzz_target;
4+
5+
use qos_nsm::nitro::unsafe_attestation_doc_from_der;
6+
use qos_nsm::nitro::verify_attestation_doc_against_user_input;
7+
8+
// constants are copied from the mock system, and represent dummy values
9+
10+
use qos_nsm::mock::{
11+
MOCK_PCR0, MOCK_PCR1, MOCK_PCR2, MOCK_PCR3,
12+
MOCK_USER_DATA_NSM_ATTESTATION_DOCUMENT,
13+
};
14+
15+
fuzz_target!(|data: &[u8]| {
16+
// use the unsafe conversion variant without verification of cryptographic properties
17+
// this allows the fuzzer to more often generate a working attestation document
18+
let attestation_result = unsafe_attestation_doc_from_der(data);
19+
20+
match attestation_result {
21+
Err(_) => {}
22+
Ok(reconstructed) => {
23+
// test the intended target function
24+
let _ = verify_attestation_doc_against_user_input(
25+
&reconstructed,
26+
&qos_hex::decode(MOCK_USER_DATA_NSM_ATTESTATION_DOCUMENT)
27+
.unwrap(),
28+
&qos_hex::decode(MOCK_PCR0).unwrap(),
29+
&qos_hex::decode(MOCK_PCR1).unwrap(),
30+
&qos_hex::decode(MOCK_PCR2).unwrap(),
31+
&qos_hex::decode(MOCK_PCR3).unwrap(),
32+
);
33+
}
34+
}
35+
});

0 commit comments

Comments
 (0)