You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesatee.apache.org by di...@apache.org on 2019/11/22 02:40:04 UTC
[incubator-mesatee-sgx] branch v1.1.0-beta updated: Fix
prost-protobuf, add sgxcounter/time
This is an automated email from the ASF dual-hosted git repository.
dingyu pushed a commit to branch v1.1.0-beta
in repository https://gitbox.apache.org/repos/asf/incubator-mesatee-sgx.git
The following commit(s) were added to refs/heads/v1.1.0-beta by this push:
new 1e3db3a Fix prost-protobuf, add sgxcounter/time
1e3db3a is described below
commit 1e3db3a57433285862eb587f0c8b2a642df5b3b5
Author: Yu Ding <di...@gmail.com>
AuthorDate: Thu Nov 21 18:39:54 2019 -0800
Fix prost-protobuf, add sgxcounter/time
---
samplecode/prost-protobuf/app/Cargo.toml | 5 +-
samplecode/prost-protobuf/app/build.rs | 54 ++++++++++++++++++
samplecode/prost-protobuf/app/src/main.rs | 82 +++------------------------
samplecode/prost-protobuf/enclave/Cargo.toml | 27 +++++++++
samplecode/prost-protobuf/enclave/Enclave.edl | 42 ++++++++++++++
samplecode/prost-protobuf/enclave/Xargo.toml | 39 +++++++------
samplecode/sgxcounter/Readme.md | 6 ++
samplecode/sgxtime/Readme.md | 6 ++
8 files changed, 170 insertions(+), 91 deletions(-)
diff --git a/samplecode/prost-protobuf/app/Cargo.toml b/samplecode/prost-protobuf/app/Cargo.toml
index 357ccb6..905fe20 100644
--- a/samplecode/prost-protobuf/app/Cargo.toml
+++ b/samplecode/prost-protobuf/app/Cargo.toml
@@ -7,10 +7,13 @@ build = "build.rs"
[dependencies]
sgx_types = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git" }
sgx_urts = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git" }
-dirs = "1.0.2"
prost = "*"
prost-types = "*"
bytes = "*"
+[patch.'https://github.com/baidu/rust-sgx-sdk.git']
+sgx_types = { path = "../../../sgx_types" }
+sgx_urts = { path = "../../../sgx_urts" }
+
[build-dependencies]
prost-build = "*"
diff --git a/samplecode/prost-protobuf/app/build.rs b/samplecode/prost-protobuf/app/build.rs
new file mode 100644
index 0000000..6d04c68
--- /dev/null
+++ b/samplecode/prost-protobuf/app/build.rs
@@ -0,0 +1,54 @@
+// Copyright (C) 2017-2018 Baidu, Inc. All Rights Reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in
+// the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Baidu, Inc., nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+use std::env;
+use std::path::PathBuf;
+
+fn main () {
+
+ let sdk_dir = env::var("SGX_SDK")
+ .unwrap_or_else(|_| "/opt/intel/sgxsdk".to_string());
+ let is_sim = env::var("SGX_MODE")
+ .unwrap_or_else(|_| "HW".to_string());
+
+ println!("cargo:rustc-link-search=native=../lib");
+ println!("cargo:rustc-link-lib=static=Enclave_u");
+
+ println!("cargo:rustc-link-search=native={}/lib64", sdk_dir);
+ match is_sim.as_ref() {
+ "SW" => println!("cargo:rustc-link-lib=dylib=sgx_urts_sim"),
+ "HW" => println!("cargo:rustc-link-lib=dylib=sgx_urts"),
+ _ => println!("cargo:rustc-link-lib=dylib=sgx_urts"), // Treat undefined as HW
+ }
+
+ let src = PathBuf::from("..");
+ let includes = &[src.clone()];
+ let mut config = prost_build::Config::new();
+
+ config.compile_protos(&[src.join("person.proto")], includes).unwrap();
+}
diff --git a/samplecode/prost-protobuf/app/src/main.rs b/samplecode/prost-protobuf/app/src/main.rs
index eaaaa2c..5bdf834 100644
--- a/samplecode/prost-protobuf/app/src/main.rs
+++ b/samplecode/prost-protobuf/app/src/main.rs
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2018 Baidu, Inc. All Rights Reserved.
+// Copyright (C) 2017-2019 Baidu, Inc. All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
@@ -28,21 +28,14 @@
extern crate sgx_types;
extern crate sgx_urts;
-extern crate dirs;
-extern crate prost;
-extern crate bytes;
-
use sgx_types::*;
use sgx_urts::SgxEnclave;
-use std::io::{Read, Write};
-use std::fs;
-use std::path;
-
+extern crate prost;
+extern crate bytes;
use prost::Message;
static ENCLAVE_FILE: &'static str = "enclave.signed.so";
-static ENCLAVE_TOKEN: &'static str = "enclave.token";
extern {
fn say_something(eid: sgx_enclave_id_t, retval: *mut sgx_status_t,
@@ -54,75 +47,20 @@ mod person{
}
fn init_enclave() -> SgxResult<SgxEnclave> {
-
let mut launch_token: sgx_launch_token_t = [0; 1024];
let mut launch_token_updated: i32 = 0;
- // Step 1: try to retrieve the launch token saved by last transaction
- // if there is no token, then create a new one.
- //
- // try to get the token saved in $HOME */
- let mut home_dir = path::PathBuf::new();
- let use_token = match dirs::home_dir() {
- Some(path) => {
- println!("[+] Home dir is {}", path.display());
- home_dir = path;
- true
- },
- None => {
- println!("[-] Cannot get home dir");
- false
- }
- };
-
- let token_file: path::PathBuf = home_dir.join(ENCLAVE_TOKEN);;
- if use_token == true {
- match fs::File::open(&token_file) {
- Err(_) => {
- println!("[-] Open token file {} error! Will create one.", token_file.as_path().to_str().unwrap());
- },
- Ok(mut f) => {
- println!("[+] Open token file success! ");
- match f.read(&mut launch_token) {
- Ok(1024) => {
- println!("[+] Token file valid!");
- },
- _ => println!("[+] Token file invalid, will create new token file"),
- }
- }
- }
- }
-
- // Step 2: call sgx_create_enclave to initialize an enclave instance
+ // call sgx_create_enclave to initialize an enclave instance
// Debug Support: set 2nd parameter to 1
let debug = 1;
let mut misc_attr = sgx_misc_attribute_t {secs_attr: sgx_attributes_t { flags:0, xfrm:0}, misc_select:0};
- let enclave = try!(SgxEnclave::create(ENCLAVE_FILE,
- debug,
- &mut launch_token,
- &mut launch_token_updated,
- &mut misc_attr));
-
- // Step 3: save the launch token if it is updated
- if use_token == true && launch_token_updated != 0 {
- // reopen the file with write capablity
- match fs::File::create(&token_file) {
- Ok(mut f) => {
- match f.write_all(&launch_token) {
- Ok(()) => println!("[+] Saved updated launch token!"),
- Err(_) => println!("[-] Failed to save updated launch token!"),
- }
- },
- Err(_) => {
- println!("[-] Failed to save updated enclave token, but doesn't matter");
- },
- }
- }
-
- Ok(enclave)
+ SgxEnclave::create(ENCLAVE_FILE,
+ debug,
+ &mut launch_token,
+ &mut launch_token_updated,
+ &mut misc_attr)
}
fn main() {
-
let enclave = match init_enclave() {
Ok(r) => {
println!("[+] Init Enclave Successful {}!", r.geteid());
@@ -134,8 +72,6 @@ fn main() {
},
};
- //let input_string = String::from("This is a normal world string passed into Enclave!\n");
-
let david: person::Person = person::Person {
name: "David".to_string(),
id: 0x12345678,
diff --git a/samplecode/prost-protobuf/enclave/Cargo.toml b/samplecode/prost-protobuf/enclave/Cargo.toml
index ac13992..3e511fa 100644
--- a/samplecode/prost-protobuf/enclave/Cargo.toml
+++ b/samplecode/prost-protobuf/enclave/Cargo.toml
@@ -21,3 +21,30 @@ prost-build = "*"
[target.'cfg(not(target_env = "sgx"))'.dependencies]
sgx_types = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git" }
sgx_tstd = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git" }
+
+[patch.'https://github.com/baidu/rust-sgx-sdk.git']
+sgx_alloc = { path = "../../../sgx_alloc" }
+sgx_build_helper = { path = "../../../sgx_build_helper" }
+sgx_cov = { path = "../../../sgx_cov" }
+sgx_crypto_helper = { path = "../../../sgx_crypto_helper" }
+sgx_libc = { path = "../../../sgx_libc" }
+sgx_rand = { path = "../../../sgx_rand" }
+sgx_rand_derive = { path = "../../../sgx_rand_derive" }
+sgx_serialize = { path = "../../../sgx_serialize" }
+sgx_serialize_derive = { path = "../../../sgx_serialize_derive" }
+sgx_serialize_derive_internals = { path = "../../../sgx_serialize_derive_internals" }
+sgx_tcrypto = { path = "../../../sgx_tcrypto" }
+sgx_tcrypto_helper = { path = "../../../sgx_tcrypto_helper" }
+sgx_tdh = { path = "../../../sgx_tdh" }
+sgx_tkey_exchange = { path = "../../../sgx_tkey_exchange" }
+sgx_tprotected_fs = { path = "../../../sgx_tprotected_fs" }
+sgx_trts = { path = "../../../sgx_trts" }
+sgx_tse = { path = "../../../sgx_tse" }
+sgx_tseal = { path = "../../../sgx_tseal" }
+sgx_tservice = { path = "../../../sgx_tservice" }
+sgx_tstd = { path = "../../../sgx_tstd" }
+sgx_tunittest = { path = "../../../sgx_tunittest" }
+sgx_types = { path = "../../../sgx_types" }
+sgx_ucrypto = { path = "../../../sgx_ucrypto" }
+sgx_unwind = { path = "../../../sgx_unwind" }
+sgx_urts = { path = "../../../sgx_urts" }
diff --git a/samplecode/prost-protobuf/enclave/Enclave.edl b/samplecode/prost-protobuf/enclave/Enclave.edl
new file mode 100644
index 0000000..2e1491b
--- /dev/null
+++ b/samplecode/prost-protobuf/enclave/Enclave.edl
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017-2018 Baidu, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Baidu, Inc., nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+enclave {
+ from "sgx_tstd.edl" import *;
+ from "sgx_stdio.edl" import *;
+ from "sgx_backtrace.edl" import *;
+ from "sgx_tstdc.edl" import *;
+ trusted {
+ /* define ECALLs here. */
+
+ public sgx_status_t say_something([in, size=len] const uint8_t* some_string, size_t len);
+ };
+};
diff --git a/samplecode/prost-protobuf/enclave/Xargo.toml b/samplecode/prost-protobuf/enclave/Xargo.toml
index c088ebb..866117d 100644
--- a/samplecode/prost-protobuf/enclave/Xargo.toml
+++ b/samplecode/prost-protobuf/enclave/Xargo.toml
@@ -5,6 +5,14 @@ alloc = {}
path = "../../../sgx_types"
stage = 1
+[dependencies.sgx_alloc]
+path = "../../../sgx_alloc"
+stage = 1
+
+[dependencies.sgx_unwind]
+path = "../../../sgx_unwind"
+stage = 1
+
[dependencies.sgx_demangle]
path = "../../../sgx_demangle"
stage = 1
@@ -41,9 +49,9 @@ stage = 3
path = "../../../sgx_backtrace_sys"
stage = 3
-[dependencies.sgx_unwind]
-path = "../../../sgx_unwind"
-stage = 4
+[dependencies.panic_unwind]
+path = "../../../sgx_panic_unwind"
+stage = 3
[dependencies.sgx_tdh]
path = "../../../sgx_tdh"
@@ -57,34 +65,31 @@ stage = 4
path = "../../../sgx_tprotected_fs"
stage = 4
-[dependencies.sgx_alloc]
-path = "../../../sgx_alloc"
-stage = 4
-
-[dependencies.panic_unwind]
-path = "../../../sgx_panic_unwind"
-stage = 5
-
[dependencies.std]
path = "../../../xargo/sgx_tstd"
-stage = 6
+stage = 5
+features = ["backtrace"]
+
+[dependencies.sgx_no_tstd]
+path = "../../../sgx_no_tstd"
+stage = 5
[dependencies.sgx_rand]
path = "../../../sgx_rand"
-stage = 7
+stage = 6
[dependencies.sgx_serialize]
path = "../../../sgx_serialize"
-stage = 7
+stage = 6
[dependencies.sgx_tunittest]
path = "../../../sgx_tunittest"
-stage = 7
+stage = 6
[dependencies.sgx_backtrace]
path = "../../../sgx_backtrace"
-stage = 8
+stage = 7
[dependencies.sgx_cov]
path = "../../../sgx_cov"
-stage = 8
+stage = 7
diff --git a/samplecode/sgxcounter/Readme.md b/samplecode/sgxcounter/Readme.md
new file mode 100644
index 0000000..338a063
--- /dev/null
+++ b/samplecode/sgxcounter/Readme.md
@@ -0,0 +1,6 @@
+# Trusted Counter is deprecated
+
+According to the following discussion, PSE is officially unsupported since 2.7. Discussions are:
+
+(1) [Intel SGX SDK Github issue 373](https://github.com/intel/linux-sgx/issues/373#issuecomment-546231049)
+(2) [Intel SGX forum thread 820329](https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/820329)
diff --git a/samplecode/sgxtime/Readme.md b/samplecode/sgxtime/Readme.md
new file mode 100644
index 0000000..fe2d62a
--- /dev/null
+++ b/samplecode/sgxtime/Readme.md
@@ -0,0 +1,6 @@
+# Trusted Timer is deprecated
+
+According to the following discussion, PSE is officially unsupported since 2.7. Discussions are:
+
+(1) [Intel SGX SDK Github issue 373](https://github.com/intel/linux-sgx/issues/373#issuecomment-546231049)
+(2) [Intel SGX forum thread 820329](https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/820329)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@mesatee.apache.org
For additional commands, e-mail: commits-help@mesatee.apache.org