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/02/05 23:52:53 UTC

[incubator-teaclave] branch develop updated (61f41db -> c66d56b)

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

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


    from 61f41db  [protected_fs_rs] Make protected_fs compatible with sgx 2.8. (#218)
     new d7f26d5  [proto] Add new/constructor for small request/response structure
     new c66d56b  [rpc] Default max frame length is 8MB

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 rpc/src/protocol.rs                                | 15 ++++-
 rpc/src/transport.rs                               |  2 +-
 .../proto/src/teaclave_access_control_service.rs   | 68 +++++++++++++++++++---
 services/proto/src/teaclave_storage_service.rs     | 38 +++++-------
 .../enclave/src/teaclave_access_control_service.rs | 54 +++++------------
 5 files changed, 104 insertions(+), 73 deletions(-)


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


[incubator-teaclave] 01/02: [proto] Add new/constructor for small request/response structure

Posted by ms...@apache.org.
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 d7f26d5bec46c8e3e630eaf927792e7cd035553a
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Tue Feb 4 19:51:49 2020 -0800

    [proto] Add new/constructor for small request/response structure
---
 .../proto/src/teaclave_access_control_service.rs   | 68 +++++++++++++++++++---
 services/proto/src/teaclave_storage_service.rs     | 38 +++++-------
 .../enclave/src/teaclave_access_control_service.rs | 54 +++++------------
 3 files changed, 89 insertions(+), 71 deletions(-)

diff --git a/services/proto/src/teaclave_access_control_service.rs b/services/proto/src/teaclave_access_control_service.rs
index 2a51071..4b71116 100644
--- a/services/proto/src/teaclave_access_control_service.rs
+++ b/services/proto/src/teaclave_access_control_service.rs
@@ -1,6 +1,5 @@
 use crate::teaclave_access_control_service_proto as proto;
 use anyhow::{Error, Result};
-use serde::{Deserialize, Serialize};
 use std::prelude::v1::*;
 
 pub use proto::TeaclaveAccessControl;
@@ -8,40 +7,85 @@ pub use proto::TeaclaveAccessControlClient;
 pub use proto::TeaclaveAccessControlRequest;
 pub use proto::TeaclaveAccessControlResponse;
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug)]
 pub struct AuthorizeDataRequest {
     pub subject_user_id: String,
     pub object_data_id: String,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+impl AuthorizeDataRequest {
+    pub fn new(subject_user_id: impl Into<String>, object_data_id: impl Into<String>) -> Self {
+        Self {
+            subject_user_id: subject_user_id.into(),
+            object_data_id: object_data_id.into(),
+        }
+    }
+}
+
+#[derive(Debug)]
 pub struct AuthorizeDataResponse {
     pub accept: bool,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+impl AuthorizeDataResponse {
+    pub fn new(accept: bool) -> Self {
+        Self { accept }
+    }
+}
+
+#[derive(Debug)]
 pub struct AuthorizeFunctionRequest {
     pub subject_user_id: String,
     pub object_function_id: String,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+impl AuthorizeFunctionRequest {
+    pub fn new(subject_user_id: impl Into<String>, object_function_id: impl Into<String>) -> Self {
+        Self {
+            subject_user_id: subject_user_id.into(),
+            object_function_id: object_function_id.into(),
+        }
+    }
+}
+
+#[derive(Debug)]
 pub struct AuthorizeFunctionResponse {
     pub accept: bool,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+impl AuthorizeFunctionResponse {
+    pub fn new(accept: bool) -> Self {
+        Self { accept }
+    }
+}
+
+#[derive(Debug)]
 pub struct AuthorizeTaskRequest {
     pub subject_user_id: String,
     pub object_task_id: String,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+impl AuthorizeTaskRequest {
+    pub fn new(subject_user_id: impl Into<String>, object_task_id: impl Into<String>) -> Self {
+        Self {
+            subject_user_id: subject_user_id.into(),
+            object_task_id: object_task_id.into(),
+        }
+    }
+}
+
+#[derive(Debug)]
 pub struct AuthorizeTaskResponse {
     pub accept: bool,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+impl AuthorizeTaskResponse {
+    pub fn new(accept: bool) -> Self {
+        Self { accept }
+    }
+}
+
+#[derive(Debug)]
 pub struct AuthorizeStagedTaskRequest {
     pub subject_task_id: String,
     pub object_function_id: String,
@@ -49,11 +93,17 @@ pub struct AuthorizeStagedTaskRequest {
     pub object_output_data_id_list: Vec<String>,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug)]
 pub struct AuthorizeStagedTaskResponse {
     pub accept: bool,
 }
 
+impl AuthorizeStagedTaskResponse {
+    pub fn new(accept: bool) -> Self {
+        Self { accept }
+    }
+}
+
 impl std::convert::TryFrom<proto::AuthorizeDataRequest> for AuthorizeDataRequest {
     type Error = Error;
 
diff --git a/services/proto/src/teaclave_storage_service.rs b/services/proto/src/teaclave_storage_service.rs
index 71956f6..6e1b200 100644
--- a/services/proto/src/teaclave_storage_service.rs
+++ b/services/proto/src/teaclave_storage_service.rs
@@ -13,10 +13,8 @@ pub struct GetRequest {
 }
 
 impl GetRequest {
-    pub fn new(key: impl AsRef<[u8]>) -> Self {
-        Self {
-            key: key.as_ref().into(),
-        }
+    pub fn new(key: impl Into<Vec<u8>>) -> Self {
+        Self { key: key.into() }
     }
 }
 
@@ -26,9 +24,9 @@ pub struct GetResponse {
 }
 
 impl GetResponse {
-    pub fn new(value: impl AsRef<[u8]>) -> Self {
+    pub fn new(value: impl Into<Vec<u8>>) -> Self {
         Self {
-            value: value.as_ref().into(),
+            value: value.into(),
         }
     }
 }
@@ -40,10 +38,10 @@ pub struct PutRequest {
 }
 
 impl PutRequest {
-    pub fn new(key: impl AsRef<[u8]>, value: impl AsRef<[u8]>) -> Self {
+    pub fn new(key: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self {
         Self {
-            key: key.as_ref().into(),
-            value: value.as_ref().into(),
+            key: key.into(),
+            value: value.into(),
         }
     }
 }
@@ -57,10 +55,8 @@ pub struct DeleteRequest {
 }
 
 impl DeleteRequest {
-    pub fn new(key: impl AsRef<[u8]>) -> Self {
-        Self {
-            key: key.as_ref().into(),
-        }
+    pub fn new(key: impl Into<Vec<u8>>) -> Self {
+        Self { key: key.into() }
     }
 }
 
@@ -74,10 +70,10 @@ pub struct EnqueueRequest {
 }
 
 impl EnqueueRequest {
-    pub fn new(key: impl AsRef<[u8]>, value: impl AsRef<[u8]>) -> Self {
+    pub fn new(key: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self {
         Self {
-            key: key.as_ref().into(),
-            value: value.as_ref().into(),
+            key: key.into(),
+            value: value.into(),
         }
     }
 }
@@ -91,10 +87,8 @@ pub struct DequeueRequest {
 }
 
 impl DequeueRequest {
-    pub fn new(key: impl AsRef<[u8]>) -> Self {
-        Self {
-            key: key.as_ref().into(),
-        }
+    pub fn new(key: impl Into<Vec<u8>>) -> Self {
+        Self { key: key.into() }
     }
 }
 
@@ -104,9 +98,9 @@ pub struct DequeueResponse {
 }
 
 impl DequeueResponse {
-    pub fn new(value: impl AsRef<[u8]>) -> Self {
+    pub fn new(value: impl Into<Vec<u8>>) -> Self {
         Self {
-            value: value.as_ref().into(),
+            value: value.into(),
         }
     }
 }
diff --git a/tests/functional_tests/enclave/src/teaclave_access_control_service.rs b/tests/functional_tests/enclave/src/teaclave_access_control_service.rs
index 32ebb43..c8ddfcd 100644
--- a/tests/functional_tests/enclave/src/teaclave_access_control_service.rs
+++ b/tests/functional_tests/enclave/src/teaclave_access_control_service.rs
@@ -51,10 +51,7 @@ fn get_client() -> TeaclaveAccessControlClient {
 fn test_authorize_data_success() {
     let mut client = get_client();
 
-    let request = AuthorizeDataRequest {
-        subject_user_id: "mock_user_a".to_string(),
-        object_data_id: "mock_data".to_string(),
-    };
+    let request = AuthorizeDataRequest::new("mock_user_a", "mock_data");
     let response_result = client.authorize_data(request);
     assert!(response_result.is_ok());
     assert!(response_result.unwrap().accept);
@@ -63,18 +60,12 @@ fn test_authorize_data_success() {
 fn test_authorize_data_fail() {
     let mut client = get_client();
 
-    let request = AuthorizeDataRequest {
-        subject_user_id: "mock_user_d".to_string(),
-        object_data_id: "mock_data".to_string(),
-    };
+    let request = AuthorizeDataRequest::new("mock_user_d", "mock_data");
     let response_result = client.authorize_data(request);
     assert!(response_result.is_ok());
     assert!(!response_result.unwrap().accept);
 
-    let request = AuthorizeDataRequest {
-        subject_user_id: "mock_user_a".to_string(),
-        object_data_id: "mock_data_b".to_string(),
-    };
+    let request = AuthorizeDataRequest::new("mock_user_a", "mock_data_b");
     let response_result = client.authorize_data(request);
     assert!(response_result.is_ok());
     assert!(!response_result.unwrap().accept);
@@ -83,26 +74,20 @@ fn test_authorize_data_fail() {
 fn test_authorize_function_success() {
     let mut client = get_client();
 
-    let request = AuthorizeFunctionRequest {
-        subject_user_id: "mock_public_function_owner".to_string(),
-        object_function_id: "mock_public_function".to_string(),
-    };
+    let request =
+        AuthorizeFunctionRequest::new("mock_public_function_owner", "mock_public_function");
     let response_result = client.authorize_function(request);
     assert!(response_result.is_ok());
     assert!(response_result.unwrap().accept);
 
-    let request = AuthorizeFunctionRequest {
-        subject_user_id: "mock_private_function_owner".to_string(),
-        object_function_id: "mock_private_function".to_string(),
-    };
+    let request =
+        AuthorizeFunctionRequest::new("mock_private_function_owner", "mock_private_function");
     let response_result = client.authorize_function(request);
     assert!(response_result.is_ok());
     assert!(response_result.unwrap().accept);
 
-    let request = AuthorizeFunctionRequest {
-        subject_user_id: "mock_private_function_owner".to_string(),
-        object_function_id: "mock_public_function".to_string(),
-    };
+    let request =
+        AuthorizeFunctionRequest::new("mock_private_function_owner", "mock_public_function");
     let response_result = client.authorize_function(request);
     assert!(response_result.is_ok());
     assert!(response_result.unwrap().accept);
@@ -110,10 +95,8 @@ fn test_authorize_function_success() {
 
 fn test_authorize_function_fail() {
     let mut client = get_client();
-    let request = AuthorizeFunctionRequest {
-        subject_user_id: "mock_public_function_owner".to_string(),
-        object_function_id: "mock_private_function".to_string(),
-    };
+    let request =
+        AuthorizeFunctionRequest::new("mock_public_function_owner", "mock_private_function");
     let response_result = client.authorize_function(request);
     assert!(response_result.is_ok());
     assert!(!response_result.unwrap().accept);
@@ -121,18 +104,12 @@ fn test_authorize_function_fail() {
 
 fn test_authorize_task_success() {
     let mut client = get_client();
-    let request = AuthorizeTaskRequest {
-        subject_user_id: "mock_participant_a".to_string(),
-        object_task_id: "mock_task".to_string(),
-    };
+    let request = AuthorizeTaskRequest::new("mock_participant_a", "mock_task");
     let response_result = client.authorize_task(request);
     assert!(response_result.is_ok());
     assert!(response_result.unwrap().accept);
 
-    let request = AuthorizeTaskRequest {
-        subject_user_id: "mock_participant_b".to_string(),
-        object_task_id: "mock_task".to_string(),
-    };
+    let request = AuthorizeTaskRequest::new("mock_participant_b", "mock_task");
     let response_result = client.authorize_task(request);
     assert!(response_result.is_ok());
     assert!(response_result.unwrap().accept);
@@ -140,10 +117,7 @@ fn test_authorize_task_success() {
 
 fn test_authorize_task_fail() {
     let mut client = get_client();
-    let request = AuthorizeTaskRequest {
-        subject_user_id: "mock_participant_c".to_string(),
-        object_task_id: "mock_task".to_string(),
-    };
+    let request = AuthorizeTaskRequest::new("mock_participant_c", "mock_task");
     let response_result = client.authorize_task(request);
     assert!(response_result.is_ok());
     assert!(!response_result.unwrap().accept);


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


[incubator-teaclave] 02/02: [rpc] Default max frame length is 8MB

Posted by ms...@apache.org.
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 c66d56bcb8ae2f2a18bddeac5b67304ca8a4bf46
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Wed Feb 5 15:38:32 2020 -0800

    [rpc] Default max frame length is 8MB
---
 rpc/src/protocol.rs  | 15 ++++++++++++++-
 rpc/src/transport.rs |  2 +-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/rpc/src/protocol.rs b/rpc/src/protocol.rs
index a4a51c8..0230c79 100644
--- a/rpc/src/protocol.rs
+++ b/rpc/src/protocol.rs
@@ -13,6 +13,8 @@ pub enum ProtocolError {
     IoError(#[from] io::Error),
     #[error("SerdeError")]
     SerdeError(#[from] serde_json::error::Error),
+    #[error(transparent)]
+    Other(#[from] anyhow::Error),
 }
 
 pub(crate) struct JsonProtocol<'a, T>
@@ -20,6 +22,7 @@ where
     T: io::Read + io::Write,
 {
     pub transport: &'a mut T,
+    max_frame_len: u64,
 }
 
 impl<'a, T> JsonProtocol<'a, T>
@@ -27,7 +30,11 @@ where
     T: io::Read + io::Write,
 {
     pub fn new(transport: &'a mut T) -> JsonProtocol<'a, T> {
-        Self { transport }
+        Self {
+            transport,
+            // Default max frame length is 8MB
+            max_frame_len: 8 * 1_024 * 1_024,
+        }
     }
 
     pub fn read_message<V>(&mut self) -> std::result::Result<V, ProtocolError>
@@ -39,6 +46,12 @@ where
         self.transport.read_exact(&mut header)?;
         let buf_len = u64::from_be(unsafe { transmute::<[u8; 8], u64>(header) });
 
+        if buf_len > self.max_frame_len {
+            return Err(ProtocolError::Other(anyhow::anyhow!(
+                "Exceed max frame length"
+            )));
+        }
+
         let mut recv_buf: Vec<u8> = vec![0u8; buf_len as usize];
         self.transport.read_exact(&mut recv_buf)?;
 
diff --git a/rpc/src/transport.rs b/rpc/src/transport.rs
index ab75160..7c967bd 100644
--- a/rpc/src/transport.rs
+++ b/rpc/src/transport.rs
@@ -89,7 +89,7 @@ where
                         debug!("Connection disconnected.");
                         return Ok(());
                     }
-                    protocol::ProtocolError::SerdeError(_) => {
+                    _ => {
                         debug!("{:?}", e);
                         let response: JsonProtocolResult<U, TeaclaveServiceResponseError> =
                             Err(TeaclaveServiceResponseError::RequestError(


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