oasis_core_runtime/
lib.rs1#![feature(test)]
14#![feature(arbitrary_self_types)]
15#![feature(const_option)]
16
17use lazy_static::lazy_static;
18#[cfg(target_env = "sgx")]
19use sgx_isa::{AttributesFlags, Report};
20
21#[cfg_attr(test, macro_use)]
22extern crate base64_serde;
23
24#[macro_use]
25pub mod common;
26pub mod app;
27mod attestation;
28pub mod cache;
29pub mod config;
30pub mod consensus;
31pub mod dispatcher;
32pub mod enclave_rpc;
33pub mod future;
34pub mod host;
35pub mod identity;
36pub mod init;
37pub mod policy;
38pub mod protocol;
39pub mod storage;
40pub mod transaction;
41pub mod types;
42
43use common::{
44 sgx::{EnclaveIdentity, MrSigner},
45 version::{Version, PROTOCOL_VERSION},
46};
47
48#[cfg(all(target_env = "sgx", feature = "debug-mock-sgx"))]
50compile_error!("the debug-mock-sgx feature can only be enabled on non-sgx targets");
51
52#[cfg(all(target_env = "sgx", feature = "tdx"))]
53compile_error!("the tdx feature can only be enabled on non-sgx targets");
54
55#[cfg(all(feature = "tdx", feature = "debug-mock-sgx"))]
56compile_error!("the tdx feature can't be enabled together with debug-mock-sgx");
57
58lazy_static! {
59 pub static ref BUILD_INFO: BuildInfo = {
60 let tee_type = if cfg!(any(target_env = "sgx", feature = "debug-mock-sgx")) {
62 TeeType::Sgx
63 } else if cfg!(feature = "tdx") {
64 TeeType::Tdx
65 } else {
66 TeeType::None
67 };
68
69 #[allow(clippy::let_and_return)]
71 let is_secure = match tee_type {
72 TeeType::Sgx => {
73 let maybe_secure = true;
78
79 let maybe_secure = maybe_secure && option_env!("OASIS_UNSAFE_SKIP_AVR_VERIFY").is_none();
81
82 let maybe_secure = maybe_secure && option_env!("OASIS_UNSAFE_ALLOW_DEBUG_ENCLAVES").is_none();
84
85 let maybe_secure = maybe_secure && option_env!("OASIS_UNSAFE_LAX_AVR_VERIFY").is_none();
91
92 #[cfg(target_env = "sgx")]
94 let maybe_secure = maybe_secure && !Report::for_self().attributes.flags.contains(AttributesFlags::DEBUG);
95
96 let enclave_identity = EnclaveIdentity::current().unwrap();
98 let fortanix_mrsigner = MrSigner::from("9affcfae47b848ec2caf1c49b4b283531e1cc425f93582b36806e52a43d78d1a");
99 let maybe_secure = maybe_secure && (enclave_identity.mr_signer != fortanix_mrsigner);
100
101 maybe_secure
102 }
103 TeeType::Tdx => {
104 let maybe_secure = true;
109
110 let maybe_secure = maybe_secure && option_env!("OASIS_UNSAFE_SKIP_AVR_VERIFY").is_none();
112
113 let maybe_secure = maybe_secure && option_env!("OASIS_UNSAFE_ALLOW_DEBUG_ENCLAVES").is_none();
115
116 let maybe_secure = maybe_secure && option_env!("OASIS_UNSAFE_LAX_AVR_VERIFY").is_none();
122
123 maybe_secure
126 }
127 TeeType::None => {
128 false
130 }
131 };
132
133 BuildInfo {
134 tee_type,
135 protocol_version: PROTOCOL_VERSION,
136 is_secure,
137 }
138 };
139}
140
141#[derive(Debug, Default, PartialEq, Eq)]
143pub enum TeeType {
144 #[default]
145 None,
146 Sgx,
147 Tdx,
148}
149
150#[derive(Debug)]
152pub struct BuildInfo {
153 pub tee_type: TeeType,
155 pub protocol_version: Version,
157 pub is_secure: bool,
159}
160
161pub use self::{
163 enclave_rpc::{demux::Demux as RpcDemux, dispatcher::Dispatcher as RpcDispatcher},
164 init::start_runtime,
165 protocol::Protocol,
166 transaction::dispatcher::Dispatcher as TxnDispatcher,
167};
168
169pub use cbor;