Skip to content

Commit

Permalink
- intermidiete
Browse files Browse the repository at this point in the history
  • Loading branch information
nshyrei committed Mar 6, 2024
1 parent 9b7bb70 commit db29630
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 128 deletions.
19 changes: 10 additions & 9 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions intel-sgx/aesm-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ byteorder = "1.0" # Unlicense/MIT
lazy_static = "1" # MIT/Apache-2.0
protobuf = "2.22.1" # MIT/Apache-2.0
thiserror = "1.0" # MIT/Apache-2.0
anyhow = "1.0" # MIT/Apache-2.0

[target.'cfg(unix)'.dependencies]
# We require a version of unix-socket with the following change:
Expand Down
3 changes: 2 additions & 1 deletion intel-sgx/aesm-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#![deny(warnings)]

extern crate byteorder;
pub extern crate anyhow;
pub extern crate thiserror;
#[macro_use]
#[cfg(unix)]
Expand Down Expand Up @@ -267,7 +268,7 @@ impl EinittokenProvider for AesmClient {
sigstruct: &Sigstruct,
attributes: Attributes,
_retry: bool,
) -> StdResult<Einittoken, ::failure::Error> {
) -> StdResult<Einittoken, ::anyhow::Error> {
let token = self.get_launch_token(
sigstruct,
attributes,
Expand Down
2 changes: 1 addition & 1 deletion intel-sgx/dcap-ql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ verify = ["mbedtls", "num", "yasna"]

# External dependencies
byteorder = "1.1.0" # Unlicense/MIT
failure = "0.1.1" # MIT/Apache-2.0
anyhow = "1.0" # MIT/Apache-2.0
lazy_static = "1" # MIT/Apache-2.0
libc = { version = "0.2", optional = true } # MIT/Apache-2.0
mbedtls = { version = ">=0.8.0, <0.10.0", default-features = false, features = ["std"], optional = true }
Expand Down
2 changes: 1 addition & 1 deletion intel-sgx/dcap-ql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

extern crate byteorder;
#[macro_use]
extern crate failure;
extern crate anyhow;
#[cfg(all(feature="bindings", not(feature = "link")))]
#[macro_use]
extern crate lazy_static;
Expand Down
3 changes: 2 additions & 1 deletion intel-sgx/dcap-ql/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize};
use sgx_isa::Report;
use std::borrow::Cow;
use std::mem;
use anyhow::bail;

// ====================================================
// ================= TYPE DEFINITIONS =================
Expand Down Expand Up @@ -93,7 +94,7 @@ pub struct Qe3CertDataPckCertChain<'a> {

pub type RawQe3CertData<'a> = Cow<'a, [u8]>;

pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
pub type Result<T> = ::std::result::Result<T, anyhow::Error>;

// ===========================================
// ================= PARSING =================
Expand Down
2 changes: 1 addition & 1 deletion intel-sgx/dcap-retrieve-pckid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ categories = ["command-line-utilities"]
"sgxs-loaders" = { version = "0.3.0", path = "../sgxs-loaders" }

# External dependencies
failure = "0.1.1" # MIT/Apache-2.0
anyhow = "1.0" # MIT/Apache-2.0
14 changes: 7 additions & 7 deletions intel-sgx/dcap-retrieve-pckid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use std::convert::TryInto;
use std::fmt;

use anyhow::anyhow;
use aesm_client::AesmClient;
use dcap_ql::quote::{Qe3CertDataPpid, Quote, Quote3SignatureEcdsaP256, QuoteHeader};
use failure::Error as FailureError;
use sgx_isa::Targetinfo;
#[cfg(windows)]
use sgxs_loaders::enclaveapi::Sgx as IsgxDevice;
Expand Down Expand Up @@ -54,35 +54,35 @@ impl ToString for PckId {
}
}

