diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..4618d389 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,5 @@ +# https://rust-lang.github.io/rustfmt/ + +imports_layout = "HorizontalVertical" +imports_granularity = "Module" +group_imports = "StdExternalCrate" diff --git a/rtc_data_enclave/src/data_upload.rs b/rtc_data_enclave/src/data_upload.rs index 5ca4c567..2dfd25de 100644 --- a/rtc_data_enclave/src/data_upload.rs +++ b/rtc_data_enclave/src/data_upload.rs @@ -1,14 +1,17 @@ +use std::prelude::v1::*; + use rand::prelude::*; -use rtc_tenclave::crypto::RtcCrypto; -use rtc_tenclave::crypto::SodaBoxCrypto as Crypto; +use rtc_tenclave::crypto::{RtcCrypto, SodaBoxCrypto as Crypto}; use rtc_tenclave::util; -use rtc_types::DataUploadError as DataError; -use rtc_types::UploadMetadata as Metadata; -use rtc_types::{CryptoError, DataUploadResponse}; +use rtc_types::{ + CryptoError, + DataUploadError as DataError, + DataUploadResponse, + UploadMetadata as Metadata, +}; use secrecy::{ExposeSecret, Zeroize}; use sgx_tseal::SgxSealedData; use sgx_types::*; -use std::prelude::v1::*; use uuid::Uuid; pub struct SealedResult { diff --git a/rtc_data_enclave/src/lib.rs b/rtc_data_enclave/src/lib.rs index 205f0dcc..f6e047dc 100644 --- a/rtc_data_enclave/src/lib.rs +++ b/rtc_data_enclave/src/lib.rs @@ -15,12 +15,12 @@ mod data_upload; mod ocalls; use core::slice; -use rtc_types::*; -use sgx_types::*; use std::prelude::v1::*; #[allow(unused_imports)] // for ECALL linking use rtc_tenclave::enclave::enclave_create_report; +use rtc_types::*; +use sgx_types::*; /// Validates and save a payload encrypted for the enclave /// diff --git a/rtc_data_enclave/src/ocalls.rs b/rtc_data_enclave/src/ocalls.rs index 512849be..69ebb93b 100644 --- a/rtc_data_enclave/src/ocalls.rs +++ b/rtc_data_enclave/src/ocalls.rs @@ -1,5 +1,6 @@ -use sgx_types::*; use std::boxed::Box; + +use sgx_types::*; use uuid::Uuid; extern "C" { diff --git a/rtc_data_service/http_server/src/main.rs b/rtc_data_service/http_server/src/main.rs index 05a83bec..f99020a3 100644 --- a/rtc_data_service/http_server/src/main.rs +++ b/rtc_data_service/http_server/src/main.rs @@ -5,6 +5,13 @@ mod tls; +use std::sync::Arc; + +use actix::{Arbiter, Supervisor}; +use actix_cors::Cors; +use actix_web::http::header; +use actix_web::web::{self, Data}; +use actix_web::{App, HttpServer}; use rtc_data_service::app_config::AppConfig; use rtc_data_service::auth_enclave_actor::AuthEnclaveActor; use rtc_data_service::data_enclave_actor::DataEnclaveActor; @@ -14,16 +21,6 @@ use rtc_data_service::exec_enclave_actor::ExecEnclaveActor; use rtc_data_service::exec_token::*; use rtc_data_service::handlers::*; -use std::sync::Arc; - -use actix::{Arbiter, Supervisor}; -use actix_cors::Cors; -use actix_web::{ - http::header, - web::{self, Data}, - App, HttpServer, -}; - #[actix_web::main] async fn main() -> std::io::Result<()> { let config = AppConfig::new().expect("Server config expected"); diff --git a/rtc_data_service/http_server/src/tls.rs b/rtc_data_service/http_server/src/tls.rs index 47e6f709..53d0dbd8 100644 --- a/rtc_data_service/http_server/src/tls.rs +++ b/rtc_data_service/http_server/src/tls.rs @@ -1,15 +1,17 @@ +use std::io::BufReader; +use std::{fs, io, iter}; + use rtc_data_service::app_config::TlsConfig; use rustls::{ - AllowAnyAuthenticatedClient, NoClientAuth, PrivateKey, RootCertStore, + AllowAnyAuthenticatedClient, + NoClientAuth, + PrivateKey, + RootCertStore, ServerConfig as TlsServerConfig, }; use rustls_pemfile::{self, read_one, Item}; use thiserror::Error; -use std::io::BufReader; -use std::iter; -use std::{fs, io}; - pub fn get_tls_server_config(config: TlsConfig) -> Result { let client_auth = match config.client_cert_path { Some(path) => { diff --git a/rtc_data_service/src/app_config.rs b/rtc_data_service/src/app_config.rs index 1f1b1b6b..e3471b8d 100644 --- a/rtc_data_service/src/app_config.rs +++ b/rtc_data_service/src/app_config.rs @@ -1,7 +1,8 @@ +use std::env; + use config::{Config, ConfigError, Environment, File}; use rtc_uenclave::EnclaveConfig; use serde::Deserialize; -use std::env; // Configuration specific to the server #[derive(Deserialize, Clone, Default)] diff --git a/rtc_data_service/src/auth_enclave_actor.rs b/rtc_data_service/src/auth_enclave_actor.rs index d246c45c..0628e91f 100644 --- a/rtc_data_service/src/auth_enclave_actor.rs +++ b/rtc_data_service/src/auth_enclave_actor.rs @@ -3,9 +3,10 @@ //! TODO: The `*_enclave_actor` modules currently mirror each other, //! and should be kept in sync until we factor out the shared code. +use std::sync::Arc; + use actix::prelude::*; use rtc_uenclave::{AttestationError, EnclaveConfig, RtcAuthEnclave}; -use std::sync::Arc; #[derive(Default)] pub(crate) struct RequestAttestation; diff --git a/rtc_data_service/src/data_enclave_actor.rs b/rtc_data_service/src/data_enclave_actor.rs index 884a0ad8..c8f2fe63 100644 --- a/rtc_data_service/src/data_enclave_actor.rs +++ b/rtc_data_service/src/data_enclave_actor.rs @@ -3,9 +3,10 @@ //! TODO: The `*_enclave_actor` modules currently mirror each other, //! and should be kept in sync until we factor out the shared code. +use std::sync::Arc; + use actix::prelude::*; use rtc_uenclave::{AttestationError, EnclaveConfig, RtcDataEnclave}; -use std::sync::Arc; #[derive(Default)] pub(crate) struct RequestAttestation; diff --git a/rtc_data_service/src/data_upload/message.rs b/rtc_data_service/src/data_upload/message.rs index 4569a304..6ead76c8 100644 --- a/rtc_data_service/src/data_upload/message.rs +++ b/rtc_data_service/src/data_upload/message.rs @@ -1,7 +1,8 @@ -use crate::data_enclave_actor::DataEnclaveActor; use actix::{Handler, Message}; use rtc_types::{DataUploadError, DataUploadResponse, EcallError, UploadMetadata}; +use crate::data_enclave_actor::DataEnclaveActor; + pub struct DataUploadMessage { pub metadata: UploadMetadata, pub payload: Box<[u8]>, diff --git a/rtc_data_service/src/data_upload/service.rs b/rtc_data_service/src/data_upload/service.rs index e5d8b250..e5988411 100644 --- a/rtc_data_service/src/data_upload/service.rs +++ b/rtc_data_service/src/data_upload/service.rs @@ -1,14 +1,15 @@ +use std::convert::TryInto; + use actix::{Addr, MailboxError}; -use actix_web::{error::ErrorInternalServerError, post, web}; +use actix_web::error::ErrorInternalServerError; +use actix_web::{post, web}; use models::*; use rtc_types::{DataUploadError, DataUploadResponse, EcallError}; +use super::DataUploadMessage; use crate::data_enclave_actor::DataEnclaveActor; use crate::merge_error::*; -use super::DataUploadMessage; -use std::convert::TryInto; - /// Save uploaded data file using a [`DataUploadMessage`] for [`DataEnclaveActor`]. /// /// * Request: POST [`RequestBody`] @@ -34,13 +35,14 @@ pub async fn upload_file( } pub mod models { - use crate::validation::ValidationError; - use crate::Base64Standard; + use std::convert::TryFrom; + use rtc_types::{DataUploadResponse, UploadMetadata}; use serde::{Deserialize, Serialize}; - use std::convert::TryFrom; use crate::data_upload::DataUploadMessage; + use crate::validation::ValidationError; + use crate::Base64Standard; #[derive(Serialize, Deserialize, Debug)] pub struct RequestBody { diff --git a/rtc_data_service/src/exec/message.rs b/rtc_data_service/src/exec/message.rs index 479c6e8d..343bdb65 100644 --- a/rtc_data_service/src/exec/message.rs +++ b/rtc_data_service/src/exec/message.rs @@ -1,8 +1,9 @@ use std::convert::Infallible; -use crate::exec_enclave_actor::ExecEnclaveActor; use actix::{Handler, Message}; +use crate::exec_enclave_actor::ExecEnclaveActor; + // TODO: Replace with types from rtc_types pub(crate) type RequestExecutionResponse = (); pub(crate) type RequestExecutionError = Infallible; diff --git a/rtc_data_service/src/exec/service.rs b/rtc_data_service/src/exec/service.rs index 08bd3af0..5be93ccb 100644 --- a/rtc_data_service/src/exec/service.rs +++ b/rtc_data_service/src/exec/service.rs @@ -1,14 +1,13 @@ use std::convert::TryInto; use actix::{Addr, MailboxError}; -use actix_web::{error::ErrorInternalServerError, post, web}; +use actix_web::error::ErrorInternalServerError; +use actix_web::{post, web}; use models::*; -use crate::{ - exec::{RequestExecutionError, RequestExecutionMessage, RequestExecutionResponse}, - exec_enclave_actor::ExecEnclaveActor, - merge_error::*, -}; +use crate::exec::{RequestExecutionError, RequestExecutionMessage, RequestExecutionResponse}; +use crate::exec_enclave_actor::ExecEnclaveActor; +use crate::merge_error::*; /// Request execution using an execution token #[post("/exec/request")] @@ -27,11 +26,13 @@ pub async fn request_execution( } pub mod models { + use std::convert::TryFrom; + + use serde::{Deserialize, Serialize}; + use crate::exec::{RequestExecutionMessage, RequestExecutionResponse}; use crate::validation::ValidationError; use crate::Base64Standard; - use serde::{Deserialize, Serialize}; - use std::convert::TryFrom; #[derive(Serialize, Deserialize, Debug)] pub struct Metadata { diff --git a/rtc_data_service/src/exec_enclave_actor.rs b/rtc_data_service/src/exec_enclave_actor.rs index 96773611..18d46f4e 100644 --- a/rtc_data_service/src/exec_enclave_actor.rs +++ b/rtc_data_service/src/exec_enclave_actor.rs @@ -3,9 +3,10 @@ //! TODO: The `*_enclave_actor` modules currently mirror each other, //! and should be kept in sync until we factor out the shared code. +use std::sync::Arc; + use actix::prelude::*; use rtc_uenclave::{AttestationError, EnclaveConfig, RtcExecEnclave}; -use std::sync::Arc; #[derive(Default)] pub(crate) struct RequestAttestation; diff --git a/rtc_data_service/src/exec_token/message.rs b/rtc_data_service/src/exec_token/message.rs index e6cd7cee..c6b926b3 100644 --- a/rtc_data_service/src/exec_token/message.rs +++ b/rtc_data_service/src/exec_token/message.rs @@ -1,7 +1,8 @@ -use crate::data_enclave_actor::DataEnclaveActor; use actix::{Handler, Message}; use rtc_types::{ExecReqMetadata, ExecTokenError, ExecTokenResponse}; +use crate::data_enclave_actor::DataEnclaveActor; + // TODO : Change struct values to resemble request Body (add data access key, uuid, hash, keypair, nonce..) pub struct ExecTokenMessage { pub metadata: ExecReqMetadata, diff --git a/rtc_data_service/src/exec_token/service.rs b/rtc_data_service/src/exec_token/service.rs index 609498dd..94b0be76 100644 --- a/rtc_data_service/src/exec_token/service.rs +++ b/rtc_data_service/src/exec_token/service.rs @@ -1,15 +1,15 @@ use std::convert::TryInto; use actix::{Addr, MailboxError}; -use actix_web::{error::ErrorInternalServerError, post, web, HttpRequest}; +use actix_web::error::ErrorInternalServerError; +use actix_web::{post, web, HttpRequest}; use models::*; use rtc_types::{ExecTokenError, ExecTokenResponse}; +use super::ExecTokenMessage; use crate::data_enclave_actor::DataEnclaveActor; use crate::merge_error::*; -use super::ExecTokenMessage; - #[post("auth/tokens")] pub async fn req_exec_token( _req: HttpRequest, @@ -27,13 +27,14 @@ pub async fn req_exec_token( } pub mod models { - use crate::validation::ValidationError; - use crate::Base64Standard; + use std::convert::TryFrom; + use rtc_types::{ExecReqMetadata, ExecTokenResponse}; use serde::{Deserialize, Serialize}; - use std::convert::TryFrom; use crate::exec_token::ExecTokenMessage; + use crate::validation::ValidationError; + use crate::Base64Standard; #[derive(Serialize, Deserialize, Debug)] pub struct RequestBody { diff --git a/rtc_data_service/src/handlers.rs b/rtc_data_service/src/handlers.rs index adbd44c9..1fcad676 100644 --- a/rtc_data_service/src/handlers.rs +++ b/rtc_data_service/src/handlers.rs @@ -1,14 +1,13 @@ use actix::Addr; -use actix_web::{error::ErrorInternalServerError, get, web, HttpRequest, HttpResponse}; +use actix_web::error::ErrorInternalServerError; +use actix_web::{get, web, HttpRequest, HttpResponse}; use models::Status; -use crate::auth_enclave_actor; use crate::auth_enclave_actor::AuthEnclaveActor; -use crate::data_enclave_actor; use crate::data_enclave_actor::DataEnclaveActor; -use crate::exec_enclave_actor; use crate::exec_enclave_actor::ExecEnclaveActor; use crate::merge_error::*; +use crate::{auth_enclave_actor, data_enclave_actor, exec_enclave_actor}; pub async fn server_status(_req: HttpRequest) -> HttpResponse { HttpResponse::Ok().json(Status { diff --git a/rtc_data_service/src/merge_error.rs b/rtc_data_service/src/merge_error.rs index 8b5d6725..83034e91 100644 --- a/rtc_data_service/src/merge_error.rs +++ b/rtc_data_service/src/merge_error.rs @@ -1,5 +1,4 @@ -use std::fmt::Debug; -use std::fmt::Display; +use std::fmt::{Debug, Display}; // TODO: Pull this into the rtc_types library? diff --git a/rtc_data_service/tests/helpers/mod.rs b/rtc_data_service/tests/helpers/mod.rs index 43f9f32f..7be06d6b 100644 --- a/rtc_data_service/tests/helpers/mod.rs +++ b/rtc_data_service/tests/helpers/mod.rs @@ -6,9 +6,6 @@ use std::sync::Arc; use actix::Actor; use actix_web::App; - -use rtc_uenclave::{EnclaveConfig, RtcAuthEnclave, RtcDataEnclave}; - use rtc_data_service::auth_enclave_actor::AuthEnclaveActor; use rtc_data_service::data_enclave_actor::DataEnclaveActor; use rtc_data_service::data_upload::upload_file; @@ -16,6 +13,7 @@ use rtc_data_service::exec::request_execution; use rtc_data_service::exec_enclave_actor::ExecEnclaveActor; use rtc_data_service::exec_token::req_exec_token; use rtc_data_service::handlers; +use rtc_uenclave::{EnclaveConfig, RtcAuthEnclave, RtcDataEnclave}; /// Initialise an auth enclave for testing. pub(crate) fn init_auth_enclave() -> RtcAuthEnclave { diff --git a/rtc_data_service/tests/web_api/data_upload.rs b/rtc_data_service/tests/web_api/data_upload.rs index 00cd8bef..276ff54f 100644 --- a/rtc_data_service/tests/web_api/data_upload.rs +++ b/rtc_data_service/tests/web_api/data_upload.rs @@ -3,18 +3,13 @@ use std::convert::TryInto; use std::path::Path; -use sgx_types::sgx_target_info_t; - use actix_web::test; -use uuid::Uuid; - use rtc_data_service::data_upload::models; - -use crate::helpers; +use sgx_types::sgx_target_info_t; +use uuid::Uuid; // See rtc_tenclave/src/crypto.rs -use crate::CRYPTO_BOX_BOXZEROBYTES; -use crate::CRYPTO_BOX_ZEROBYTES; +use crate::{helpers, CRYPTO_BOX_BOXZEROBYTES, CRYPTO_BOX_ZEROBYTES}; /// Upload some data, decrypt and check the result. #[actix_rt::test] diff --git a/rtc_data_service/tests/web_api/exec.rs b/rtc_data_service/tests/web_api/exec.rs index c80af91f..67c18206 100644 --- a/rtc_data_service/tests/web_api/exec.rs +++ b/rtc_data_service/tests/web_api/exec.rs @@ -2,7 +2,6 @@ use actix_web::web::Bytes; use actix_web::{http, test}; - use rtc_data_service::exec; use crate::helpers; diff --git a/rtc_data_service/tests/web_api/exec_token.rs b/rtc_data_service/tests/web_api/exec_token.rs index 0a9acdc8..b0b5cb36 100644 --- a/rtc_data_service/tests/web_api/exec_token.rs +++ b/rtc_data_service/tests/web_api/exec_token.rs @@ -2,7 +2,6 @@ use actix_web::web::Bytes; use actix_web::{http, test}; - use rtc_data_service::exec_token; use crate::helpers; diff --git a/rtc_tenclave/src/crypto.rs b/rtc_tenclave/src/crypto.rs index 4acf844b..80e9a62b 100644 --- a/rtc_tenclave/src/crypto.rs +++ b/rtc_tenclave/src/crypto.rs @@ -1,13 +1,13 @@ +use std::convert::TryInto; +use std::prelude::v1::*; + use rand::prelude::*; -use rtc_types::EncryptedMessage; -use rtc_types::{CryptoError as Error, SizedEncryptedMessage}; +use rtc_types::{CryptoError as Error, EncryptedMessage, SizedEncryptedMessage}; use secrecy::{ExposeSecret, Secret}; -use sgx_types::*; -use std::{convert::TryInto, prelude::v1::*}; -use zeroize::Zeroize; - #[cfg(not(test))] use sgx_tse::{rsgx_get_key, rsgx_self_report}; +use sgx_types::*; +use zeroize::Zeroize; // FIXME: sodalite should expose these padding constants. // Values referenced from https://tweetnacl.cr.yp.to/20140427/tweetnacl.h diff --git a/rtc_tenclave/src/dh/protected_channel.rs b/rtc_tenclave/src/dh/protected_channel.rs index 33fe8769..f3d14f3e 100644 --- a/rtc_tenclave/src/dh/protected_channel.rs +++ b/rtc_tenclave/src/dh/protected_channel.rs @@ -1,18 +1,16 @@ //! Secure symmetric communication channels based on [`sgx_tcrypto`]'s AES-GCM. +use rtc_types::enclave_messages::{EncryptedEnclaveMessage, RecommendedAesGcmIv}; use secrecy::{ExposeSecret, Secret}; use sgx_tcrypto::{rsgx_rijndael128GCM_decrypt, rsgx_rijndael128GCM_encrypt}; +#[cfg(not(test))] +use sgx_tstd::enclave; use sgx_types::*; -use rtc_types::enclave_messages::{EncryptedEnclaveMessage, RecommendedAesGcmIv}; - -use super::types::AlignedKey; -use crate::util::concat_u8; - #[cfg(test)] use super::enclave; -#[cfg(not(test))] -use sgx_tstd::enclave; +use super::types::AlignedKey; +use crate::util::concat_u8; pub struct ProtectedChannel { iv_constructor: DeterministicAesGcmIvConstructor, diff --git a/rtc_tenclave/src/dh/sessions.rs b/rtc_tenclave/src/dh/sessions.rs index aa829cca..2edde967 100644 --- a/rtc_tenclave/src/dh/sessions.rs +++ b/rtc_tenclave/src/dh/sessions.rs @@ -2,27 +2,27 @@ use std::collections::HashMap; use std::marker::PhantomData; use std::prelude::v1::*; use std::sync::Arc; +#[cfg(test)] +use std::sync::{Mutex, RwLock, RwLockWriteGuard}; use once_cell::sync::OnceCell; use rtc_types::dh::{ExchangeReportResult, SessionRequestResult}; use rtc_types::enclave_messages::errors::AcquireSessionError; use secrecy::Secret; -use sgx_types::*; - -pub use super::protected_channel::ProtectedChannel; -use super::types::{AlignedKey, RtcDhInitiator, RtcDhResponder}; - #[cfg(not(test))] use sgx_tstd::enclave; #[cfg(not(test))] use sgx_tstd::sync::{ - SgxMutex as Mutex, SgxRwLock as RwLock, SgxRwLockWriteGuard as RwLockWriteGuard, + SgxMutex as Mutex, + SgxRwLock as RwLock, + SgxRwLockWriteGuard as RwLockWriteGuard, }; +use sgx_types::*; #[cfg(test)] use super::enclave; -#[cfg(test)] -use std::sync::{Mutex, RwLock, RwLockWriteGuard}; +pub use super::protected_channel::ProtectedChannel; +use super::types::{AlignedKey, RtcDhInitiator, RtcDhResponder}; extern "C" { pub fn rtc_session_request_u( @@ -322,15 +322,15 @@ fn verify_peer_enclave_trust(peer_identity: &sgx_dh_session_enclave_identity_t) #[cfg(not(test))] pub use sgx_impl::dh_sessions; - #[cfg(test)] pub use test::dh_sessions; #[cfg(not(test))] mod sgx_impl { - use super::*; use sgx_tdh::{SgxDhInitiator, SgxDhResponder}; + use super::*; + pub fn dh_sessions() -> &'static DhSessions { // NOTE: Something similar can be done in the OCALL library // (by storing pointers to data inside the enclave, outside of the enclave) diff --git a/rtc_tenclave/src/dh/types.rs b/rtc_tenclave/src/dh/types.rs index 3988f798..235ebcfd 100644 --- a/rtc_tenclave/src/dh/types.rs +++ b/rtc_tenclave/src/dh/types.rs @@ -1,8 +1,7 @@ -use secrecy::{Secret, Zeroize}; -use sgx_types::*; - #[cfg(test)] use mockall::automock; +use secrecy::{Secret, Zeroize}; +use sgx_types::*; pub struct AlignedKey(sgx_align_key_128bit_t); @@ -53,10 +52,11 @@ pub trait RtcDhResponder { #[cfg(not(test))] pub mod impl_sgx { - use super::*; use sgx_tdh::{SgxDhInitiator, SgxDhMsg3, SgxDhResponder}; use sgx_tstd::mem; + use super::*; + impl RtcDhInitiator for SgxDhInitiator { fn init_session() -> Self { SgxDhInitiator::init_session() diff --git a/rtc_tenclave/src/enclave.rs b/rtc_tenclave/src/enclave.rs index 06e04592..4c9fdc1e 100644 --- a/rtc_tenclave/src/enclave.rs +++ b/rtc_tenclave/src/enclave.rs @@ -1,14 +1,13 @@ -use crate::crypto::{RtcCrypto, SodaBoxCrypto}; +#[cfg(test)] +use mock::mock_rsgx_create_report as rsgx_create_report; use rtc_types::{CreateReportResult, EnclaveHeldData, ENCLAVE_HELD_PUB_KEY_SIZE}; use secrecy::Zeroize; use sgx_tcrypto::rsgx_sha256_slice; -use sgx_types::*; - #[cfg(not(test))] use sgx_tse::rsgx_create_report; +use sgx_types::*; -#[cfg(test)] -use mock::mock_rsgx_create_report as rsgx_create_report; +use crate::crypto::{RtcCrypto, SodaBoxCrypto}; fn create_report_impl( qe_target_info: &sgx_target_info_t, diff --git a/rtc_tenclave/src/kv_store/fs/inspect.rs b/rtc_tenclave/src/kv_store/fs/inspect.rs index f49ccb06..56a97a30 100644 --- a/rtc_tenclave/src/kv_store/fs/inspect.rs +++ b/rtc_tenclave/src/kv_store/fs/inspect.rs @@ -5,18 +5,17 @@ use std::ffi::OsStr; use std::fs::DirEntry; use std::io; use std::iter::Iterator; +use std::path::PathBuf; use serde::de::DeserializeOwned; use serde::Serialize; +use super::std_filer::StdFiler; +use super::FsStore; use crate::kv_store::fs::decode_from_fs_safe; use crate::kv_store::inspect::InspectStore; use crate::kv_store::KvStore; -use super::std_filer::StdFiler; -use super::FsStore; -use std::path::PathBuf; - impl InspectStore for FsStore where V: Serialize + DeserializeOwned, diff --git a/rtc_tenclave/src/kv_store/fs/mod.rs b/rtc_tenclave/src/kv_store/fs/mod.rs index 18968e1f..0ae5ebe0 100644 --- a/rtc_tenclave/src/kv_store/fs/mod.rs +++ b/rtc_tenclave/src/kv_store/fs/mod.rs @@ -5,21 +5,18 @@ pub mod std_filer; #[cfg(not(test))] pub mod sgx_filer; -#[cfg(not(test))] -pub use sgx_filer::SgxFiler; - // sgx_tstd (v1.1.3) does not support `fs::read_dir`, so limit the following to tests, for now. // // See: https://github.com/apache/incubator-teaclave-sgx-sdk/blob/v1.1.3/release_notes.md#partially-supported-modstraits-in-sgx_tstd - -#[cfg(not(test))] -use std::prelude::v1::*; - use std::io; use std::path::{Path, PathBuf}; +#[cfg(not(test))] +use std::prelude::v1::*; use serde::de::DeserializeOwned; use serde::Serialize; +#[cfg(not(test))] +pub use sgx_filer::SgxFiler; use super::KvStore; @@ -139,8 +136,7 @@ mod inspect; mod tests { use proptest::prelude::*; - use super::decode_from_fs_safe; - use super::encode_to_fs_safe; + use super::{decode_from_fs_safe, encode_to_fs_safe}; /// [`encode_to_fs_safe`] encodes to filesystem-safe, and [`decode_from_fs_safe`] round-trips. #[test] diff --git a/rtc_tenclave/src/kv_store/fs/sgx_filer.rs b/rtc_tenclave/src/kv_store/fs/sgx_filer.rs index feaf696b..de40bac4 100644 --- a/rtc_tenclave/src/kv_store/fs/sgx_filer.rs +++ b/rtc_tenclave/src/kv_store/fs/sgx_filer.rs @@ -1,11 +1,9 @@ //! [`SgxFile`] support -use std::prelude::v1::Vec; - use std::io::ErrorKind::NotFound; -use std::io::Result; -use std::io::Write; +use std::io::{Result, Write}; use std::path::Path; +use std::prelude::v1::Vec; use sgx_tstd::sgxfs; use sgx_tstd::sgxfs::SgxFile; diff --git a/rtc_tenclave/src/kv_store/fs/std_filer.rs b/rtc_tenclave/src/kv_store/fs/std_filer.rs index 0a147d9f..e65774da 100644 --- a/rtc_tenclave/src/kv_store/fs/std_filer.rs +++ b/rtc_tenclave/src/kv_store/fs/std_filer.rs @@ -1,13 +1,9 @@ //! [`File`] support -use std::prelude::v1::Vec; - use std::io::ErrorKind::NotFound; -use std::io::Result; -use std::io::Write; - +use std::io::{Result, Write}; use std::path::Path; - +use std::prelude::v1::Vec; // Under sgx_tstd, fs needs the std::untrusted prefix: #[cfg(not(test))] use std::untrusted::{fs, fs::File}; diff --git a/rtc_tenclave/src/kv_store/in_memory.rs b/rtc_tenclave/src/kv_store/in_memory.rs index 93122353..81820d86 100644 --- a/rtc_tenclave/src/kv_store/in_memory.rs +++ b/rtc_tenclave/src/kv_store/in_memory.rs @@ -1,10 +1,11 @@ //! In-memory implementations of [`KvStore`] (for testing) -use serde::de::DeserializeOwned; -use serde::Serialize; use std::collections::HashMap; use std::prelude::v1::*; +use serde::de::DeserializeOwned; +use serde::Serialize; + use super::KvStore; /// In-memory [`KvStore`] using [`HashMap`] diff --git a/rtc_tenclave/src/kv_store/inspect.rs b/rtc_tenclave/src/kv_store/inspect.rs index b37ec8dc..f24ef3f6 100644 --- a/rtc_tenclave/src/kv_store/inspect.rs +++ b/rtc_tenclave/src/kv_store/inspect.rs @@ -1,10 +1,9 @@ //! Support for inspecting [`KvStore`] instances (for testing and debugging) -#[cfg(not(test))] -use std::prelude::v1::*; - use std::borrow::ToOwned; use std::collections::HashMap; +#[cfg(not(test))] +use std::prelude::v1::*; use serde::de::DeserializeOwned; use serde::Serialize; diff --git a/rtc_tenclave/src/kv_store/tests.rs b/rtc_tenclave/src/kv_store/tests.rs index 14a4b45f..1198f783 100644 --- a/rtc_tenclave/src/kv_store/tests.rs +++ b/rtc_tenclave/src/kv_store/tests.rs @@ -1,15 +1,15 @@ //! Tests for [`rtc_tenclave::kv_store`] +use std::collections::HashMap; #[cfg(not(test))] use std::prelude::v1::*; -use std::collections::HashMap; - use proptest::prelude::*; use proptest::test_runner::TestCaseResult; use tempfile::TempDir; -use super::fs::{std_filer::StdFiler, FsStore}; +use super::fs::std_filer::StdFiler; +use super::fs::FsStore; use super::in_memory::{InMemoryJsonStore, InMemoryStore}; use super::inspect::InspectStore; use super::KvStore; diff --git a/rtc_types/src/byte_formats/rkyv_format.rs b/rtc_types/src/byte_formats/rkyv_format.rs index 6eba3d9b..d0a1579d 100644 --- a/rtc_types/src/byte_formats/rkyv_format.rs +++ b/rtc_types/src/byte_formats/rkyv_format.rs @@ -2,14 +2,9 @@ use core::mem::size_of; -use rkyv::{ - archived_root, - ser::{ - serializers::{BufferSerializer, BufferSerializerError}, - Serializer, - }, - Aligned, Archive, Deserialize, Infallible, Serialize, Unreachable, -}; +use rkyv::ser::serializers::{BufferSerializer, BufferSerializerError}; +use rkyv::ser::Serializer; +use rkyv::{archived_root, Aligned, Archive, Deserialize, Infallible, Serialize, Unreachable}; pub fn write_array(value: &T) -> Result<[u8; size_of::()], BufferSerializerError> where @@ -57,13 +52,12 @@ where mod tests { use core::mem::{size_of, size_of_val}; + use proptest::prelude::*; + use proptest_derive::Arbitrary; use rkyv::{Archive, Deserialize, Serialize}; use super::*; - use proptest::prelude::*; - use proptest_derive::Arbitrary; - /// Arbitrary structure to test with. #[derive( Debug, diff --git a/rtc_types/src/data_upload.rs b/rtc_types/src/data_upload.rs index 70ee3f3b..b21f6f39 100644 --- a/rtc_types/src/data_upload.rs +++ b/rtc_types/src/data_upload.rs @@ -1,7 +1,8 @@ -use super::*; use thiserror; use thiserror::Error; +use super::*; + #[repr(C)] #[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Debug, Error)] pub enum DataUploadError { diff --git a/rtc_types/src/dh.rs b/rtc_types/src/dh.rs index d4dac2a3..23907164 100644 --- a/rtc_types/src/dh.rs +++ b/rtc_types/src/dh.rs @@ -1,6 +1,7 @@ -use crate::EcallResult; use sgx_types::*; +use crate::EcallResult; + pub type SessionRequestResult = EcallResult; pub type ExchangeReportResult = EcallResult; diff --git a/rtc_types/src/lib.rs b/rtc_types/src/lib.rs index e3c46650..84a118a6 100644 --- a/rtc_types/src/lib.rs +++ b/rtc_types/src/lib.rs @@ -12,12 +12,11 @@ extern crate thiserror; #[cfg(feature = "teaclave_sgx")] extern crate thiserror_sgx as thiserror; +use std::boxed::Box; use std::fmt::Display; -use thiserror::Error; use sgx_types::*; - -use std::boxed::Box; +use thiserror::Error; mod data_upload; pub mod dh; diff --git a/rtc_udh/src/lib.rs b/rtc_udh/src/lib.rs index bfee8573..3e064dd7 100644 --- a/rtc_udh/src/lib.rs +++ b/rtc_udh/src/lib.rs @@ -1,19 +1,15 @@ mod responder; -use std::{ - collections::HashMap, - sync::{Arc, Mutex, RwLock}, -}; +use std::collections::hash_map::Entry; +use std::collections::HashMap; +use std::sync::{Arc, Mutex, RwLock}; use once_cell::sync::OnceCell; use responder::Responder; pub use responder::ResponderSys; -use rtc_types::{ - dh::{ExchangeReportResult, SessionRequestResult}, - EcallResult, -}; +use rtc_types::dh::{ExchangeReportResult, SessionRequestResult}; +use rtc_types::EcallResult; use sgx_types::*; -use std::collections::hash_map::Entry; type SyncSendResponder = Arc>; diff --git a/rtc_udh/src/responder.rs b/rtc_udh/src/responder.rs index 0629d337..d0528c55 100644 --- a/rtc_udh/src/responder.rs +++ b/rtc_udh/src/responder.rs @@ -1,7 +1,5 @@ -use rtc_types::{ - dh::{ExchangeReportResult, SessionRequestResult}, - EcallResult, -}; +use rtc_types::dh::{ExchangeReportResult, SessionRequestResult}; +use rtc_types::EcallResult; use sgx_types::*; pub trait ResponderSys: Send { diff --git a/rtc_uenclave/auth-sys/build.rs b/rtc_uenclave/auth-sys/build.rs index 81e40bdd..a62a2188 100644 --- a/rtc_uenclave/auth-sys/build.rs +++ b/rtc_uenclave/auth-sys/build.rs @@ -1,7 +1,8 @@ +use std::env; +use std::path::{Path, PathBuf}; + use bindgen::{self, CodegenConfig}; use cc; -use std::path::PathBuf; -use std::{env, path::Path}; fn main() { let sdk_dir = env::var("SGX_SDK").unwrap_or_else(|_| "/opt/sgxsdk".to_string()); diff --git a/rtc_uenclave/auth-sys/src/lib.rs b/rtc_uenclave/auth-sys/src/lib.rs index 1b9ceca6..13234a1a 100644 --- a/rtc_uenclave/auth-sys/src/lib.rs +++ b/rtc_uenclave/auth-sys/src/lib.rs @@ -1,11 +1,10 @@ -#[allow(unused_imports)] -pub use sgx_urts; - use rtc_ecalls::RtcEnclaveEcalls; use rtc_types::dh::*; use rtc_types::*; use rtc_udh; use sgx_types::*; +#[allow(unused_imports)] +pub use sgx_urts; pub mod ffi { use super::*; diff --git a/rtc_uenclave/data-ocalls/src/lib.rs b/rtc_uenclave/data-ocalls/src/lib.rs index 82d30945..56d57e62 100644 --- a/rtc_uenclave/data-ocalls/src/lib.rs +++ b/rtc_uenclave/data-ocalls/src/lib.rs @@ -1,12 +1,11 @@ #![deny(unsafe_op_in_unsafe_fn)] -use std::fs; use std::fs::OpenOptions; use std::io::Write; -use std::slice; -use uuid::Uuid; +use std::{fs, slice}; use sgx_types::*; +use uuid::Uuid; /// Saves a blob of data received from the enclave /// diff --git a/rtc_uenclave/data-sys/build.rs b/rtc_uenclave/data-sys/build.rs index 8f413937..478c55e5 100644 --- a/rtc_uenclave/data-sys/build.rs +++ b/rtc_uenclave/data-sys/build.rs @@ -1,7 +1,8 @@ +use std::env; +use std::path::{Path, PathBuf}; + use bindgen::{self, CodegenConfig}; use cc; -use std::path::PathBuf; -use std::{env, path::Path}; fn main() { let sdk_dir = env::var("SGX_SDK").unwrap_or_else(|_| "/opt/sgxsdk".to_string()); diff --git a/rtc_uenclave/data-sys/src/lib.rs b/rtc_uenclave/data-sys/src/lib.rs index 76cc786d..90ca8fd6 100644 --- a/rtc_uenclave/data-sys/src/lib.rs +++ b/rtc_uenclave/data-sys/src/lib.rs @@ -5,14 +5,13 @@ #[allow(unused_imports)] use data_ocalls; -#[allow(unused_imports)] -use sgx_urts; - use rtc_ecalls::RtcEnclaveEcalls; use rtc_types::dh::*; use rtc_types::*; use rtc_udh; use sgx_types::*; +#[allow(unused_imports)] +use sgx_urts; pub mod ffi { use super::*; diff --git a/rtc_uenclave/exec-sys/build.rs b/rtc_uenclave/exec-sys/build.rs index bb6d8143..fef5aa96 100644 --- a/rtc_uenclave/exec-sys/build.rs +++ b/rtc_uenclave/exec-sys/build.rs @@ -1,7 +1,8 @@ +use std::env; +use std::path::{Path, PathBuf}; + use bindgen::{self, CodegenConfig}; use cc; -use std::path::PathBuf; -use std::{env, path::Path}; fn main() { let sdk_dir = env::var("SGX_SDK").unwrap_or_else(|_| "/opt/sgxsdk".to_string()); diff --git a/rtc_uenclave/exec-sys/src/lib.rs b/rtc_uenclave/exec-sys/src/lib.rs index 1daf0722..64e4a266 100644 --- a/rtc_uenclave/exec-sys/src/lib.rs +++ b/rtc_uenclave/exec-sys/src/lib.rs @@ -1,11 +1,10 @@ -#[allow(unused_imports)] -pub use sgx_urts; - use rtc_ecalls::RtcEnclaveEcalls; use rtc_types::dh::*; use rtc_types::*; use rtc_udh; use sgx_types::*; +#[allow(unused_imports)] +pub use sgx_urts; pub mod ffi { use super::*; diff --git a/rtc_uenclave/src/azure_attestation.rs b/rtc_uenclave/src/azure_attestation.rs index aa5030e1..b7689842 100644 --- a/rtc_uenclave/src/azure_attestation.rs +++ b/rtc_uenclave/src/azure_attestation.rs @@ -1,13 +1,14 @@ // TODO: Change some of this to use https://github.com/Azure/azure-sdk-for-rust // once the api have been stabilized -use crate::http_client::HttpClient; -use crate::http_client::HttpRequestError; +use std::time::Duration; + use base64::{self, encode_config}; use serde::{Deserialize, Serialize}; -use std::time::Duration; use ureq::AgentBuilder; +use crate::http_client::{HttpClient, HttpRequestError}; + // Types from: https://docs.microsoft.com/en-us/rest/api/attestation/attestation/attestsgxenclave#definitions #[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)] pub struct QuoteRuntimeData { @@ -80,10 +81,10 @@ pub(crate) struct AttestationResponse { #[cfg(test)] mod test { - use crate::http_client::MockHttpClient; use base64::decode_config; use super::*; + use crate::http_client::MockHttpClient; #[test] fn from_quote_works() { diff --git a/rtc_uenclave/src/ecalls.rs b/rtc_uenclave/src/ecalls.rs index 8090d259..7529a94f 100644 --- a/rtc_uenclave/src/ecalls.rs +++ b/rtc_uenclave/src/ecalls.rs @@ -4,7 +4,6 @@ use mockall::automock; use mockall::mock; #[cfg(test)] use mockall::predicate::*; - use rtc_ecalls::RtcEnclaveEcalls; use rtc_types::*; use sgx_types::*; @@ -68,9 +67,10 @@ impl RtcEcalls for T { #[cfg(test)] mod test { - use super::*; use rtc_ecalls::MockRtcEnclaveEcalls; + use super::*; + #[test] fn it_works() { let eid = 12u64; diff --git a/rtc_uenclave/src/enclaves/rtc_auth.rs b/rtc_uenclave/src/enclaves/rtc_auth.rs index 579a706c..a1fd4552 100644 --- a/rtc_uenclave/src/enclaves/rtc_auth.rs +++ b/rtc_uenclave/src/enclaves/rtc_auth.rs @@ -1,10 +1,11 @@ use std::borrow::Borrow; -use crate::{AttestationError, EnclaveConfig, EnclaveReportResult, RtcEnclave}; use auth_sys::AuthSys; use rtc_types::{EcallError, EncryptedMessage, ExecReqMetadata, ExecTokenError}; use sgx_types::*; +use crate::{AttestationError, EnclaveConfig, EnclaveReportResult, RtcEnclave}; + /// Wraps all the functionality for interacting with the auth enclave pub struct RtcAuthEnclave(RtcEnclave) where diff --git a/rtc_uenclave/src/enclaves/rtc_exec.rs b/rtc_uenclave/src/enclaves/rtc_exec.rs index 492f8dec..d9baead8 100644 --- a/rtc_uenclave/src/enclaves/rtc_exec.rs +++ b/rtc_uenclave/src/enclaves/rtc_exec.rs @@ -1,9 +1,10 @@ use std::borrow::Borrow; -use crate::{AttestationError, EnclaveConfig, EnclaveReportResult, RtcEnclave}; use exec_sys::ExecSys; use sgx_types::*; +use crate::{AttestationError, EnclaveConfig, EnclaveReportResult, RtcEnclave}; + /// Wraps all the functionality for interacting with the exec enclave pub struct RtcExecEnclave(RtcEnclave) where diff --git a/rtc_uenclave/src/http_client.rs b/rtc_uenclave/src/http_client.rs index 701cb30b..97d15d24 100644 --- a/rtc_uenclave/src/http_client.rs +++ b/rtc_uenclave/src/http_client.rs @@ -1,12 +1,11 @@ +#[cfg(test)] +use mockall::*; use serde::de::DeserializeOwned; use serde::Serialize; use thiserror::Error; use ureq; use ureq::Agent; -#[cfg(test)] -use mockall::*; - // 200 KB const ERR_RESPONSE_READ_LIMIT: usize = 200 * 1_024; diff --git a/rtc_uenclave/src/quote.rs b/rtc_uenclave/src/quote.rs index f4805a8f..11b96cd8 100644 --- a/rtc_uenclave/src/quote.rs +++ b/rtc_uenclave/src/quote.rs @@ -26,7 +26,6 @@ mod qe_functions { #[cfg(test)] use self::mock_qe_functions::*; - #[cfg(not(test))] use self::qe_functions::*; diff --git a/rtc_uenclave/src/rtc_enclave.rs b/rtc_uenclave/src/rtc_enclave.rs index 0f76b553..61681a41 100644 --- a/rtc_uenclave/src/rtc_enclave.rs +++ b/rtc_uenclave/src/rtc_enclave.rs @@ -1,8 +1,5 @@ use std::borrow::Borrow; -use crate::{ - azure_attestation::AttestSgxEnclaveRequest, ecalls::RtcEcalls, http_client::HttpRequestError, -}; use ecalls::EnclaveReportResult; #[cfg(test)] use mockall::predicate::*; @@ -12,22 +9,22 @@ use mockall_double::double; use rtc_udh::{self, ResponderSys}; use serde::Deserialize; use sgx_types::*; -use thiserror::Error; - -use crate::{ecalls, CreateReportError}; - -#[double] -use crate::quote::QuotingEnclave; - -#[cfg(test)] -pub use self::MockSgxEnclave as SgxEnclave; #[cfg(not(test))] pub use sgx_urts::SgxEnclave; +use thiserror::Error; #[cfg(test)] use self::MockAzureAttestationClient as AzureAttestationClient; +#[cfg(test)] +pub use self::MockSgxEnclave as SgxEnclave; +use crate::azure_attestation::AttestSgxEnclaveRequest; #[cfg(not(test))] use crate::azure_attestation::AzureAttestationClient; +use crate::ecalls::RtcEcalls; +use crate::http_client::HttpRequestError; +#[double] +use crate::quote::QuotingEnclave; +use crate::{ecalls, CreateReportError}; /// Configuration for a RtcEnclave #[derive(Default, Clone, Deserialize, Debug)] @@ -206,19 +203,24 @@ mock! { #[cfg(test)] mod tests { - use super::*; - use crate::azure_attestation::AttestationResponse; + use std::convert::TryInto; + use num_bigint; use num_traits::FromPrimitive; use proptest::collection::size_range; use proptest::prelude::*; use rtc_ecalls::MockRtcEnclaveEcalls; use rtc_types::dh::{ExchangeReportResult, SessionRequestResult}; - use rtc_types::CreateReportResult; - use rtc_types::EnclaveHeldData; - use rtc_types::{ENCLAVE_HELD_DATA_SIZE, RSA3072_PKCS8_DER_SIZE}; + use rtc_types::{ + CreateReportResult, + EnclaveHeldData, + ENCLAVE_HELD_DATA_SIZE, + RSA3072_PKCS8_DER_SIZE, + }; use simple_asn1::{to_der, ASN1Block, BigInt, BigUint, OID}; - use std::convert::TryInto; + + use super::*; + use crate::azure_attestation::AttestationResponse; mock! { TEcalls {}