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