Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,48 @@ name = "fuzz_tbor_rsa_mod_exp"
path = "fuzz_targets/ddi/tbor/fuzz_tbor_rsa_mod_exp.rs"
test = false

[[bin]]
bench = false
doc = false
name = "fuzz_tbor_sd_create_peer_backup"
path = "fuzz_targets/ddi/tbor/fuzz_tbor_sd_create_peer_backup.rs"
test = false

[[bin]]
bench = false
doc = false
name = "fuzz_tbor_sd_create_remote_backup"
path = "fuzz_targets/ddi/tbor/fuzz_tbor_sd_create_remote_backup.rs"
test = false

[[bin]]
bench = false
doc = false
name = "fuzz_tbor_sd_reseal_remote_backup"
path = "fuzz_targets/ddi/tbor/fuzz_tbor_sd_reseal_remote_backup.rs"
test = false

[[bin]]
bench = false
doc = false
name = "fuzz_tbor_sd_restore_local_backup"
path = "fuzz_targets/ddi/tbor/fuzz_tbor_sd_restore_local_backup.rs"
test = false

[[bin]]
bench = false
doc = false
name = "fuzz_tbor_sd_restore_peer_backup"
path = "fuzz_targets/ddi/tbor/fuzz_tbor_sd_restore_peer_backup.rs"
test = false

[[bin]]
bench = false
doc = false
name = "fuzz_tbor_sd_sealing_key_gen"
path = "fuzz_targets/ddi/tbor/fuzz_tbor_sd_sealing_key_gen.rs"
test = false

[[bin]]
bench = false
doc = false
Expand Down
52 changes: 52 additions & 0 deletions fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_sd_create_peer_backup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![no_main]

use azihsm_ddi_tbor_test_harness::TestCtx;
use azihsm_ddi_tbor_types::MASKED_SD_LEN;
use azihsm_ddi_tbor_types::MASKED_SEALING_KEY_LEN;
use azihsm_ddi_tbor_types::PartPolicy;
use azihsm_ddi_tbor_types::ReportDescriptor;
use azihsm_ddi_tbor_types::SessionType;
use azihsm_ddi_tbor_types::TborSdCreatePeerBackupReq;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

const CU: u8 = 1;
static CTX: std::sync::OnceLock<TestCtx> = std::sync::OnceLock::new();

#[derive(Arbitrary, Debug)]
struct FuzzInput {
masked_sealing_key: [u8; MASKED_SEALING_KEY_LEN],
pok_local_backup: [u8; MASKED_SD_LEN],
report_index: u8,
report_length: u16,
}

fuzz_target!(|input: FuzzInput| {
let ctx = CTX.get_or_init(TestCtx::new);
ctx.erase().expect("erase should succeed");

let session = ctx
.open_session(CU, SessionType::PlainText)
.expect("session open should succeed");

let req = TborSdCreatePeerBackupReq {
session_id: session.session_id(),
masked_sealing_key: input.masked_sealing_key,
policy: PartPolicy::zeroed(),
dst_mfgr_cert_chain: Vec::new(),
dst_owner_cert_chain: Vec::new(),
dst_part_owner_cert_chain: Vec::new(),
dst_report: ReportDescriptor {
index: input.report_index,
length: zerocopy::little_endian::U16::new(input.report_length),
},
pok_local_backup: input.pok_local_backup,
};
let _ = ctx.tbor(&req);

session.close().expect("session close should succeed");
});
49 changes: 49 additions & 0 deletions fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_sd_create_remote_backup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![no_main]

use azihsm_ddi_tbor_test_harness::TestCtx;
use azihsm_ddi_tbor_types::MASKED_SEALING_KEY_LEN;
use azihsm_ddi_tbor_types::PartPolicy;
use azihsm_ddi_tbor_types::ReportDescriptor;
use azihsm_ddi_tbor_types::SessionType;
use azihsm_ddi_tbor_types::TborSdCreateRemoteBackupReq;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