pub fn retrieve_pckid_str() -> Result<PckId, FailureError> {
pub fn retrieve_pckid_str() -> Result<PckId, anyhow::Error> {
const SGX_QL_ALG_ECDSA_P256: u32 = 2;

let mut device = IsgxDevice::new()
.map_err(|err| FailureError::from(err).context("Error opening SGX device"))?
.map_err(|err| anyhow::Error::from(err).context("Error opening SGX device"))?
.einittoken_provider(AesmClient::new())
.build();

let client = AesmClient::new();

let key_ids = client
.get_supported_att_key_ids()
.map_err(|err| FailureError::from(err).context("AESM communication error getting attestation key ID"))?;
.map_err(|err| anyhow::Error::from(err).context("AESM communication error getting attestation key ID"))?;

let ecdsa_key_id = key_ids
.into_iter()
.find(|id| SGX_QL_ALG_ECDSA_P256 == get_algorithm_id(id))
.ok_or(::failure::err_msg("No appropriate attestation key ID"))?;
.ok_or(anyhow!("No appropriate attestation key ID"))?;

let quote_info = client
.init_quote_ex(ecdsa_key_id.clone())
.map_err(|err| FailureError::from(err).context("Error during quote initialization"))?;
.map_err(|err| anyhow::Error::from(err).context("Error during quote initialization"))?;

let ti = Targetinfo::try_copy_from(quote_info.target_info()).unwrap();
let report = report_test::report(&ti, &mut device).unwrap();

let res = client
.get_quote_ex(ecdsa_key_id, report.as_ref().to_owned(), None, vec![0; 16])
.map_err(|err| FailureError::from(err).context("Error obtaining quote"))?;
.map_err(|err| anyhow::Error::from(err).context("Error obtaining quote"))?;

let quote = Quote::parse(res.quote()).map_err(|err| err.context("Error parsing quote"))?;
let QuoteHeader::V3 { user_data, .. } = quote.header();
Expand Down
4 changes: 2 additions & 2 deletions intel-sgx/enclave-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ sgx-isa = { version = "0.4.0", path = "../sgx-isa" }
ipc-queue = { version = "0.2.0", path = "../../ipc-queue" }

# External dependencies
failure = "0.1.1" # MIT/Apache-2.0
failure_derive = "0.1.1" # MIT/Apache-2.0
anyhow = "1.0" # MIT/Apache-2.0
thiserror = "1.0" # MIT/Apache-2.0
fnv = "1" # MIT/Apache-2.0
lazy_static = "1.2.0" # MIT/Apache-2.0
libc = "0.2.48" # MIT/Apache-2.0
Expand Down
2 changes: 1 addition & 1 deletion intel-sgx/enclave-runner/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::path::Path;

use failure::Error;
use anyhow::Error;
use sgxs::loader::{Load, MappingInfo};

use crate::loader::{EnclaveBuilder, ErasedTcs};
Expand Down
2 changes: 1 addition & 1 deletion intel-sgx/enclave-runner/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::path::Path;
use std::sync::Arc;

use failure::Error;
use anyhow::Error;
use sgxs::loader::{Load, MappingInfo};

use crate::loader::{EnclaveBuilder, ErasedTcs};
Expand Down
29 changes: 15 additions & 14 deletions intel-sgx/enclave-runner/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::os::raw::c_void;
use std::path::Path;
use std::{arch, str};

use failure::{format_err, Error, ResultExt};
use failure_derive::Fail;
use thiserror::Error as ThisError;
use anyhow::Context;
use anyhow::anyhow;

#[cfg(feature = "crypto-openssl")]
use openssl::{
Expand Down Expand Up @@ -65,23 +66,23 @@ pub struct EnclaveBuilder<'a> {
attributes: Option<Attributes>,
miscselect: Option<Miscselect>,
usercall_ext: Option<Box<dyn UsercallExtension>>,
load_and_sign: Option<Box<dyn FnOnce(Signer) -> Result<Sigstruct, Error>>>,
hash_enclave: Option<Box<dyn FnOnce(&mut EnclaveSource<'_>) -> Result<EnclaveHash, Error>>>,
load_and_sign: Option<Box<dyn FnOnce(Signer) -> Result<Sigstruct, anyhow::Error>>>,
hash_enclave: Option<Box<dyn FnOnce(&mut EnclaveSource<'_>) -> Result<EnclaveHash, anyhow::Error>>>,
forward_panics: bool,
cmd_args: Option<Vec<Vec<u8>>>,
}

#[derive(Debug, Fail)]
#[derive(Debug, ThisError)]
pub enum EnclavePanic {
/// The first byte of the debug buffer was 0
#[fail(display = "Enclave panicked.")]
#[error("Enclave panicked.")]
NoDebugBuf,
/// The debug buffer could be interpreted as a zero-terminated UTF-8 string
#[fail(display = "Enclave panicked: {}", _0)]
#[error("Enclave panicked: {}", _0)]
DebugStr(String),
/// The first byte of the debug buffer was not 0, but it was also not a
/// zero-terminated UTF-8 string
#[fail(display = "Enclave panicked: {:?}", _0)]
#[error("Enclave panicked: {:?}", _0)]
DebugBuf(Vec<u8>),
}

Expand Down Expand Up @@ -158,15 +159,15 @@ impl<'a> EnclaveBuilder<'a> {
ret
}

fn generate_dummy_signature(&mut self) -> Result<Sigstruct, Error> {
fn generate_dummy_signature(&mut self) -> Result<Sigstruct, anyhow::Error> {
fn xgetbv0() -> u64 {
unsafe { arch::x86_64::_xgetbv(0) }
}

let mut enclave = self.enclave.try_clone().unwrap();
let hash = match self.hash_enclave.take() {
Some(f) => f(&mut enclave)?,
None => return Err(format_err!("either compile with default features or use with_dummy_signature_signer()"))
None => return Err(anyhow!("either compile with default features or use with_dummy_signature_signer()"))
};
let mut signer = Signer::new(hash);

Expand All @@ -184,7 +185,7 @@ impl<'a> EnclaveBuilder<'a> {

match self.load_and_sign.take() {
Some(f) => f(signer),
None => Err(format_err!("either compile with default features or use with_dummy_signature_signer()"))
None => Err(anyhow!("either compile with default features or use with_dummy_signature_signer()"))
}
}

Expand Down Expand Up @@ -309,7 +310,7 @@ impl<'a> EnclaveBuilder<'a> {
fn load<T: Load>(
mut self,
loader: &mut T,
) -> Result<(Vec<ErasedTcs>, *mut c_void, usize, bool), Error> {
) -> Result<(Vec<ErasedTcs>, *mut c_void, usize, bool), anyhow::Error> {
let signature = match self.signature {
Some(sig) => sig,
None => self
Expand All @@ -331,7 +332,7 @@ impl<'a> EnclaveBuilder<'a> {
))
}

pub fn build<T: Load>(mut self, loader: &mut T) -> Result<Command, Error> {
pub fn build<T: Load>(mut self, loader: &mut T) -> Result<Command, anyhow::Error> {
self.initialized_args_mut();
let args = self.cmd_args.take().unwrap_or_default();
let c = self.usercall_ext.take();
Expand All @@ -343,7 +344,7 @@ impl<'a> EnclaveBuilder<'a> {
///
/// [`arg`]: struct.EnclaveBuilder.html#method.arg
/// [`args`]: struct.EnclaveBuilder.html#method.args
pub fn build_library<T: Load>(mut self, loader: &mut T) -> Result<Library, Error> {
pub fn build_library<T: Load>(mut self, loader: &mut T) -> Result<Library, anyhow::Error> {
if self.cmd_args.is_some() {
panic!("Command arguments do not apply to Library enclaves.");
}
Expand Down
6 changes: 3 additions & 3 deletions intel-sgx/enclave-runner/src/usercalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::thread::{self, JoinHandle};
use std::time::{self, Duration};
use std::{cmp, fmt, str};

use failure::bail;
use anyhow::bail;
use fnv::FnvHashMap;
use futures::future::{poll_fn, Either, Future, FutureExt};
use futures::lock::Mutex;
Expand Down Expand Up @@ -1086,7 +1086,7 @@ impl EnclaveState {
usercall_ext: Option<Box<dyn UsercallExtension>>,
forward_panics: bool,
cmd_args: Vec<Vec<u8>>,
) -> StdResult<(), failure::Error> {
) -> StdResult<(), anyhow::Error> {
let mut event_queues =
FnvHashMap::with_capacity_and_hasher(threads.len() + 1, Default::default());
let main = Self::event_queue_add_tcs(&mut event_queues, main);
Expand Down Expand Up @@ -1184,7 +1184,7 @@ impl EnclaveState {
p3: u64,
p4: u64,
p5: u64,
) -> StdResult<(u64, u64), failure::Error> {
) -> StdResult<(u64, u64), anyhow::Error> {
let thread = enclave.threads_queue.pop().expect("threads queue empty");
let work = Work {
tcs: RunningTcs {
Expand Down
4 changes: 2 additions & 2 deletions intel-sgx/fortanix-sgx-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ sgx-isa = { version = "0.4.0", path = "../sgx-isa" }
# External dependencies
xmas-elf = "0.6.0" # Apache-2.0/MIT
clap = "2.2.5" # MIT
failure = "0.1.1" # MIT/Apache-2.0
failure_derive = "0.1.1" # MIT/Apache-2.0
anyhow = "1.0" # MIT/Apache-2.0
thiserror = "1.0" # MIT/Apache-2.0
serde_derive = "1.0.84" # MIT/Apache-2.0
serde = "1.0.84" # MIT/Apache-2.0
toml = "0.4.10" # MIT/Apache-2.0
Expand Down
Loading

0 comments on commit db29630

Please sign in to comment.