Skip to content

Commit c408047

Browse files
committed
Enable passing enclave signature file path to ftxsgx-runner
1 parent 5dca7b2 commit c408047

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intel-sgx/fortanix-sgx-tools/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ sgxs = { version = "0.8.0", path = "../sgxs" }
2727
sgx-isa = { version = "0.4.0", path = "../sgx-isa" }
2828

2929
# External dependencies
30-
xmas-elf = "0.10.0" # Apache-2.0/MIT
31-
clap = "2.34.0" # MIT
30+
xmas-elf = "0.10.0" # Apache-2.0/MIT
31+
clap = "2.34.0" # MIT
3232
anyhow = "1.0" # MIT/Apache-2.0
3333
thiserror = "1.0" # MIT/Apache-2.0
3434
serde_derive = "1.0.84" # MIT/Apache-2.0
3535
serde = "1.0.84" # MIT/Apache-2.0
3636
toml = "0.8.19" # MIT/Apache-2.0
3737
num_cpus = "1.9.0" # MIT/Apache-2.0
38-
libc = "0.2" # MIT/Apache-2.0
38+
libc = "0.2" # MIT/Apache-2.0
3939
nix = "0.13.0" # MIT
40+
os_str_bytes = "7" # MIT/Apache-2.0

intel-sgx/fortanix-sgx-tools/src/bin/ftxsgx-runner.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

7-
#[macro_use]
87
extern crate clap;
98

9+
use std::convert::{TryFrom, TryInto};
10+
use std::ffi::{OsStr, OsString};
1011
#[cfg(unix)]
1112
use std::io::{stderr, Write};
13+
use std::path::Path;
1214

1315
use aesm_client::AesmClient;
1416
use enclave_runner::EnclaveBuilder;
@@ -17,19 +19,36 @@ use anyhow::Context;
1719
use libc::{c_int, c_void, siginfo_t};
1820
#[cfg(unix)]
1921
use nix::sys::signal;
22+
use os_str_bytes::OsStrBytesExt;
2023
#[cfg(unix)]
2124
use sgxs_loaders::isgx::Device as IsgxDevice;
2225
#[cfg(windows)]
2326
use sgxs_loaders::enclaveapi::Sgx as IsgxDevice;
2427

2528
use clap::{App, Arg};
2629

27-
arg_enum!{
28-
#[derive(PartialEq, Debug)]
29-
#[allow(non_camel_case_types)]
30-
pub enum Signature {
31-
coresident,
32-
dummy
30+
#[derive(PartialEq, Debug)]
31+
pub enum Signature<'s> {
32+
Coresident,
33+
Dummy,
34+
File(&'s Path),
35+
}
36+
37+
impl<'s> TryFrom<&'s OsStr> for Signature<'s> {
38+
type Error = OsString;
39+
40+
fn try_from(s: &'s OsStr) -> Result<Self, Self::Error> {
41+
if let Some(path) = s.strip_prefix("file=") {
42+
return Ok(Self::File(Path::new(path)));
43+
}
44+
45+
if s == "coresident" {
46+
Ok(Self::Coresident)
47+
} else if s == "dummy" {
48+
Ok(Self::Dummy)
49+
} else {
50+
Err("expected coresident, dummy or file=<path>".to_owned().into())
51+
}
3352
}
3453
}
3554

@@ -59,9 +78,10 @@ fn main() -> Result<(), anyhow::Error> {
5978
.arg(Arg::with_name("signature")
6079
.short("s")
6180
.long("signature")
81+
.long_help("Possible values: coresident, dummy, file=<path>. Defaults to 'coresident' with a fallback to 'dummy' if no coresident signature file is found.")
6282
.required(false)
6383
.takes_value(true)
64-
.possible_values(&Signature::variants()))
84+
.validator_os(|s| Signature::try_from(s.as_ref()).map(|_| ())))
6585
.arg(Arg::with_name("enclave-args")
6686
.long_help("Arguments passed to the enclave. \
6787
Note that this is not an appropriate channel for passing \
@@ -78,9 +98,10 @@ fn main() -> Result<(), anyhow::Error> {
7898

7999
let mut enclave_builder = EnclaveBuilder::new(file.as_ref());
80100

81-
match args.value_of("signature").map(|v| v.parse().expect("validated")) {
82-
Some(Signature::coresident) => { enclave_builder.coresident_signature().context("While loading coresident signature")?; }
83-
Some(Signature::dummy) => { enclave_builder.dummy_signature(); },
101+
match args.value_of_os("signature").map(|v| v.try_into().expect("validated")) {
102+
Some(Signature::Coresident) => { enclave_builder.coresident_signature().context("While loading coresident signature")?; }
103+
Some(Signature::Dummy) => { enclave_builder.dummy_signature(); },
104+
Some(Signature::File(path)) => { enclave_builder.signature(path).with_context(|| format!("Failed to load signature file '{}'", path.display()))?; },
84105
None => (),
85106
}
86107

0 commit comments

Comments
 (0)