[toolchain] Do cargo fmt for the dcap lib
This commit is contained in:
parent
887fbf2441
commit
86539bf98e
@ -1,8 +1,8 @@
|
|||||||
extern crate occlum_dcap;
|
extern crate occlum_dcap;
|
||||||
use std::str;
|
|
||||||
use std::io::Result;
|
|
||||||
use std::convert::TryFrom;
|
|
||||||
use occlum_dcap::*;
|
use occlum_dcap::*;
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
use std::io::Result;
|
||||||
|
use std::str;
|
||||||
|
|
||||||
struct DcapDemo {
|
struct DcapDemo {
|
||||||
dcap_quote: DcapQuote,
|
dcap_quote: DcapQuote,
|
||||||
@ -10,7 +10,7 @@ struct DcapDemo {
|
|||||||
quote_buf: Vec<u8>,
|
quote_buf: Vec<u8>,
|
||||||
req_data: sgx_report_data_t,
|
req_data: sgx_report_data_t,
|
||||||
supplemental_size: u32,
|
supplemental_size: u32,
|
||||||
suppl_buf: Vec<u8>
|
suppl_buf: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DcapDemo {
|
impl DcapDemo {
|
||||||
@ -33,12 +33,15 @@ impl DcapDemo {
|
|||||||
quote_buf: quote_buf,
|
quote_buf: quote_buf,
|
||||||
req_data: req_data,
|
req_data: req_data,
|
||||||
supplemental_size: supplemental_size,
|
supplemental_size: supplemental_size,
|
||||||
suppl_buf: suppl_buf
|
suppl_buf: suppl_buf,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dcap_quote_gen(&mut self) -> i32 {
|
fn dcap_quote_gen(&mut self) -> i32 {
|
||||||
let ret = self.dcap_quote.generate_quote(self.quote_buf.as_mut_ptr(), &mut self.req_data).unwrap();
|
let ret = self
|
||||||
|
.dcap_quote
|
||||||
|
.generate_quote(self.quote_buf.as_mut_ptr(), &mut self.req_data)
|
||||||
|
.unwrap();
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
println!("DCAP generate quote failed");
|
println!("DCAP generate quote failed");
|
||||||
} else {
|
} else {
|
||||||
@ -58,8 +61,8 @@ impl DcapDemo {
|
|||||||
|
|
||||||
fn dcap_quote_get_report_body(&mut self) -> Result<*const sgx_report_body_t> {
|
fn dcap_quote_get_report_body(&mut self) -> Result<*const sgx_report_body_t> {
|
||||||
let report_body_offset = std::mem::size_of::<sgx_quote_header_t>();
|
let report_body_offset = std::mem::size_of::<sgx_quote_header_t>();
|
||||||
let report_body: *const sgx_report_body_t
|
let report_body: *const sgx_report_body_t =
|
||||||
= (self.quote_buf[report_body_offset..]).as_ptr() as _;
|
(self.quote_buf[report_body_offset..]).as_ptr() as _;
|
||||||
|
|
||||||
Ok(report_body)
|
Ok(report_body)
|
||||||
}
|
}
|
||||||
@ -148,7 +151,7 @@ fn main() {
|
|||||||
|
|
||||||
// compare the report data in quote buffer
|
// compare the report data in quote buffer
|
||||||
let report_data_ptr = dcap_demo.dcap_quote_get_report_data().unwrap();
|
let report_data_ptr = dcap_demo.dcap_quote_get_report_data().unwrap();
|
||||||
let string = str::from_utf8( unsafe { &(*report_data_ptr).d } ).unwrap();
|
let string = str::from_utf8(unsafe { &(*report_data_ptr).d }).unwrap();
|
||||||
|
|
||||||
if report_str == &string[..report_str.len()] {
|
if report_str == &string[..report_str.len()] {
|
||||||
println!("Report data from Quote: '{}' exactly matches.", string);
|
println!("Report data from Quote: '{}' exactly matches.", string);
|
||||||
@ -162,15 +165,20 @@ fn main() {
|
|||||||
match result {
|
match result {
|
||||||
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_OK => {
|
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_OK => {
|
||||||
println!("Succeed to verify the quote!");
|
println!("Succeed to verify the quote!");
|
||||||
},
|
|
||||||
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_CONFIG_NEEDED |
|
|
||||||
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_OUT_OF_DATE |
|
|
||||||
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_OUT_OF_DATE_CONFIG_NEEDED |
|
|
||||||
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_SW_HARDENING_NEEDED |
|
|
||||||
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_CONFIG_AND_SW_HARDENING_NEEDED => {
|
|
||||||
println!("WARN: App: Verification completed with Non-terminal result: {:?}", result);
|
|
||||||
},
|
|
||||||
_ => println!("Error: App: Verification completed with Terminal result: {:?}", result),
|
|
||||||
}
|
}
|
||||||
|
sgx_ql_qv_result_t::SGX_QL_QV_RESULT_CONFIG_NEEDED
|
||||||
|
| sgx_ql_qv_result_t::SGX_QL_QV_RESULT_OUT_OF_DATE
|
||||||
|
| sgx_ql_qv_result_t::SGX_QL_QV_RESULT_OUT_OF_DATE_CONFIG_NEEDED
|
||||||
|
| sgx_ql_qv_result_t::SGX_QL_QV_RESULT_SW_HARDENING_NEEDED
|
||||||
|
| sgx_ql_qv_result_t::SGX_QL_QV_RESULT_CONFIG_AND_SW_HARDENING_NEEDED => {
|
||||||
|
println!(
|
||||||
|
"WARN: App: Verification completed with Non-terminal result: {:?}",
|
||||||
|
result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => println!(
|
||||||
|
"Error: App: Verification completed with Terminal result: {:?}",
|
||||||
|
result
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
mod occlum_dcap;
|
mod occlum_dcap;
|
||||||
mod prelude;
|
mod prelude;
|
||||||
|
|
||||||
pub use crate::prelude::*;
|
|
||||||
pub use crate::occlum_dcap::*;
|
pub use crate::occlum_dcap::*;
|
||||||
|
pub use crate::prelude::*;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn dcap_quote_open() -> *mut c_void {
|
pub extern "C" fn dcap_quote_open() -> *mut c_void {
|
||||||
@ -16,12 +16,10 @@ pub extern "C" fn dcap_quote_open() -> *mut c_void {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn dcap_get_quote_size(handle: *mut c_void) -> u32 {
|
pub extern "C" fn dcap_get_quote_size(handle: *mut c_void) -> u32 {
|
||||||
if handle.is_null() {
|
if handle.is_null() {
|
||||||
return 0
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dcap = unsafe {
|
let dcap = unsafe { &mut *(handle as *mut DcapQuote) };
|
||||||
&mut *(handle as *mut DcapQuote)
|
|
||||||
};
|
|
||||||
|
|
||||||
dcap.get_quote_size().unwrap_or(0)
|
dcap.get_quote_size().unwrap_or(0)
|
||||||
}
|
}
|
||||||
@ -30,15 +28,13 @@ pub extern "C" fn dcap_get_quote_size(handle: *mut c_void) -> u32 {
|
|||||||
pub extern "C" fn dcap_generate_quote(
|
pub extern "C" fn dcap_generate_quote(
|
||||||
handle: *mut c_void,
|
handle: *mut c_void,
|
||||||
quote_buf: *mut u8,
|
quote_buf: *mut u8,
|
||||||
report_data: *const sgx_report_data_t) -> i32
|
report_data: *const sgx_report_data_t,
|
||||||
{
|
) -> i32 {
|
||||||
if handle.is_null() {
|
if handle.is_null() {
|
||||||
return -1
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dcap = unsafe {
|
let dcap = unsafe { &mut *(handle as *mut DcapQuote) };
|
||||||
&mut *(handle as *mut DcapQuote)
|
|
||||||
};
|
|
||||||
|
|
||||||
dcap.generate_quote(quote_buf, report_data).unwrap_or(-1)
|
dcap.generate_quote(quote_buf, report_data).unwrap_or(-1)
|
||||||
}
|
}
|
||||||
@ -46,12 +42,10 @@ pub extern "C" fn dcap_generate_quote(
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn dcap_get_supplemental_data_size(handle: *mut c_void) -> u32 {
|
pub extern "C" fn dcap_get_supplemental_data_size(handle: *mut c_void) -> u32 {
|
||||||
if handle.is_null() {
|
if handle.is_null() {
|
||||||
return 0
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dcap = unsafe {
|
let dcap = unsafe { &mut *(handle as *mut DcapQuote) };
|
||||||
&mut *(handle as *mut DcapQuote)
|
|
||||||
};
|
|
||||||
|
|
||||||
dcap.get_supplemental_data_size().unwrap_or(0)
|
dcap.get_supplemental_data_size().unwrap_or(0)
|
||||||
}
|
}
|
||||||
@ -64,15 +58,13 @@ pub extern "C" fn dcap_verify_quote(
|
|||||||
collateral_expiration_status: *mut u32,
|
collateral_expiration_status: *mut u32,
|
||||||
quote_verification_result: *mut sgx_ql_qv_result_t,
|
quote_verification_result: *mut sgx_ql_qv_result_t,
|
||||||
supplemental_data_size: u32,
|
supplemental_data_size: u32,
|
||||||
supplemental_data: *mut u8) -> i32
|
supplemental_data: *mut u8,
|
||||||
{
|
) -> i32 {
|
||||||
if handle.is_null() {
|
if handle.is_null() {
|
||||||
return -1
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dcap = unsafe {
|
let dcap = unsafe { &mut *(handle as *mut DcapQuote) };
|
||||||
&mut *(handle as *mut DcapQuote)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut verify_arg = IoctlVerDCAPQuoteArg {
|
let mut verify_arg = IoctlVerDCAPQuoteArg {
|
||||||
quote_buf: quote_buf,
|
quote_buf: quote_buf,
|
||||||
@ -86,16 +78,13 @@ pub extern "C" fn dcap_verify_quote(
|
|||||||
dcap.verify_quote(&mut verify_arg).unwrap_or(-1)
|
dcap.verify_quote(&mut verify_arg).unwrap_or(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn dcap_quote_close(handle: *mut c_void) {
|
pub extern "C" fn dcap_quote_close(handle: *mut c_void) {
|
||||||
if handle.is_null() {
|
if handle.is_null() {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dcap = unsafe {
|
let dcap = unsafe { &mut *(handle as *mut DcapQuote) };
|
||||||
&mut *(handle as *mut DcapQuote)
|
|
||||||
};
|
|
||||||
|
|
||||||
dcap.close();
|
dcap.close();
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::ffi::CString;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
const SGXIOC_GET_DCAP_QUOTE_SIZE: u64 = 0x80047307;
|
const SGXIOC_GET_DCAP_QUOTE_SIZE: u64 = 0x80047307;
|
||||||
const SGXIOC_GEN_DCAP_QUOTE: u64 = 0xc0187308;
|
const SGXIOC_GEN_DCAP_QUOTE: u64 = 0xc0187308;
|
||||||
@ -77,7 +77,11 @@ impl DcapQuote {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_quote(&mut self, quote_buf: *mut u8, report_data: *const sgx_report_data_t) -> Result<i32, Error> {
|
pub fn generate_quote(
|
||||||
|
&mut self,
|
||||||
|
quote_buf: *mut u8,
|
||||||
|
report_data: *const sgx_report_data_t,
|
||||||
|
) -> Result<i32, Error> {
|
||||||
let quote_arg: IoctlGenDCAPQuoteArg = IoctlGenDCAPQuoteArg {
|
let quote_arg: IoctlGenDCAPQuoteArg = IoctlGenDCAPQuoteArg {
|
||||||
report_data: report_data,
|
report_data: report_data,
|
||||||
quote_size: &mut self.quote_size,
|
quote_size: &mut self.quote_size,
|
||||||
@ -122,4 +126,3 @@ impl DcapQuote {
|
|||||||
unsafe { libc::close(self.fd) };
|
unsafe { libc::close(self.fd) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
pub use libc::{c_int, c_void, close, ioctl, open, O_RDONLY};
|
||||||
pub use std::boxed::Box;
|
pub use std::boxed::Box;
|
||||||
pub use std::io::Error;
|
pub use std::io::Error;
|
||||||
pub use libc::{open, ioctl, close, c_void, c_int, O_RDONLY};
|
|
||||||
|
|
||||||
// Defined in "occlum/deps/rust-sgx-sdk/sgx_types"
|
// Defined in "occlum/deps/rust-sgx-sdk/sgx_types"
|
||||||
pub use sgx_types::{
|
pub use sgx_types::{
|
||||||
sgx_quote_header_t, sgx_report_data_t, sgx_ql_qv_result_t, sgx_report_body_t, sgx_quote3_t
|
sgx_ql_qv_result_t, sgx_quote3_t, sgx_quote_header_t, sgx_report_body_t, sgx_report_data_t,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user