Skip to content

Commit

Permalink
Test: add fuzz test for x509 parser
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoyuxlu <[email protected]>
  • Loading branch information
xiaoyuxlu authored and jyao1 committed Feb 21, 2024
1 parent 6b6d756 commit cdd0984
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions fuzz-target/fuzzlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async-trait = "0.1.71"
async-recursion = "1.0.4"
spin = { version = "0.9.8" }
executor = { path = "../../executor" }
codec = {path= "../../codec"}

[features]
default = ["hashed-transcript-data", "afl"]
Expand Down
6 changes: 5 additions & 1 deletion fuzz-target/fuzzlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ pub use spdmlib_test::common::secret_callback::*;
pub use spdmlib_test::common::transport::PciDoeTransportEncap;
pub use spdmlib_test::common::util::{get_rsp_cert_chain_buff, req_create_info, rsp_create_info};

pub use codec;
pub use executor;
pub use log::info;
pub use spdmlib;
pub use spdmlib::common::{SpdmDeviceIo, SpdmTransportEncap};
pub use spdmlib::error::SpdmResult;
pub use spdmlib::{common, config, requester, responder};
pub use spdmlib::{common, config, error, protocol, requester, responder};
pub use spin;

pub use flexi_logger;
pub use flexi_logger::FileSpec;
Expand Down
14 changes: 13 additions & 1 deletion spdmlib/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,16 @@ doc = false
name = "encapsulated_request_req"
path = "fuzz_targets/encapsulated_request_req.rs"
test = false
doc = false
doc = false

[[bin]]
name = "fuzz_x509v3"
path = "fuzz_targets/fuzz_x509v3.rs"
test = false
doc = false
bench = false

[patch.crates-io]
ring = { path = "../../external/ring" }
webpki = { path = "../../external/webpki" }
mbedtls-platform-support = { path = "../../spdmlib_crypto_mbedtls/mbedtls-platform-support" }
25 changes: 25 additions & 0 deletions spdmlib/fuzz/fuzz_targets/fuzz_x509v3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

pub use fuzzlib::*;

include!("../../src/crypto/x509v3.rs");

fuzz_target!(|cert: &[u8]| {
for f in [
SpdmBaseAsymAlgo::TPM_ALG_ECDSA_ECC_NIST_P256,
SpdmBaseAsymAlgo::TPM_ALG_ECDSA_ECC_NIST_P256,
SpdmBaseAsymAlgo::TPM_ALG_RSASSA_2048,
SpdmBaseAsymAlgo::TPM_ALG_RSASSA_3072,
SpdmBaseAsymAlgo::TPM_ALG_RSAPSS_4096,
SpdmBaseAsymAlgo::TPM_ALG_RSASSA_2048,
SpdmBaseAsymAlgo::TPM_ALG_RSASSA_3072,
SpdmBaseAsymAlgo::TPM_ALG_RSASSA_4096,
] {
let _ = check_cert_chain_format(cert, f);
let _ = check_leaf_certificate(cert, true);
let _ = check_leaf_certificate(cert, false);
let _ = is_root_certificate(cert);
}
});

0 comments on commit cdd0984

Please sign in to comment.