Skip to content

Commit

Permalink
AA: Allow setting custom KBS certificates to enable TLS
Browse files Browse the repository at this point in the history
Add parameters for setting customized KBS Root certificate when creating HTTP client,
so that TLS communication can be enabled in various deployment scenarios.

Signed-off-by: Jiale Zhang <zhangjiale@linux.alibaba.com>
  • Loading branch information
jialez0 committed Jul 18, 2023
1 parent f3d9264 commit e26aa2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion attestation-agent/kbc/src/cc_kbc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Kbc {
Ok(Kbc {
kbs_uri: url,
token: None,
kbs_protocol_wrapper: KbsProtocolWrapper::new().unwrap(),
kbs_protocol_wrapper: KbsProtocolWrapper::new(vec![]).unwrap(),
})
}

Expand Down
19 changes: 13 additions & 6 deletions attestation-agent/kbs_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct KbsProtocolWrapper {
}

impl KbsProtocolWrapper {
pub fn new() -> Result<KbsProtocolWrapper> {
pub fn new(kbs_root_certs_pem: Vec<String>) -> Result<KbsProtocolWrapper> {
// Detect TEE type of the current platform.
let tee_type = detect_tee_type();
// Create attester instance.
Expand All @@ -48,7 +48,7 @@ impl KbsProtocolWrapper {
tee_key: None,
nonce: String::default(),
attester,
http_client: build_http_client().unwrap(),
http_client: build_http_client(kbs_root_certs_pem).unwrap(),
authenticated: false,
})
}
Expand Down Expand Up @@ -87,7 +87,7 @@ impl KbsProtocolWrapper {

async fn attestation(
&mut self,
kbs_root_url: String
kbs_root_url: String,
tee_pubkey_pem: Option<String>,
) -> Result<String> {
let challenge = self
Expand Down Expand Up @@ -191,14 +191,21 @@ impl KbsRequest for KbsProtocolWrapper {
}
}

fn build_http_client() -> Result<reqwest::Client> {
reqwest::Client::builder()
fn build_http_client(kbs_root_certs_pem: Vec<String>) -> Result<reqwest::Client> {
let mut client_builder = reqwest::Client::builder()
.cookie_store(true)
.user_agent(format!(
"attestation-agent-kbs-client/{}",
env!("CARGO_PKG_VERSION")
))
.timeout(Duration::from_secs(KBS_REQ_TIMEOUT_SEC))
.timeout(Duration::from_secs(KBS_REQ_TIMEOUT_SEC));

for custom_root_cert in kbs_root_certs_pem.iter() {
let cert = reqwest::Certificate::from_pem(custom_root_cert.as_bytes())?;
client_builder = client_builder.add_root_certificate(cert);
}

client_builder
.build()
.map_err(|e| anyhow!("Build KBS http client failed: {:?}", e))
}

0 comments on commit e26aa2c

Please sign in to comment.