-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AA: support get CoCo AS Attestation Token
Signed-off-by: Jiale Zhang <zhangjiale@linux.alibaba.com>
- Loading branch information
Showing
6 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2024 Alibaba Cloud | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
use super::GetToken; | ||
use anyhow::*; | ||
use async_trait::async_trait; | ||
use base64::engine::general_purpose::URL_SAFE_NO_PAD; | ||
use base64::Engine; | ||
|
||
#[derive(Default)] | ||
pub struct CoCoASTokenGetter {} | ||
|
||
#[async_trait] | ||
impl GetToken for CoCoASTokenGetter { | ||
async fn get_token(&self, as_url: String) -> Result<Vec<u8>> { | ||
let tee_type = attester::detect_tee_type(); | ||
let attester = attester::BoxedAttester::try_from(tee_type)?; | ||
let evidence = attester.get_evidence(vec![]).await?; | ||
|
||
let request_body = serde_json::json!({ | ||
"tee": serde_json::to_string(&tee_type)?, | ||
"evidence": URL_SAFE_NO_PAD.encode(evidence.as_bytes()), | ||
}); | ||
|
||
let client = reqwest::Client::new(); | ||
let res = client | ||
.post(as_url) | ||
.header("Content-Type", "application/json") | ||
.json(&request_body) | ||
.send() | ||
.await?; | ||
|
||
match res.status() { | ||
reqwest::StatusCode::OK => { | ||
let token = res.text().await?; | ||
Ok(token.as_bytes().to_vec()) | ||
} | ||
_ => { | ||
bail!( | ||
"Rmote Attestation Failed, AS Response: {:?}", | ||
res.text().await? | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters