Skip to content

Commit

Permalink
kbs_protocol: Return unquoted string from attestation()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jepio authored and jialez0 committed Jul 3, 2023
1 parent 18332aa commit ba1f62e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions attestation-agent/kbs_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl KbsProtocolWrapper {
match attest_response.status() {
reqwest::StatusCode::OK => {
self.authenticated = true;
let token = attest_response.json::<serde_json::Value>().await?["token"].to_string();
Ok(token)
let resp = attest_response.json::<AttestationResponseData>().await?;
Ok(resp.token)
}
reqwest::StatusCode::UNAUTHORIZED => {
let error_info = attest_response.json::<ErrorInformation>().await?;
Expand Down
6 changes: 6 additions & 0 deletions attestation-agent/kbs_protocol/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ba1f62e

Please sign in to comment.