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


The following commit(s) were added to refs/heads/develop by this push:
     new 83fbdc0  [frontend] Support passing message to management service
83fbdc0 is described below

commit 83fbdc018227cfcc467ebcf29529b6e0fdb8b3e5
Author: Mingshen Sun <[email protected]>
AuthorDate: Fri Feb 14 23:27:54 2020 -0800

    [frontend] Support passing message to management service
---
 cmake/scripts/test.sh                              |  3 +-
 services/frontend/enclave/src/lib.rs               | 18 ++++++++-
 services/frontend/enclave/src/service.rs           | 45 ++++++++++++++++------
 services/proto/proto_gen/main.rs                   | 15 +++-----
 services/proto/proto_gen/templates/proto.j2        | 10 +++--
 .../proto/src/teaclave_authentication_service.rs   | 22 +++++++++++
 services/proto/src/teaclave_execution_service.rs   | 12 ++++++
 services/proto/src/teaclave_frontend_service.rs    |  4 +-
 services/proto/src/teaclave_management_service.rs  | 17 ++++++++
 .../enclave/src/teaclave_management_service.rs     |  2 +-
 types/src/crypto.rs                                |  8 ++--
 11 files changed, 121 insertions(+), 35 deletions(-)

diff --git a/cmake/scripts/test.sh b/cmake/scripts/test.sh
index 1d6bdd1..42e210d 100755
--- a/cmake/scripts/test.sh
+++ b/cmake/scripts/test.sh
@@ -52,10 +52,11 @@ run_functional_tests() {
   ./teaclave_authentication_service &
   ./teaclave_storage_service &
   sleep 3    # wait for authentication and storage service
+  ./teaclave_management_service &
+  sleep 3    # wait for management service
   ./teaclave_access_control_service &
   ./teaclave_execution_service &
   ./teaclave_frontend_service &
-  ./teaclave_management_service &
   popd
   sleep 3    # wait for other services
   ./teaclave_functional_tests
diff --git a/services/frontend/enclave/src/lib.rs 
b/services/frontend/enclave/src/lib.rs
index 495cde0..ee642c0 100644
--- a/services/frontend/enclave/src/lib.rs
+++ b/services/frontend/enclave/src/lib.rs
@@ -86,7 +86,23 @@ fn start_service(args: &StartServiceInput) -> 
anyhow::Result<()> {
     let authentication_service_endpoint =
         Endpoint::new(authentication_service_address).config(config);
 
-    let service = 
service::TeaclaveFrontendService::new(authentication_service_endpoint)?;
+    let enclave_attr = enclave_info
+        .get_enclave_attr("teaclave_management_service")
+        .expect("management");
+    let config = SgxTrustedTlsClientConfig::new()
+        .client_cert(&attestation.cert, &attestation.private_key)
+        .attestation_report_verifier(
+            vec![enclave_attr],
+            BUILD_CONFIG.as_root_ca_cert,
+            verifier::universal_quote_verifier,
+        );
+    let management_service_address = 
&args.config.internal_endpoints.management.advertised_address;
+    let management_service_endpoint = 
Endpoint::new(management_service_address).config(config);
+
+    let service = service::TeaclaveFrontendService::new(
+        authentication_service_endpoint,
+        management_service_endpoint,
+    )?;
     match server.start(service) {
         Ok(_) => (),
         Err(e) => {
diff --git a/services/frontend/enclave/src/service.rs 
b/services/frontend/enclave/src/service.rs
index a241894..3909f69 100644
--- a/services/frontend/enclave/src/service.rs
+++ b/services/frontend/enclave/src/service.rs
@@ -1,13 +1,15 @@
 use anyhow::Result;
 use std::prelude::v1::*;
 use std::sync::{Arc, SgxMutex as Mutex};
-use 
teaclave_proto::teaclave_authentication_service::TeaclaveAuthenticationInternalClient;
-use teaclave_proto::teaclave_authentication_service::UserAuthenticateRequest;
+use teaclave_proto::teaclave_authentication_service::{
+    TeaclaveAuthenticationInternalClient, UserAuthenticateRequest,
+};
 use teaclave_proto::teaclave_common::UserCredential;
 use teaclave_proto::teaclave_frontend_service::{
     RegisterInputFileRequest, RegisterInputFileResponse, 
RegisterOutputFileRequest,
     RegisterOutputFileResponse, TeaclaveFrontend,
 };
+use teaclave_proto::teaclave_management_service::TeaclaveManagementClient;
 use teaclave_rpc::endpoint::Endpoint;
 use teaclave_rpc::Request;
 use teaclave_service_enclave_utils::teaclave_service;
@@ -30,14 +32,27 @@ impl From<TeaclaveFrontendError> for 
TeaclaveServiceResponseError {
 #[derive(Clone)]
 pub(crate) struct TeaclaveFrontendService {
     authentication_client: Arc<Mutex<TeaclaveAuthenticationInternalClient>>,
+    management_client: Arc<Mutex<TeaclaveManagementClient>>,
 }
 
 impl TeaclaveFrontendService {
-    pub(crate) fn new(authentication_service_endpoint: Endpoint) -> 
Result<Self> {
-        let channel = authentication_service_endpoint.connect()?;
-        let client = TeaclaveAuthenticationInternalClient::new(channel)?;
+    pub(crate) fn new(
+        authentication_service_endpoint: Endpoint,
+        management_service_endpoint: Endpoint,
+    ) -> Result<Self> {
+        let authentication_channel = 
authentication_service_endpoint.connect()?;
+        let authentication_client = Arc::new(Mutex::new(
+            TeaclaveAuthenticationInternalClient::new(authentication_channel)?,
+        ));
+
+        let management_channel = management_service_endpoint.connect()?;
+        let management_client = 
Arc::new(Mutex::new(TeaclaveManagementClient::new(
+            management_channel,
+        )?));
+
         Ok(Self {
-            authentication_client: Arc::new(Mutex::new(client)),
+            authentication_client,
+            management_client,
         })
     }
 }
@@ -51,9 +66,12 @@ impl TeaclaveFrontend for TeaclaveFrontendService {
             Ok(true) => (),
             _ => return Err(TeaclaveFrontendError::AuthenticationError.into()),
         }
-        let response = RegisterInputFileResponse {
-            data_id: "".to_string(),
-        };
+        let response = self
+            .management_client
+            .clone()
+            .lock()
+            .unwrap()
+            .register_input_file(request.message)?;
         Ok(response)
     }
 
@@ -65,9 +83,12 @@ impl TeaclaveFrontend for TeaclaveFrontendService {
             Ok(true) => (),
             _ => return Err(TeaclaveFrontendError::AuthenticationError.into()),
         }
-        let response = RegisterOutputFileResponse {
-            data_id: "".to_string(),
-        };
+        let response = self
+            .management_client
+            .clone()
+            .lock()
+            .unwrap()
+            .register_output_file(request.message)?;
         Ok(response)
     }
 }
diff --git a/services/proto/proto_gen/main.rs b/services/proto/proto_gen/main.rs
index db73c28..d686980 100644
--- a/services/proto/proto_gen/main.rs
+++ b/services/proto/proto_gen/main.rs
@@ -47,16 +47,11 @@ struct Service {
 impl Service {
     fn from_prost(prost_service: &prost_build::Service) -> Self {
         fn convert_to_impl_type(current_package_name: &str, proto_type: &str) 
-> String {
-            if proto_type.starts_with("super::") {
-                format!(
-                    "crate::{}",
-                    proto_type
-                        .trim_start_matches("super::")
-                        .replacen("_proto", "", 1)
-                )
-            } else {
-                format!("crate::{}::{}", current_package_name, proto_type)
-            }
+            format!(
+                "crate::{}::{}",
+                current_package_name,
+                proto_type.rsplitn(2, 
"::").collect::<Vec<&str>>()[0].replacen("_proto", "", 1)
+            )
         }
         let mut methods = vec![];
         let package_name = prost_service.package.trim_end_matches("_proto");
diff --git a/services/proto/proto_gen/templates/proto.j2 
b/services/proto/proto_gen/templates/proto.j2
index d4b9383..979c872 100644
--- a/services/proto/proto_gen/templates/proto.j2
+++ b/services/proto/proto_gen/templates/proto.j2
@@ -77,15 +77,17 @@ impl {{ service.proto_name }}Client {
     pub fn {{ m.name }}<T: teaclave_rpc::IntoRequest<{{ service.proto_name 
}}Request>>(
         &mut self,
         request: T
-    ) -> teaclave_types::TeaclaveServiceResponseResult<{{ m.output_type }}> {
-        {%- if service.methods.len() > 1 %}
+    ) -> teaclave_types::TeaclaveServiceResponseResult<{{ m.impl_output_type 
}}> {
+        use core::convert::TryInto;
         use std::string::ToString;
-        {%- endif %}
+        {# {%- if service.methods.len() > 1 %} #}
+        {# use std::string::ToString; #}
+        {# {%- endif %} #}
         let mut request = request.into_request();
         request.metadata = self.metadata.clone();
 
         match self.channel.invoke(request) {
-            Ok({{ service.proto_name }}Response::{{ m.proto_name }}(response)) 
=> Ok(response),
+            Ok({{ service.proto_name }}Response::{{ m.proto_name }}(response)) 
=> Ok(response.try_into().map_err(|_| 
teaclave_types::TeaclaveServiceResponseError::InternalError("internal".to_string()))?),
             Err(e) => Err(e),
             {%- if service.methods.len() > 1 %}
             _ => 
Err(teaclave_types::TeaclaveServiceResponseError::InternalError("internal".to_string())),
diff --git a/services/proto/src/teaclave_authentication_service.rs 
b/services/proto/src/teaclave_authentication_service.rs
index 2c453b9..5ec220a 100644
--- a/services/proto/src/teaclave_authentication_service.rs
+++ b/services/proto/src/teaclave_authentication_service.rs
@@ -147,6 +147,16 @@ impl From<UserLoginRequest> for proto::UserLoginRequest {
     }
 }
 
+impl std::convert::TryFrom<proto::UserLoginResponse> for UserLoginResponse {
+    type Error = Error;
+
+    fn try_from(proto: proto::UserLoginResponse) -> Result<Self> {
+        let ret = Self { token: proto.token };
+
+        Ok(ret)
+    }
+}
+
 impl From<UserLoginResponse> for proto::UserLoginResponse {
     fn from(response: UserLoginResponse) -> Self {
         Self {
@@ -178,6 +188,18 @@ impl From<UserAuthenticateRequest> for 
proto::UserAuthenticateRequest {
     }
 }
 
+impl std::convert::TryFrom<proto::UserAuthenticateResponse> for 
UserAuthenticateResponse {
+    type Error = Error;
+
+    fn try_from(proto: proto::UserAuthenticateResponse) -> Result<Self> {
+        let ret = Self {
+            accept: proto.accept,
+        };
+
+        Ok(ret)
+    }
+}
+
 impl From<UserAuthenticateResponse> for proto::UserAuthenticateResponse {
     fn from(response: UserAuthenticateResponse) -> Self {
         Self {
diff --git a/services/proto/src/teaclave_execution_service.rs 
b/services/proto/src/teaclave_execution_service.rs
index ced78cc..3840fe5 100644
--- a/services/proto/src/teaclave_execution_service.rs
+++ b/services/proto/src/teaclave_execution_service.rs
@@ -58,6 +58,18 @@ impl 
std::convert::TryFrom<proto::StagedFunctionExecuteRequest> for StagedFuncti
     }
 }
 
+impl std::convert::TryFrom<proto::StagedFunctionExecuteResponse> for 
StagedFunctionExecuteResponse {
+    type Error = Error;
+
+    fn try_from(proto: proto::StagedFunctionExecuteResponse) -> Result<Self> {
+        let ret = Self {
+            summary: proto.summary,
+        };
+
+        Ok(ret)
+    }
+}
+
 // For client side
 impl std::convert::From<TeaclaveWorkerFileInfo> for proto::WorkerFileInfo {
     fn from(info: TeaclaveWorkerFileInfo) -> Self {
diff --git a/services/proto/src/teaclave_frontend_service.rs 
b/services/proto/src/teaclave_frontend_service.rs
index b0f1468..4e3454a 100644
--- a/services/proto/src/teaclave_frontend_service.rs
+++ b/services/proto/src/teaclave_frontend_service.rs
@@ -19,7 +19,7 @@ pub use proto::TeaclaveFrontendResponse;
 
 #[into_request(TeaclaveFrontendRequest::RegisterInputFile)]
 #[into_request(TeaclaveManagementRequest::RegisterInputFile)]
-#[derive(Debug)]
+#[derive(Debug, PartialEq)]
 pub struct RegisterInputFileRequest {
     pub url: Url,
     pub hash: String,
@@ -28,7 +28,7 @@ pub struct RegisterInputFileRequest {
 
 #[into_request(TeaclaveFrontendResponse::RegisterInputFile)]
 #[into_request(TeaclaveManagementResponse::RegisterInputFile)]
-#[derive(Debug)]
+#[derive(Debug, PartialEq)]
 pub struct RegisterInputFileResponse {
     pub data_id: String,
 }
diff --git a/services/proto/src/teaclave_management_service.rs 
b/services/proto/src/teaclave_management_service.rs
index a04622b..a0d313f 100644
--- a/services/proto/src/teaclave_management_service.rs
+++ b/services/proto/src/teaclave_management_service.rs
@@ -4,3 +4,20 @@ pub use proto::TeaclaveManagement;
 pub use proto::TeaclaveManagementClient;
 pub use proto::TeaclaveManagementRequest;
 pub use proto::TeaclaveManagementResponse;
+
+pub type RegisterInputFileRequest = 
crate::teaclave_frontend_service::RegisterInputFileRequest;
+pub type RegisterInputFileResponse = 
crate::teaclave_frontend_service::RegisterInputFileResponse;
+pub type RegisterOutputFileRequest = 
crate::teaclave_frontend_service::RegisterOutputFileRequest;
+pub type RegisterOutputFileResponse = 
crate::teaclave_frontend_service::RegisterOutputFileResponse;
+pub type GetOutputFileRequest = 
crate::teaclave_frontend_service::GetOutputFileRequest;
+pub type GetOutputFileResponse = 
crate::teaclave_frontend_service::GetOutputFileResponse;
+pub type GetFusionDataRequest = 
crate::teaclave_frontend_service::GetFusionDataRequest;
+pub type GetFusionDataResponse = 
crate::teaclave_frontend_service::GetFusionDataResponse;
+pub type RegisterFunctionRequest = 
crate::teaclave_frontend_service::RegisterFunctionRequest;
+pub type RegisterFunctionResponse = 
crate::teaclave_frontend_service::RegisterFunctionResponse;
+pub type GetFunctionRequest = 
crate::teaclave_frontend_service::GetFunctionRequest;
+pub type GetFunctionResponse = 
crate::teaclave_frontend_service::GetFunctionResponse;
+pub type CreateTaskRequest = 
crate::teaclave_frontend_service::CreateTaskRequest;
+pub type CreateTaskResponse = 
crate::teaclave_frontend_service::CreateTaskResponse;
+pub type GetTaskRequest = crate::teaclave_frontend_service::GetTaskRequest;
+pub type GetTaskResponse = crate::teaclave_frontend_service::GetTaskResponse;
diff --git a/tests/functional/enclave/src/teaclave_management_service.rs 
b/tests/functional/enclave/src/teaclave_management_service.rs
index 949b705..36b75d2 100644
--- a/tests/functional/enclave/src/teaclave_management_service.rs
+++ b/tests/functional/enclave/src/teaclave_management_service.rs
@@ -3,7 +3,7 @@ use std::prelude::v1::*;
 use teaclave_attestation::verifier;
 use teaclave_config::RuntimeConfig;
 use teaclave_config::BUILD_CONFIG;
-use teaclave_proto::teaclave_frontend_service::*;
+use teaclave_proto::teaclave_frontend_service::{DataOwnerList, FunctionInput, 
FunctionOutput};
 use teaclave_proto::teaclave_management_service::*;
 use teaclave_rpc::config::SgxTrustedTlsClientConfig;
 use teaclave_rpc::endpoint::Endpoint;
diff --git a/types/src/crypto.rs b/types/src/crypto.rs
index 04c7b84..466361a 100644
--- a/types/src/crypto.rs
+++ b/types/src/crypto.rs
@@ -10,7 +10,7 @@ use std::format;
 const AES_GCM_256_KEY_LENGTH: usize = 32;
 const AES_GCM_256_IV_LENGTH: usize = 12;
 
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
 pub struct AesGcm256CryptoInfo {
     pub key: [u8; AES_GCM_256_KEY_LENGTH],
     pub iv: [u8; AES_GCM_256_IV_LENGTH],
@@ -61,7 +61,7 @@ impl Default for AesGcm256CryptoInfo {
 const AES_GCM_128_KEY_LENGTH: usize = 16;
 const AES_GCM_128_IV_LENGTH: usize = 12;
 
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
 pub struct AesGcm128CryptoInfo {
     pub key: [u8; AES_GCM_128_KEY_LENGTH],
     pub iv: [u8; AES_GCM_128_IV_LENGTH],
@@ -113,7 +113,7 @@ impl Default for AesGcm128CryptoInfo {
 
 const TEACLAVE_FILE_ROOT_KEY_128_LENGTH: usize = 16;
 
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
 pub struct TeaclaveFileRootKey128 {
     pub key: [u8; TEACLAVE_FILE_ROOT_KEY_128_LENGTH],
 }
@@ -140,7 +140,7 @@ impl Default for TeaclaveFileRootKey128 {
     }
 }
 
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
 pub enum TeaclaveFileCryptoInfo {
     AesGcm128(AesGcm128CryptoInfo),
     AesGcm256(AesGcm256CryptoInfo),


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to