const CU: u8 = 1;
static CTX: std::sync::OnceLock<TestCtx> = std::sync::OnceLock::new();

#[derive(Arbitrary, Debug)]
struct FuzzInput {
masked_sealing_key: [u8; MASKED_SEALING_KEY_LEN],
report_index: u8,
report_length: u16,
}

fuzz_target!(|input: FuzzInput| {
let ctx = CTX.get_or_init(TestCtx::new);
ctx.erase().expect("erase should succeed");

let session = ctx
.open_session(CU, SessionType::PlainText)
.expect("session open should succeed");

let req = TborSdCreateRemoteBackupReq {
session_id: session.session_id(),
masked_sealing_key: input.masked_sealing_key,
receiver_mfgr_cert_chain: Vec::new(),
receiver_owner_cert_chain: Vec::new(),
receiver_part_owner_cert_chain: Vec::new(),
receiver_report: ReportDescriptor {
index: input.report_index,
length: zerocopy::little_endian::U16::new(input.report_length),
},
policy: PartPolicy::zeroed(),
};
let _ = ctx.tbor(&req);

session.close().expect("session close should succeed");
});
61 changes: 61 additions & 0 deletions fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_sd_reseal_remote_backup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![no_main]

use azihsm_ddi_tbor_test_harness::TestCtx;
use azihsm_ddi_tbor_types::MASKED_SEALING_KEY_LEN;
use azihsm_ddi_tbor_types::POK_REMOTE_BACKUP_LEN;
use azihsm_ddi_tbor_types::PartPolicy;
use azihsm_ddi_tbor_types::ReportDescriptor;
use azihsm_ddi_tbor_types::SessionType;
use azihsm_ddi_tbor_types::TborSdResealRemoteBackupReq;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

const CU: u8 = 1;
static CTX: std::sync::OnceLock<TestCtx> = std::sync::OnceLock::new();

#[derive(Arbitrary, Debug)]
struct FuzzInput {
masked_sealing_key: [u8; MASKED_SEALING_KEY_LEN],
src_remote_backup: [u8; POK_REMOTE_BACKUP_LEN],
src_report_index: u8,
src_report_length: u16,
dest_report_index: u8,
dest_report_length: u16,
}

fuzz_target!(|input: FuzzInput| {
let ctx = CTX.get_or_init(TestCtx::new);
ctx.erase().expect("erase should succeed");

let session = ctx
.open_session(CU, SessionType::PlainText)
.expect("session open should succeed");

let req = TborSdResealRemoteBackupReq {
session_id: session.session_id(),
masked_sealing_key: input.masked_sealing_key,
policy: PartPolicy::zeroed(),
src_mfgr_cert_chain: Vec::new(),
src_owner_cert_chain: Vec::new(),
src_part_owner_cert_chain: Vec::new(),
src_report: ReportDescriptor {
index: input.src_report_index,
length: zerocopy::little_endian::U16::new(input.src_report_length),
},
dest_mfgr_cert_chain: Vec::new(),
dest_owner_cert_chain: Vec::new(),
dest_part_owner_cert_chain: Vec::new(),
dest_report: ReportDescriptor {
index: input.dest_report_index,
length: zerocopy::little_endian::U16::new(input.dest_report_length),
},
src_remote_backup: input.src_remote_backup,
};
let _ = ctx.tbor(&req);

session.close().expect("session close should succeed");
});
50 changes: 50 additions & 0 deletions fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_sd_restore_local_backup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![no_main]

use azihsm_ddi_tbor_test_harness::TestCtx;
use azihsm_ddi_tbor_types::SessionType;
use azihsm_ddi_tbor_types::TborSdRestoreLocalBackupReq;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

const CU: u8 = 1;
static CTX: std::sync::OnceLock<TestCtx> = std::sync::OnceLock::new();

