Skip to content

Commit 4ea1151

Browse files
committed
add mrenclave to service start log
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent 6faf57b commit 4ea1151

File tree

7 files changed

+54
-10
lines changed

7 files changed

+54
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/commands/service.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::enclave::EnclaveLoader;
22
use crate::opts::{EnclaveOpts, Opts};
33
use anyhow::Result;
44
use clap::Parser;
5-
use enclave_api::{Enclave, EnclaveProtoAPI};
5+
use enclave_api::{Enclave, EnclaveInfo, EnclaveProtoAPI};
66
use host::store::transaction::CommitStore;
77
use log::*;
88
use service::{run_service, AppService};
@@ -49,7 +49,8 @@ impl ServiceCmd {
4949
let addr = cmd.address.parse()?;
5050
let enclave =
5151
enclave_loader.load(opts, cmd.enclave.path.as_ref(), cmd.enclave.is_debug())?;
52-
52+
let metadata = enclave.metadata()?;
53+
let mrenclave = metadata.mrenclave().to_hex_string();
5354
let mut rb = Builder::new_multi_thread();
5455
let rb = if let Some(threads) = cmd.threads {
5556
rb.worker_threads(threads)
@@ -59,7 +60,7 @@ impl ServiceCmd {
5960
let rt = Arc::new(rb.enable_all().build()?);
6061
let srv = AppService::new(opts.get_home(), enclave);
6162

62-
info!("start service: addr={addr}");
63+
info!("start service: addr={addr} mrenclave={mrenclave}");
6364
run_service(srv, rt, addr)
6465
}
6566
}

modules/enclave-api/src/enclave.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::errors::Result;
22
use keymanager::EnclaveKeyManager;
3-
use sgx_types::{metadata::metadata_t, sgx_enclave_id_t, SgxResult};
3+
use lcp_types::EnclaveMetadata;
4+
use sgx_types::{sgx_enclave_id_t, SgxResult};
45
use sgx_urts::SgxEnclave;
56
use std::path::PathBuf;
67
use std::sync::{Arc, RwLock};
@@ -54,7 +55,7 @@ pub trait EnclaveInfo: Sync + Send {
5455
/// `get_eid` returns the enclave id
5556
fn get_eid(&self) -> sgx_enclave_id_t;
5657
/// `metadata` returns the metadata of the enclave
57-
fn metadata(&self) -> SgxResult<metadata_t>;
58+
fn metadata(&self) -> SgxResult<EnclaveMetadata>;
5859
/// `is_debug` returns true if the enclave is in debug mode
5960
fn is_debug(&self) -> bool;
6061
/// `get_key_manager` returns a key manager for Enclave Keys
@@ -67,7 +68,7 @@ impl<S: CommitStore> EnclaveInfo for Enclave<S> {
6768
self.sgx_enclave.geteid()
6869
}
6970
/// `metadata` returns the metadata of the enclave
70-
fn metadata(&self) -> SgxResult<metadata_t> {
71+
fn metadata(&self) -> SgxResult<EnclaveMetadata> {
7172
host::sgx_get_metadata(&self.path)
7273
}
7374
/// `is_debug` returns true if the enclave is in debug mode

modules/host/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ log = "0.4.8"
1010
once_cell = "1.15.0"
1111
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }
1212

13+
lcp-types = { path = "../types" }
1314
ocall-commands = { path = "../ocall-commands" }
1415
ocall-handler = { path = "../ocall-handler", default-features = false }
1516

modules/host/src/enclave.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
use lcp_types::EnclaveMetadata;
12
use sgx_types::{metadata::metadata_t, *};
23
use sgx_urts::SgxEnclave;
34
use std::{ffi::CString, mem::MaybeUninit, path::PathBuf};
45

6+
/// Create an enclave with the given path and debug flag
7+
///
8+
/// # Arguments
9+
/// - `path`: path to the enclave binary
10+
/// - `debug`: debug flag
511
pub fn create_enclave(path: impl Into<PathBuf>, debug: bool) -> SgxResult<SgxEnclave> {
612
let mut launch_token: sgx_launch_token_t = [0; 1024];
713
let mut launch_token_updated: i32 = 0;
@@ -18,7 +24,11 @@ pub fn create_enclave(path: impl Into<PathBuf>, debug: bool) -> SgxResult<SgxEnc
1824
)
1925
}
2026

21-
pub fn sgx_get_metadata(path: impl Into<PathBuf>) -> SgxResult<metadata_t> {
27+
/// Get the metadata of an enclave from the given path
28+
///
29+
/// # Arguments
30+
/// - `path`: path to the enclave binary
31+
pub fn sgx_get_metadata(path: impl Into<PathBuf>) -> SgxResult<EnclaveMetadata> {
2232
let path = path.into();
2333
let enclave_path = CString::new(path.as_os_str().to_str().unwrap()).unwrap();
2434
let (metadata, status) = unsafe {
@@ -27,7 +37,7 @@ pub fn sgx_get_metadata(path: impl Into<PathBuf>) -> SgxResult<metadata_t> {
2737
(metadata, status)
2838
};
2939
if status == sgx_status_t::SGX_SUCCESS {
30-
Ok(metadata)
40+
Ok(metadata.into())
3141
} else {
3242
Err(status)
3343
}

modules/types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use height::Height;
99
pub use host::ClientId;
1010
/// re-export
1111
pub use lcp_proto as proto;
12-
pub use sgx::Mrenclave;
12+
pub use sgx::{EnclaveMetadata, Mrenclave};
1313
pub use time::{nanos_to_duration, Time, MAX_UNIX_TIMESTAMP_NANOS};
1414
pub use transmuter::{deserialize_bytes, serialize_bytes, BytesTransmuter};
1515

modules/types/src/sgx.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::{prelude::*, TypeError};
22
use core::fmt::Display;
33
use core::ops::Deref;
4-
use sgx_types::{sgx_measurement_t, SGX_HASH_SIZE};
4+
use sgx_types::{metadata::metadata_t, sgx_measurement_t, SGX_HASH_SIZE};
55

6+
/// MRENCLAVE is a measurement of the enclave
67
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
78
pub struct Mrenclave(pub [u8; SGX_HASH_SIZE]);
89

@@ -60,3 +61,32 @@ impl Mrenclave {
6061
Ok(Self(bytes))
6162
}
6263
}
64+
65+
/// EnclaveMetadata is the metadata of an enclave
66+
pub struct EnclaveMetadata(metadata_t);
67+
68+
impl Deref for EnclaveMetadata {
69+
type Target = metadata_t;
70+
fn deref(&self) -> &Self::Target {
71+
&self.0
72+
}
73+
}
74+
75+
impl From<metadata_t> for EnclaveMetadata {
76+
fn from(metadata: metadata_t) -> Self {
77+
Self(metadata)
78+
}
79+
}
80+
81+
impl From<EnclaveMetadata> for metadata_t {
82+
fn from(metadata: EnclaveMetadata) -> Self {
83+
metadata.0
84+
}
85+
}
86+
87+
impl EnclaveMetadata {
88+
/// Get the MRENCLAVE of the enclave from the metadata
89+
pub fn mrenclave(&self) -> Mrenclave {
90+
self.enclave_css.body.enclave_hash.m.into()
91+
}
92+
}

0 commit comments

Comments
 (0)