cycles-quartz/utils/quartz-relayer/src/main.rs

52 lines
1.7 KiB
Rust
Raw Normal View History

2024-02-23 22:28:52 +00:00
mod cli;
2024-02-26 21:57:54 +00:00
use std::{
fs::{read_to_string, File},
io::Write,
process::Command,
};
2024-02-23 22:28:52 +00:00
use clap::Parser;
use quartz_proto::quartz::{core_client::CoreClient, InstantiateRequest};
use quartz_relayer::types::InstantiateResponse;
2024-02-26 21:57:54 +00:00
use serde_json::json;
2024-02-23 22:28:52 +00:00
2024-02-26 21:57:54 +00:00
use crate::cli::Cli;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2024-02-23 22:28:52 +00:00
let args = Cli::parse();
2024-02-23 22:28:52 +00:00
let mut client = CoreClient::connect(args.enclave_addr).await?;
let response = client.instantiate(InstantiateRequest {}).await?;
let response: InstantiateResponse = response.into_inner().try_into()?;
2024-02-26 21:57:54 +00:00
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");
2024-02-26 22:10:45 +00:00
let mut quote_file = File::create(quote_file_path.clone())?;
2024-02-23 22:28:52 +00:00
quote_file.write_all(response.quote())?;
2024-02-23 22:49:21 +00:00
let gramine_sgx_ias_request_output = Command::new("gramine-sgx-ias-request")
.arg("report")
.args(["-g", "51CAF5A48B450D624AEFE3286D314894"])
.args(["-k", "669244b3e6364b5888289a11d2a1726d"])
2024-02-26 22:10:45 +00:00
.args(["-q", &quote_file_path.display().to_string()])
.args(["-r", &datareport_file_path.display().to_string()])
.args(["-s", &datareportsig_file_path.display().to_string()])
2024-02-23 22:49:21 +00:00
.output()?;
println!("{gramine_sgx_ias_request_output:?}");
2024-02-26 21:57:54 +00:00
let report = read_to_string(datareport_file_path)?;
let report_sig = read_to_string(datareportsig_file_path)?;
2024-02-23 22:49:21 +00:00
let ias_report = json!({"report": report, "reportsig": report_sig});
2024-02-26 21:57:54 +00:00
println!(
"{}",
serde_json::to_string(&ias_report).expect("infallible serializer")
);
2024-02-23 22:49:21 +00:00
Ok(())
}