You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2020/01/05 04:41:08 UTC

[incubator-teaclave] branch develop updated: [rpc] Add SgxTrustedTlsServerConfig struct to new server config

This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/develop by this push:
     new de77d49  [rpc] Add SgxTrustedTlsServerConfig struct to new server config
de77d49 is described below

commit de77d49f148da97591e6eb173b5baa9fd3e2705a
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Sat Jan 4 20:39:09 2020 -0800

    [rpc] Add SgxTrustedTlsServerConfig struct to new server config
---
 attestation/src/lib.rs                              |  1 -
 attestation/src/rpc.rs                              | 16 ----------------
 rpc/src/config.rs                                   | 21 +++++++++++++++++++++
 rpc/src/lib.rs                                      |  1 +
 rpc/src/server.rs                                   |  6 +++---
 .../teaclave_frontend/sgx_trusted_lib/src/lib.rs    | 11 +++++------
 6 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/attestation/src/lib.rs b/attestation/src/lib.rs
index 2758967..036f46f 100644
--- a/attestation/src/lib.rs
+++ b/attestation/src/lib.rs
@@ -35,7 +35,6 @@ pub enum AttestationError {
 #[macro_use]
 mod cert;
 pub mod quote;
-pub mod rpc;
 pub mod verifier;
 
 use cfg_if::cfg_if;
diff --git a/attestation/src/rpc.rs b/attestation/src/rpc.rs
deleted file mode 100644
index c351f9f..0000000
--- a/attestation/src/rpc.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use anyhow::Result;
-use rustls;
-use std::prelude::v1::*;
-
-pub fn new_tls_server_config_without_verifier(
-    cert: Vec<u8>,
-    key_der: Vec<u8>,
-) -> Result<rustls::ServerConfig> {
-    let cert_chain = vec![rustls::Certificate(cert)];
-    let key_der = rustls::PrivateKey(key_der);
-    let client_cert_verifier = rustls::NoClientAuth::new();
-    let mut config = rustls::ServerConfig::new(client_cert_verifier);
-    config.set_single_cert(cert_chain, key_der)?;
-
-    Ok(config)
-}
diff --git a/rpc/src/config.rs b/rpc/src/config.rs
new file mode 100644
index 0000000..fc07d05
--- /dev/null
+++ b/rpc/src/config.rs
@@ -0,0 +1,21 @@
+use anyhow::Result;
+use rustls;
+use std::sync::Arc;
+
+pub struct SgxTrustedTlsServerConfig {
+    pub config: Arc<rustls::ServerConfig>,
+}
+
+impl SgxTrustedTlsServerConfig {
+    pub fn new_without_verifier(cert: &[u8], key_der: &[u8]) -> Result<Self> {
+        let cert_chain = vec![rustls::Certificate(cert.to_vec())];
+        let key_der = rustls::PrivateKey(key_der.to_vec());
+        let client_cert_verifier = rustls::NoClientAuth::new();
+        let mut config = rustls::ServerConfig::new(client_cert_verifier);
+        config.set_single_cert(cert_chain, key_der)?;
+
+        Ok(Self {
+            config: Arc::new(config),
+        })
+    }
+}
diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs
index 2d98f24..c3d5db7 100644
--- a/rpc/src/lib.rs
+++ b/rpc/src/lib.rs
@@ -15,6 +15,7 @@ where
 }
 
 pub mod channel;
+pub mod config;
 mod protocol;
 pub mod server;
 mod transport;
diff --git a/rpc/src/server.rs b/rpc/src/server.rs
index 03e2404..0d59ac4 100644
--- a/rpc/src/server.rs
+++ b/rpc/src/server.rs
@@ -8,11 +8,11 @@ cfg_if! {
 
 #[cfg(feature = "mesalock_sgx")]
 mod sgx_trusted_tls {
+    use crate::config::SgxTrustedTlsServerConfig;
     use crate::transport::{ServerTransport, SgxTrustedTlsTransport};
     use crate::TeaclaveService;
     use anyhow::Result;
     use serde::{Deserialize, Serialize};
-    use std::sync::Arc;
 
     pub struct SgxTrustedTlsServer<U, V>
     where
@@ -41,9 +41,9 @@ mod sgx_trusted_tls {
 
         pub fn new_with_config(
             stream: std::net::TcpStream,
-            server_config: &Arc<rustls::ServerConfig>,
+            server_config: &SgxTrustedTlsServerConfig,
         ) -> SgxTrustedTlsServer<U, V> {
-            let session = rustls::ServerSession::new(server_config);
+            let session = rustls::ServerSession::new(&server_config.config);
             let stream = rustls::StreamOwned::new(session, stream);
             Self::new(stream)
         }
diff --git a/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs b/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs
index 56af6ef..e05bbec 100644
--- a/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs
+++ b/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs
@@ -42,7 +42,6 @@ use teaclave_service_sgx_utils;
 
 use std::net::TcpStream;
 use std::sync::mpsc;
-use std::sync::Arc;
 
 use lazy_static::lazy_static;
 use std::os::raw::c_int;
@@ -50,6 +49,7 @@ use std::sync::SgxMutex as Mutex;
 use teaclave_attestation;
 use teaclave_attestation::RemoteAttestation;
 use teaclave_frontend_proto::*;
+use teaclave_rpc::config::SgxTrustedTlsServerConfig;
 use teaclave_rpc::server::SgxTrustedTlsServer;
 
 mod service;
@@ -82,17 +82,16 @@ fn handle_start_service(_args: &StartServiceInput) -> Result<StartServiceOutput>
             &config::runtime_config().env.ias_spid,
         )
         .unwrap();
-        let config = teaclave_attestation::rpc::new_tls_server_config_without_verifier(
-            attestation.cert,
-            attestation.private_key,
+        let config = SgxTrustedTlsServerConfig::new_without_verifier(
+            &attestation.cert,
+            &attestation.private_key,
         )
         .unwrap();
-        let rc_config = Arc::new(config);
 
         let mut server = SgxTrustedTlsServer::<
             proto::TeaclaveFrontendResponse,
             proto::TeaclaveFrontendRequest,
-        >::new_with_config(stream, &rc_config);
+        >::new_with_config(stream, &config);
         match server.start(service::TeaclaveFrontendService) {
             Ok(_) => (),
             Err(e) => {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org