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

Handle PCK certificates #1068

Merged
merged 44 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
44501dc
Add x509-parser dependency and helper fns
ameba23 Sep 24, 2024
d27ceba
Add pck cert chain parser
ameba23 Sep 25, 2024
ca6e09c
Doccomments
ameba23 Sep 25, 2024
11575c4
Use x509 crate that works with no-std
ameba23 Sep 26, 2024
6834392
Tidy, comments
ameba23 Sep 26, 2024
a1ae9e4
Merge branch 'master' into peg/handle-pck-certs
ameba23 Oct 2, 2024
8ed311a
WIP - handle PCK certs in staking pallet
ameba23 Oct 2, 2024
721bc82
Rm pck cert stuff from attestation pallet
ameba23 Oct 2, 2024
94d563f
Fix mock pck cert chain verifying
ameba23 Oct 3, 2024
6420aa9
Taplo
ameba23 Oct 3, 2024
a170da5
Compress verifying key
ameba23 Oct 3, 2024
d0663b7
Add missing import
ameba23 Oct 3, 2024
eda8bf0
Add missing implementations of PckCertVerifyier
ameba23 Oct 3, 2024
e02b0f4
Fix staking pallet benchmarks
ameba23 Oct 3, 2024
aac90aa
Validate cert chain of arbitrary length
ameba23 Oct 3, 2024
f5941a2
Tidy, fix tests
ameba23 Oct 3, 2024
1d6da3a
Lockfile
ameba23 Oct 3, 2024
0c50bbb
Merge master
ameba23 Oct 3, 2024
55abbd3
Clippy
ameba23 Oct 3, 2024
7815a87
Error handling
ameba23 Oct 3, 2024
31eca99
Add test for production cert verifyer
ameba23 Oct 3, 2024
8c15035
Rm commented code in test
ameba23 Oct 3, 2024
198da10
Changelog
ameba23 Oct 3, 2024
eef45ce
Merge branch 'master' into peg/handle-pck-certs
ameba23 Oct 3, 2024
e8d7a78
update metadata
JesseAbram Oct 3, 2024
672a1bf
Merge master
ameba23 Oct 23, 2024
021aac3
Hopefully fix staking extension pallet benchmarking for validate extr…
ameba23 Oct 23, 2024
097c188
Update pallets/staking/src/lib.rs
ameba23 Oct 24, 2024
6f0acd6
Update pallets/staking/src/tests.rs
ameba23 Oct 24, 2024
689e2f0
Update pallets/staking/src/pck/production.rs
ameba23 Oct 24, 2024
4fc7cb2
Update pallets/staking/src/pck/production.rs
ameba23 Oct 24, 2024
a6c5cea
Typo in struct name and improve test readablilty
ameba23 Oct 24, 2024
841b167
Rm calls to mock_attest_validate in staking pallet test as fn is now …
ameba23 Oct 24, 2024
03c6b37
Handle errors in production verify_cert fn
ameba23 Oct 24, 2024
d99fc35
Doccomments
ameba23 Oct 24, 2024
8d57919
Alphabetically sort runtime config types
ameba23 Oct 24, 2024
beb4e7e
Changelog
ameba23 Oct 24, 2024
3968d6e
derive serialize and deserialize for JoiningServerInfo
ameba23 Oct 24, 2024
a053e3b
Rename struct (typo)
ameba23 Oct 24, 2024
d7feb00
Make it clearer what is happenning with the PCK generation in staking…
ameba23 Oct 25, 2024
27d64eb
Use intel root cert from web link and link to it in doccomments
ameba23 Oct 25, 2024
06d3028
Fix staking pallet benchmarks in always generate a mock quote before …
ameba23 Oct 28, 2024
944f931
Slightly improve error conversion
ameba23 Oct 28, 2024
14014a0
Merge master
ameba23 Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 103 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pallets/attestation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sp-staking ={ version="27.0.0", default-features=false }
frame-benchmarking={ version="29.0.0", default-features=false, optional=true }
sp-std ={ version="14.0.0", default-features=false }
pallet-session ={ version="29.0.0", default-features=false, optional=true }
x509-parser ={ version="0.16.0", features=["verify"] }
ameba23 marked this conversation as resolved.
Show resolved Hide resolved

pallet-parameters={ version="0.2.0", path="../parameters", default-features=false }
entropy-shared={ version="0.2.0", path="../../crates/shared", features=[
Expand Down
3 changes: 3 additions & 0 deletions pallets/attestation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub mod benchmarking;

pub mod weights;

mod pck;

#[cfg(test)]
mod mock;

Expand All @@ -53,6 +55,7 @@ pub mod pallet {
use sp_std::vec::Vec;
use tdx_quote::Quote;

pub use crate::pck::parse_pck_cert_chain;
pub use crate::weights::WeightInfo;

/// A nonce included as input for a TDX quote
Expand Down
60 changes: 60 additions & 0 deletions pallets/attestation/src/pck.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (C) 2023 Entropy Cryptography Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use x509_parser::{
certificate::X509Certificate, error::X509Error, prelude::FromDer, public_key::PublicKey,
x509::SubjectPublicKeyInfo,
};

/// Intel's root public key together with metadata, encoded as der
const INTEL_ROOT_CA_PK_DER: [u8; 91] = [
48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66,
0, 4, 11, 169, 196, 192, 192, 200, 97, 147, 163, 254, 35, 214, 176, 44, 218, 16, 168, 187, 212,
232, 142, 72, 180, 69, 133, 97, 163, 110, 112, 85, 37, 245, 103, 145, 142, 46, 220, 136, 228,
13, 134, 11, 208, 204, 78, 226, 106, 172, 201, 136, 229, 5, 169, 83, 85, 140, 69, 63, 107, 9,
4, 174, 115, 148,
];

/// Parse a der encoded certificate to an X509Certificate struct
fn parse_der(input: &[u8]) -> Result<X509Certificate, X509Error> {
let (_remaining, cert) = X509Certificate::from_der(input)?;
Ok(cert)
}

/// Given an X509Certificate, get the subject public key, assuming it is ECDSA, and encoded it to
/// bytes
fn x509_to_subject_public_key(input: X509Certificate) -> Result<Vec<u8>, X509Error> {
let public_key = input.tbs_certificate.subject_pki.parsed()?;
match public_key {
PublicKey::EC(ec_point) => Ok(ec_point.data().to_vec()),
_ => Err(X509Error::Generic),
}
}

pub fn parse_pck_cert_chain(pck: Vec<u8>, pck_provider: Vec<u8>) -> Result<[u8; 65], X509Error> {
// Parse input certificates from der encoding
let pck = parse_der(&pck)?;
let pck_provider = parse_der(&pck_provider)?;

// Check PCK signature matches provider public key
pck.verify_signature(Some(pck_provider.public_key()))?;

// Check provider signature matches root public key
let (_, root_public_key) = SubjectPublicKeyInfo::from_der(&INTEL_ROOT_CA_PK_DER).unwrap();
pck_provider.verify_signature(Some(&root_public_key))?;

// Return the PCK public key
Ok(x509_to_subject_public_key(pck)?.try_into().unwrap())
}
Loading