Skip to content

Commit 859981e

Browse files
committed
Passing resource path to eif builder
1 parent a6fdf92 commit 859981e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

fortanix-vme/eif-tools/src/bin/ftxvme-elf2eif.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fs::File;
22
use std::io::Write;
3+
use std::path::Path;
34

45
use anyhow::Result;
56
use clap::{Arg, crate_authors, crate_version};
@@ -47,6 +48,13 @@ fn main() {
4748
.required(true)
4849
.value_name("FILE")
4950
.help("Path to output EIF file"))
51+
.arg(Arg::with_name("resource-path")
52+
.short("r")
53+
.long("resource-path")
54+
.required(false)
55+
.value_name("resource_path")
56+
.help("Path to the resource directory")
57+
.validator_os(is_directory))
5058
.arg(Arg::with_name("signing-certificate")
5159
.short("c")
5260
.long("signing-certificate")
@@ -66,7 +74,8 @@ fn main() {
6674
let output_path = args.value_of("eiffile").unwrap();
6775
let signing_certificate = args.value_of("signing-certificate").map(|c| c.to_string());
6876
let private_key = args.value_of("private-key").map(|k| k.to_string());
69-
77+
let resource_path = args.value_of("resource-path").unwrap_or("/usr/share/nitro_enclaves/blobs/");
78+
let resource_path = Path::new(resource_path).to_path_buf();
7079
let mut logger = env_logger::Builder::from_default_env();
7180
let logger = logger.format(|buf, record| writeln!(buf, "{}", record.args()));
7281
if verbose {
@@ -87,7 +96,7 @@ fn main() {
8796
let docker_dir_path = docker_dir.path().to_str().map(|s| s.to_string());
8897
debug!("Created docker dir `{:?}`", docker_dir_path);
8998

90-
let (_output_file, measurements) = match build_from_docker("elf2eif", &docker_dir_path, output_path, &signing_certificate, &private_key) {
99+
let (_output_file, measurements) = match build_from_docker(&resource_path, "elf2eif", &docker_dir_path, output_path, &signing_certificate, &private_key) {
91100
Ok((o, m)) => {
92101
if let Err(_) = docker_dir.close() {
93102
debug!("Could not clean up docker directory `{:?}`", docker_dir_path)

fortanix-vme/eif-tools/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ffi::{OsStr, OsString};
22
use std::fs::File;
3+
use std::path::PathBuf;
34

45
/// Verify that the given path points to a readable file.
56
pub fn readable_file(path: &OsStr) -> Result<(), OsString> {
@@ -17,3 +18,13 @@ pub fn readable_elf_file(path: &OsStr) -> Result<(), OsString> {
1718
Err(e) => Err(format!("{:?} while opening file: {}", e, path.to_string_lossy()).into()),
1819
}
1920
}
21+
22+
/// Verify that the given path points to a directory
23+
pub fn is_directory(path: &OsStr) -> Result<(), OsString> {
24+
if PathBuf::from(path).is_dir() {
25+
Ok(())
26+
} else {
27+
Err(format!("{} is not a directory", path.to_string_lossy()).into())
28+
}
29+
}
30+

0 commit comments

Comments
 (0)