You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2020/01/21 23:33:53 UTC

[incubator-teaclave] 02/02: [utils] Deprecate service_config and start to redesign measurements configuration

This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git

commit 01bee69b1418a1402530974f9183a8b301bead15
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Tue Jan 21 15:26:47 2020 -0800

    [utils] Deprecate service_config and start to redesign measurements configuration
---
 attestation/Cargo.toml                             |  1 -
 config/src/lib.rs                                  |  4 +--
 services/authentication/enclave/Cargo.toml         |  1 +
 services/database/enclave/Cargo.toml               |  1 +
 services/execution/enclave/Cargo.toml              |  1 +
 tests/functional_tests/enclave/Cargo.toml          |  3 +-
 .../enclave/src/teaclave_authentication_service.rs |  2 +-
 tests/integration_tests/enclave/Cargo.toml         |  3 +-
 tests/unit_tests/enclave/Cargo.toml                |  3 +-
 types/src/lib.rs                                   | 36 ++++++++++++++++------
 utils/service_enclave_utils/Cargo.toml             |  2 --
 utils/service_enclave_utils/src/lib.rs             |  5 ---
 12 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/attestation/Cargo.toml b/attestation/Cargo.toml
index 6b2f965..b924346 100644
--- a/attestation/Cargo.toml
+++ b/attestation/Cargo.toml
@@ -35,7 +35,6 @@ webpki           = { version = "0.21.0" }
 webpki-roots     = { version = "0.17.0" }
 yasna            = { version = "0.3.0", features = ["bit-vec", "num-bigint", "chrono"] }
 
-teaclave_config = { path = "../config" }
 teaclave_types  = { path = "../types" }
 
 sgx_rand    = { version = "1.1.0", optional = true }
diff --git a/config/src/lib.rs b/config/src/lib.rs
index 7b8a7c0..7b001d2 100644
--- a/config/src/lib.rs
+++ b/config/src/lib.rs
@@ -75,7 +75,7 @@ pub mod runtime_config {
         enclave_info_source: ConfigSource,
         #[serde(rename(serialize = "auditor_signatures", deserialize = "auditor_signatures"))]
         auditor_signatures_source: Vec<ConfigSource>,
-        pub enclave_info_bytes: Option<String>,
+        pub enclave_info_bytes: Option<Vec<u8>>,
         pub auditor_signatures_bytes: Option<Vec<Vec<u8>>>,
     }
 
