11use anyhow:: { anyhow, ensure} ;
2+ use attested_tls:: attestation:: measurements:: MultiMeasurements ;
23use clap:: { Parser , Subcommand } ;
34use std:: {
45 fs:: File ,
@@ -126,6 +127,9 @@ enum CliCommand {
126127 /// Enables verification of self-signed TLS certificates
127128 #[ arg( long) ]
128129 allow_self_signed : bool ,
130+ /// Filename to write measurements as JSON to
131+ #[ arg( long) ]
132+ out_measurements : Option < PathBuf > ,
129133 } ,
130134 /// Serve a filesystem path over an attested channel
131135 AttestedFileServer {
@@ -201,12 +205,22 @@ async fn main() -> anyhow::Result<()> {
201205 MeasurementPolicy :: from_file_or_url ( server_measurements) . await ?
202206 }
203207 None => {
204- let allowed_server_attestation_type: AttestationType = serde_json:: from_value (
205- serde_json:: Value :: String ( cli. allowed_remote_attestation_type . ok_or ( anyhow ! (
208+ match cli
209+ . allowed_remote_attestation_type
210+ . ok_or ( anyhow ! (
206211 "Either a measurements file or an allowed attestation type must be provided"
207- ) ) ?) ,
208- ) ?;
209- MeasurementPolicy :: single_attestation_type ( allowed_server_attestation_type)
212+ ) ) ?
213+ . to_lowercase ( )
214+ . as_str ( )
215+ {
216+ "tdx" => MeasurementPolicy :: tdx ( ) ,
217+ attestation_type => {
218+ let allowed_server_attestation_type: AttestationType = serde_json:: from_value (
219+ serde_json:: Value :: String ( attestation_type. to_string ( ) ) ,
220+ ) ?;
221+ MeasurementPolicy :: single_attestation_type ( allowed_server_attestation_type)
222+ }
223+ }
210224 }
211225 } ;
212226
@@ -340,6 +354,7 @@ async fn main() -> anyhow::Result<()> {
340354 server,
341355 tls_ca_certificate,
342356 allow_self_signed,
357+ out_measurements,
343358 } => {
344359 let remote_tls_cert = match tls_ca_certificate {
345360 Some ( remote_cert_filename) => Some (
@@ -350,13 +365,24 @@ async fn main() -> anyhow::Result<()> {
350365 ) ,
351366 None => None ,
352367 } ;
353- let cert_chain = get_tls_cert (
368+ let ( cert_chain, measurements ) = get_tls_cert (
354369 server,
355370 attestation_verifier,
356371 remote_tls_cert,
357372 allow_self_signed,
358373 )
359374 . await ?;
375+
376+ // If the user chose to write measurements to a file as JSON
377+ if let Some ( path_to_write_measurements) = out_measurements {
378+ std:: fs:: write (
379+ path_to_write_measurements,
380+ measurements
381+ . unwrap_or ( MultiMeasurements :: NoAttestation )
382+ . to_header_format ( ) ?
383+ . as_bytes ( ) ,
384+ ) ?;
385+ }
360386 println ! ( "{}" , certs_to_pem_string( & cert_chain) ?) ;
361387 }
362388 CliCommand :: AttestedFileServer {
0 commit comments