From ba1f62ef4cf956729e20ad688ed9e1f03a326649 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Thu, 8 Jun 2023 16:59:14 +0200 Subject: [PATCH] kbs_protocol: Return unquoted string from attestation() Currently the String returned from attestation() is quoted, because Value["token"] is a Value, and to_string() returns the "string representation" of the Value instead of the contained string. Introduce a struct representing the data returned from /attest, and deserialize into that so that we return the correct, raw string. Signed-off-by: Jeremi Piotrowski --- attestation-agent/kbs_protocol/src/lib.rs | 4 ++-- attestation-agent/kbs_protocol/src/types.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/attestation-agent/kbs_protocol/src/lib.rs b/attestation-agent/kbs_protocol/src/lib.rs index 8ba6267c0..c1bcce617 100644 --- a/attestation-agent/kbs_protocol/src/lib.rs +++ b/attestation-agent/kbs_protocol/src/lib.rs @@ -116,8 +116,8 @@ impl KbsProtocolWrapper { match attest_response.status() { reqwest::StatusCode::OK => { self.authenticated = true; - let token = attest_response.json::().await?["token"].to_string(); - Ok(token) + let resp = attest_response.json::().await?; + Ok(resp.token) } reqwest::StatusCode::UNAUTHORIZED => { let error_info = attest_response.json::().await?; diff --git a/attestation-agent/kbs_protocol/src/types.rs b/attestation-agent/kbs_protocol/src/types.rs index 0460905dc..385eeda53 100644 --- a/attestation-agent/kbs_protocol/src/types.rs +++ b/attestation-agent/kbs_protocol/src/types.rs @@ -40,6 +40,12 @@ pub struct Challenge { pub extra_params: String, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct AttestationResponseData { + // Attestation token in JWT format + pub token: String, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Response { pub protected: String,