@@ -111,7 +111,7 @@ pub mod runtime_config {
 
             config.audit.enclave_info_bytes = match &config.audit.enclave_info_source {
                 ConfigSource::Path(ref enclave_info_path) => {
-                    let content = fs::read_to_string(enclave_info_path).unwrap_or_else(|_| {
+                    let content = fs::read(enclave_info_path).unwrap_or_else(|_| {
                         panic!("Cannot find enclave info at {:?}.", enclave_info_path)
                     });
                     Some(content)
diff --git a/services/authentication/enclave/Cargo.toml b/services/authentication/enclave/Cargo.toml
index 008feb3..9201adc 100644
--- a/services/authentication/enclave/Cargo.toml
+++ b/services/authentication/enclave/Cargo.toml
@@ -20,6 +20,7 @@ mesalock_sgx = [
   "teaclave_rpc/mesalock_sgx",
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
+  "teaclave_config/mesalock_sgx",
 ]
 cov = ["teaclave_service_enclave_utils/cov"]
 enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "sgx_tunittest"]
diff --git a/services/database/enclave/Cargo.toml b/services/database/enclave/Cargo.toml
index 8b161a7..9a67cce 100644
--- a/services/database/enclave/Cargo.toml
+++ b/services/database/enclave/Cargo.toml
@@ -20,6 +20,7 @@ mesalock_sgx = [
   "teaclave_rpc/mesalock_sgx",
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
+  "teaclave_config/mesalock_sgx",
   "rusty-leveldb/mesalock_sgx",
 ]
 cov = ["teaclave_service_enclave_utils/cov"]
diff --git a/services/execution/enclave/Cargo.toml b/services/execution/enclave/Cargo.toml
index e700ffe..7a420db 100644
--- a/services/execution/enclave/Cargo.toml
+++ b/services/execution/enclave/Cargo.toml
@@ -20,6 +20,7 @@ mesalock_sgx = [
   "teaclave_rpc/mesalock_sgx",
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
+  "teaclave_config/mesalock_sgx",
 ]
 cov = ["sgx_cov"]
 enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "sgx_tunittest"]
diff --git a/tests/functional_tests/enclave/Cargo.toml b/tests/functional_tests/enclave/Cargo.toml
index 2441383..695db8d 100644
--- a/tests/functional_tests/enclave/Cargo.toml
+++ b/tests/functional_tests/enclave/Cargo.toml
@@ -18,7 +18,7 @@ mesalock_sgx = [
   "teaclave_proto/mesalock_sgx",
   "teaclave_ipc/mesalock_sgx",
   "teaclave_rpc/mesalock_sgx",
-  "teaclave_service_config/mesalock_sgx",
+  "teaclave_config/mesalock_sgx",
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
 ]
@@ -35,7 +35,6 @@ teaclave_attestation           = { path = "../../../attestation" }
 teaclave_config                = { path = "../../../config" }
 teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
-teaclave_service_config        = { path = "../../../utils/service_config" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
 teaclave_proto                 = { path = "../../../services/proto" }
diff --git a/tests/functional_tests/enclave/src/teaclave_authentication_service.rs b/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
index 79f0012..4fa78f7 100644
--- a/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
+++ b/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
@@ -21,7 +21,7 @@ pub fn run_tests() {
 fn test_login_success() {
     let runtime_config = RuntimeConfig::from_toml("runtime.config.toml").expect("runtime");
     let enclave_info =
-        EnclaveInfo::load_enclave_info(&runtime_config.audit.enclave_info_bytes.as_ref().unwrap());
+        EnclaveInfo::from_bytes(&runtime_config.audit.enclave_info_bytes.as_ref().unwrap());
     let measure = enclave_info
         .measurements
         .get("teaclave_authentication_service")
diff --git a/tests/integration_tests/enclave/Cargo.toml b/tests/integration_tests/enclave/Cargo.toml
index 1396d75..8660a2c 100644
--- a/tests/integration_tests/enclave/Cargo.toml
+++ b/tests/integration_tests/enclave/Cargo.toml
@@ -17,8 +17,8 @@ mesalock_sgx = [
   "teaclave_attestation/mesalock_sgx",
   "teaclave_proto/mesalock_sgx",
   "teaclave_ipc/mesalock_sgx",
+  "teaclave_config/mesalock_sgx",
   "teaclave_rpc/mesalock_sgx",
-  "teaclave_service_config/mesalock_sgx",
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
   "rusty-leveldb/mesalock_sgx",
@@ -40,7 +40,6 @@ teaclave_attestation           = { path = "../../../attestation" }
 teaclave_config                = { path = "../../../config" }
 teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
-teaclave_service_config        = { path = "../../../utils/service_config" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
 teaclave_proto                 = { path = "../../../services/proto" }
diff --git a/tests/unit_tests/enclave/Cargo.toml b/tests/unit_tests/enclave/Cargo.toml
index 080aff3..0591813 100644
--- a/tests/unit_tests/enclave/Cargo.toml
+++ b/tests/unit_tests/enclave/Cargo.toml
@@ -17,9 +17,9 @@ mesalock_sgx = [
   "teaclave_attestation/mesalock_sgx",
   "teaclave_ipc/mesalock_sgx",
   "teaclave_rpc/mesalock_sgx",
-  "teaclave_service_config/mesalock_sgx",
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
+  "teaclave_config/mesalock_sgx",
   "teaclave_authentication_service_enclave/mesalock_sgx",
   "teaclave_authentication_service_enclave/enclave_unit_test",
   "teaclave_database_service_enclave/mesalock_sgx",
@@ -43,7 +43,6 @@ teaclave_attestation           = { path = "../../../attestation" }
 teaclave_config                = { path = "../../../config" }
 teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
-teaclave_service_config        = { path = "../../../utils/service_config" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
 
diff --git a/types/src/lib.rs b/types/src/lib.rs
index c78a832..20b6b20 100644
--- a/types/src/lib.rs
+++ b/types/src/lib.rs
@@ -5,6 +5,8 @@ extern crate sgx_tstd as std;
 #[cfg(feature = "mesalock_sgx")]
 use std::prelude::v1::*;
 
+use anyhow::Result;
+use anyhow::{bail, ensure};
 use hex;
 use serde::Deserializer;
 use serde_derive::Deserialize;
@@ -81,9 +83,29 @@ pub struct EnclaveInfo {
 struct EnclaveInfoToml(HashMap<String, EnclaveMeasurement>);
 
 impl EnclaveInfo {
-    pub fn load_enclave_info(content: &str) -> Self {
-        let config: EnclaveInfoToml =
-            toml::from_str(&content).expect("Content not correct, unable to load enclave info.");
+    pub fn load_and_verify<T, U>(
+        enclave_info: &[u8],
+        public_keys: &[T],
+        signatures: &[U],
+    ) -> Result<Self>
+    where
+        T: AsRef<[u8]>,
+        U: AsRef<[u8]>,
+    {
+        ensure!(
+            signatures.len() <= public_keys.len(),
+            "Invalid number of public keys"
+        );
+        if !Self::verify(enclave_info, public_keys, signatures) {
+            bail!("Invalid enclave_info");
+        }
+
+        Ok(Self::from_bytes(enclave_info))
+    }
+
+    pub fn from_bytes(enclave_info: &[u8]) -> Self {
+        let config: EnclaveInfoToml = toml::from_slice(enclave_info)
+            .expect("Content not correct, unable to load enclave info.");
         let mut info_map = std::collections::HashMap::new();
         for (k, v) in config.0 {
             info_map.insert(k, EnclaveMeasurement::new(v.mr_enclave, v.mr_signer));
@@ -94,11 +116,7 @@ impl EnclaveInfo {
         }
     }
 
-    pub fn verify_enclave_info<T, U>(
-        enclave_info: &str,
-        public_keys: &[T],
-        signatures: &[U],
-    ) -> bool
+    pub fn verify<T, U>(enclave_info: &[u8], public_keys: &[T], signatures: &[U]) -> bool
     where
         T: AsRef<[u8]>,
         U: AsRef<[u8]>,
@@ -109,7 +127,7 @@ impl EnclaveInfo {
             let mut verified = false;
             for s in signatures {
                 if signature::UnparsedPublicKey::new(&signature::RSA_PKCS1_2048_8192_SHA256, k)
-                    .verify(enclave_info.as_bytes(), s.as_ref())
+                    .verify(enclave_info, s.as_ref())
                     .is_ok()
                 {
                     verified = true;
diff --git a/utils/service_enclave_utils/Cargo.toml b/utils/service_enclave_utils/Cargo.toml
index 3997dc5..233ac22 100644
--- a/utils/service_enclave_utils/Cargo.toml
+++ b/utils/service_enclave_utils/Cargo.toml
@@ -10,7 +10,6 @@ edition = "2018"
 default = []
 mesalock_sgx = [
     "sgx_tstd",
-    "teaclave_service_config/mesalock_sgx",
 ]
 cov = ["sgx_cov", "sgx_trts"]
 
@@ -19,7 +18,6 @@ anyhow     = { version = "1.0.26" }
 env_logger = { version = "0.7.1" }
 log        = { version = "0.4.6" }
 
-teaclave_service_config                   = { path = "../service_config" }
 teaclave_service_enclave_utils_proc_macro = { path = "./proc_macro" }
 
 sgx_cov  = { version = "1.1.0", optional = true }
diff --git a/utils/service_enclave_utils/src/lib.rs b/utils/service_enclave_utils/src/lib.rs
index 13e1f13..818ff6c 100644
--- a/utils/service_enclave_utils/src/lib.rs
+++ b/utils/service_enclave_utils/src/lib.rs
@@ -4,7 +4,6 @@
 extern crate sgx_tstd as std;
 
 use anyhow::{bail, Result};
-use teaclave_service_config as config;
 
 use log::debug;
 use log::error;
@@ -33,10 +32,6 @@ impl ServiceEnclave {
             error!("Cannot enable backtrace");
             bail!("ecall error");
         }
-        if !config::is_runtime_config_initialized() {
-            error!("Runtime config is not initialized");
-            bail!("ecall error");
-        }
 
         Ok(())
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org