fn bounded_pok(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Vec<u8>> {
let len = usize::arbitrary(u)? % (180 + 1);
Ok(u.bytes(len)?.to_vec())
}

fn bounded_sd_mk(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Vec<u8>> {
let len = usize::arbitrary(u)? % (164 + 1);
Ok(u.bytes(len)?.to_vec())
}
Comment on lines +6 to +24

#[derive(Arbitrary, Debug)]
struct FuzzInput {
#[arbitrary(with = bounded_pok)]
pok_local_backup: Vec<u8>,
#[arbitrary(with = bounded_sd_mk)]
sd_mk_backup: Vec<u8>,
}

fuzz_target!(|input: FuzzInput| {
let ctx = CTX.get_or_init(TestCtx::new);
ctx.erase().expect("erase should succeed");

let session = ctx
.open_session(CU, SessionType::PlainText)
.expect("session open should succeed");

let req = TborSdRestoreLocalBackupReq {
session_id: session.session_id(),
pok_local_backup: input.pok_local_backup,
sd_mk_backup: input.sd_mk_backup,
};
let _ = ctx.tbor(&req);

session.close().expect("session close should succeed");
});
55 changes: 55 additions & 0 deletions fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_sd_restore_peer_backup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![no_main]

use azihsm_ddi_tbor_test_harness::TestCtx;
use azihsm_ddi_tbor_types::MASKED_SEALING_KEY_LEN;
use azihsm_ddi_tbor_types::POK_REMOTE_BACKUP_LEN;
use azihsm_ddi_tbor_types::PartPolicy;
use azihsm_ddi_tbor_types::ReportDescriptor;
use azihsm_ddi_tbor_types::SD_MK_BACKUP_LEN;
use azihsm_ddi_tbor_types::SessionType;
use azihsm_ddi_tbor_types::TborSdRestorePeerBackupReq;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

const CU: u8 = 1;
static CTX: std::sync::OnceLock<TestCtx> = std::sync::OnceLock::new();

#[derive(Arbitrary, Debug)]
struct FuzzInput {
masked_sealing_key: [u8; MASKED_SEALING_KEY_LEN],
pok_peer_backup: [u8; POK_REMOTE_BACKUP_LEN],
prev_sd_mk_backup: [u8; SD_MK_BACKUP_LEN],
report_index: u8,
report_length: u16,
}

fuzz_target!(|input: FuzzInput| {
let ctx = CTX.get_or_init(TestCtx::new);
ctx.erase().expect("erase should succeed");

let session = ctx
.open_session(CU, SessionType::PlainText)
.expect("session open should succeed");

let req = TborSdRestorePeerBackupReq {
session_id: session.session_id(),
masked_sealing_key: input.masked_sealing_key,
policy: PartPolicy::zeroed(),
src_mfgr_cert_chain: Vec::new(),
src_owner_cert_chain: Vec::new(),
src_part_owner_cert_chain: Vec::new(),
src_report: ReportDescriptor {
index: input.report_index,
length: zerocopy::little_endian::U16::new(input.report_length),
},
pok_peer_backup: input.pok_peer_backup,
prev_sd_mk_backup: input.prev_sd_mk_backup,
};
let _ = ctx.tbor(&req);

session.close().expect("session close should succeed");
});
36 changes: 36 additions & 0 deletions fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_sd_sealing_key_gen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![no_main]

use azihsm_ddi_tbor_test_harness::TestCtx;
use azihsm_ddi_tbor_types::SessionType;
use azihsm_ddi_tbor_types::TborSdSealingKeyGenReq;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

const CU: u8 = 1;
static CTX: std::sync::OnceLock<TestCtx> = std::sync::OnceLock::new();

#[derive(Arbitrary, Debug)]
struct FuzzInput {
scope: u8,
}

fuzz_target!(|input: FuzzInput| {
let ctx = CTX.get_or_init(TestCtx::new);
ctx.erase().expect("erase should succeed");

let session = ctx
.open_session(CU, SessionType::PlainText)
.expect("session open should succeed");

let req = TborSdSealingKeyGenReq {
session_id: session.session_id(),
scope: input.scope,
};
let _ = ctx.tbor(&req);

session.close().expect("session close should succeed");
});
Loading