From c3e9af7ce92e23da1ce6f8efc84cd73dd418656e Mon Sep 17 00:00:00 2001 From: hu55a1n1 Date: Mon, 26 Feb 2024 14:43:44 -0800 Subject: [PATCH] Extract gramine_sgx_ias_report --- utils/quartz-relayer/src/main.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/utils/quartz-relayer/src/main.rs b/utils/quartz-relayer/src/main.rs index 4c277f5..347d059 100644 --- a/utils/quartz-relayer/src/main.rs +++ b/utils/quartz-relayer/src/main.rs @@ -1,6 +1,7 @@ mod cli; use std::{ + error::Error, fs::{read_to_string, File}, io::Write, process::Command, @@ -9,7 +10,7 @@ use std::{ use clap::Parser; use quartz_proto::quartz::{core_client::CoreClient, InstantiateRequest}; use quartz_relayer::types::InstantiateResponse; -use serde_json::json; +use serde_json::{json, Value}; use crate::cli::Cli; @@ -21,13 +22,23 @@ async fn main() -> Result<(), Box> { let response = client.instantiate(InstantiateRequest {}).await?; let response: InstantiateResponse = response.into_inner().try_into()?; + let ias_report = gramine_sgx_ias_report(response.quote())?; + println!( + "{}", + serde_json::to_string(&ias_report).expect("infallible serializer") + ); + + Ok(()) +} + +fn gramine_sgx_ias_report(quote: &[u8]) -> Result> { let dir = tempfile::tempdir()?; let quote_file_path = dir.path().join("test.quote"); let datareport_file_path = dir.path().join("datareport"); let datareportsig_file_path = dir.path().join("datareportsig"); let mut quote_file = File::create(quote_file_path.clone())?; - quote_file.write_all(response.quote())?; + quote_file.write_all(quote)?; let gramine_sgx_ias_request_output = Command::new("gramine-sgx-ias-request") .arg("report") @@ -42,10 +53,5 @@ async fn main() -> Result<(), Box> { let report = read_to_string(datareport_file_path)?; let report_sig = read_to_string(datareportsig_file_path)?; let ias_report = json!({"report": report, "reportsig": report_sig}); - println!( - "{}", - serde_json::to_string(&ias_report).expect("infallible serializer") - ); - - Ok(()) + Ok(ias_report) }