yangfh2004 commented on code in PR #448: URL: https://github.com/apache/incubator-teaclave-sgx-sdk/pull/448#discussion_r1414113351
########## samplecode/microsoft_azure_attestation/app/src/main.rs: ########## @@ -0,0 +1,425 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +#![allow(non_snake_case)] + +extern crate base64; +extern crate base64_url; +extern crate jsonwebkey; +extern crate jsonwebtoken; +extern crate libloading; +extern crate serde; +extern crate serde_json; +extern crate sgx_types; +extern crate sgx_urts; +extern crate sha2; +extern crate x509_certificate; + +use std::convert::{TryFrom, TryInto}; + +use base64::{engine::general_purpose, Engine as _}; +use jsonwebkey::{JsonWebKey, Key, PublicExponent, RsaPublic}; +use jsonwebtoken as jwt; +use serde::{Deserialize, Serialize}; +use sgx_types::*; +use sgx_urts::SgxEnclave; +use sha2::{Digest, Sha256}; +use x509_certificate::{X509Certificate, X509CertificateError}; + +static ENCLAVE_FILE: &'static str = "enclave.signed.so"; +const ATTESTATION_PROVIDER_URL: &'static str = "https://sharedeus.eus.attest.azure.net"; +const SGX_ATTESTATION_URI: &'static str = "/attest/SgxEnclave?api-version=2022-08-01"; + +extern "C" { + fn enclave_create_report( + eid: sgx_enclave_id_t, + retval: *mut i32, + p_qe3_target: &sgx_target_info_t, + p_report_data: &sgx_report_data_t, + p_report: *mut sgx_report_t, + ) -> sgx_status_t; +} + +fn init_enclave() -> SgxResult<SgxEnclave> { + let mut launch_token: sgx_launch_token_t = [0; 1024]; + let mut launch_token_updated: i32 = 0; + // call sgx_create_enclave to initialize an enclave instance + // Debug Support: set 2nd parameter to 1 + let debug = 0; + let mut misc_attr = sgx_misc_attribute_t { + secs_attr: sgx_attributes_t { flags: 0, xfrm: 0 }, + misc_select: 0, + }; + SgxEnclave::create( + ENCLAVE_FILE, + debug, + &mut launch_token, + &mut launch_token_updated, + &mut misc_attr, + ) +} + +// Re-invent App/utility.cpp +// int generate_quote(uint8_t **quote_buffer, uint32_t& quote_size) +fn generate_quote(runtime_data: &[u8]) -> Option<Vec<u8>> { + let mut ti: sgx_target_info_t = sgx_target_info_t::default(); + + // let _l = unsafe { libloading::Library::new("./libdcap_quoteprov.so.1").unwrap() }; + println!("Step1: Call sgx_qe_get_target_info:"); + //println!("sgx_qe_get_target_info = {:p}", sgx_qe_get_target_info as * const _); + + let qe3_ret = unsafe { sgx_qe_get_target_info(&mut ti as *mut _) }; + + if qe3_ret != sgx_quote3_error_t::SGX_QL_SUCCESS { + println!("Error in sgx_qe_get_target_info. {:?}\n", qe3_ret); + return None; + } + + //println!("target_info.mr_enclave = {:?}", ti.mr_enclave.m); + //println!("target_info.config_id = {:02x}", ti.config_id.iter().format(" ")); + + let quote_size = std::mem::size_of::<sgx_target_info_t>(); + let mut v: Vec<u8> = vec![0; quote_size]; Review Comment: @volcano0dr removed ########## samplecode/microsoft_azure_attestation/bin/maa: ########## Review Comment: @volcano0dr deleted -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@teaclave.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@teaclave.apache.org For additional commands, e-mail: notifications-h...@teaclave.apache.org