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 093ee1687b276f5ca48cd92374d1c276328f2b08 Author: Mingshen Sun <[email protected]> AuthorDate: Thu Jan 30 20:53:28 2020 -0800 [proto] Polish proto implementations --- services/frontend/enclave/src/service.rs | 4 +-- services/proto/Cargo.toml | 1 + .../src/proto/teaclave_frontend_service.proto | 6 ++-- .../proto/src/teaclave_authentication_service.rs | 13 ++++---- services/proto/src/teaclave_common.rs | 3 +- services/proto/src/teaclave_database_service.rs | 21 +++++++------ services/proto/src/teaclave_frontend_service.rs | 35 +++++++--------------- tests/functional_tests/enclave/Cargo.toml | 1 + .../enclave/src/teaclave_frontend_service.rs | 10 ++----- 9 files changed, 37 insertions(+), 57 deletions(-) diff --git a/services/frontend/enclave/src/service.rs b/services/frontend/enclave/src/service.rs index b5fb700..86d9ba1 100644 --- a/services/frontend/enclave/src/service.rs +++ b/services/frontend/enclave/src/service.rs @@ -50,7 +50,7 @@ impl TeaclaveFrontend for TeaclaveFrontendService { request: Request<RegisterInputFileRequest>, ) -> TeaclaveServiceResponseResult<RegisterInputFileResponse> { match self.authenticate(&request) { - Ok(r) if r => (), + Ok(true) => (), _ => return Err(TeaclaveFrontendError::AuthenticationError.into()), } let response = RegisterInputFileResponse { @@ -64,7 +64,7 @@ impl TeaclaveFrontend for TeaclaveFrontendService { request: Request<RegisterOutputFileRequest>, ) -> TeaclaveServiceResponseResult<RegisterOutputFileResponse> { match self.authenticate(&request) { - Ok(r) if r => (), + Ok(true) => (), _ => return Err(TeaclaveFrontendError::AuthenticationError.into()), } let response = RegisterOutputFileResponse { diff --git a/services/proto/Cargo.toml b/services/proto/Cargo.toml index fa3484b..b1d898d 100644 --- a/services/proto/Cargo.toml +++ b/services/proto/Cargo.toml @@ -22,6 +22,7 @@ prost = { version = "0.6.0" } rand = { version = "0.7.0" } serde = { version = "1.0.39", features = ["derive"] } serde_json = { version = "1.0.39" } +url = { version = "2.1.1" } sgx_cov = { version = "1.1.0", optional = true } sgx_tstd = { version = "1.1.0", features = ["net", "backtrace"], optional = true } diff --git a/services/proto/src/proto/teaclave_frontend_service.proto b/services/proto/src/proto/teaclave_frontend_service.proto index a80daa9..d1b9c39 100644 --- a/services/proto/src/proto/teaclave_frontend_service.proto +++ b/services/proto/src/proto/teaclave_frontend_service.proto @@ -5,10 +5,9 @@ package teaclave_frontend_service_proto; import "teaclave_common.proto"; message RegisterInputFileRequest { - string uri = 1; + string url = 1; string hash = 2; teaclave_common_proto.FileCryptoInfo crypto_info = 3; - teaclave_common_proto.UserCredential credential = 99; } message RegisterInputFileResponse { @@ -16,9 +15,8 @@ message RegisterInputFileResponse { } message RegisterOutputFileRequest { - string uri = 1; + string url = 1; teaclave_common_proto.FileCryptoInfo crypto_info = 2; - teaclave_common_proto.UserCredential credential = 99; } message RegisterOutputFileResponse { diff --git a/services/proto/src/teaclave_authentication_service.rs b/services/proto/src/teaclave_authentication_service.rs index 7409c98..dd38701 100644 --- a/services/proto/src/teaclave_authentication_service.rs +++ b/services/proto/src/teaclave_authentication_service.rs @@ -1,7 +1,6 @@ use anyhow::anyhow; use anyhow::{Error, Result}; use core::convert::TryInto; -use serde::{Deserialize, Serialize}; use crate::teaclave_authentication_service_proto as proto; use crate::teaclave_common; @@ -14,32 +13,32 @@ pub use proto::TeaclaveAuthenticationInternalClient; pub use proto::TeaclaveAuthenticationInternalRequest; pub use proto::TeaclaveAuthenticationInternalResponse; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct UserRegisterRequest { pub id: std::string::String, pub password: std::string::String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct UserRegisterResponse {} -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct UserLoginRequest { pub id: std::string::String, pub password: std::string::String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct UserLoginResponse { pub token: std::string::String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct UserAuthenticateRequest { pub credential: teaclave_common::UserCredential, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct UserAuthenticateResponse { pub accept: bool, } diff --git a/services/proto/src/teaclave_common.rs b/services/proto/src/teaclave_common.rs index cb28604..fe98ec5 100644 --- a/services/proto/src/teaclave_common.rs +++ b/services/proto/src/teaclave_common.rs @@ -2,7 +2,6 @@ use std::prelude::v1::*; use anyhow::{bail, ensure, Error, Result}; -use serde::{Deserialize, Serialize}; use std::format; use teaclave_types::{ AesGcm128CryptoInfo, AesGcm256CryptoInfo, TeaclaveFileCryptoInfo, TeaclaveFileRootKey128, @@ -10,7 +9,7 @@ use teaclave_types::{ use crate::teaclave_common_proto as proto; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct UserCredential { pub id: std::string::String, pub token: std::string::String, diff --git a/services/proto/src/teaclave_database_service.rs b/services/proto/src/teaclave_database_service.rs index 9844b0c..db17da5 100644 --- a/services/proto/src/teaclave_database_service.rs +++ b/services/proto/src/teaclave_database_service.rs @@ -1,5 +1,4 @@ use anyhow::{Error, Result}; -use serde::{Deserialize, Serialize}; use std::prelude::v1::*; use crate::teaclave_database_service_proto as proto; @@ -8,48 +7,48 @@ pub use proto::TeaclaveDatabaseClient; pub use proto::TeaclaveDatabaseRequest; pub use proto::TeaclaveDatabaseResponse; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct GetRequest { pub key: Vec<u8>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct GetResponse { pub value: Vec<u8>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct PutRequest { pub key: Vec<u8>, pub value: Vec<u8>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct PutResponse; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct DeleteRequest { pub key: Vec<u8>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct DeleteResponse; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct EnqueueRequest { pub key: Vec<u8>, pub value: Vec<u8>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct EnqueueResponse; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct DequeueRequest { pub key: Vec<u8>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct DequeueResponse { pub value: Vec<u8>, } diff --git a/services/proto/src/teaclave_frontend_service.rs b/services/proto/src/teaclave_frontend_service.rs index 1015392..0a0b40b 100644 --- a/services/proto/src/teaclave_frontend_service.rs +++ b/services/proto/src/teaclave_frontend_service.rs @@ -1,37 +1,34 @@ -use crate::teaclave_common; use crate::teaclave_frontend_service_proto as proto; use anyhow::anyhow; use anyhow::{Error, Result}; use core::convert::TryInto; -use serde::{Deserialize, Serialize}; use teaclave_types::TeaclaveFileCryptoInfo; +use url::Url; pub use proto::TeaclaveFrontend; pub use proto::TeaclaveFrontendClient; pub use proto::TeaclaveFrontendRequest; pub use proto::TeaclaveFrontendResponse; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct RegisterInputFileRequest { - pub uri: std::string::String, + pub url: Url, pub hash: std::string::String, pub crypto_info: TeaclaveFileCryptoInfo, - pub credential: teaclave_common::UserCredential, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct RegisterInputFileResponse { pub data_id: std::string::String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct RegisterOutputFileRequest { - pub uri: std::string::String, + pub url: Url, pub crypto_info: TeaclaveFileCryptoInfo, - pub credential: teaclave_common::UserCredential, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug)] pub struct RegisterOutputFileResponse { pub data_id: std::string::String, } @@ -41,16 +38,12 @@ impl std::convert::TryFrom<proto::RegisterInputFileRequest> for RegisterInputFil fn try_from(proto: proto::RegisterInputFileRequest) -> Result<Self> { let ret = Self { - uri: proto.uri, + url: Url::parse(&proto.url)?, hash: proto.hash, crypto_info: proto .crypto_info .ok_or_else(|| anyhow!("missing crypto_info"))? .try_into()?, - credential: proto - .credential - .ok_or_else(|| anyhow!("missing credential"))? - .try_into()?, }; Ok(ret) @@ -60,10 +53,9 @@ impl std::convert::TryFrom<proto::RegisterInputFileRequest> for RegisterInputFil impl From<RegisterInputFileRequest> for proto::RegisterInputFileRequest { fn from(request: RegisterInputFileRequest) -> Self { Self { - uri: request.uri, + url: request.url.into_string(), hash: request.hash, crypto_info: Some(request.crypto_info.into()), - credential: Some(request.credential.into()), } } } @@ -91,15 +83,11 @@ impl std::convert::TryFrom<proto::RegisterOutputFileRequest> for RegisterOutputF fn try_from(proto: proto::RegisterOutputFileRequest) -> Result<Self> { let ret = Self { - uri: proto.uri, + url: Url::parse(&proto.url)?, crypto_info: proto .crypto_info .ok_or_else(|| anyhow!("missing crypto_info"))? .try_into()?, - credential: proto - .credential - .ok_or_else(|| anyhow!("missing credential"))? - .try_into()?, }; Ok(ret) @@ -109,9 +97,8 @@ impl std::convert::TryFrom<proto::RegisterOutputFileRequest> for RegisterOutputF impl From<RegisterOutputFileRequest> for proto::RegisterOutputFileRequest { fn from(request: RegisterOutputFileRequest) -> Self { Self { - uri: request.uri, + url: request.url.into_string(), crypto_info: Some(request.crypto_info.into()), - credential: Some(request.credential.into()), } } } diff --git a/tests/functional_tests/enclave/Cargo.toml b/tests/functional_tests/enclave/Cargo.toml index 1382713..d7cb5c5 100644 --- a/tests/functional_tests/enclave/Cargo.toml +++ b/tests/functional_tests/enclave/Cargo.toml @@ -31,6 +31,7 @@ anyhow = { version = "1.0.26" } serde = { version = "1.0.92" } serde_json = { version = "1.0.39" } thiserror = { version = "1.0.9" } +url = { version = "2.1.1" } teaclave_attestation = { path = "../../../attestation" } teaclave_config = { path = "../../../config" } diff --git a/tests/functional_tests/enclave/src/teaclave_frontend_service.rs b/tests/functional_tests/enclave/src/teaclave_frontend_service.rs index eb6ba4c..516c488 100644 --- a/tests/functional_tests/enclave/src/teaclave_frontend_service.rs +++ b/tests/functional_tests/enclave/src/teaclave_frontend_service.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; use std::prelude::v1::*; -use teaclave_proto::teaclave_common::*; use teaclave_proto::teaclave_frontend_service::*; use teaclave_rpc::endpoint::Endpoint; use teaclave_types::*; +use url::Url; pub fn run_tests() -> bool { use teaclave_test_utils::*; @@ -13,16 +13,12 @@ pub fn run_tests() -> bool { fn test_register_input_file_authentication_error() { let request = RegisterInputFileRequest { - uri: "".to_string(), - hash: "".to_string(), + url: Url::parse("s3://s3.us-west-2.amazonaws.com/mybucket/puppy.jpg.enc?key-id=deadbeefdeadbeef&key=deadbeefdeadbeef").unwrap(), + hash: "deadbeefdeadbeef".to_string(), crypto_info: TeaclaveFileCryptoInfo::AesGcm128(AesGcm128CryptoInfo { key: [0x90u8; 16], iv: [0x89u8; 12], }), - credential: UserCredential { - id: "".to_string(), - token: "".to_string(), - }, }; let mut metadata = HashMap::new(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
