Skip to content

attestation crate: Add builder pattern for constructing AttestationVerifier - #70

Open
ameba23 wants to merge 8 commits into
mainfrom
peg/attestation-verifier-builder
Open

attestation crate: Add builder pattern for constructing AttestationVerifier#70
ameba23 wants to merge 8 commits into
mainfrom
peg/attestation-verifier-builder

Conversation

@ameba23

@ameba23 ameba23 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This is a library API breaking change.

This adds a builder pattern for constructing AttestationVerifier. It removes the old constructor and makes several fields private which were public before, so it breaks the API.

@ameba23
ameba23 force-pushed the peg/attestation-verifier-builder branch from ddfdb7b to ecfa3b7 Compare August 25, 2026 09:02
@ameba23
ameba23 force-pushed the peg/attestation-verifier-builder branch from ecfa3b7 to 6dc3123 Compare August 25, 2026 09:38

@samlaf samlaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving comments, as requested in #84 (comment)

Comment thread crates/attestation-provider-server/src/main.rs Outdated
Comment thread crates/attestation/src/lib.rs Outdated
Comment thread crates/attestation/src/lib.rs Outdated
Comment on lines +379 to +397
pub fn dump_dcap_quotes(mut self) -> Self {
self.dump_dcap_quotes = true;
self
}

/// Whether to override outdated TCB when on Azure
///
/// This provides a workaround for a known outdated FMSPC used by Azure
#[cfg(feature = "azure-verifier")]
pub fn override_azure_outdated_tcb(mut self) -> Self {
self.override_azure_outdated_tcb = true;
self
}

/// Do not keep an internal DCAP collateral cache
pub fn with_no_internal_pccs(mut self) -> Self {
self.internal_pccs_prewarm = None;
self
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent use of with_ prefix. I'd make all of them start with with_ personally.
Also woulld make all of them take the field explicitly, even when its a boolean). Will make the building syntax cleaner (see my other comment in attestation-provider-server)

Comment thread crates/attestation/src/lib.rs Outdated
Comment on lines +399 to +417
/// Keep a DCAP collateral cache, and pre-fill it with all available
/// collateral
pub fn with_pccs_prewarmed(mut self) -> Self {
self.internal_pccs_prewarm = Some(true);
self
}

/// Keep a DCAP collateral cache, starting empty
pub fn with_pccs_not_prewarmed(mut self) -> Self {
self.internal_pccs_prewarm = Some(false);
self
}

/// Set the URL used by internal PCCS
pub fn pccs_url(mut self, pccs_url: String) -> Self {
self.pccs_url = Some(pccs_url);
self
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these pccs functions are a bit confusing. Didn't understand the difference between internal_pccs_prewarm = None and Some(false) at first... and then having pccs_url and internal_pccs_prewarm separate is kind of weird and even allows a combination that is nonsense (passing a url but setting prewarm to None).

How about refactoring into an enum instead?

  /// How the verifier obtains DCAP collateral
  #[derive(Clone, Debug)]
  pub enum PccsMode {
      /// No internal collateral cache. DCAP/Azure verification returns
      /// [AttestationError::NoPccs].
      None,
      /// Internal cache pre-filled with all available collateral at build
      /// time. `url` defaults to Intel PCS.
      Prewarmed { url: Option<String> },
      /// Internal cache that starts empty and fetches on demand.
      /// `url` defaults to Intel PCS.
      Lazy { url: Option<String> },
  }

then you can do something like:

  AttestationVerifier::builder(policy)
      .with_pccs(PccsMode::Prewarmed { url: cli.pccs_url })
      .with_dump_dcap_quotes(cli.log_dcap_quote)
      .build()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agree this is better. Did this, but did not put the url in because we also need the URL in the 'none' case. In the async version of the verifier, no pccs mean it will always use the remote service (given url or intel pcs) on every verification.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice! Think this is starting to make more sense to me. Then I'd consider renaming PccsMode to CollateralCache or PccsCache something. CollateralCache::None is a lot more explicit about what its doing.

Also looks like there's a bug since in the None case the pccs_url is not being used and it always defaults to intel.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also found a related issue while reviewing this, created #87

Comment thread crates/attestation/src/lib.rs Outdated
…ts/attested-tls into peg/attestation-verifier-builder

* 'peg/attestation-verifier-builder' of github.com:flashbots/attested-tls:
  Add builder pattern for constructing AttestationVerifier
  Add builder pattern for constructing AttestationVerifier
  Run clippy on stable in CI to avoid issue with it failing with dependencies
@ameba23
ameba23 requested a review from samlaf August 26, 2026 06:59

@samlaf samlaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM outside of the fix below and the ongoing discussion above

Comment on lines +364 to +365
#[cfg_attr(not(feature = "azure-verifier"), allow(dead_code))]
override_azure_outdated_tcb: bool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[cfg_attr(not(feature = "azure-verifier"), allow(dead_code))]
override_azure_outdated_tcb: bool,
override_azure_outdated_tcb: bool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think you meant to remove this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants