[demos] Do cargo fmt for azure attestation
This commit is contained in:
parent
86539bf98e
commit
970157f13f
@ -1,8 +1,7 @@
|
||||
use occlum_dcap::*;
|
||||
use reqwest::blocking::Client;
|
||||
use serde_json::json;
|
||||
use sha2::{Digest, Sha256};
|
||||
use reqwest::blocking::Client;
|
||||
use occlum_dcap::*;
|
||||
|
||||
|
||||
pub const MAX_REPORT_DATA_SIZE: usize = 64;
|
||||
|
||||
@ -25,7 +24,9 @@ fn maa_get_quote_base64(user_data: &[u8]) -> Result<String, &'static str> {
|
||||
report_data.d[i] = user_data[i];
|
||||
}
|
||||
|
||||
let ret = dcap.generate_quote(quote_buf.as_mut_ptr(), &mut report_data).unwrap();
|
||||
let ret = dcap
|
||||
.generate_quote(quote_buf.as_mut_ptr(), &mut report_data)
|
||||
.unwrap();
|
||||
dcap.close();
|
||||
if ret < 0 {
|
||||
return Err("DCAP generate quote failed");
|
||||
@ -52,31 +53,28 @@ pub fn maa_generate_json(user_data: &[u8]) -> Result<serde_json::Value, &'static
|
||||
}
|
||||
});
|
||||
|
||||
*maa_json
|
||||
.pointer_mut("/quote")
|
||||
.unwrap() = serde_json::Value::String(quote_base64);
|
||||
*maa_json.pointer_mut("/quote").unwrap() = serde_json::Value::String(quote_base64);
|
||||
|
||||
*maa_json
|
||||
.pointer_mut("/runtimeData/data")
|
||||
.unwrap() = serde_json::Value::String(base64::encode(&user_data));
|
||||
*maa_json.pointer_mut("/runtimeData/data").unwrap() =
|
||||
serde_json::Value::String(base64::encode(&user_data));
|
||||
|
||||
Ok(maa_json.to_owned())
|
||||
}
|
||||
|
||||
|
||||
pub fn maa_attestation(url: String, request_body: serde_json::Value) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
pub fn maa_attestation(
|
||||
url: String,
|
||||
request_body: serde_json::Value,
|
||||
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
let client = Client::new();
|
||||
let att_url = format!("{}/attest/SgxEnclave?api-version=2020-10-01", url);
|
||||
|
||||
let resp = client.post(att_url)
|
||||
.json(&request_body)
|
||||
.send()?;
|
||||
|
||||
let resp = client.post(att_url).json(&request_body).send()?;
|
||||
|
||||
match resp.status() {
|
||||
reqwest::StatusCode::OK => {
|
||||
println!("success!");
|
||||
Ok(resp.json().unwrap())
|
||||
},
|
||||
}
|
||||
s => {
|
||||
println!("Received response status: {:?}", s);
|
||||
Err("maa attestation failed".into())
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::maa::{maa_generate_json, maa_attestation};
|
||||
use crate::maa::{maa_attestation, maa_generate_json};
|
||||
|
||||
pub mod maa;
|
||||
|
||||
@ -6,7 +6,7 @@ const ATTESTATION_PROVIDER_URL: &str = "https://shareduks.uks.attest.azure.net";
|
||||
|
||||
fn main() {
|
||||
// Sample enclave held data
|
||||
let ehd: [u8;8] = [1,2,3,4,5,6,7,8];
|
||||
let ehd: [u8; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
|
||||
|
||||
let maa_json = maa_generate_json(&ehd).unwrap();
|
||||
println!("maa json: {}", maa_json);
|
||||
|
@ -1,8 +1,7 @@
|
||||
use occlum_dcap::*;
|
||||
use reqwest::blocking::Client;
|
||||
use serde_json::json;
|
||||
use sha2::{Digest, Sha256};
|
||||
use reqwest::blocking::Client;
|
||||
use occlum_dcap::*;
|
||||
|
||||
|
||||
pub const MAX_REPORT_DATA_SIZE: usize = 64;
|
||||
|
||||
@ -25,7 +24,9 @@ fn maa_get_quote_base64(user_data: &[u8]) -> Result<String, &'static str> {
|
||||
report_data.d[i] = user_data[i];
|
||||
}
|
||||
|
||||
let ret = dcap.generate_quote(quote_buf.as_mut_ptr(), &mut report_data).unwrap();
|
||||
let ret = dcap
|
||||
.generate_quote(quote_buf.as_mut_ptr(), &mut report_data)
|
||||
.unwrap();
|
||||
dcap.close();
|
||||
if ret < 0 {
|
||||
return Err("DCAP generate quote failed");
|
||||
@ -52,31 +53,28 @@ pub fn maa_generate_json(user_data: &[u8]) -> Result<serde_json::Value, &'static
|
||||
}
|
||||
});
|
||||
|
||||
*maa_json
|
||||
.pointer_mut("/quote")
|
||||
.unwrap() = serde_json::Value::String(quote_base64);
|
||||
*maa_json.pointer_mut("/quote").unwrap() = serde_json::Value::String(quote_base64);
|
||||
|
||||
*maa_json
|
||||
.pointer_mut("/runtimeData/data")
|
||||
.unwrap() = serde_json::Value::String(base64::encode(&user_data));
|
||||
*maa_json.pointer_mut("/runtimeData/data").unwrap() =
|
||||
serde_json::Value::String(base64::encode(&user_data));
|
||||
|
||||
Ok(maa_json.to_owned())
|
||||
}
|
||||
|
||||
|
||||
pub fn maa_attestation(url: String, request_body: serde_json::Value) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
pub fn maa_attestation(
|
||||
url: String,
|
||||
request_body: serde_json::Value,
|
||||
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
let client = Client::new();
|
||||
let att_url = format!("{}/attest/SgxEnclave?api-version=2020-10-01", url);
|
||||
|
||||
let resp = client.post(att_url)
|
||||
.json(&request_body)
|
||||
.send()?;
|
||||
|
||||
let resp = client.post(att_url).json(&request_body).send()?;
|
||||
|
||||
match resp.status() {
|
||||
reqwest::StatusCode::OK => {
|
||||
// println!("success!");
|
||||
Ok(resp.json().unwrap())
|
||||
},
|
||||
}
|
||||
s => {
|
||||
println!("Received response status: {:?}", s);
|
||||
Err("maa attestation failed".into())
|
||||
|
@ -5,12 +5,12 @@ extern crate serde_json;
|
||||
use libc::syscall;
|
||||
use serde::Deserialize;
|
||||
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fs::{write, File};
|
||||
use std::io::{ErrorKind, Read};
|
||||
use std::env;
|
||||
|
||||
use crate::maa::{maa_generate_json, maa_attestation};
|
||||
use crate::maa::{maa_attestation, maa_generate_json};
|
||||
pub mod maa;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
@ -40,10 +40,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Get Attestation provider URL, rootfs token path and report data string from env
|
||||
let maa_provider_url = env::var("MAA_PROVIDER_URL")
|
||||
.unwrap_or("https://shareduks.uks.attest.azure.net".to_string());
|
||||
let maa_token_path = env::var("MAA_TOKEN_PATH")
|
||||
.unwrap_or("/root".to_string());
|
||||
let report_data_base64 = env::var("MAA_REPORT_DATA")
|
||||
.unwrap_or("example".to_string());
|
||||
let maa_token_path = env::var("MAA_TOKEN_PATH").unwrap_or("/root".to_string());
|
||||
let report_data_base64 = env::var("MAA_REPORT_DATA").unwrap_or("example".to_string());
|
||||
let report_data = base64::decode(&report_data_base64).unwrap();
|
||||
|
||||
// Get maa quote json
|
||||
@ -58,8 +56,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
// User can provide valid path for runtime mount and boot
|
||||
// Otherwise, just pass null pointer to do general mount and boot
|
||||
let root_config_path: *const i8 = std::ptr::null();
|
||||
let ret = unsafe { syscall(
|
||||
SYS_MOUNT_FS, key_ptr, root_config_path) };
|
||||
let ret = unsafe { syscall(SYS_MOUNT_FS, key_ptr, root_config_path) };
|
||||
if ret < 0 {
|
||||
return Err(Box::new(std::io::Error::last_os_error()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user