Skip to content

Commit 514cc8c

Browse files
committed
Bunch of renaming and comment updates
1 parent d0b2c27 commit 514cc8c

File tree

14 files changed

+576
-731
lines changed

14 files changed

+576
-731
lines changed

src/Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/integration/src/bin/pivot_remote_tls.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use qos_core::{
1010
io::{SocketAddress, TimeVal},
1111
server::{RequestProcessor, SocketServer},
1212
};
13-
use qos_net::remote_stream::RemoteStream;
13+
use qos_net::proxy_stream::ProxyStream;
1414
use rustls::RootCertStore;
1515

1616
struct Processor {
@@ -31,7 +31,7 @@ impl RequestProcessor for Processor {
3131
match msg {
3232
PivotRemoteTlsMsg::RemoteTlsRequest { host, path } => {
3333
let timeout = TimeVal::new(1, 0);
34-
let mut stream = RemoteStream::new_by_name(
34+
let mut stream = ProxyStream::connect_by_name(
3535
&self.net_proxy,
3636
timeout,
3737
host.clone(),
@@ -61,12 +61,10 @@ impl RequestProcessor for Processor {
6161
let http_request = format!(
6262
"GET {path} HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\n\r\n"
6363
);
64-
println!("=== making HTTP request: \n{http_request}");
6564

6665
tls.write_all(http_request.as_bytes()).unwrap();
67-
let ciphersuite = tls.conn.negotiated_cipher_suite().unwrap();
66+
let _ciphersuite = tls.conn.negotiated_cipher_suite().unwrap();
6867

69-
println!("=== current ciphersuite: {:?}", ciphersuite.suite());
7068
let mut response_bytes = Vec::new();
7169
let read_to_end_result: usize =
7270
tls.read_to_end(&mut response_bytes).unwrap();
@@ -90,8 +88,8 @@ impl RequestProcessor for Processor {
9088

9189
fn main() {
9290
// Parse args:
93-
// - first argument is the socket to bind to (server)
94-
// - second argument is the socket to query (net proxy)
91+
// - first argument is the socket to bind to (normal server server)
92+
// - second argument is the socket to use for remote proxying
9593
let args: Vec<String> = std::env::args().collect();
9694

9795
let socket_path: &String = &args[1];

src/qos_core/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ aws-nitro-enclaves-nsm-api = { version = "0.3", default-features = false }
2020
serde_bytes = { version = "0.11", default-features = false }
2121
serde = { version = "1", features = ["derive"], default-features = false }
2222

23-
hickory-resolver = { version = "0.24.1", features = ["tokio-runtime"], default-features = false, optional = true}
24-
rand = { version = "0.8.5", default-features = false, optional = true }
2523
[dev-dependencies]
2624
qos_test_primitives = { path = "../qos_test_primitives" }
2725
qos_p256 = { path = "../qos_p256", features = ["mock"] }

src/qos_core/src/io/stream.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Stream {
201201
&mut buf[received_bytes..len],
202202
MsgFlags::empty(),
203203
) {
204-
Ok(size) if size == 0 => {
204+
Ok(0) => {
205205
return Err(IOError::RecvConnectionClosed);
206206
}
207207
Ok(size) => size,
@@ -234,7 +234,7 @@ impl Stream {
234234
&mut buf[received_bytes..length],
235235
MsgFlags::empty(),
236236
) {
237-
Ok(size) if size == 0 => {
237+
Ok(0) => {
238238
return Err(IOError::RecvConnectionClosed);
239239
}
240240
Ok(size) => size,
@@ -257,7 +257,7 @@ impl Stream {
257257
impl Read for Stream {
258258
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
259259
match recv(self.fd, buf, MsgFlags::empty()) {
260-
Ok(size) if size == 0 => Err(std::io::Error::new(
260+
Ok(0) => Err(std::io::Error::new(
261261
ErrorKind::ConnectionAborted,
262262
"read 0 bytes",
263263
)),
@@ -270,7 +270,7 @@ impl Read for Stream {
270270
impl Write for Stream {
271271
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
272272
match send(self.fd, buf, MsgFlags::empty()) {
273-
Ok(size) if size == 0 => Err(std::io::Error::new(
273+
Ok(0) => Err(std::io::Error::new(
274274
ErrorKind::ConnectionAborted,
275275
"wrote 0 bytes",
276276
)),
@@ -398,8 +398,10 @@ mod test {
398398
assert_eq!(data, resp);
399399
}
400400

401+
// TODO: replace this test with something simpler. Local socket which does a
402+
// simple echo?
401403
#[test]
402-
fn stream_implement_reader_writer_interfaces() {
404+
fn stream_implement_read_write_traits() {
403405
let host = "api.turnkey.com";
404406
let path = "/health";
405407

src/qos_core/src/protocol/error.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//! Quorum protocol error
2-
use std::net::AddrParseError;
3-
42
use borsh::{BorshDeserialize, BorshSerialize};
53
use qos_p256::P256Error;
64

@@ -143,8 +141,6 @@ pub enum ProtocolError {
143141
/// The new manifest was different from the old manifest when we expected
144142
/// them to be the same because they have the same nonce
145143
DifferentManifest,
146-
/// Parsing error with a protocol message component
147-
ParseError(String),
148144
}
149145

150146
impl From<std::io::Error> for ProtocolError {
@@ -188,10 +184,3 @@ impl From<qos_nsm::nitro::AttestError> for ProtocolError {
188184
Self::QosAttestError(msg)
189185
}
190186
}
191-
192-
impl From<AddrParseError> for ProtocolError {
193-
fn from(err: AddrParseError) -> Self {
194-
let msg = format!("{err:?}");
195-
Self::ParseError(msg)
196-
}
197-
}

src/qos_core/src/protocol/msg.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -138,55 +138,6 @@ pub enum ProtocolMsg {
138138
/// if the manifest envelope does not exist.
139139
manifest_envelope: Box<Option<ManifestEnvelope>>,
140140
},
141-
142-
/// Request from the enclave app to open a TCP connection to a remote host
143-
/// This results in a new remote connection saved in protocol state
144-
RemoteOpenRequest {
145-
/// The hostname to connect to, e.g. "www.googleapis.com"
146-
hostname: String,
147-
/// e.g. 443
148-
port: u16,
149-
/// An array of DNS resolvers e.g. ["8.8.8.8", "8.8.4.4"]
150-
dns_resolvers: Vec<String>,
151-
/// Port number to perform DNS resolution, e.g. 53
152-
dns_port: u16,
153-
},
154-
/// Response for `OpenTcpConnectionRequest`
155-
RemoteOpenResponse {
156-
/// Connection ID to reference the opened connection when used with
157-
/// `RemoteRequest` and `RemoteResponse`. TODO: maybe we reply with a
158-
/// fd name directly? Not sure what this ID will map to.
159-
connection_id: u32,
160-
},
161-
/// Read from a remote connection
162-
RemoteReadRequest {
163-
/// A connection ID from `RemoteOpenResponse`
164-
connection_id: u32,
165-
/// number of bytes to read
166-
size: usize,
167-
},
168-
/// Response to `RemoteReadRequest` containing read data
169-
RemoteReadResponse {
170-
/// A connection ID from `RemoteOpenResponse`
171-
connection_id: u32,
172-
/// number of bytes read
173-
data: Vec<u8>,
174-
},
175-
/// Write to a remote connection
176-
RemoteWriteRequest {
177-
/// A connection ID from `RemoteOpenResponse`
178-
connection_id: u32,
179-
/// Data to be sent
180-
data: Vec<u8>,
181-
},
182-
/// Response to `RemoteWriteRequest` containing the number of successfully
183-
/// written bytes.
184-
RemoteWriteResponse {
185-
/// Connection ID from `RemoteOpenResponse`
186-
connection_id: u32,
187-
/// Number of bytes written successfully
188-
size: usize,
189-
},
190141
}
191142

192143
#[cfg(test)]

src/qos_net/README.MD

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# QOS Net
22

3-
This crate contains a proxy server which implements the protocol messages to implement remote connections:
4-
* `ProtocolMsg::RemoteOpenConnection`
5-
* `ProtocolMsg::RemoteRead`
6-
* `ProtocolMsg::RemoteWrite`
3+
This crate contains a proxy server and utilities to work with it. This server is a socket proxy: it listens on a socket (USOCK or VSOCK) and opens TCP connections to the outside. By sending `Proxy::*` messages over the socket, clients of the proxy can read/write/flush the TCP connections.
74

8-
It also contains a protocol and libraries to interact with the protocol
5+
When the proxy is run outside of an enclave and listening on a VSOCK port, the enclave process running on the inside can thus communicate with the outside and execute any protocol on top of a TCP connection by:
6+
* Opening a connection to a target hostname (`Proxy::ConnectByName`) or IP (`ProxyMsg::ConnectByIp`): this returns a connection ID for subsequent messages.
7+
* Sending `ProxyMsg::Read`, `ProxyMsg::Write` or `ProxyMsg::Flush` using the connection ID
8+
9+
Libraries like [`rustls`](https://github.com/rustls/rustls) are built generically to let users run the TLS protocol over any struct which implements [`Read`](https://doc.rust-lang.org/std/io/trait.Read.html) and [`Write`](https://doc.rust-lang.org/std/io/trait.Write.html) traits.
10+
11+
These traits are implemented in the `ProxyStream` struct: its `read`, `write`, and `flush` methods send `ProxyMsg` to a socket instead of manipulating a local socket or file descriptor.
12+
13+
Binaries running in enclaves can thus open connections to the outside world by importing and using `ProxyStream`. See the following integration test: [src/integration/tests/remote_tls.rs](../integration/tests/remote_tls.rs).

src/qos_net/src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use qos_core::{
88
server::SocketServer,
99
};
1010

11-
use crate::processor::Processor;
11+
use crate::proxy::Proxy;
1212

1313
/// "cid"
1414
pub const CID: &str = "cid";
@@ -68,7 +68,7 @@ impl CLI {
6868
} else if opts.parsed.help() {
6969
println!("{}", opts.parsed.info());
7070
} else {
71-
SocketServer::listen(opts.addr(), Processor::new()).unwrap();
71+
SocketServer::listen(opts.addr(), Proxy::new()).unwrap();
7272
}
7373
}
7474
}

src/qos_net/src/error.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//! Remote protocol error
1+
//! qos_net errors related to creating and using proxy connections.
22
use std::net::AddrParseError;
33

44
use borsh::{BorshDeserialize, BorshSerialize};
55
use hickory_resolver::error::ResolveError;
66

7-
/// Errors during protocol execution.
7+
/// Errors related to creating and using proxy connections
88
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
9-
pub enum ProtocolError {
9+
pub enum QosNetError {
1010
/// Error variant encapsulating OS IO errors
1111
IOError,
1212
/// Error variant encapsulating OS IO errors
@@ -25,38 +25,38 @@ pub enum ProtocolError {
2525
/// Attempt to save a connection with a duplicate ID
2626
DuplicateConnectionId(u32),
2727
/// Attempt to send a message to a remote connection, but ID isn't found
28-
RemoteConnectionIdNotFound(u32),
28+
ConnectionIdNotFound(u32),
2929
/// Attempting to read on a closed remote connection (`.read` returned 0
3030
/// bytes)
31-
RemoteConnectionClosed,
32-
/// Happens if a RemoteRead response has empty data
33-
RemoteReadEmpty,
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.
37-
RemoteReadOverflow(usize, usize),
31+
ConnectionClosed,
32+
/// Happens when a socket `read` results in no data
33+
EmptyRead,
34+
/// Happens when a socket `read` returns too much data for the provided
35+
/// buffer and the data doesn't fit. The first `usize` is the size of the
36+
/// received data, the second `usize` is the size of the buffer.
37+
ReadOverflow(usize, usize),
3838
}
3939

40-
impl From<std::io::Error> for ProtocolError {
40+
impl From<std::io::Error> for QosNetError {
4141
fn from(_err: std::io::Error) -> Self {
4242
Self::IOError
4343
}
4444
}
4545

46-
impl From<qos_core::io::IOError> for ProtocolError {
46+
impl From<qos_core::io::IOError> for QosNetError {
4747
fn from(_err: qos_core::io::IOError) -> Self {
4848
Self::QOSIOError
4949
}
5050
}
5151

52-
impl From<AddrParseError> for ProtocolError {
52+
impl From<AddrParseError> for QosNetError {
5353
fn from(err: AddrParseError) -> Self {
5454
let msg = format!("{err:?}");
5555
Self::ParseError(msg)
5656
}
5757
}
5858

59-
impl From<ResolveError> for ProtocolError {
59+
impl From<ResolveError> for QosNetError {
6060
fn from(err: ResolveError) -> Self {
6161
let msg = format!("{err:?}");
6262
Self::ParseError(msg)

src/qos_net/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
//! This crate contains a simple proxy server to implement QOS protocol messages
2-
//! related to establishing and using remote connections.
1+
//! This crate contains a simple proxy server which binds to a local socket and
2+
//! opens TCP connection It exposes a simple protocol for remote clients who
3+
//! connect to let them manipulate these connections (read/write/flush)
34
45
#![deny(clippy::all, unsafe_code)]
56
pub mod cli;
67
pub mod error;
7-
pub mod processor;
8-
pub mod remote_connection;
9-
pub mod remote_stream;
8+
pub mod proxy;
9+
pub mod proxy_connection;
10+
pub mod proxy_stream;

0 commit comments

Comments
 (0)