Skip to content

Commit

Permalink
Merge branch 'codegen'
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhu committed Jun 7, 2021
2 parents 9d8c33b + 3aa8d8f commit 4a796f9
Show file tree
Hide file tree
Showing 41 changed files with 631 additions and 4,408 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ root := ./
domain_list := $(addprefix domains/build/, \
redleaf_init \
dom_proxy \
dom_a \
dom_b \
dom_c \
dom_d \
shadow \
Expand Down
34 changes: 0 additions & 34 deletions domains/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions domains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ members = [
"usr/test/benchhash",
"usr/test/benchnet_inside",
"usr/test/benchnvme",
"usr/test/dom_a",
"usr/test/dom_b",
"usr/test/dom_c",
"usr/test/dom_d",
"usr/test/shadow",
Expand Down
48 changes: 24 additions & 24 deletions domains/lib/libbenchtpm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {

// Changing locality
let locality = 0;
println!("burst_count {}", tpm.tpm_get_burst(locality));
println!("burst_count {}", tpm.tpm_get_burst(locality).unwrap());
// Initially we have locality 0
println!("request locality {}", tpm.tpm_request_locality(locality));
println!("validate locality {}", tpm.tpm_validate_locality(locality));
println!("request locality {}", tpm.tpm_request_locality(locality).unwrap());
println!("validate locality {}", tpm.tpm_validate_locality(locality).unwrap());
// Deactivate all localities
tpm.tpm_deactivate_all_localities();
let locality = 2;
// Then request target localities
println!("request locality {}", tpm.tpm_request_locality(locality));
println!("validate locality {}", tpm.tpm_validate_locality(locality));
println!("request locality {}", tpm.tpm_request_locality(locality).unwrap());
println!("validate locality {}", tpm.tpm_validate_locality(locality).unwrap());

// Get 1 byte of random value
println!("random {}", tpm.tpm_get_random(locality, 1));
println!("random {}", tpm.tpm_get_random(locality, 1).unwrap());

// PCR extend
// First we obtain "banks" that are allocated in the TPM.
// In TPM2, there can be multiple banks, each implementing different hash algorithms.
let tpm_info = tpm.tpm_get_pcr_allocation(locality);
let tpm_info = tpm.tpm_get_pcr_allocation(locality).unwrap();
let mut digests: Vec<TpmTHa> = Vec::new();
for i in 0..(tpm_info.nr_allocated_banks as usize) {
let mut digest: Vec<u8> = Vec::new();
Expand All @@ -53,7 +53,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {
TpmAlgorithms::TPM_ALG_SHA256 as u16,
&mut pcr_size,
&mut pcr,
);
).unwrap();
println!("pre-extend pcr {:x?}", pcr);
println!("pcr_size {}", pcr_size);
// Then extend the PCR
Expand All @@ -67,7 +67,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {
TpmAlgorithms::TPM_ALG_SHA256 as u16,
&mut pcr_size,
&mut pcr,
);
).unwrap();
println!("post-extend pcr {:x?}", pcr);
println!("pcr_size {}", pcr_size);

Expand All @@ -87,17 +87,17 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {
&mut parent_handle,
&mut primary_pubkey_size,
&mut primary_pubkey,
);
).unwrap();
println!("parent_handle {:x?}", parent_handle);
// Start authenticated session
let mut session_handle: u32 = 0 as u32;
let nonce = alloc::vec![0; 32];
tpm.tpm_start_auth_session(locality, TpmSE::TPM_SE_TRIAL, nonce, &mut session_handle);
tpm.tpm_start_auth_session(locality, TpmSE::TPM_SE_TRIAL, nonce, &mut session_handle).unwrap();
// Tie session to PCR 17
tpm.tpm_policy_pcr(locality, session_handle, b"".to_vec(), pcr_idx);
tpm.tpm_policy_pcr(locality, session_handle, b"".to_vec(), pcr_idx).unwrap();
// Get digest of authenticated session
let mut policy_digest: Vec<u8> = Vec::new();
tpm.tpm_policy_get_digest(locality, session_handle, &mut policy_digest);
tpm.tpm_policy_get_digest(locality, session_handle, &mut policy_digest).unwrap();
// Create Child key wrapped with SRK
// Load Child key to TPM
// Seal data under PCR 17 using Child key
Expand All @@ -115,15 +115,15 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {
/*sign=*/ false,
&mut create_out_private,
&mut create_out_public,
);
).unwrap();
let mut item_handle: u32 = 0 as u32;
tpm.tpm_load(
locality,
parent_handle,
create_out_private,
create_out_public,
&mut item_handle,
);
).unwrap();

