Skip to content

Commit 16ad6f7

Browse files
committed
Accept hostnames as target server for proxy server
1 parent 3cca29f commit 16ad6f7

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

src/attested_get.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mod tests {
8181
cert_chain,
8282
server_config,
8383
"127.0.0.1:0",
84-
target_addr,
84+
target_addr.to_string(),
8585
AttestationGenerator::new_not_dummy(AttestationType::DcapTdx).unwrap(),
8686
AttestationVerifier::expect_none(),
8787
)

src/file_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub async fn attested_file_server(
1818
let server = ProxyServer::new(
1919
cert_and_key,
2020
listen_addr,
21-
target_addr,
21+
target_addr.to_string(),
2222
attestation_generator,
2323
attestation_verifier,
2424
client_auth,
@@ -103,7 +103,7 @@ mod tests {
103103
cert_chain,
104104
server_config,
105105
"127.0.0.1:0",
106-
target_addr,
106+
target_addr.to_string(),
107107
AttestationGenerator::new_not_dummy(AttestationType::DcapTdx).unwrap(),
108108
AttestationVerifier::expect_none(),
109109
)

src/lib.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ pub struct ProxyServer {
5959
attested_tls_server: AttestedTlsServer,
6060
/// The underlying TCP listener
6161
listener: Arc<TcpListener>,
62-
/// The address of the target service we are proxying to
63-
target: SocketAddr,
62+
/// The address/hostname of the target service we are proxying to
63+
target: String,
6464
}
6565

6666
impl ProxyServer {
6767
pub async fn new(
6868
cert_and_key: TlsCertAndKey,
6969
local: impl ToSocketAddrs,
70-
target: SocketAddr,
70+
target: String,
7171
attestation_generator: AttestationGenerator,
7272
attestation_verifier: AttestationVerifier,
7373
client_auth: bool,
@@ -97,7 +97,7 @@ impl ProxyServer {
9797
cert_chain: Vec<CertificateDer<'static>>,
9898
server_config: Arc<ServerConfig>,
9999
local: impl ToSocketAddrs,
100-
target: SocketAddr,
100+
target: String,
101101
attestation_generator: AttestationGenerator,
102102
attestation_verifier: AttestationVerifier,
103103
) -> Result<Self, ProxyError> {
@@ -120,7 +120,7 @@ impl ProxyServer {
120120

121121
/// Accept an incoming connection and handle it in a seperate task
122122
pub async fn accept(&self) -> Result<(), ProxyError> {
123-
let target = self.target;
123+
let target = self.target.clone();
124124
let (inbound, _client_addr) = self.listener.accept().await?;
125125
let attested_tls_server = self.attested_tls_server.clone();
126126

@@ -153,7 +153,7 @@ impl ProxyServer {
153153
tls_stream: tokio_rustls::server::TlsStream<tokio::net::TcpStream>,
154154
measurements: Option<MultiMeasurements>,
155155
remote_attestation_type: AttestationType,
156-
target: SocketAddr,
156+
target: String,
157157
) -> Result<(), ProxyError> {
158158
tracing::debug!("proxy-server accepted connection");
159159

@@ -183,6 +183,7 @@ impl ProxyServer {
183183
.expect("Attestation type should be able to be encoded as a header value"),
184184
);
185185

186+
let target = target.clone();
186187
async move {
187188
match Self::handle_http_request(req, target).await {
188189
Ok(res) => {
@@ -208,7 +209,7 @@ impl ProxyServer {
208209
// Handle a request from the proxy client to the target server
209210
async fn handle_http_request(
210211
req: hyper::Request<hyper::body::Incoming>,
211-
target: SocketAddr,
212+
target: String,
212213
) -> Result<Response<BoxBody<bytes::Bytes, hyper::Error>>, ProxyError> {
213214
// Connect to the target server
214215
let outbound = TcpStream::connect(target).await?;
@@ -595,7 +596,7 @@ mod tests {
595596
cert_chain,
596597
server_config,
597598
"127.0.0.1:0",
598-
target_addr,
599+
target_addr.to_string(),
599600
AttestationGenerator::new_not_dummy(AttestationType::DcapTdx).unwrap(),
600601
AttestationVerifier::expect_none(),
601602
)
@@ -672,7 +673,7 @@ mod tests {
672673
server_cert_chain,
673674
server_tls_server_config,
674675
"127.0.0.1:0",
675-
target_addr,
676+
target_addr.to_string(),
676677
AttestationGenerator::with_no_attestation(),
677678
AttestationVerifier::mock(),
678679
)
@@ -743,7 +744,7 @@ mod tests {
743744
server_cert_chain,
744745
server_config,
745746
"127.0.0.1:0",
746-
target_addr,
747+
target_addr.to_string(),
747748
AttestationGenerator::with_no_attestation(),
748749
AttestationVerifier::mock(),
749750
)
@@ -824,7 +825,7 @@ mod tests {
824825
server_cert_chain,
825826
server_tls_server_config,
826827
"127.0.0.1:0",
827-
target_addr,
828+
target_addr.to_string(),
828829
AttestationGenerator::new_not_dummy(AttestationType::DcapTdx).unwrap(),
829830
AttestationVerifier::mock(),
830831
)
@@ -923,7 +924,7 @@ mod tests {
923924
cert_chain.clone(),
924925
server_config,
925926
"127.0.0.1:0",
926-
target_addr,
927+
target_addr.to_string(),
927928
AttestationGenerator::new_not_dummy(AttestationType::DcapTdx).unwrap(),
928929
AttestationVerifier::expect_none(),
929930
)
@@ -960,7 +961,7 @@ mod tests {
960961
cert_chain,
961962
server_config,
962963
"127.0.0.1:0",
963-
target_addr,
964+
target_addr.to_string(),
964965
AttestationGenerator::with_no_attestation(),
965966
AttestationVerifier::expect_none(),
966967
)
@@ -1004,7 +1005,7 @@ mod tests {
10041005
cert_chain,
10051006
server_config,
10061007
"127.0.0.1:0",
1007-
target_addr,
1008+
target_addr.to_string(),
10081009
AttestationGenerator::new_not_dummy(AttestationType::DcapTdx).unwrap(),
10091010
AttestationVerifier::expect_none(),
10101011
)

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ enum CliCommand {
7373
/// Socket address to listen on
7474
#[arg(short, long, default_value = "0.0.0.0:0", env = "LISTEN_ADDR")]
7575
listen_addr: SocketAddr,
76-
/// Socket address of the target service to forward traffic to
77-
target_addr: SocketAddr,
76+
/// The hostname:port or ip:port of the target service to forward traffic to
77+
target_addr: String,
7878
/// Type of attestation to present (dafaults to 'auto' for automatic detection)
7979
/// If other than None, a TLS key and certicate must also be given
8080
#[arg(long, env = "SERVER_ATTESTATION_TYPE")]

0 commit comments

Comments
 (0)