Skip to content

Commit ad91b6a

Browse files
committed
Default to auto, not none
1 parent 9bd2bc7 commit ad91b6a

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/attestation/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,12 @@ impl AttestationGenerator {
121121
attestation_type_string: Option<String>,
122122
dummy_dcap_url: Option<String>,
123123
) -> Result<Self, AttestationError> {
124-
let attestaton_type = if attestation_type_string.as_deref() == Some("auto") {
124+
let attestation_type_string = attestation_type_string.unwrap_or_else(|| "auto".to_string());
125+
let attestaton_type = if attestation_type_string == "auto" {
125126
tracing::info!("Doing attestation type detection...");
126127
AttestationType::detect().await
127128
} else {
128-
serde_json::from_value(serde_json::Value::String(
129-
attestation_type_string.unwrap_or("none".to_string()),
130-
))
131-
.unwrap()
129+
serde_json::from_value(serde_json::Value::String(attestation_type_string))?
132130
};
133131
tracing::info!("Local platform: {attestaton_type}");
134132

@@ -392,6 +390,8 @@ pub enum AttestationError {
392390
DummyUrl,
393391
#[error("Dummy server: {0}")]
394392
DummyServer(String),
393+
#[error("JSON: {0}")]
394+
SerdeJson(#[from] serde_json::Error),
395395
}
396396

397397
#[cfg(test)]
@@ -401,6 +401,6 @@ mod tests {
401401
#[tokio::test]
402402
async fn attestation_detection_does_not_panic() {
403403
// We dont enforce what platform the test is run on, only that the function does not panic
404-
let _ = AttestationGenerator::new_with_detection(Some("auto".to_string()), None).await;
404+
let _ = AttestationGenerator::new_with_detection(None, None).await;
405405
}
406406
}

src/main.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum CliCommand {
4343
listen_addr: SocketAddr,
4444
/// The hostname:port or ip:port of the proxy server (port defaults to 443)
4545
target_addr: String,
46-
/// Type of attestation to present (dafaults to none)
46+
/// Type of attestation to present (dafaults to 'auto' for automatic detection)
4747
/// If other than None, a TLS key and certicate must also be given
4848
#[arg(long, env = "CLIENT_ATTESTATION_TYPE")]
4949
client_attestation_type: Option<String>,
@@ -68,7 +68,7 @@ enum CliCommand {
6868
listen_addr: SocketAddr,
6969
/// Socket address of the target service to forward traffic to
7070
target_addr: SocketAddr,
71-
/// Type of attestation to present (dafaults to none)
71+
/// Type of attestation to present (dafaults to 'auto' for automatic detection)
7272
/// If other than None, a TLS key and certicate must also be given
7373
#[arg(long, env = "SERVER_ATTESTATION_TYPE")]
7474
server_attestation_type: Option<String>,
@@ -177,10 +177,6 @@ async fn main() -> anyhow::Result<()> {
177177
None
178178
};
179179

180-
let client_attestation_type: AttestationType = serde_json::from_value(
181-
serde_json::Value::String(client_attestation_type.unwrap_or("none".to_string())),
182-
)?;
183-
184180
let remote_tls_cert = match tls_ca_certificate {
185181
Some(remote_cert_filename) => Some(
186182
load_certs_pem(remote_cert_filename)?
@@ -192,7 +188,8 @@ async fn main() -> anyhow::Result<()> {
192188
};
193189

194190
let client_attestation_generator =
195-
AttestationGenerator::new(client_attestation_type, dev_dummy_dcap)?;
191+
AttestationGenerator::new_with_detection(client_attestation_type, dev_dummy_dcap)
192+
.await?;
196193

197194
let client = ProxyClient::new(
198195
tls_cert_and_chain,
@@ -222,12 +219,9 @@ async fn main() -> anyhow::Result<()> {
222219
let tls_cert_and_chain =
223220
load_tls_cert_and_key(tls_certificate_path, tls_private_key_path)?;
224221

225-
let server_attestation_type: AttestationType = serde_json::from_value(
226-
serde_json::Value::String(server_attestation_type.unwrap_or("none".to_string())),
227-
)?;
228-
229222
let local_attestation_generator =
230-
AttestationGenerator::new(server_attestation_type, dev_dummy_dcap)?;
223+
AttestationGenerator::new_with_detection(server_attestation_type, dev_dummy_dcap)
224+
.await?;
231225

232226
let server = ProxyServer::new(
233227
tls_cert_and_chain,

0 commit comments

Comments
 (0)