// Unsealing Data
// Start authenticated session
Expand All @@ -134,18 +134,18 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {
TpmSE::TPM_SE_POLICY,
nonce,
&mut unseal_session_handle,
);
).unwrap();
// Tie session to PCR 17
tpm.tpm_policy_pcr(locality, unseal_session_handle, b"".to_vec(), pcr_idx);
tpm.tpm_policy_pcr(locality, unseal_session_handle, b"".to_vec(), pcr_idx).unwrap();
// Unseal data under PCR 17 using Child key (should succeed)
let mut out_data: Vec<u8> = Vec::new();
tpm.tpm_unseal(locality, unseal_session_handle, item_handle, &mut out_data);
tpm.tpm_unseal(locality, unseal_session_handle, item_handle, &mut out_data).unwrap();

// Unload all objects from TPM memory
tpm.tpm_flush_context(locality, parent_handle);
tpm.tpm_flush_context(locality, session_handle);
tpm.tpm_flush_context(locality, item_handle);
tpm.tpm_flush_context(locality, unseal_session_handle);
tpm.tpm_flush_context(locality, parent_handle).unwrap();
tpm.tpm_flush_context(locality, session_handle).unwrap();
tpm.tpm_flush_context(locality, item_handle).unwrap();
tpm.tpm_flush_context(locality, unseal_session_handle).unwrap();

// Create Attestation Identity Key
let aik_unique = b"remote_attestation";
Expand All @@ -162,7 +162,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {
&mut aik_handle,
&mut aik_pubkey_size,
&mut aik_pubkey,
);
).unwrap();
println!("aik_handle {:x?}", aik_handle);
// Generate random nonce. This should be generated by remote verifier.
let nonce = b"random_nonce";
Expand All @@ -180,7 +180,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) {
pcr_idxs,
&mut out_pcr_digest,
&mut out_sig,
);
).unwrap();
println!("out_pcr_digest {:x?}", out_pcr_digest);
println!("out_sig {:x?}", out_sig);
}
60 changes: 32 additions & 28 deletions domains/sys/driver/pci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use console::println;
use core::panic::PanicInfo;
use libsyscalls::syscalls::{sys_backtrace, sys_println};
use syscalls::{Heap, Syscall};
use interface::rpc::RpcResult;
use interface::error::{Result, ErrorKind};

use pci_driver::{PciClass, PciDriver};

Expand All @@ -35,36 +37,38 @@ impl interface::pci::PCI for PCI {
pci_driver: &mut dyn PciDriver,
bar_index: usize,
class: Option<(PciClass, u8)>,
) -> Result<(), ()> {
println!("Register driver called");
let vendor_id = pci_driver.get_vid();
let device_id = pci_driver.get_did();
// match vid, dev_id with the registered pci devices we have and
// typecast the barregion to the appropriate one for this device
let pci_devs = &*PCI_DEVICES.lock();
let pci_dev: &PciDevice = match class {
Some((class, subclass)) => pci_devs
.iter()
.filter(|header| header.class() == class && header.subclass() == subclass)
.next()
.ok_or(()),
None => pci_devs
.iter()
.filter(|header| header.vendor_id() == vendor_id && header.device_id() == device_id)
.next()
.ok_or(()),
}?;

// TODO: dont panic here
let bar = pci_dev.get_bar(bar_index, pci_driver.get_driver_type());

pci_driver.probe(bar);

Ok(())
) -> RpcResult<Result<()>> {
Ok(|| -> Result<()> {
println!("Register driver called");
let vendor_id = pci_driver.get_vid();
let device_id = pci_driver.get_did();
// match vid, dev_id with the registered pci devices we have and
// typecast the barregion to the appropriate one for this device
let pci_devs = &*PCI_DEVICES.lock();
let pci_dev = match class {
Some((class, subclass)) => pci_devs
.iter()
.filter(|header| header.class() == class && header.subclass() == subclass)
.next()
.ok_or(ErrorKind::InvalidPciClass),
None => pci_devs
.iter()
.filter(|header| header.vendor_id() == vendor_id && header.device_id() == device_id)
.next()
.ok_or(ErrorKind::InvalidPciDeviceID),
};
let pci_dev = pci_dev?;

// TODO: dont panic here
let bar = pci_dev.get_bar(bar_index, pci_driver.get_driver_type());

pci_driver.probe(bar);
Ok(())
}())
}

fn pci_clone(&self) -> Box<dyn interface::pci::PCI> {
Box::new((*self).clone())
fn pci_clone(&self) -> RpcResult<Box<dyn interface::pci::PCI>> {
Ok(Box::new((*self).clone()))
}
}

Expand Down
Loading

0 comments on commit 4a796f9

Please sign in to comment.