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/03/19 18:45:33 UTC
[incubator-teaclave] branch develop updated: [services] Move
handle_file_request to the ocall module
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 1e818bc [services] Move handle_file_request to the ocall module
1e818bc is described below
commit 1e818bc4649088af44770a3a5620f006c85dafa6
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Thu Mar 19 11:20:56 2020 -0700
[services] Move handle_file_request to the ocall module
---
services/execution/enclave/src/lib.rs | 3 +-
services/execution/enclave/src/ocall.rs | 72 +++++++++++++++++++++++++++++++
services/execution/enclave/src/service.rs | 35 ---------------
3 files changed, 74 insertions(+), 36 deletions(-)
diff --git a/services/execution/enclave/src/lib.rs b/services/execution/enclave/src/lib.rs
index f4fcbfb..49c50f9 100644
--- a/services/execution/enclave/src/lib.rs
+++ b/services/execution/enclave/src/lib.rs
@@ -35,6 +35,7 @@ use teaclave_service_enclave_utils::create_trusted_scheduler_endpoint;
use teaclave_service_enclave_utils::ServiceEnclave;
use teaclave_types::{EnclaveInfo, TeeServiceError, TeeServiceResult};
+mod ocall;
mod service;
const AS_ROOT_CA_CERT: &[u8] = BUILD_CONFIG.as_root_ca_cert;
@@ -101,7 +102,7 @@ pub mod tests {
pub fn run_tests() -> bool {
run_tests!(
- service::tests::test_ocall,
+ ocall::tests::test_handle_file_request,
service::tests::test_invoke_echo_function,
service::tests::test_invoke_gbdt_training,
service::tests::test_invoke_gbdt_prediction
diff --git a/services/execution/enclave/src/ocall.rs b/services/execution/enclave/src/ocall.rs
new file mode 100644
index 0000000..ffbc774
--- /dev/null
+++ b/services/execution/enclave/src/ocall.rs
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use anyhow::ensure;
+use anyhow::Result;
+use sgx_types::sgx_status_t;
+use std::prelude::v1::*;
+use teaclave_types::FileAgentRequest;
+
+extern "C" {
+ fn ocall_handle_file_request(
+ p_retval: *mut u32,
+ in_buf: *const u8,
+ in_len: u32,
+ ) -> sgx_status_t;
+}
+
+#[allow(dead_code)]
+pub(crate) fn handle_file_request(request: FileAgentRequest) -> Result<()> {
+ let mut rt: u32 = 2;
+ let bytes = serde_json::to_vec(&request)?;
+ let buf_len = bytes.len();
+ let res =
+ unsafe { ocall_handle_file_request(&mut rt as _, bytes.as_ptr() as _, buf_len as u32) };
+
+ ensure!(
+ res == sgx_status_t::SGX_SUCCESS,
+ "ocall sgx_error = {:?}",
+ res
+ );
+ ensure!(rt == 0, "ocall error = {:?}", rt);
+ Ok(())
+}
+
+#[cfg(feature = "enclave_unit_test")]
+pub mod tests {
+ use super::*;
+ use std::path::PathBuf;
+ use std::vec;
+ use teaclave_types::*;
+ use url::Url;
+
+ pub fn test_handle_file_request() {
+ let test_install_dir = env!("TEACLAVE_TEST_INSTALL_DIR");
+ let fixture_dir = format!(
+ "file:///{}/fixtures/functions/mesapy/input.txt",
+ test_install_dir
+ );
+ let url = Url::parse(&fixture_dir).unwrap();
+ let dest = PathBuf::from("/tmp/execution_input_test.txt");
+
+ let info = HandleFileInfo::new(&dest, &url);
+ let request = FileAgentRequest::new(HandleFileCommand::Download, vec![info]);
+
+ handle_file_request(request).unwrap();
+ std::untrusted::fs::remove_file(&dest).unwrap();
+ }
+}
diff --git a/services/execution/enclave/src/service.rs b/services/execution/enclave/src/service.rs
index 24d64c4..48430f4 100644
--- a/services/execution/enclave/src/service.rs
+++ b/services/execution/enclave/src/service.rs
@@ -101,48 +101,13 @@ mod test_mode {
#[cfg(feature = "enclave_unit_test")]
pub mod tests {
use super::*;
- use sgx_types::sgx_status_t::SGX_SUCCESS;
- use sgx_types::*;
use std::collections::HashMap;
use std::convert::TryInto;
use std::format;
- use std::path::PathBuf;
use std::vec;
use teaclave_types::*;
use url::Url;
use uuid::Uuid;
- extern "C" {
- fn ocall_handle_file_request(
- p_retval: *mut u32,
- in_buf: *const u8,
- in_len: u32,
- ) -> sgx_status_t;
- }
-
- fn handle_file_request(bytes: Vec<u8>) -> anyhow::Result<()> {
- let mut rt: u32 = 2;
- let buf_len = bytes.len();
- let res =
- unsafe { ocall_handle_file_request(&mut rt as _, bytes.as_ptr() as _, buf_len as u32) };
-
- anyhow::ensure!(res == SGX_SUCCESS, "ocall sgx_error = {:?}", res);
- anyhow::ensure!(rt == 0, "ocall error = {:?}", rt);
- Ok(())
- }
-
- pub fn test_ocall() {
- let s = "http://localhost:6789/fixtures/functions/mesapy/input.txt";
- let url = Url::parse(s).unwrap();
- let dest = PathBuf::from("/tmp/execution_input_test.txt");
-
- let info = HandleFileInfo::new(&dest, &url);
- let req = FileAgentRequest::new(HandleFileCommand::Download, vec![info]);
-
- let bytes = serde_json::to_vec(&req).unwrap();
-
- handle_file_request(bytes).unwrap();
- std::untrusted::fs::remove_file(&dest).unwrap();
- }
pub fn test_invoke_gbdt_training() {
let function_args = TeaclaveFunctionArguments::new(&hashmap!(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org