95 lines
3.5 KiB
Diff
95 lines
3.5 KiB
Diff
|
|
From e835af7ff3667005be6893dedcb46a18452450d2 Mon Sep 17 00:00:00 2001
|
||
|
|
From: houmingyong <houmingyong@huawei.com>
|
||
|
|
Date: Mon, 14 Oct 2024 11:35:12 +0800
|
||
|
|
Subject: [PATCH] add parse report c interface
|
||
|
|
|
||
|
|
Conflict: remove /attestation-agent/c_header/example.c,c_header/rust_attestation_agent.h
|
||
|
|
|
||
|
|
---
|
||
|
|
.../attestation-agent/agent/src/lib.rs | 31 +++++++++++++++++++
|
||
|
|
.../attestation-service/verifier/src/lib.rs | 7 +++++
|
||
|
|
.../verifier/src/virtcca/mod.rs | 10 ++++++
|
||
|
|
3 files changed, 48 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/service/attestation/attestation-agent/agent/src/lib.rs b/service/attestation/attestation-agent/agent/src/lib.rs
|
||
|
|
index f1c4510..1164e2a 100644
|
||
|
|
--- a/service/attestation/attestation-agent/agent/src/lib.rs
|
||
|
|
+++ b/service/attestation/attestation-agent/agent/src/lib.rs
|
||
|
|
@@ -373,6 +373,37 @@ pub fn get_report(c_challenge: Option<&repr_c::Vec<u8>>, c_ima: &repr_c::TaggedO
|
||
|
|
report.into()
|
||
|
|
}
|
||
|
|
|
||
|
|
+#[cfg(feature = "no_as")]
|
||
|
|
+use verifier::virtcca_parse_evidence;
|
||
|
|
+
|
||
|
|
+#[cfg(feature = "no_as")]
|
||
|
|
+#[ffi_export]
|
||
|
|
+pub fn parse_report(report: Option<&repr_c::Vec<u8>>) -> repr_c::String {
|
||
|
|
+ let report = match report {
|
||
|
|
+ None => {
|
||
|
|
+ log::error!("report is null");
|
||
|
|
+ return "".to_string().into();
|
||
|
|
+ },
|
||
|
|
+ Some(report) => report.clone().to_vec(),
|
||
|
|
+ };
|
||
|
|
+ let rt = Runtime::new().unwrap();
|
||
|
|
+ let fut = async {virtcca_parse_evidence(&report)};
|
||
|
|
+ let ret = rt.block_on(fut);
|
||
|
|
+
|
||
|
|
+ let ret = match ret {
|
||
|
|
+ Ok(claim) => {
|
||
|
|
+ log::debug!("claim: {:?}", claim);
|
||
|
|
+ claim.to_string()
|
||
|
|
+ },
|
||
|
|
+ Err(e) =>{
|
||
|
|
+ log::error!("{e}");
|
||
|
|
+ "".to_string()
|
||
|
|
+ },
|
||
|
|
+ };
|
||
|
|
+
|
||
|
|
+ return ret.into();
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
#[ffi_export]
|
||
|
|
pub fn verify_report(c_challenge: Option<&repr_c::Vec<u8>>, report: Option<&repr_c::Vec<u8>>) -> repr_c::String {
|
||
|
|
let challenge = match c_challenge {
|
||
|
|
diff --git a/service/attestation/attestation-service/verifier/src/lib.rs b/service/attestation/attestation-service/verifier/src/lib.rs
|
||
|
|
index 0b776c2..a0e0b58 100644
|
||
|
|
--- a/service/attestation/attestation-service/verifier/src/lib.rs
|
||
|
|
+++ b/service/attestation/attestation-service/verifier/src/lib.rs
|
||
|
|
@@ -58,3 +58,10 @@ impl VerifierAPIs for Verifier {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
+
|
||
|
|
+pub fn virtcca_parse_evidence(evidence: &[u8]) -> Result<TeeClaim> {
|
||
|
|
+ let aa_evidence: Evidence = serde_json::from_slice(evidence)?;
|
||
|
|
+ let evidence = aa_evidence.evidence.as_bytes();
|
||
|
|
+
|
||
|
|
+ return virtcca::Evidence::parse_evidence(evidence);
|
||
|
|
+}
|
||
|
|
diff --git a/service/attestation/attestation-service/verifier/src/virtcca/mod.rs b/service/attestation/attestation-service/verifier/src/virtcca/mod.rs
|
||
|
|
index 3de7c9f..ca3a2ff 100644
|
||
|
|
--- a/service/attestation/attestation-service/verifier/src/virtcca/mod.rs
|
||
|
|
+++ b/service/attestation/attestation-service/verifier/src/virtcca/mod.rs
|
||
|
|
@@ -114,6 +114,16 @@ impl Evidence {
|
||
|
|
// todo parsed TeeClaim
|
||
|
|
evidence.parse_claim_from_evidence(ima)
|
||
|
|
}
|
||
|
|
+ pub fn parse_evidence(evidence: &[u8]) -> Result<TeeClaim> {
|
||
|
|
+ let virtcca_ev: VirtccaEvidence = serde_json::from_slice(evidence)?;
|
||
|
|
+ let evidence = virtcca_ev.evidence;
|
||
|
|
+ let evidence = Evidence::decode(evidence)?;
|
||
|
|
+
|
||
|
|
+ let ima = json!("");
|
||
|
|
+ // parsed TeeClaim
|
||
|
|
+ let claim = evidence.parse_claim_from_evidence(ima).unwrap();
|
||
|
|
+ Ok(claim["payload"].clone() as TeeClaim)
|
||
|
|
+ }
|
||
|
|
fn parse_claim_from_evidence(&self, ima: serde_json::Value) -> Result<TeeClaim> {
|
||
|
|
let payload = json!({
|
||
|
|
"vcca.cvm.challenge": hex::encode(self.cvm_token.challenge.clone()),
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|