Skip to content

Commit

Permalink
add env variable LCP_ENCLAVE_DEBUG
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jan 30, 2024
1 parent 71dd7fb commit ccd35d5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/src/commands/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl AttestationCmd {
bail!("home directory doesn't exist at {:?}", home);
}
run_ias_remote_attestation(
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.debug)?,
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.is_debug())?,
cmd,
)
}
Expand All @@ -44,7 +44,7 @@ impl AttestationCmd {
bail!("home directory doesn't exist at {:?}", home);
}
run_simulate_remote_attestation(
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.debug)?,
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.is_debug())?,
cmd,
)
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/commands/elc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ impl ELCCmd {
L: EnclaveLoader<S>,
{
let elc_opts = self.opts();
let enclave =
enclave_loader.load(opts, elc_opts.enclave.path.as_ref(), elc_opts.enclave.debug)?;
let enclave = enclave_loader.load(
opts,
elc_opts.enclave.path.as_ref(),
elc_opts.enclave.is_debug(),
)?;
match self {
Self::CreateClient(_) => {
let _ = enclave.proto_create_client(elc_opts.load()?)?;
Expand Down
6 changes: 3 additions & 3 deletions app/src/commands/enclave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ impl EnclaveCmd {
}
match self {
Self::GenerateKey(cmd) => run_generate_key(
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.debug)?,
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.is_debug())?,
cmd,
),
Self::ListKeys(cmd) => run_list_keys(
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.debug)?,
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.is_debug())?,
cmd,
),
Self::PruneKeys(cmd) => run_prune_keys(
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.debug)?,
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.is_debug())?,
cmd,
),
Self::Metadata(cmd) => run_print_metadata(opts, cmd),
Expand Down
2 changes: 1 addition & 1 deletion app/src/commands/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ServiceCmd {
Self::Start(cmd) => {
let addr = cmd.address.parse()?;
let enclave =
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.debug)?;
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.is_debug())?;

let mut rb = Builder::new_multi_thread();
let rb = if let Some(threads) = cmd.threads {
Expand Down
43 changes: 32 additions & 11 deletions app/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use clap::Parser;
use log::LevelFilter;
use std::{path::PathBuf, str::FromStr};

const ENV_VAR_DEBUG: &str = "LCP_ENCLAVE_DEBUG";

const DEFAULT_HOME: &str = "~/.lcp";
const DEFAULT_ENCLAVE: &str = "enclave.signed.so";

#[derive(Debug, Clone, Parser)]
pub struct Opts {
/// Path to the home directory
Expand All @@ -16,26 +21,17 @@ pub struct Opts {
pub log_level: Option<String>,
}

#[derive(Debug, Clone, Parser, PartialEq)]
pub struct EnclaveOpts {
/// Path to the enclave binary
#[clap(long = "enclave", help = "Path to enclave binary")]
pub path: Option<PathBuf>,
#[clap(long = "enclave_debug", help = "Enable enclave debug mode")]
pub debug: bool,
}

impl Opts {
pub fn get_home(&self) -> PathBuf {
if let Some(home) = self.home.as_ref() {
home.clone()
} else {
dirs::home_dir().unwrap().join(".lcp")
dirs::home_dir().unwrap().join(DEFAULT_HOME)
}
}

pub fn default_enclave(&self) -> PathBuf {
self.get_home().join("enclave.signed.so")
self.get_home().join(DEFAULT_ENCLAVE)
}

pub fn get_state_store_path(&self) -> PathBuf {
Expand All @@ -52,3 +48,28 @@ impl Opts {
}
}
}

#[derive(Debug, Clone, Parser, PartialEq)]
pub struct EnclaveOpts {
/// Path to the enclave binary
#[clap(long = "enclave", help = "Path to enclave binary")]
pub path: Option<PathBuf>,
/// Priority for debug flag:
/// 1. command line option
/// 2. environment variable
#[clap(long = "enclave_debug", help = "Enable enclave debug mode")]
debug: bool,
}

impl EnclaveOpts {
pub fn is_debug(&self) -> bool {
if self.debug {
true
} else {
match std::env::var(ENV_VAR_DEBUG).map(|val| val.to_lowercase()) {
Ok(val) => val == "1" || val == "true",
Err(_) => false,
}
}
}
}

0 comments on commit ccd35d5

Please sign in to comment.