mirror of
https://github.com/matter-labs/teepot.git
synced 2025-07-21 15:13:56 +02:00
Introduce root_hash option
This commit is contained in:
parent
f90088be76
commit
f3f6ea1dba
4 changed files with 816 additions and 164 deletions
898
Cargo.lock
generated
898
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -19,6 +19,7 @@ homepage = "https://github.com/matter-labs/teepot"
|
||||||
actix-http = "3"
|
actix-http = "3"
|
||||||
actix-tls = "3"
|
actix-tls = "3"
|
||||||
actix-web = { version = "4.5", features = ["rustls-0_22"] }
|
actix-web = { version = "4.5", features = ["rustls-0_22"] }
|
||||||
|
alloy-primitives = "0.7.7"
|
||||||
anyhow = "1.0.82"
|
anyhow = "1.0.82"
|
||||||
awc = { version = "3.4", features = ["rustls-0_22-webpki-roots"] }
|
awc = { version = "3.4", features = ["rustls-0_22-webpki-roots"] }
|
||||||
base64 = "0.22.0"
|
base64 = "0.22.0"
|
||||||
|
@ -34,7 +35,7 @@ getrandom = "0.2.14"
|
||||||
hex = { version = "0.4.3", features = ["std"], default-features = false }
|
hex = { version = "0.4.3", features = ["std"], default-features = false }
|
||||||
intel-tee-quote-verification-rs = { package = "teepot-tee-quote-verification-rs", path = "crates/teepot-tee-quote-verification-rs", version = "0.2.3-alpha.1" }
|
intel-tee-quote-verification-rs = { package = "teepot-tee-quote-verification-rs", path = "crates/teepot-tee-quote-verification-rs", version = "0.2.3-alpha.1" }
|
||||||
intel-tee-quote-verification-sys = { version = "0.2.1" }
|
intel-tee-quote-verification-sys = { version = "0.2.1" }
|
||||||
secp256k1 = { version = "0.29", features = ["rand-std"] }
|
secp256k1 = { version = "0.29", features = ["rand-std", "global-context"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
num-integer = "0.1.46"
|
num-integer = "0.1.46"
|
||||||
num-traits = "0.2.18"
|
num-traits = "0.2.18"
|
||||||
|
|
|
@ -8,6 +8,7 @@ repository.workspace = true
|
||||||
homepage.workspace = true
|
homepage.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
alloy-primitives.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
clap.workspace = true
|
clap.workspace = true
|
||||||
hex.workspace = true
|
hex.workspace = true
|
||||||
|
|
|
@ -3,50 +3,80 @@
|
||||||
|
|
||||||
//! Tool for SGX attestation and batch signature verification
|
//! Tool for SGX attestation and batch signature verification
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use alloy_primitives::B256;
|
||||||
use clap::Parser;
|
use anyhow::{Context, Result};
|
||||||
|
use clap::{Args, Parser, Subcommand};
|
||||||
use secp256k1::{ecdsa::Signature, Message, PublicKey};
|
use secp256k1::{ecdsa::Signature, Message, PublicKey};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::UNIX_EPOCH;
|
use std::time::UNIX_EPOCH;
|
||||||
use teepot::client::TcbLevel;
|
use teepot::{
|
||||||
use teepot::sgx::{tee_qv_get_collateral, verify_quote_with_collateral, QuoteVerificationResult};
|
client::TcbLevel,
|
||||||
|
sgx::{tee_qv_get_collateral, verify_quote_with_collateral, QuoteVerificationResult},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author = "Matter Labs", version, about = "TEE attestation verifier", long_about = None)]
|
#[command(author = "Matter Labs", version, about = "SGX attestation and batch signature verifier", long_about = None)]
|
||||||
struct Arguments {
|
struct Arguments {
|
||||||
/// File containing a batch signature signed within a TEE enclave.
|
|
||||||
#[clap(long)]
|
|
||||||
signature_file: Option<PathBuf>,
|
|
||||||
/// File with attestation quote proving signature originated from a TEE enclave.
|
/// File with attestation quote proving signature originated from a TEE enclave.
|
||||||
#[clap(long)]
|
#[clap()]
|
||||||
attestation_file: PathBuf,
|
attestation_file: PathBuf,
|
||||||
|
/// An optional subcommand, for instance, for optional signature verification.
|
||||||
|
#[clap(subcommand)]
|
||||||
|
command: Option<SubCommands>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Args, Debug)]
|
||||||
|
struct SignatureArgs {
|
||||||
|
/// File containing a batch signature signed within a TEE enclave.
|
||||||
|
#[arg(long)]
|
||||||
|
signature_file: PathBuf,
|
||||||
|
/// Batch root hash for signature verification.
|
||||||
|
#[arg(long)]
|
||||||
|
root_hash: B256,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
enum SubCommands {
|
||||||
|
/// Provide both signature_file and root_hash
|
||||||
|
SignVerify(SignatureArgs),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let args = Arguments::parse();
|
let args = Arguments::parse();
|
||||||
|
|
||||||
let attestation_quote_bytes = fs::read(&args.attestation_file)?;
|
let attestation_quote_bytes = fs::read(&args.attestation_file)?;
|
||||||
let quote_verification_result = verify_attestation_quote(&attestation_quote_bytes)?;
|
let quote_verification_result = verify_attestation_quote(&attestation_quote_bytes)?;
|
||||||
print_quote_verification_summary("e_verification_result);
|
print_quote_verification_summary("e_verification_result);
|
||||||
if let Some(signature_file) = args.signature_file {
|
|
||||||
let reportdata = "e_verification_result.quote.report_body.reportdata;
|
match &args.command {
|
||||||
let verifying_key = PublicKey::from_slice(reportdata)?;
|
Some(SubCommands::SignVerify(signature_args)) => {
|
||||||
// let signature_bytes = fs::read(&args.signature_file)?;
|
verify_signature("e_verification_result, signature_args)?;
|
||||||
// let signature = Signature::from_compact(&signature_bytes)?;
|
|
||||||
let signature = fs::read(&args.signature_file)?.map(Signature::from_compact)?;
|
|
||||||
let message = Message::from_slice(reportdata)?; // TODO
|
|
||||||
if signature.verify(&message, &verifying_key).is_ok() {
|
|
||||||
println!("Signature verified successfully");
|
|
||||||
} else {
|
|
||||||
println!("Failed to verify signature");
|
|
||||||
}
|
}
|
||||||
|
None => {}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_attestation_quote<'a>(
|
fn verify_signature(
|
||||||
attestation_quote_bytes: &'a Vec<u8>,
|
quote_verification_result: &QuoteVerificationResult,
|
||||||
) -> Result<QuoteVerificationResult<'a>> {
|
signature_args: &SignatureArgs,
|
||||||
|
) -> Result<()> {
|
||||||
|
let reportdata = "e_verification_result.quote.report_body.reportdata;
|
||||||
|
let public_key = PublicKey::from_slice(reportdata)?;
|
||||||
|
println!("Public key from attestation quote: {}", public_key);
|
||||||
|
let signature_bytes = fs::read(&signature_args.signature_file)?;
|
||||||
|
let signature = Signature::from_compact(&signature_bytes)?;
|
||||||
|
let root_hash_msg = Message::from_digest_slice(&signature_args.root_hash.0)?;
|
||||||
|
if signature.verify(&root_hash_msg, &public_key).is_ok() {
|
||||||
|
println!("Signature verified successfully");
|
||||||
|
} else {
|
||||||
|
println!("Failed to verify signature");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify_attestation_quote(attestation_quote_bytes: &[u8]) -> Result<QuoteVerificationResult> {
|
||||||
println!(
|
println!(
|
||||||
"Verifying quote ({} bytes)...",
|
"Verifying quote ({} bytes)...",
|
||||||
attestation_quote_bytes.len()
|
attestation_quote_bytes.len()
|
||||||
|
@ -60,7 +90,7 @@ fn verify_attestation_quote<'a>(
|
||||||
.context("Failed to verify quote with collateral")
|
.context("Failed to verify quote with collateral")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_quote_verification_summary<'a>(quote_verification_result: &QuoteVerificationResult<'a>) {
|
fn print_quote_verification_summary(quote_verification_result: &QuoteVerificationResult) {
|
||||||
let QuoteVerificationResult {
|
let QuoteVerificationResult {
|
||||||
collateral_expired,
|
collateral_expired,
|
||||||
result,
|
result,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue