Skip to content

Commit d0b2c27

Browse files
committed
Cleanup uneeded read/write interfaces, rename remote http to remote TLS
1 parent 7e61149 commit d0b2c27

File tree

10 files changed

+376
-368
lines changed

10 files changed

+376
-368
lines changed
Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use core::panic;
2-
use std::{io::{Read, Write}, sync::Arc};
2+
use std::{
3+
io::{Read, Write},
4+
sync::Arc,
5+
};
36

47
use borsh::{BorshDeserialize, BorshSerialize};
5-
use integration::PivotRemoteHttpMsg;
8+
use integration::PivotRemoteTlsMsg;
69
use qos_core::{
710
io::{SocketAddress, TimeVal},
811
server::{RequestProcessor, SocketServer},
@@ -16,19 +19,17 @@ struct Processor {
1619

1720
impl Processor {
1821
fn new(proxy_address: String) -> Self {
19-
Processor {
20-
net_proxy: SocketAddress::new_unix(&proxy_address)
21-
}
22+
Processor { net_proxy: SocketAddress::new_unix(&proxy_address) }
2223
}
2324
}
2425

2526
impl RequestProcessor for Processor {
2627
fn process(&mut self, request: Vec<u8>) -> Vec<u8> {
27-
let msg = PivotRemoteHttpMsg::try_from_slice(&request)
28+
let msg = PivotRemoteTlsMsg::try_from_slice(&request)
2829
.expect("Received invalid message - test is broken!");
2930

3031
match msg {
31-
PivotRemoteHttpMsg::RemoteHttpRequest{ host, path } => {
32+
PivotRemoteTlsMsg::RemoteTlsRequest { host, path } => {
3233
let timeout = TimeVal::new(1, 0);
3334
let mut stream = RemoteStream::new_by_name(
3435
&self.net_proxy,
@@ -37,19 +38,24 @@ impl RequestProcessor for Processor {
3738
443,
3839
vec!["8.8.8.8".to_string()],
3940
53,
40-
).unwrap();
41+
)
42+
.unwrap();
4143

42-
let root_store =
43-
RootCertStore { roots: webpki_roots::TLS_SERVER_ROOTS.into() };
44+
let root_store = RootCertStore {
45+
roots: webpki_roots::TLS_SERVER_ROOTS.into(),
46+
};
4447

4548
let server_name: rustls::pki_types::ServerName<'_> =
4649
host.clone().try_into().unwrap();
47-
let config: rustls::ClientConfig = rustls::ClientConfig::builder()
48-
.with_root_certificates(root_store)
49-
.with_no_client_auth();
50-
let mut conn =
51-
rustls::ClientConnection::new(Arc::new(config), server_name)
52-
.unwrap();
50+
let config: rustls::ClientConfig =
51+
rustls::ClientConfig::builder()
52+
.with_root_certificates(root_store)
53+
.with_no_client_auth();
54+
let mut conn = rustls::ClientConnection::new(
55+
Arc::new(config),
56+
server_name,
57+
)
58+
.unwrap();
5359
let mut tls = rustls::Stream::new(&mut conn, &mut stream);
5460

5561
let http_request = format!(
@@ -62,19 +68,21 @@ impl RequestProcessor for Processor {
6268

6369
println!("=== current ciphersuite: {:?}", ciphersuite.suite());
6470
let mut response_bytes = Vec::new();
65-
let read_to_end_result: usize = tls.read_to_end(&mut response_bytes).unwrap();
71+
let read_to_end_result: usize =
72+
tls.read_to_end(&mut response_bytes).unwrap();
6673

6774
// Ignore eof errors: https://docs.rs/rustls/latest/rustls/manual/_03_howto/index.html#unexpected-eof
6875

69-
let fetched_content = std::str::from_utf8(&response_bytes).unwrap();
70-
PivotRemoteHttpMsg::RemoteHttpResponse(format!(
76+
let fetched_content =
77+
std::str::from_utf8(&response_bytes).unwrap();
78+
PivotRemoteTlsMsg::RemoteTlsResponse(format!(
7179
"Content fetched successfully ({read_to_end_result} bytes): {fetched_content}"
7280
))
7381
.try_to_vec()
74-
.expect("RemoteHttpResponse is valid borsh")
82+
.expect("RemoteTlsResponse is valid borsh")
7583
}
76-
PivotRemoteHttpMsg::RemoteHttpResponse(_) => {
77-
panic!("Unexpected RemoteHttpResponse - test is broken")
84+
PivotRemoteTlsMsg::RemoteTlsResponse(_) => {
85+
panic!("Unexpected RemoteTlsResponse - test is broken")
7886
}
7987
}
8088
}
@@ -85,12 +93,13 @@ fn main() {
8593
// - first argument is the socket to bind to (server)
8694
// - second argument is the socket to query (net proxy)
8795
let args: Vec<String> = std::env::args().collect();
88-
96+
8997
let socket_path: &String = &args[1];
9098
let proxy_path: &String = &args[2];
91-
99+
92100
SocketServer::listen(
93101
SocketAddress::new_unix(socket_path),
94102
Processor::new(proxy_path.to_string()),
95-
).unwrap();
103+
)
104+
.unwrap();
96105
}

src/integration/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub const PIVOT_ABORT_PATH: &str = "../target/debug/pivot_abort";
2626
/// Path to pivot panic for tests.
2727
pub const PIVOT_PANIC_PATH: &str = "../target/debug/pivot_panic";
2828
/// Path to an enclave app that has routes to test remote connection features.
29-
pub const PIVOT_REMOTE_HTTP_PATH: &str = "../target/debug/pivot_remote_http";
29+
pub const PIVOT_REMOTE_TLS_PATH: &str = "../target/debug/pivot_remote_tls";
3030
/// Path to an enclave app that has routes to test remote connection features.
3131
pub const QOS_NET_PATH: &str = "../target/debug/qos_net";
3232
/// Path to an enclave app that has routes to stress our socket.
@@ -59,18 +59,19 @@ pub enum PivotSocketStressMsg {
5959

6060
/// Request/Response messages for "socket stress" pivot app.
6161
#[derive(BorshDeserialize, BorshSerialize, Debug, PartialEq, Eq)]
62-
pub enum PivotRemoteHttpMsg {
62+
pub enum PivotRemoteTlsMsg {
6363
/// Request a remote host / port to be fetched over the socket.
64-
/// We assume the port to be 443, and we use Google's servers to perform DNS resolution (8.8.8.8)
65-
RemoteHttpRequest {
64+
/// We assume the port to be 443, and we use Google's servers to perform
65+
/// DNS resolution (8.8.8.8)
66+
RemoteTlsRequest {
6667
/// Hostname (e.g. "api.turnkey.com")
6768
host: String,
6869
/// Path to fetch (e.g. "/health")
6970
path: String,
7071
},
71-
/// A successful response to [`Self::RemoteHttpRequest`] with the contents
72+
/// A successful response to [`Self::RemoteTlsRequest`] with the contents
7273
/// of the response.
73-
RemoteHttpResponse(String),
74+
RemoteTlsResponse(String),
7475
}
7576

7677
struct PivotParser;

src/integration/tests/remote_http.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use std::{process::Command, str};
2+
3+
use borsh::BorshSerialize;
4+
use integration::{PivotRemoteTlsMsg, PIVOT_REMOTE_TLS_PATH, QOS_NET_PATH};
5+
use qos_core::{
6+
client::Client,
7+
io::{SocketAddress, TimeVal, TimeValLike},
8+
protocol::ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS,
9+
};
10+
use qos_test_primitives::ChildWrapper;
11+
12+
const REMOTE_TLS_TEST_NET_PROXY_SOCKET: &str = "/tmp/remote_tls_test.net.sock";
13+
const REMOTE_TLS_TEST_ENCLAVE_SOCKET: &str =
14+
"/tmp/remote_tls_test.enclave.sock";
15+
16+
#[test]
17+
fn fetch_remote_tls_content() {
18+
let _net_proxy: ChildWrapper = Command::new(QOS_NET_PATH)
19+
.arg("--usock")
20+
.arg(REMOTE_TLS_TEST_NET_PROXY_SOCKET)
21+
.spawn()
22+
.unwrap()
23+
.into();
24+
25+
let _enclave_app: ChildWrapper = Command::new(PIVOT_REMOTE_TLS_PATH)
26+
.arg(REMOTE_TLS_TEST_ENCLAVE_SOCKET)
27+
.arg(REMOTE_TLS_TEST_NET_PROXY_SOCKET)
28+
.spawn()
29+
.unwrap()
30+
.into();
31+
32+
let enclave_client = Client::new(
33+
SocketAddress::new_unix(REMOTE_TLS_TEST_ENCLAVE_SOCKET),
34+
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS),
35+
);
36+
37+
let app_request = PivotRemoteTlsMsg::RemoteTlsRequest {
38+
host: "api.turnkey.com".to_string(),
39+
path: "/health".to_string(),
40+
}
41+
.try_to_vec()
42+
.unwrap();
43+
44+
let response = enclave_client.send(&app_request).unwrap();
45+
let response_text = str::from_utf8(&response).unwrap();
46+
47+
assert!(response_text.contains("Content fetched successfully"));
48+
assert!(response_text.contains("HTTP/1.1 200 OK"));
49+
assert!(response_text.contains("currentTime"));
50+
}

src/qos_core/src/io/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
mod stream;
77

88
pub use stream::{
9-
Listener, Stream,
10-
SocketAddress, TimeVal, TimeValLike, VMADDR_FLAG_TO_HOST, VMADDR_NO_FLAGS,
9+
Listener, SocketAddress, Stream, TimeVal, TimeValLike, VMADDR_FLAG_TO_HOST,
10+
VMADDR_NO_FLAGS,
1111
};
1212

1313
/// QOS I/O error

src/qos_core/src/io/stream.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl SocketAddress {
9090
}
9191

9292
/// Get the `AddressFamily` of the socket.
93+
#[must_use]
9394
pub fn family(&self) -> AddressFamily {
9495
match *self {
9596
#[cfg(feature = "vm")]
@@ -99,6 +100,7 @@ impl SocketAddress {
99100
}
100101

101102
/// Convenience method for accessing the wrapped address
103+
#[must_use]
102104
pub fn addr(&self) -> Box<dyn SockaddrLike> {
103105
match *self {
104106
#[cfg(feature = "vm")]
@@ -114,7 +116,7 @@ pub struct Stream {
114116
}
115117

116118
impl Stream {
117-
/// Create a new `Stream` from a SocketAddress and a timeout
119+
/// Create a new `Stream` from a `SocketAddress` and a timeout
118120
pub fn connect(
119121
addr: &SocketAddress,
120122
timeout: TimeVal,

src/qos_net/src/error.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ pub enum ProtocolError {
3131
RemoteConnectionClosed,
3232
/// Happens if a RemoteRead response has empty data
3333
RemoteReadEmpty,
34-
/// Happens if a RemoteRead returns too much data for the provided buffer and the data doesn't fit.
35-
/// The first `usize` is the size of the received data, the second `usize` is the size of the buffer.
34+
/// Happens if a RemoteRead returns too much data for the provided buffer
35+
/// and the data doesn't fit. The first `usize` is the size of the received
36+
/// data, the second `usize` is the size of the buffer.
3637
RemoteReadOverflow(usize, usize),
3738
}
3839

0 commit comments

Comments
 (0)