From 6535a00bab5388ea5c95e5992f7112faa9fad5cb Mon Sep 17 00:00:00 2001 From: Yu Ding Date: Mon, 12 Feb 2018 18:31:38 -0800 Subject: [PATCH] v0.9.7 release. Provides sgx_tstd::untrusted --- Readme.md | 3 + release_notes.md | 5 + samplecode/backtrace/enclave/Cargo.toml | 2 +- samplecode/crypto/enclave/Cargo.toml | 2 +- samplecode/file/enclave/Cargo.toml | 2 +- samplecode/hello-rust/app/Cargo.toml | 2 +- samplecode/hello-rust/enclave/Cargo.toml | 2 +- samplecode/helloworld/enclave/Cargo.toml | 2 +- samplecode/hugemem/enclave/Cargo.toml | 2 +- .../localattestation/attestation/Cargo.toml | 2 +- .../localattestation/enclave1/Cargo.toml | 2 +- .../localattestation/enclave2/Cargo.toml | 2 +- .../localattestation/enclave3/Cargo.toml | 2 +- samplecode/machine-learning/app/Cargo.toml | 2 +- .../machine-learning/enclave/Cargo.toml | 2 +- .../Application/enclave/Cargo.toml | 2 +- samplecode/sealeddata/enclave/Cargo.toml | 2 +- samplecode/serialize/enclave/Cargo.toml | 2 +- samplecode/sgxtime/app/Cargo.toml | 2 +- samplecode/sgxtime/enclave/Cargo.toml | 2 +- samplecode/thread/enclave/Cargo.toml | 2 +- samplecode/tls/tlsclient/app/Cargo.toml | 2 +- samplecode/tls/tlsclient/enclave/Cargo.toml | 4 +- samplecode/tls/tlsclient/enclave/Enclave.edl | 1 - samplecode/tls/tlsclient/enclave/Xargo.toml | 2 +- samplecode/tls/tlsclient/enclave/src/lib.rs | 2 +- samplecode/tls/tlsserver/app/Cargo.toml | 2 +- samplecode/tls/tlsserver/enclave/Cargo.toml | 6 +- samplecode/tls/tlsserver/enclave/Enclave.edl | 1 - samplecode/tls/tlsserver/enclave/Xargo.toml | 2 +- samplecode/tls/tlsserver/enclave/src/lib.rs | 2 +- samplecode/unit-test/app/Cargo.toml | 2 +- samplecode/unit-test/enclave/Cargo.toml | 4 +- samplecode/unit-test/enclave/Xargo.toml | 4 +- samplecode/unit-test/enclave/src/lib.rs | 2 + samplecode/unit-test/enclave/src/test_file.rs | 26 +++- samplecode/unit-test/enclave/src/test_time.rs | 2 +- .../zlib-lazy-static-sample/app/Cargo.toml | 2 +- .../enclave/Cargo.toml | 2 +- sgx_alloc/Cargo.toml | 2 +- sgx_rand/Cargo.toml | 2 +- sgx_rand_derive/Cargo.toml | 2 +- sgx_serialize/Cargo.toml | 2 +- sgx_serialize_derive/Cargo.toml | 2 +- sgx_serialize_derive_internals/Cargo.toml | 2 +- sgx_tcrypto/Cargo.toml | 2 +- sgx_tdh/Cargo.toml | 2 +- sgx_tkey_exchange/Cargo.toml | 2 +- sgx_tprotected_fs/Cargo.toml | 2 +- sgx_trts/Cargo.toml | 2 +- sgx_tse/Cargo.toml | 2 +- sgx_tseal/Cargo.toml | 2 +- sgx_tservice/Cargo.toml | 2 +- sgx_tstd/Cargo.toml | 4 +- sgx_tstd/src/lib.rs | 3 + sgx_tstd/src/net/mod.rs | 8 +- sgx_tstd/src/os/fs.rs | 3 + sgx_tstd/src/os/mod.rs | 1 - sgx_tstd/src/sgxfs.rs | 1 - sgx_tstd/src/sys/ext/fs.rs | 3 + sgx_tstd/src/sys/ext/io.rs | 5 +- sgx_tstd/src/sys/ext/mod.rs | 5 +- sgx_tstd/src/sys/fs.rs | 11 +- sgx_tstd/src/sys/mod.rs | 3 +- sgx_tstd/src/sys/sgxfs.rs | 11 +- sgx_tstd/src/sys_common/mod.rs | 2 +- sgx_tstd/src/untrusted/fs.rs | 30 +++++ sgx_tstd/src/untrusted/mod.rs | 31 +++++ sgx_tstd/src/untrusted/path.rs | 124 ++++++++++++++++++ sgx_tstd/src/untrusted/time.rs | 92 +++++++++++++ sgx_tunittest/Cargo.toml | 2 +- sgx_types/Cargo.toml | 2 +- sgx_urts/Cargo.toml | 2 +- third_party/rulinalg/Cargo.toml | 2 +- third_party/rulinalg/Xargo.toml | 1 - third_party/rust-csv/Cargo.toml | 2 +- third_party/rust-csv/Xargo.toml | 1 - third_party/rust-csv/src/reader.rs | 2 +- third_party/rust-csv/src/writer.rs | 2 +- third_party/rustls/Cargo.toml | 2 +- third_party/rustls/Xargo.toml | 1 - third_party/rustls/src/ticketer.rs | 1 + third_party/rustls/src/verify.rs | 1 + third_party/rusty-machine/Cargo.toml | 2 +- third_party/rusty-machine/Xargo.toml | 1 - third_party/webpki/Cargo.toml | 2 +- third_party/webpki/Xargo.toml | 1 - xargo/sgx_rand/Cargo.toml | 2 +- xargo/sgx_serialize/Cargo.toml | 2 +- xargo/sgx_tstd/Cargo.toml | 2 +- xargo/sgx_tunittest/Cargo.toml | 2 +- 91 files changed, 418 insertions(+), 96 deletions(-) create mode 100644 sgx_tstd/src/untrusted/fs.rs create mode 100644 sgx_tstd/src/untrusted/mod.rs create mode 100644 sgx_tstd/src/untrusted/path.rs create mode 100644 sgx_tstd/src/untrusted/time.rs diff --git a/Readme.md b/Readme.md index 2b7059fcf..8874dfc9b 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,9 @@ # Rust SGX SDK Rust SGX SDK helps developers write Intel SGX applications in Rust programming language. [[Paper pdf]](documents/ccsp17.pdf) +## v0.9.7 Release +This version provides a new namespace: `sgx_tstd::untrusted`, including `sgx_tstd::untrusted::fs` `sgx_tstd::untrusted::time` and `sgx_tstd::untrusted::path`, providing supports to operation to ocalls in a **untrusted** namespace. The **untrusted** namespace is always enabled no matter `untrusted_*` is set or not. We **urge** the developers to use the `sgx_tstd::untrusted` namespace to port their crates, instead of enabling the `untrusted_` series of features. Also, we renamed the `untrusted_net` feature to `net` for feature name unification. Please refer to [release_notes](release_notes.md) for further details. + ## v0.9.6 Release This version provides security enhancement for untrusted IO and additional support for monotonic counter. Untrusted IO operations in `sgx_tstd::fs` `sgx_tstd::net` and `sgx_tstd::time` are **DISABLED by default** to reduce the untrusted surface, and can be enabled by features. Trusted time support is moved to `sgx_tservice::sgxtime` and monotonic counter is provided by `sgx_tservice::sgxcounter`. Please refer to [release_notes](release_notes.md) for further details. diff --git a/release_notes.md b/release_notes.md index 66a351bcd..9291e3b98 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,3 +1,8 @@ +# Rust SGX SDK v0.9.7 Release Notes +**Provide `sgx_tstd::untrusted` namespace** v0.9.7 provides `sgx_tstd::untrusted::{fs,path,time}` which related to ocall functions. They are always enabled no matter `untrusted_fs` or `untrusted_time` feature is enabled or not. The major concern of providing such a namespace is that we want the developer to know they are invoking ocall related functions which brings **untrusted data** into the trusted execution engine. For the best security practice, explicitly importing from `sgx_tstd::untrusted` is better than enabling feature in `Cargo.toml`. We stress that `untrusted_fs` and `untrusted_time` features are designed to be **contingency plans** and should only be enabled when porting an very complex Rust crate to Rust-SGX enclaves. + +**Rename feature `untrusted_net` to `net`** `net` is well-known as untrusted and we think `net` is a better choice and similar to current features: `backtrace` and `stdio`. + # Rust SGX SDK v0.9.6 Release Notes **Support latest Rust nightly build (nightly-2018-02-05-x86_64-unknown-linux-gnu)** diff --git a/samplecode/backtrace/enclave/Cargo.toml b/samplecode/backtrace/enclave/Cargo.toml index 1d4397452..5f82328f3 100644 --- a/samplecode/backtrace/enclave/Cargo.toml +++ b/samplecode/backtrace/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Backtracesampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/crypto/enclave/Cargo.toml b/samplecode/crypto/enclave/Cargo.toml index 915996cd3..f2125f051 100644 --- a/samplecode/crypto/enclave/Cargo.toml +++ b/samplecode/crypto/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Cryptosampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/file/enclave/Cargo.toml b/samplecode/file/enclave/Cargo.toml index 9c25bb076..b61841f2e 100644 --- a/samplecode/file/enclave/Cargo.toml +++ b/samplecode/file/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Filesampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/hello-rust/app/Cargo.toml b/samplecode/hello-rust/app/Cargo.toml index 1e54aa457..d021e0a18 100644 --- a/samplecode/hello-rust/app/Cargo.toml +++ b/samplecode/hello-rust/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.6" +version = "0.9.7" authors = ["duanran01 "] build = "build.rs" diff --git a/samplecode/hello-rust/enclave/Cargo.toml b/samplecode/hello-rust/enclave/Cargo.toml index b20378a8d..6193979d9 100644 --- a/samplecode/hello-rust/enclave/Cargo.toml +++ b/samplecode/hello-rust/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Helloworldsampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/helloworld/enclave/Cargo.toml b/samplecode/helloworld/enclave/Cargo.toml index b20378a8d..6193979d9 100644 --- a/samplecode/helloworld/enclave/Cargo.toml +++ b/samplecode/helloworld/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Helloworldsampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/hugemem/enclave/Cargo.toml b/samplecode/hugemem/enclave/Cargo.toml index 22e761455..f7887574f 100644 --- a/samplecode/hugemem/enclave/Cargo.toml +++ b/samplecode/hugemem/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Hugememsampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/localattestation/attestation/Cargo.toml b/samplecode/localattestation/attestation/Cargo.toml index b69e7d5ad..a51e2f3f4 100644 --- a/samplecode/localattestation/attestation/Cargo.toml +++ b/samplecode/localattestation/attestation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "attestation" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [features] diff --git a/samplecode/localattestation/enclave1/Cargo.toml b/samplecode/localattestation/enclave1/Cargo.toml index 24424fd92..306799f2f 100644 --- a/samplecode/localattestation/enclave1/Cargo.toml +++ b/samplecode/localattestation/enclave1/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "enclave1" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/localattestation/enclave2/Cargo.toml b/samplecode/localattestation/enclave2/Cargo.toml index afe350338..c5cd86dc4 100644 --- a/samplecode/localattestation/enclave2/Cargo.toml +++ b/samplecode/localattestation/enclave2/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "enclave2" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/localattestation/enclave3/Cargo.toml b/samplecode/localattestation/enclave3/Cargo.toml index 764f24eb4..f9c723df5 100644 --- a/samplecode/localattestation/enclave3/Cargo.toml +++ b/samplecode/localattestation/enclave3/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "enclave3" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/machine-learning/app/Cargo.toml b/samplecode/machine-learning/app/Cargo.toml index 1e54aa457..d021e0a18 100644 --- a/samplecode/machine-learning/app/Cargo.toml +++ b/samplecode/machine-learning/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.6" +version = "0.9.7" authors = ["duanran01 "] build = "build.rs" diff --git a/samplecode/machine-learning/enclave/Cargo.toml b/samplecode/machine-learning/enclave/Cargo.toml index 65ffd161c..63203a501 100644 --- a/samplecode/machine-learning/enclave/Cargo.toml +++ b/samplecode/machine-learning/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Machinelearningsampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/remoteattestation/Application/enclave/Cargo.toml b/samplecode/remoteattestation/Application/enclave/Cargo.toml index 5b364aa0b..c075d7f05 100644 --- a/samplecode/remoteattestation/Application/enclave/Cargo.toml +++ b/samplecode/remoteattestation/Application/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "RAenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/sealeddata/enclave/Cargo.toml b/samplecode/sealeddata/enclave/Cargo.toml index 875829e1c..10e1d15ee 100644 --- a/samplecode/sealeddata/enclave/Cargo.toml +++ b/samplecode/sealeddata/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Sealdatasampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/serialize/enclave/Cargo.toml b/samplecode/serialize/enclave/Cargo.toml index 181e59cff..1141279b3 100644 --- a/samplecode/serialize/enclave/Cargo.toml +++ b/samplecode/serialize/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Serializesampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/sgxtime/app/Cargo.toml b/samplecode/sgxtime/app/Cargo.toml index 1e54aa457..d021e0a18 100644 --- a/samplecode/sgxtime/app/Cargo.toml +++ b/samplecode/sgxtime/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.6" +version = "0.9.7" authors = ["duanran01 "] build = "build.rs" diff --git a/samplecode/sgxtime/enclave/Cargo.toml b/samplecode/sgxtime/enclave/Cargo.toml index 4545e78ba..68bd36583 100644 --- a/samplecode/sgxtime/enclave/Cargo.toml +++ b/samplecode/sgxtime/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Sgxtimeenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/thread/enclave/Cargo.toml b/samplecode/thread/enclave/Cargo.toml index d1e16e550..760ad05ec 100644 --- a/samplecode/thread/enclave/Cargo.toml +++ b/samplecode/thread/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Threadsampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/samplecode/tls/tlsclient/app/Cargo.toml b/samplecode/tls/tlsclient/app/Cargo.toml index 796bbf5ce..71d049c58 100644 --- a/samplecode/tls/tlsclient/app/Cargo.toml +++ b/samplecode/tls/tlsclient/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.6" +version = "0.9.7" authors = ["duanran01 "] build = "build.rs" diff --git a/samplecode/tls/tlsclient/enclave/Cargo.toml b/samplecode/tls/tlsclient/enclave/Cargo.toml index 7025578c3..0db256973 100644 --- a/samplecode/tls/tlsclient/enclave/Cargo.toml +++ b/samplecode/tls/tlsclient/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tlsclient" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] @@ -13,7 +13,7 @@ default = [] [target.'cfg(not(target_env = "sgx"))'.dependencies] sgx_types = { path = "../../../../sgx_types" } sgx_trts = { path = "../../../../sgx_trts" } -sgx_tstd = { path = "../../../../sgx_tstd", features = ["untrusted_fs", "untrusted_net", "untrusted_time"] } +sgx_tstd = { path = "../../../../sgx_tstd", features = ["net"] } [dependencies] rustls = { path = "../../../../third_party/rustls" } diff --git a/samplecode/tls/tlsclient/enclave/Enclave.edl b/samplecode/tls/tlsclient/enclave/Enclave.edl index edbd0fdb9..6899fe42f 100644 --- a/samplecode/tls/tlsclient/enclave/Enclave.edl +++ b/samplecode/tls/tlsclient/enclave/Enclave.edl @@ -32,7 +32,6 @@ enclave { from "sgx_tstd.edl" import *; from "sgx_stdio.edl" import *; - from "sgx_backtrace.edl" import *; from "sgx_net.edl" import *; from "sgx_time.edl" import *; from "sgx_tstdc.edl" import *; diff --git a/samplecode/tls/tlsclient/enclave/Xargo.toml b/samplecode/tls/tlsclient/enclave/Xargo.toml index ddb9ad1d5..66ae2d2a4 100644 --- a/samplecode/tls/tlsclient/enclave/Xargo.toml +++ b/samplecode/tls/tlsclient/enclave/Xargo.toml @@ -10,7 +10,7 @@ stage = 1 [dependencies.std] path = "../../../../xargo/sgx_tstd" -features = ["untrusted_fs", "untrusted_net", "untrusted_time"] +features = ["net"] stage = 2 [dependencies.sgx_rand] diff --git a/samplecode/tls/tlsclient/enclave/src/lib.rs b/samplecode/tls/tlsclient/enclave/src/lib.rs index 1aa455de6..b4c98de34 100644 --- a/samplecode/tls/tlsclient/enclave/src/lib.rs +++ b/samplecode/tls/tlsclient/enclave/src/lib.rs @@ -41,7 +41,7 @@ extern crate sgx_tstd as std; use sgx_types::*; use std::collections; -use std::fs; +use std::untrusted::fs; use std::io::BufReader; use std::ffi::CStr; diff --git a/samplecode/tls/tlsserver/app/Cargo.toml b/samplecode/tls/tlsserver/app/Cargo.toml index 796bbf5ce..71d049c58 100644 --- a/samplecode/tls/tlsserver/app/Cargo.toml +++ b/samplecode/tls/tlsserver/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.6" +version = "0.9.7" authors = ["duanran01 "] build = "build.rs" diff --git a/samplecode/tls/tlsserver/enclave/Cargo.toml b/samplecode/tls/tlsserver/enclave/Cargo.toml index 3fe5ca346..0eba1782a 100644 --- a/samplecode/tls/tlsserver/enclave/Cargo.toml +++ b/samplecode/tls/tlsserver/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "tlsclient" -version = "0.9.6" +name = "tlsserver" +version = "0.9.7" authors = ["Baidu"] [lib] @@ -13,7 +13,7 @@ default = [] [target.'cfg(not(target_env = "sgx"))'.dependencies] sgx_types = { path = "../../../../sgx_types" } sgx_trts = { path = "../../../../sgx_trts" } -sgx_tstd = { path = "../../../../sgx_tstd", features = ["untrusted_fs", "untrusted_net", "untrusted_time"] } +sgx_tstd = { path = "../../../../sgx_tstd", features = ["net"] } [dependencies] rustls = { path = "../../../../third_party/rustls" } diff --git a/samplecode/tls/tlsserver/enclave/Enclave.edl b/samplecode/tls/tlsserver/enclave/Enclave.edl index b99c54472..e821fad8d 100644 --- a/samplecode/tls/tlsserver/enclave/Enclave.edl +++ b/samplecode/tls/tlsserver/enclave/Enclave.edl @@ -32,7 +32,6 @@ enclave { from "sgx_tstd.edl" import *; from "sgx_stdio.edl" import *; - from "sgx_backtrace.edl" import *; from "sgx_net.edl" import *; from "sgx_time.edl" import *; from "sgx_tstdc.edl" import *; diff --git a/samplecode/tls/tlsserver/enclave/Xargo.toml b/samplecode/tls/tlsserver/enclave/Xargo.toml index ddb9ad1d5..66ae2d2a4 100644 --- a/samplecode/tls/tlsserver/enclave/Xargo.toml +++ b/samplecode/tls/tlsserver/enclave/Xargo.toml @@ -10,7 +10,7 @@ stage = 1 [dependencies.std] path = "../../../../xargo/sgx_tstd" -features = ["untrusted_fs", "untrusted_net", "untrusted_time"] +features = ["net"] stage = 2 [dependencies.sgx_rand] diff --git a/samplecode/tls/tlsserver/enclave/src/lib.rs b/samplecode/tls/tlsserver/enclave/src/lib.rs index f55372136..7bea1da4d 100644 --- a/samplecode/tls/tlsserver/enclave/src/lib.rs +++ b/samplecode/tls/tlsserver/enclave/src/lib.rs @@ -40,7 +40,7 @@ extern crate sgx_tstd as std; use sgx_types::*; -use std::fs; +use std::untrusted::fs; use std::io::BufReader; use std::ffi::CStr; diff --git a/samplecode/unit-test/app/Cargo.toml b/samplecode/unit-test/app/Cargo.toml index 1e54aa457..d021e0a18 100644 --- a/samplecode/unit-test/app/Cargo.toml +++ b/samplecode/unit-test/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.6" +version = "0.9.7" authors = ["duanran01 "] build = "build.rs" diff --git a/samplecode/unit-test/enclave/Cargo.toml b/samplecode/unit-test/enclave/Cargo.toml index 2302d8d0c..11153c16e 100644 --- a/samplecode/unit-test/enclave/Cargo.toml +++ b/samplecode/unit-test/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Unittestsampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] @@ -12,7 +12,7 @@ default = [] [target.'cfg(not(target_env = "sgx"))'.dependencies] sgx_types = { path = "../../../sgx_types" } -sgx_tstd = { path = "../../../sgx_tstd", features = ["untrusted_fs", "untrusted_time"] } +sgx_tstd = { path = "../../../sgx_tstd",features = ["untrusted_fs"]} sgx_tcrypto = { path = "../../../sgx_tcrypto" } sgx_tunittest = { path = "../../../sgx_tunittest" } sgx_trts = { path = "../../../sgx_trts" } diff --git a/samplecode/unit-test/enclave/Xargo.toml b/samplecode/unit-test/enclave/Xargo.toml index 7584c5bc6..c91357a55 100644 --- a/samplecode/unit-test/enclave/Xargo.toml +++ b/samplecode/unit-test/enclave/Xargo.toml @@ -10,7 +10,7 @@ stage = 1 [dependencies.std] path = "../../../xargo/sgx_tstd" -features = ["untrusted_fs", "untrusted_time"] +features = ["untrusted_fs"] stage = 2 [dependencies.sgx_rand] @@ -23,4 +23,4 @@ stage = 3 [dependencies.sgx_tunittest] path = "../../../xargo/sgx_tunittest" -stage = 3 \ No newline at end of file +stage = 3 diff --git a/samplecode/unit-test/enclave/src/lib.rs b/samplecode/unit-test/enclave/src/lib.rs index 346edc4cd..b75a1f75e 100644 --- a/samplecode/unit-test/enclave/src/lib.rs +++ b/samplecode/unit-test/enclave/src/lib.rs @@ -134,6 +134,8 @@ fn test_main_entrance() -> sgx_status_t { test_sgxfs, // std::fs test_fs, + // std::fs untrusted mode + test_fs_untrusted_fs_feature_enabled, // std::time test_std_time ); diff --git a/samplecode/unit-test/enclave/src/test_file.rs b/samplecode/unit-test/enclave/src/test_file.rs index ea1eccefe..88a039c51 100644 --- a/samplecode/unit-test/enclave/src/test_file.rs +++ b/samplecode/unit-test/enclave/src/test_file.rs @@ -28,8 +28,8 @@ use sgx_rand::{Rng, StdRng}; use std::sgxfs::{self, SgxFile}; -use std::fs::File; -use std::fs::remove_file; +use std::untrusted::fs::File; +use std::untrusted::fs::remove_file; use std::io::{Read, Write}; use std::string::*; @@ -116,3 +116,25 @@ pub fn test_fs () { assert!(f.is_ok()); } } + +pub fn test_fs_untrusted_fs_feature_enabled() { + { + use std::fs; + let f = fs::File::create("foo.txt"); + assert!(f.is_ok()); + + let result = f.unwrap().write_all(b"Hello, world!"); + assert!(result.is_ok()); + + let f = fs::File::open("foo.txt"); + assert!(f.is_ok()); + + let mut s = String::new(); + let result = f.unwrap().read_to_string(&mut s); + assert!(result.is_ok()); + assert_eq!(s, "Hello, world!"); + + let f = remove_file("foo.txt"); + assert!(f.is_ok()); + } +} diff --git a/samplecode/unit-test/enclave/src/test_time.rs b/samplecode/unit-test/enclave/src/test_time.rs index 218cd8429..d566f81ff 100644 --- a/samplecode/unit-test/enclave/src/test_time.rs +++ b/samplecode/unit-test/enclave/src/test_time.rs @@ -1,6 +1,6 @@ use std::time::*; use std::panic; -//use std::thread::sleep; +use std::untrusted::time::{InstantEx, SystemTimeEx}; pub fn test_std_time() { macro_rules! assert_almost_eq { diff --git a/samplecode/zlib-lazy-static-sample/app/Cargo.toml b/samplecode/zlib-lazy-static-sample/app/Cargo.toml index 1e54aa457..d021e0a18 100644 --- a/samplecode/zlib-lazy-static-sample/app/Cargo.toml +++ b/samplecode/zlib-lazy-static-sample/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.6" +version = "0.9.7" authors = ["duanran01 "] build = "build.rs" diff --git a/samplecode/zlib-lazy-static-sample/enclave/Cargo.toml b/samplecode/zlib-lazy-static-sample/enclave/Cargo.toml index 6b77dd85a..c2bcf9ea3 100644 --- a/samplecode/zlib-lazy-static-sample/enclave/Cargo.toml +++ b/samplecode/zlib-lazy-static-sample/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Zlibsampleenclave" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_alloc/Cargo.toml b/sgx_alloc/Cargo.toml index ba21ff83c..b2006e8a6 100644 --- a/sgx_alloc/Cargo.toml +++ b/sgx_alloc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_alloc" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_rand/Cargo.toml b/sgx_rand/Cargo.toml index 70a1158ed..bbb58b9d4 100644 --- a/sgx_rand/Cargo.toml +++ b/sgx_rand/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_rand" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_rand_derive/Cargo.toml b/sgx_rand_derive/Cargo.toml index 0d25d2c39..fbeb61167 100644 --- a/sgx_rand_derive/Cargo.toml +++ b/sgx_rand_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_rand_derive" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_serialize/Cargo.toml b/sgx_serialize/Cargo.toml index 1600eef43..f9fddd09f 100644 --- a/sgx_serialize/Cargo.toml +++ b/sgx_serialize/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_serialize" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_serialize_derive/Cargo.toml b/sgx_serialize_derive/Cargo.toml index 95c62be33..108c81ab9 100644 --- a/sgx_serialize_derive/Cargo.toml +++ b/sgx_serialize_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_serialize_derive" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_serialize_derive_internals/Cargo.toml b/sgx_serialize_derive_internals/Cargo.toml index 1cb3f1e07..65020fa91 100644 --- a/sgx_serialize_derive_internals/Cargo.toml +++ b/sgx_serialize_derive_internals/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_serialize_derive_internals" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tcrypto/Cargo.toml b/sgx_tcrypto/Cargo.toml index 83e0c2411..327ea2e05 100644 --- a/sgx_tcrypto/Cargo.toml +++ b/sgx_tcrypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tcrypto" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tdh/Cargo.toml b/sgx_tdh/Cargo.toml index 3e3c0ae1e..19724360d 100644 --- a/sgx_tdh/Cargo.toml +++ b/sgx_tdh/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tdh" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tkey_exchange/Cargo.toml b/sgx_tkey_exchange/Cargo.toml index eff4661b3..e5d017f72 100644 --- a/sgx_tkey_exchange/Cargo.toml +++ b/sgx_tkey_exchange/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tkey_exchange" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tprotected_fs/Cargo.toml b/sgx_tprotected_fs/Cargo.toml index a598bfc33..a9a7304aa 100644 --- a/sgx_tprotected_fs/Cargo.toml +++ b/sgx_tprotected_fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tprotected_fs" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_trts/Cargo.toml b/sgx_trts/Cargo.toml index af959d171..297671e60 100644 --- a/sgx_trts/Cargo.toml +++ b/sgx_trts/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_trts" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tse/Cargo.toml b/sgx_tse/Cargo.toml index 714d93889..1df6bfb46 100644 --- a/sgx_tse/Cargo.toml +++ b/sgx_tse/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tse" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tseal/Cargo.toml b/sgx_tseal/Cargo.toml index d393b808b..bfb2a84f6 100644 --- a/sgx_tseal/Cargo.toml +++ b/sgx_tseal/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tseal" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tservice/Cargo.toml b/sgx_tservice/Cargo.toml index 2060d97ef..74f4923a6 100644 --- a/sgx_tservice/Cargo.toml +++ b/sgx_tservice/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tservice" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_tstd/Cargo.toml b/sgx_tstd/Cargo.toml index 1372c6617..c3bb18c5d 100644 --- a/sgx_tstd/Cargo.toml +++ b/sgx_tstd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tstd" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] build = "build.rs" @@ -12,8 +12,8 @@ crate-type = ["rlib"] default = ["stdio"] backtrace = ["stdio"] stdio = [] +net = [] untrusted_fs = [] -untrusted_net = [] untrusted_time = [] [build-dependencies] diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index 5ef66f088..13479e4ef 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -211,6 +211,7 @@ pub mod sync; pub mod time; pub mod heap; pub mod enclave; +pub mod untrusted; // Platform-abstraction modules mod sys_common; @@ -220,6 +221,8 @@ mod sys; mod panicking; mod cpuid; mod memchr; +#[cfg(not(feature = "untrusted_fs"))] +mod fs; // The runtime entry point and a few unstable public functions used by the // compiler diff --git a/sgx_tstd/src/net/mod.rs b/sgx_tstd/src/net/mod.rs index d14847cf1..a481be3fb 100644 --- a/sgx_tstd/src/net/mod.rs +++ b/sgx_tstd/src/net/mod.rs @@ -38,18 +38,18 @@ use io::{self, Error, ErrorKind}; pub use self::ip::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope}; pub use self::addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; -#[cfg(feature = "untrusted_net")] +#[cfg(feature = "net")] pub use self::tcp::TcpStream; -#[cfg(feature = "untrusted_net")] +#[cfg(feature = "net")] pub use self::udp::UdpSocket; pub use self::parser::AddrParseError; mod ip; mod addr; mod parser; -#[cfg(feature = "untrusted_net")] +#[cfg(feature = "net")] mod tcp; -#[cfg(feature = "untrusted_net")] +#[cfg(feature = "net")] mod udp; /// Possible values which can be passed to the [`shutdown`] method of diff --git a/sgx_tstd/src/os/fs.rs b/sgx_tstd/src/os/fs.rs index c3bb25bdb..f8995117a 100644 --- a/sgx_tstd/src/os/fs.rs +++ b/sgx_tstd/src/os/fs.rs @@ -28,7 +28,10 @@ use sgx_trts::libc; +#[cfg(feature = "untrusted_fs")] use fs::Metadata; +#[cfg(not(feature = "untrusted_fs"))] +use untrusted::fs::Metadata; use sys_common::AsInner; use os::raw; diff --git a/sgx_tstd/src/os/mod.rs b/sgx_tstd/src/os/mod.rs index 850149696..dd8bc0ed0 100644 --- a/sgx_tstd/src/os/mod.rs +++ b/sgx_tstd/src/os/mod.rs @@ -28,5 +28,4 @@ pub use sys::ext as unix; pub mod raw; -#[cfg(feature = "untrusted_fs")] pub mod fs; \ No newline at end of file diff --git a/sgx_tstd/src/sgxfs.rs b/sgx_tstd/src/sgxfs.rs index ab14e6ead..c8fd3b6d9 100644 --- a/sgx_tstd/src/sgxfs.rs +++ b/sgx_tstd/src/sgxfs.rs @@ -320,7 +320,6 @@ pub fn import_auto_key>(path: P, key: &sgx_key_128bit_t) -> io::R /// /// On success, the total number of bytes copied is returned. /// -#[cfg(feature = "untrusted_fs")] pub fn copy, Q: AsRef>(from: P, to: Q) -> io::Result { fs_imp::copy(from.as_ref(), to.as_ref()) } diff --git a/sgx_tstd/src/sys/ext/fs.rs b/sgx_tstd/src/sys/ext/fs.rs index 338c017b7..2c6e229d2 100644 --- a/sgx_tstd/src/sys/ext/fs.rs +++ b/sgx_tstd/src/sys/ext/fs.rs @@ -27,7 +27,10 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use sgx_trts::libc; +#[cfg(feature = "untrusted_fs")] use fs::{self, Permissions, OpenOptions}; +#[cfg(not(feature = "untrusted_fs"))] +use untrusted::fs::{self, Permissions, OpenOptions}; use io; use path::Path; use sys; diff --git a/sgx_tstd/src/sys/ext/io.rs b/sgx_tstd/src/sys/ext/io.rs index f94e51af2..f264f5c6f 100644 --- a/sgx_tstd/src/sys/ext/io.rs +++ b/sgx_tstd/src/sys/ext/io.rs @@ -31,6 +31,8 @@ use sgx_trts::libc; #[cfg(feature = "untrusted_fs")] use fs; +#[cfg(not(feature = "untrusted_fs"))] +use untrusted::fs; use os::raw; use sys; use io; @@ -83,21 +85,18 @@ pub trait IntoRawFd { fn into_raw_fd(self) -> RawFd; } -#[cfg(feature = "untrusted_fs")] impl AsRawFd for fs::File { fn as_raw_fd(&self) -> RawFd { self.as_inner().fd().raw() } } -#[cfg(feature = "untrusted_fs")] impl FromRawFd for fs::File { unsafe fn from_raw_fd(fd: RawFd) -> fs::File { fs::File::from_inner(sys::fs::File::from_inner(fd)) } } -#[cfg(feature = "untrusted_fs")] impl IntoRawFd for fs::File { fn into_raw_fd(self) -> RawFd { self.into_inner().into_fd().into_raw() diff --git a/sgx_tstd/src/sys/ext/mod.rs b/sgx_tstd/src/sys/ext/mod.rs index a820717c6..3e2d74e60 100644 --- a/sgx_tstd/src/sys/ext/mod.rs +++ b/sgx_tstd/src/sys/ext/mod.rs @@ -28,9 +28,8 @@ pub mod io; pub mod ffi; -#[cfg(feature = "untrusted_fs")] pub mod fs; -#[cfg(feature = "untrusted_net")] +#[cfg(feature = "net")] pub mod net; /// A prelude for conveniently writing platform-specific code. @@ -39,8 +38,6 @@ pub mod net; pub mod prelude { pub use super::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd}; pub use super::ffi::{OsStrExt, OsStringExt}; - #[cfg(feature = "untrusted_fs")] pub use super::fs::{PermissionsExt, OpenOptionsExt, MetadataExt, FileTypeExt}; - #[cfg(feature = "untrusted_fs")] pub use super::fs::FileExt; } diff --git a/sgx_tstd/src/sys/fs.rs b/sgx_tstd/src/sys/fs.rs index 03b8d3c17..9e2a0b09a 100644 --- a/sgx_tstd/src/sys/fs.rs +++ b/sgx_tstd/src/sys/fs.rs @@ -431,7 +431,16 @@ pub fn canonicalize(p: &Path) -> io::Result { } pub fn copy(from: &Path, to: &Path) -> io::Result { - use fs::{File, set_permissions}; + + cfg_if! { + if #[cfg(feature = "untrusted_fs")] { + use fs::{File, set_permissions}; + } else { + use untrusted::fs::{File, set_permissions}; + use untrusted::path::PathEx; + } + } + if !from.is_file() { return Err(Error::new(ErrorKind::InvalidInput, "the source path is not an existing regular file")) diff --git a/sgx_tstd/src/sys/mod.rs b/sgx_tstd/src/sys/mod.rs index 798a14979..5c731e8f7 100644 --- a/sgx_tstd/src/sys/mod.rs +++ b/sgx_tstd/src/sys/mod.rs @@ -32,10 +32,9 @@ use io::{self, ErrorKind}; pub use self::rand::hashmap_random_keys; pub mod fd; -#[cfg(feature = "untrusted_fs")] pub mod fs; pub mod sgxfs; -#[cfg(feature = "untrusted_net")] +#[cfg(feature = "net")] pub mod net; pub mod os_str; pub mod path; diff --git a/sgx_tstd/src/sys/sgxfs.rs b/sgx_tstd/src/sys/sgxfs.rs index 1b8cc70a9..c6508f62c 100644 --- a/sgx_tstd/src/sys/sgxfs.rs +++ b/sgx_tstd/src/sys/sgxfs.rs @@ -299,10 +299,17 @@ impl FromInner for SgxFile { } } -#[cfg(feature = "untrusted_fs")] pub fn copy(from: &Path, to: &Path) -> io::Result { + use sgxfs::SgxFile; - use fs; + cfg_if! { + if #[cfg(feature = "untrusted_fs")] { + use fs; + } else { + use untrusted::fs; + use untrusted::path::PathEx; + } + } let metadata = from.metadata()?; if !metadata.is_file() { diff --git a/sgx_tstd/src/sys_common/mod.rs b/sgx_tstd/src/sys_common/mod.rs index 92c7a68d1..ae33c6db9 100644 --- a/sgx_tstd/src/sys_common/mod.rs +++ b/sgx_tstd/src/sys_common/mod.rs @@ -36,7 +36,7 @@ pub mod memchr; pub mod poison; pub mod thread_info; pub mod wtf8; -#[cfg(feature = "untrusted_net")] +#[cfg(feature = "net")] pub mod net; pub mod bytestring; diff --git a/sgx_tstd/src/untrusted/fs.rs b/sgx_tstd/src/untrusted/fs.rs new file mode 100644 index 000000000..726dd97c4 --- /dev/null +++ b/sgx_tstd/src/untrusted/fs.rs @@ -0,0 +1,30 @@ +// 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. + +//! Filesystem manipulation operations. +pub use fs::*; \ No newline at end of file diff --git a/sgx_tstd/src/untrusted/mod.rs b/sgx_tstd/src/untrusted/mod.rs new file mode 100644 index 000000000..19b7a1de0 --- /dev/null +++ b/sgx_tstd/src/untrusted/mod.rs @@ -0,0 +1,31 @@ +// 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. + +pub mod fs; +pub mod path; +pub mod time; diff --git a/sgx_tstd/src/untrusted/path.rs b/sgx_tstd/src/untrusted/path.rs new file mode 100644 index 000000000..21b787b3e --- /dev/null +++ b/sgx_tstd/src/untrusted/path.rs @@ -0,0 +1,124 @@ +// 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 untrusted::fs; +use io; +use path::Path; +use path::PathBuf; + +pub trait PathEx { + fn metadata(&self) -> io::Result; + fn symlink_metadata(&self) -> io::Result; + fn canonicalize(&self) -> io::Result; + fn read_link(&self) -> io::Result; + fn exists(&self) -> bool; + fn is_file(&self) -> bool; + fn is_dir(&self) -> bool; +} + +impl PathEx for Path { + /// Queries the file system to get information about a file, directory, etc. + /// + /// This function will traverse symbolic links to query information about the + /// destination file. + /// + /// This is an alias to [`fs::metadata`]. + /// + /// [`fs::metadata`]: ../fs/fn.metadata.html + /// + fn metadata(&self) -> io::Result { + fs::metadata(self) + } + + /// Queries the metadata about a file without following symlinks. + /// + /// This is an alias to [`fs::symlink_metadata`]. + /// + /// [`fs::symlink_metadata`]: ../fs/fn.symlink_metadata.html + /// + fn symlink_metadata(&self) -> io::Result { + fs::symlink_metadata(self) + } + + /// Returns the canonical form of the path with all intermediate components + /// normalized and symbolic links resolved. + /// + /// This is an alias to [`fs::canonicalize`]. + /// + /// [`fs::canonicalize`]: ../fs/fn.canonicalize.html + /// + fn canonicalize(&self) -> io::Result { + fs::canonicalize(self) + } + + /// Reads a symbolic link, returning the file that the link points to. + /// + /// This is an alias to [`fs::read_link`]. + /// + /// [`fs::read_link`]: ../fs/fn.read_link.html + /// + fn read_link(&self) -> io::Result { + fs::read_link(self) + } + + /// Returns whether the path points at an existing entity. + /// + /// This function will traverse symbolic links to query information about the + /// destination file. In case of broken symbolic links this will return `false`. + /// + /// If you cannot access the directory containing the file, e.g. because of a + /// permission error, this will return `false`. + /// + fn exists(&self) -> bool { + fs::metadata(self).is_ok() + } + + /// Returns whether the path exists on disk and is pointing at a regular file. + /// + /// This function will traverse symbolic links to query information about the + /// destination file. In case of broken symbolic links this will return `false`. + /// + /// If you cannot access the directory containing the file, e.g. because of a + /// permission error, this will return `false`. + /// + fn is_file(&self) -> bool { + fs::metadata(self).map(|m| m.is_file()).unwrap_or(false) + } + + /// Returns whether the path exists on disk and is pointing at a directory. + /// + /// This function will traverse symbolic links to query information about the + /// destination file. In case of broken symbolic links this will return `false`. + /// + /// If you cannot access the directory containing the file, e.g. because of a + /// permission error, this will return `false`. + /// + fn is_dir(&self) -> bool { + fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false) + } +} diff --git a/sgx_tstd/src/untrusted/time.rs b/sgx_tstd/src/untrusted/time.rs new file mode 100644 index 000000000..99723a231 --- /dev/null +++ b/sgx_tstd/src/untrusted/time.rs @@ -0,0 +1,92 @@ +// 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 core::mem; +use sys::time; +use time::{Instant, SystemTime, SystemTimeError, Duration}; + +pub trait InstantEx { + fn now() -> Instant; + fn elapsed(&self) -> Duration; +} + +impl InstantEx for Instant { + /// Returns an instant corresponding to "now". + /// + fn now() -> Instant { + let instant = inner::Instant(time::Instant::now()); + unsafe { mem::transmute(instant) } + } + + /// Returns the amount of time elapsed since this instant was created. + /// + /// # Panics + /// + /// This function may panic if the current time is earlier than this + /// instant, which is something that can happen if an `Instant` is + /// produced synthetically. + /// + fn elapsed(&self) -> Duration { + Instant::now() - *self + } +} + +pub trait SystemTimeEx { + fn now() -> SystemTime; + fn elapsed(&self) -> Result; +} + +impl SystemTimeEx for SystemTime { + /// Returns the system time corresponding to "now". + /// + fn now() -> SystemTime { + let systemtime = inner::SystemTime(time::SystemTime::now()); + unsafe { mem::transmute(systemtime) } + } + + /// Returns the amount of time elapsed since this system time was created. + /// + /// This function may fail as the underlying system clock is susceptible to + /// drift and updates (e.g. the system clock could go backwards), so this + /// function may not always succeed. If successful, [`Ok`]`(`[`Duration`]`)` is + /// returned where the duration represents the amount of time elapsed from + /// this time measurement to the current time. + /// + /// Returns an [`Err`] if `self` is later than the current system time, and + /// the error contains how far from the current system time `self` is. + /// + fn elapsed(&self) -> Result { + SystemTime::now().duration_since(*self) + } +} + +mod inner { + use sys::time; + pub struct Instant(pub time::Instant); + pub struct SystemTime(pub time::SystemTime); +} \ No newline at end of file diff --git a/sgx_tunittest/Cargo.toml b/sgx_tunittest/Cargo.toml index 9a92e887d..44e45bd48 100644 --- a/sgx_tunittest/Cargo.toml +++ b/sgx_tunittest/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tunittest" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_types/Cargo.toml b/sgx_types/Cargo.toml index cc550e16b..f7dfddb74 100644 --- a/sgx_types/Cargo.toml +++ b/sgx_types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_types" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/sgx_urts/Cargo.toml b/sgx_urts/Cargo.toml index 75840d71f..8d2e69944 100644 --- a/sgx_urts/Cargo.toml +++ b/sgx_urts/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_urts" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/third_party/rulinalg/Cargo.toml b/third_party/rulinalg/Cargo.toml index 76d8480f1..f0194dbca 100644 --- a/third_party/rulinalg/Cargo.toml +++ b/third_party/rulinalg/Cargo.toml @@ -15,7 +15,7 @@ license = "MIT" io = ["csv", "rustc-serialize"] [target.'cfg(not(target_env = "sgx"))'.dependencies] -sgx_tstd = { path = "../../sgx_tstd", features = ["untrusted_fs"] } +sgx_tstd = { path = "../../sgx_tstd" } [dependencies] num = {path = "../num", default-features = false } diff --git a/third_party/rulinalg/Xargo.toml b/third_party/rulinalg/Xargo.toml index 01d5cb056..ff4423196 100644 --- a/third_party/rulinalg/Xargo.toml +++ b/third_party/rulinalg/Xargo.toml @@ -10,7 +10,6 @@ stage = 1 [dependencies.std] path = "../../xargo/sgx_tstd" -features = ["untrusted_fs"] stage = 2 [dependencies.sgx_rand] diff --git a/third_party/rust-csv/Cargo.toml b/third_party/rust-csv/Cargo.toml index 17a7b23a9..b7b97fb96 100644 --- a/third_party/rust-csv/Cargo.toml +++ b/third_party/rust-csv/Cargo.toml @@ -19,7 +19,7 @@ appveyor = { repository = "BurntSushi/rust-csv" } bench = false [target.'cfg(not(target_env = "sgx"))'.dependencies] -sgx_tstd = { path = "../../sgx_tstd", features = ["untrusted_fs"] } +sgx_tstd = { path = "../../sgx_tstd" } [dependencies] csv-core = { path = "csv-core", version = "0.1.3" } diff --git a/third_party/rust-csv/Xargo.toml b/third_party/rust-csv/Xargo.toml index 01d5cb056..ff4423196 100644 --- a/third_party/rust-csv/Xargo.toml +++ b/third_party/rust-csv/Xargo.toml @@ -10,7 +10,6 @@ stage = 1 [dependencies.std] path = "../../xargo/sgx_tstd" -features = ["untrusted_fs"] stage = 2 [dependencies.sgx_rand] diff --git a/third_party/rust-csv/src/reader.rs b/third_party/rust-csv/src/reader.rs index 98ad5384b..8035bee12 100644 --- a/third_party/rust-csv/src/reader.rs +++ b/third_party/rust-csv/src/reader.rs @@ -1,4 +1,4 @@ -use std::fs::File; +use std::untrusted::fs::File; use std::boxed::*; use std::io::{self, BufRead, Seek}; use std::marker::PhantomData; diff --git a/third_party/rust-csv/src/writer.rs b/third_party/rust-csv/src/writer.rs index 020e5b8ae..cbfceca29 100644 --- a/third_party/rust-csv/src/writer.rs +++ b/third_party/rust-csv/src/writer.rs @@ -1,4 +1,4 @@ -use std::fs::File; +use std::untrusted::fs::File; use std::io; use std::path::Path; use std::result; diff --git a/third_party/rustls/Cargo.toml b/third_party/rustls/Cargo.toml index 9af0b31bf..4ff7e9c46 100644 --- a/third_party/rustls/Cargo.toml +++ b/third_party/rustls/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/ctz/rustls" categories = ["network-programming", "cryptography"] [target.'cfg(not(target_env = "sgx"))'.dependencies] -sgx_tstd = { path = "../../sgx_tstd", features = ["untrusted_time"] } +sgx_tstd = { path = "../../sgx_tstd" } [dependencies] untrusted = { version = "0.6", path = "../untrusted" } diff --git a/third_party/rustls/Xargo.toml b/third_party/rustls/Xargo.toml index ad7f49c30..ff4423196 100644 --- a/third_party/rustls/Xargo.toml +++ b/third_party/rustls/Xargo.toml @@ -10,7 +10,6 @@ stage = 1 [dependencies.std] path = "../../xargo/sgx_tstd" -features = ["untrusted_time"] stage = 2 [dependencies.sgx_rand] diff --git a/third_party/rustls/src/ticketer.rs b/third_party/rustls/src/ticketer.rs index bf3b0416b..ef3d415ab 100644 --- a/third_party/rustls/src/ticketer.rs +++ b/third_party/rustls/src/ticketer.rs @@ -9,6 +9,7 @@ use rand; use std::mem; use std::sync::{SgxMutex, Arc}; use std::time; +use std::untrusted::time::SystemTimeEx; use ring::aead; /// The timebase for expiring and rolling tickets and ticketing diff --git a/third_party/rustls/src/verify.rs b/third_party/rustls/src/verify.rs index e7d503621..2ec2a1c4b 100644 --- a/third_party/rustls/src/verify.rs +++ b/third_party/rustls/src/verify.rs @@ -6,6 +6,7 @@ use untrusted; use sct; use std; use std::sync::Arc; +use std::untrusted::time::SystemTimeEx; use key::Certificate; use msgs::handshake::DigitallySignedStruct; diff --git a/third_party/rusty-machine/Cargo.toml b/third_party/rusty-machine/Cargo.toml index 5c7382d9e..f741d0f73 100644 --- a/third_party/rusty-machine/Cargo.toml +++ b/third_party/rusty-machine/Cargo.toml @@ -16,7 +16,7 @@ stats = [] datasets = [] [target.'cfg(not(target_env = "sgx"))'.dependencies] -sgx_tstd = { path = "../../sgx_tstd", features = ["untrusted_fs"] } +sgx_tstd = { path = "../../sgx_tstd" } sgx_rand = { path = "../../sgx_rand"} [dependencies] diff --git a/third_party/rusty-machine/Xargo.toml b/third_party/rusty-machine/Xargo.toml index 01d5cb056..ff4423196 100644 --- a/third_party/rusty-machine/Xargo.toml +++ b/third_party/rusty-machine/Xargo.toml @@ -10,7 +10,6 @@ stage = 1 [dependencies.std] path = "../../xargo/sgx_tstd" -features = ["untrusted_fs"] stage = 2 [dependencies.sgx_rand] diff --git a/third_party/webpki/Cargo.toml b/third_party/webpki/Cargo.toml index a7822354d..c1c1dc3b4 100644 --- a/third_party/webpki/Cargo.toml +++ b/third_party/webpki/Cargo.toml @@ -63,7 +63,7 @@ trust_anchor_util = ["std"] std = [] [target.'cfg(not(target_env = "sgx"))'.dependencies] -sgx_tstd = { path = "../../sgx_tstd", features = ["untrusted_time"] } +sgx_tstd = { path = "../../sgx_tstd" } [dependencies] ring = { path = "../ring" } diff --git a/third_party/webpki/Xargo.toml b/third_party/webpki/Xargo.toml index ad7f49c30..ff4423196 100644 --- a/third_party/webpki/Xargo.toml +++ b/third_party/webpki/Xargo.toml @@ -10,7 +10,6 @@ stage = 1 [dependencies.std] path = "../../xargo/sgx_tstd" -features = ["untrusted_time"] stage = 2 [dependencies.sgx_rand] diff --git a/xargo/sgx_rand/Cargo.toml b/xargo/sgx_rand/Cargo.toml index b14cdbf5c..fd9c13fb0 100644 --- a/xargo/sgx_rand/Cargo.toml +++ b/xargo/sgx_rand/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_rand" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/xargo/sgx_serialize/Cargo.toml b/xargo/sgx_serialize/Cargo.toml index e0ea5a2a7..39d7ffdb1 100644 --- a/xargo/sgx_serialize/Cargo.toml +++ b/xargo/sgx_serialize/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_serialize" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib] diff --git a/xargo/sgx_tstd/Cargo.toml b/xargo/sgx_tstd/Cargo.toml index 84a8a4dfa..1892eaf9b 100644 --- a/xargo/sgx_tstd/Cargo.toml +++ b/xargo/sgx_tstd/Cargo.toml @@ -13,8 +13,8 @@ crate-type = ["rlib"] default = ["stdio"] backtrace = ["stdio"] stdio = [] +net = [] untrusted_fs = [] -untrusted_net = [] untrusted_time = [] [build-dependencies] diff --git a/xargo/sgx_tunittest/Cargo.toml b/xargo/sgx_tunittest/Cargo.toml index 8de1cd7ce..2b11b6ef5 100644 --- a/xargo/sgx_tunittest/Cargo.toml +++ b/xargo/sgx_tunittest/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgx_tunittest" -version = "0.9.6" +version = "0.9.7" authors = ["Baidu"] [lib]