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]
87extern crate clap;
98
9+ use std:: convert:: { TryFrom , TryInto } ;
10+ use std:: ffi:: { OsStr , OsString } ;
1011#[ cfg( unix) ]
1112use std:: io:: { stderr, Write } ;
13+ use std:: path:: Path ;
1214
1315use aesm_client:: AesmClient ;
1416use enclave_runner:: EnclaveBuilder ;
@@ -17,19 +19,36 @@ use anyhow::Context;
1719use libc:: { c_int, c_void, siginfo_t} ;
1820#[ cfg( unix) ]
1921use nix:: sys:: signal;
22+ use os_str_bytes:: OsStrBytesExt ;
2023#[ cfg( unix) ]
2124use sgxs_loaders:: isgx:: Device as IsgxDevice ;
2225#[ cfg( windows) ]
2326use sgxs_loaders:: enclaveapi:: Sgx as IsgxDevice ;
2427
2528use 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