Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Prepare some small changes for SGX attestation #163

Merged
merged 2 commits into from
Nov 16, 2020

Conversation

lkatalin
Copy link
Contributor

We will need an updated version of the SGX dependency and we'll need to use Intel's aesm-proto file to generate Rust structures during build.

build.rs Outdated
Comment on lines 114 to 130
protobuf_codegen_pure::Codegen::new()
.out_dir("src/protobuf")
.inputs(&["src/protobuf/aesm-proto.proto"])
.include("src/protobuf")
.run()
.expect("Protobuf codegen failed");

Command::new("mv")
.current_dir(&Path::new(CRATE).join("src/protobuf"))
.arg("aesm_proto.rs")
.arg("mod.rs")
.status()
.unwrap_or_else(|_| panic!("Could not rename aesm proto file"));

let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let out_dir_bin = out_dir.join("bin");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protobuf_codegen_pure::Codegen::new()
.out_dir("src/protobuf")
.inputs(&["src/protobuf/aesm-proto.proto"])
.include("src/protobuf")
.run()
.expect("Protobuf codegen failed");
Command::new("mv")
.current_dir(&Path::new(CRATE).join("src/protobuf"))
.arg("aesm_proto.rs")
.arg("mod.rs")
.status()
.unwrap_or_else(|_| panic!("Could not rename aesm proto file"));
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let out_dir_bin = out_dir.join("bin");
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let out_dir_proto = out_dir.join("protos");
match std::fs::create_dir(&out_dir_proto) {
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {}
Err(e) => {
eprintln!("Can't create {:#?} : {:#?}", out_dir_proto, e);
std::process::exit(1);
}
Ok(_) => {}
}
protobuf_codegen_pure::Codegen::new()
.out_dir(&out_dir_proto)
.inputs(&["src/protobuf/aesm-proto.proto"])
.include("src/protobuf")
.customize(protobuf_codegen_pure::Customize {
gen_mod_rs: Some(true),
..Default::default()
})
.run()
.expect("Protobuf codegen failed");
let out_dir_bin = out_dir.join("bin");

We should not generate code into the current source code tree. Better generate into $OUT_DIR.

See also:
stepancheg/rust-protobuf#324

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm looking for info on gen_mod_rs but it's not very obvious. I assume it lets you name the output mod.rs, which is what I was trying to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I see from the link this is how it's normally done: "And for now, you may generate that mod.rs in OUT_DIR file from build.rs, and include generated mod.rs from the src directory."

Comment on lines 3 to 4
//! This is a placeholder file for the Rust stuctures generated from
//! aesm-proto.proto during build.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! This is a placeholder file for the Rust stuctures generated from
//! aesm-proto.proto during build.
//! Provides all generated protobuf modules
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));

This then includes the generated protobuf modules.

You will then have to use crate::protobuf::aesm_proto.

@enarxbot enarxbot assigned lkatalin and unassigned ueno, npmccallum and haraldh Nov 12, 2020
This update includes changes to attestation types that make them
usable in the SGX shim.

Signed-off-by: Lily Sturmann <lsturman@redhat.com>
This generates a Rust file from Intel's aesm-proto.proto that can be used
as a module to communicate with the AESM daemon.

Signed-off-by: Lily Sturmann <lsturman@redhat.com>
@lkatalin
Copy link
Contributor Author

I pulled the error handling for create_dir() out into its own function since we use it several times.

@lkatalin lkatalin requested a review from haraldh November 13, 2020 16:34
@enarxbot enarxbot assigned haraldh, ueno and npmccallum and unassigned lkatalin Nov 13, 2020
Copy link
Contributor

@connorkuehl connorkuehl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not confirm the correctness of Intel's proto file

@enarxbot enarxbot merged commit 110007d into enarx-archive:master Nov 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants