Skip to content

Commit

Permalink
Add context when calling attest endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Dec 6, 2024
1 parent f4d4349 commit 732c1d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::{

use base64::prelude::{Engine, BASE64_STANDARD};
use entropy_protocol::RecoverableSignature;
use entropy_shared::HashingAlgorithm;
use entropy_shared::{HashingAlgorithm, QuoteContext};
use futures::stream::StreamExt;
use sp_core::{
sr25519::{self, Signature},
Expand Down Expand Up @@ -343,8 +343,11 @@ pub async fn get_quote_and_change_endpoint(
validator_keypair: sr25519::Pair,
new_endpoint: String,
) -> Result<EndpointChanged, ClientError> {
let quote =
reqwest::get(format!("http://{}/attest", new_endpoint)).await?.bytes().await?.to_vec();
let quote = reqwest::get(format!("http://{}/attest?context=change_endpoint", new_endpoint))
.await?
.bytes()
.await?
.to_vec();
change_endpoint(api, rpc, validator_keypair, new_endpoint, quote).await
}

Expand Down Expand Up @@ -476,10 +479,15 @@ pub async fn get_tdx_quote(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
validator_stash: &SubxtAccountId32,
quote_context: QuoteContext,
) -> Result<Vec<u8>, ClientError> {
let query = entropy::storage().staking_extension().threshold_servers(validator_stash);
let server_info = query_chain(api, rpc, query, None).await.unwrap().unwrap();

let tss_endpoint = std::str::from_utf8(&server_info.endpoint)?.to_string();
Ok(reqwest::get(format!("http://{}/attest", tss_endpoint)).await?.bytes().await?.to_vec())
Ok(reqwest::get(format!("http://{}/attest?context={:?}", tss_endpoint, quote_context))
.await?
.bytes()
.await?
.to_vec())
}
12 changes: 12 additions & 0 deletions crates/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ pub enum QuoteContext {
ChangeThresholdAccounts,
}

#[cfg(feature = "std")]
impl std::fmt::Display for QuoteContext {
/// Custom debug implementation so that it can be used to build a query string
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
QuoteContext::Validate => write!(f, "validate"),
QuoteContext::ChangeEndpoint => write!(f, "change_endpoint"),
QuoteContext::ChangeThresholdAccounts => write!(f, "change_threshold_accounts"),
}
}
}

/// A trait for types which can handle attestation requests.
#[cfg(not(feature = "wasm"))]
pub trait AttestationHandler<AccountId> {
Expand Down
1 change: 1 addition & 0 deletions crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ pub async fn run_command(
Ok(serde_json::to_string_pretty(&headings)?)
},
CliCommand::GetTdxQuote { tss_endpoint, output_filename } => {
// TODO add context
let quote_bytes =
reqwest::get(format!("http://{}/attest", tss_endpoint)).await?.bytes().await?;
let output_filename = output_filename.unwrap_or("quote.dat".into());
Expand Down

0 comments on commit 732c1d5

Please sign in to comment.