Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract PCK certificate chain from quotes #1209

Merged
merged 35 commits into from
Dec 18, 2024

Conversation

ameba23
Copy link
Contributor

@ameba23 ameba23 commented Dec 10, 2024

I recently figured out the PCK certificate chain is actually included in the quote, encoded as PEM. I have an open PR to tdx-quote which allows getting the certificate chain from a quote, and i have moved the cert chain parsing logic over there: entropyxyz/tdx-quote#12

This means that the extrinsics validate and change_threshold_accounts don't need to take both a quote and a certificate chain - just the quote.

My proposal is to change AttestationHandler::verify_quote to validate the quote with whatever PCK can be extracted from its certificate chain, and return the PCK upon successful verification - the staking pallet can then store it in the ServerInfo.

This also adds a production feature flag to entropy which propagates down to pallet-attestation. If present, real PCK cert chain verification will be used (previously we always mocked certificate chain verification). By default it is not used.

Closes #1208 by adding a custom error type to the attestation handler trait.

If this gets approved, i think there is maybe some refactoring that could be done as a followup - i'm not totally sure but i don't think the staking extension pallet needs to be a dependency of the attestation pallet anymore. Which means we can have the attestation pallet be a dependency of the staking extension pallet, and move the AttestationHandler trait from entropy-shared to the attestation pallet.

@ameba23 ameba23 marked this pull request as draft December 10, 2024 11:17
Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

Took a sneak peek here, seems reasonable. I like that we're able to move some of this out to the tdx-quote crate

@@ -273,3 +273,6 @@ try-runtime=[
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
]
# Enables real PCK certificate chain verification - which means TSS nodes much be runnning on TDX
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Enables real PCK certificate chain verification - which means TSS nodes much be runnning on TDX
# Enables real PCK certificate chain verification - which means TSS nodes must be runnning on TDX

Cargo.lock Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you do a full cargo update here? This seems like a lot of changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that was an accident. I couldn't update the git version tdx-quote with cargo update tdx-quote because some crates were using the git version and others the release version. So i lazily just did cargo update without thinking of the implications. Im not sure whether to revert it or just see if things still work and leave it in if the do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the end i have reverted the lockfile as there was cargo-deny related license issues popping up

node/cli/Cargo.toml Outdated Show resolved Hide resolved
entropy-testing-utils={ path="../testing-utils" }
tdx-quote ={ version="0.0.1", features=["mock"] }
tdx-quote={ git="https://github.com/entropyxyz/tdx-quote.git", branch="peg/cert-chain-parse", features=[
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm planning to re-publish this crate if this PR gets approved. Ideally i would also like to fix entropyxyz/tdx-quote#13 and entropyxyz/tdx-quote#11 before publishing.

/// An error when verifying a quote
#[cfg(not(feature = "wasm"))]
#[derive(Eq, PartialEq)]
pub enum VerifyQuoteError {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this custom error type because i couldn't figure out how to get the useful information out of a sp_runtime::DispathError without adding a lot of extra code.

}

impl<T> From<pck::PckParseVerifyError> for Error<T> {
fn from(error: pck::PckParseVerifyError) -> Self {
impl<T> From<VerifyQuoteError> for Error<T> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe its possible to remove the need for this impl by implementing PalletError for VerifyQuoteError, so that we can have a tuple enum variant of pallet::<T>::Error containing it. I would maybe try this in a followup - but i am afraid of going over the maximum encoded size of 4 bytes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like it's a compile time check anyways, so yeah would be worth trying

@ameba23 ameba23 marked this pull request as ready for review December 17, 2024 18:17
Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

Nice work, looks good 👍

I'd need to double check the diff with v0.3.0 to be sure, but this probably needs a CHANGELOG entry and a "Bump spec_version" tag.

Which means we can have the attestation pallet be a dependency of the staking extension pallet, and move the AttestationHandler trait from entropy-shared to the attestation pallet.

It would be nice to keep this flexible using associated types, but I'd be curious to see what you have in mind for this first before commenting further.

) -> Result<(), sp_runtime::DispatchError> {
Ok(())
) -> Result<BoundedVecEncodedVerifyingKey, VerifyQuoteError> {
Ok(sp_runtime::BoundedVec::new())
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to specify a size of 33 bytes here in case a caller is assuming a "valid"-ish key back

impl<T> From<pck::PckParseVerifyError> for Error<T> {
fn from(error: pck::PckParseVerifyError) -> Self {
impl<T> From<VerifyQuoteError> for Error<T> {
fn from(error: VerifyQuoteError) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, so it was really frustrating trying to debug errors stemming from the quote verification code because they'd all basically be type erased into the pallet error. While this is pretty ugly it is quite useful.

Maybe worth a comment explaining this for future readers.

}

impl<T> From<pck::PckParseVerifyError> for Error<T> {
fn from(error: pck::PckParseVerifyError) -> Self {
impl<T> From<VerifyQuoteError> for Error<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like it's a compile time check anyways, so yeah would be worth trying

crates/shared/src/types.rs Show resolved Hide resolved
@ameba23 ameba23 added the Bump `spec_version` A change which affects the current runtime behaviour label Dec 18, 2024
@ameba23
Copy link
Contributor Author

ameba23 commented Dec 18, 2024

I'd need to double check the diff with v0.3.0 to be sure, but this probably needs a CHANGELOG entry and a "Bump spec_version" tag.

Im still not super clear exactly what kinds of runtime changes mean we need to bump the spec version but i added that label for now as i figured better to have it and not need it than need it and not have it.

) -> Result<(), sp_runtime::DispatchError> {
Ok(())
) -> Result<BoundedVecEncodedVerifyingKey, VerifyQuoteError> {
// Ok(sp_runtime::BoundedVec::new())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Ok(sp_runtime::BoundedVec::new())

Comment on lines +48 to +50
- In ([#1209]()) a `production` feature flag was added to `entropy` which if enabled will use
non-mock verification of PCK certificate chains in TDX quotes, meaning TSS servers must be running
on TDX hardware
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- In ([#1209]()) a `production` feature flag was added to `entropy` which if enabled will use
non-mock verification of PCK certificate chains in TDX quotes, meaning TSS servers must be running
on TDX hardware

These sections should just have PR titles.

If anything we could maybe mention it in the Breaking Changes, but nbd. Can always add it later when prepping the release.

@ameba23 ameba23 merged commit 664e406 into master Dec 18, 2024
8 checks passed
@ameba23 ameba23 deleted the peg/extract-pck-cert-from-quotes branch December 18, 2024 16:50
HCastano pushed a commit that referenced this pull request Dec 19, 2024
Minor edits missed from PR review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bump `spec_version` A change which affects the current runtime behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Staking pallet's FailedAttestationCheck error could be more descriptive
2 participants