Skip to content

Commit 54678e0

Browse files
Merge #357
357: Pass local addr of connections to the enclave r=raoulstrackx a=raoulstrackx When handling incoming and outgoing connections, the local address of the TCP connection as used in the runner needs to be passed to the enclave so it can hide the fact from users that the connection is being proxied. Co-authored-by: Raoul Strackx <[email protected]>
2 parents 13b2e7c + c57fe69 commit 54678e0

File tree

4 files changed

+15
-1
lines changed
  • fortanix-vme

4 files changed

+15
-1
lines changed

fortanix-vme/fortanix-vme-abi/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub enum Response {
6868
Connected {
6969
/// The vsock port the proxy is listening on for an incoming connection
7070
proxy_port: u32,
71+
/// The local address (as used by the runner)
72+
local: Addr,
7173
/// The address of the remote party
7274
peer: Addr,
7375
},
@@ -79,6 +81,8 @@ pub enum Response {
7981
fd: i32,
8082
},
8183
IncomingConnection {
84+
/// The local address (as used by the runner)
85+
local: Addr,
8286
/// The address of the remote party
8387
peer: Addr,
8488
/// The vsock port number the runner will connect to the enclave in order to forward the
@@ -99,6 +103,7 @@ mod test {
99103
if let Addr::IPv4 { port, ip } = sock_addr.into() {
100104
assert_eq!(IpAddr::from(ip), sock_addr.ip());
101105
assert_eq!(port, sock_addr.port());
106+
assert_eq!(port, 4567);
102107
} else {
103108
panic!("Not IPv4")
104109
}

fortanix-vme/fortanix-vme-runner/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl Server {
188188
// Notify the enclave on which port her proxy is listening on
189189
let response = Response::Connected {
190190
proxy_port: proxy_server_port,
191+
local: remote_socket.local_addr()?.into(),
191192
peer: remote_socket.peer_addr()?.into(),
192193
};
193194
Self::log_communication(
@@ -269,6 +270,7 @@ impl Server {
269270
Ok((mut conn, peer)) => {
270271
let vsock = Vsock::new::<Std>()?;
271272
let response = Response::IncomingConnection{
273+
local: conn.local_addr()?.into(),
272274
peer: peer.into(),
273275
proxy_port: vsock.addr::<Std>()?.port(),
274276
};

fortanix-vme/tests/incoming_connection/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fn main() {
1313
Ok((mut stream, addr)) => {
1414
println!("# addr = {:?}", addr);
1515
assert_eq!(stream.peer_addr().unwrap().ip(), Ipv4Addr::new(127, 0, 0, 1));
16+
assert!(stream.peer_addr().unwrap().port() != 3400);
17+
assert_eq!(stream.local_addr().unwrap().ip(), Ipv4Addr::new(127, 0, 0, 1));
18+
assert_eq!(stream.local_addr().unwrap().port(), 3400);
1619
println!("Connection {}: Connected", id);
1720
let mut buff_in = [0u8; 4192];
1821
let n = stream.read(&mut buff_in).unwrap();

fortanix-vme/tests/outgoing_connection/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
use std::net::TcpStream;
1+
use std::net::{Ipv4Addr, TcpStream};
22
use std::io::{Read, Write};
33

44
fn main() {
55
let mut socket = TcpStream::connect(format!("google.com:80")).unwrap();
6+
// `socket.local_addr()` may return the actual local IP address, not 127.0.0.1
7+
assert!(socket.local_addr().unwrap().port() != 80);
8+
assert!(socket.peer_addr().unwrap().ip() != Ipv4Addr::new(127, 0, 0, 1));
9+
assert_eq!(socket.peer_addr().unwrap().port(), 80);
610
socket.write(b"GET / HTTP/1.1\n\n").unwrap();
711
socket.flush().unwrap();
812
let mut page = [0; 4192];

0 commit comments

Comments
 (0)