-
Notifications
You must be signed in to change notification settings - Fork 37
ocp cosesign decode/verify #713
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
Merged
+577
−1
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e2faff1
Add basic framework for the EAT verifier
752c1b0
first version change
meilu-git 49bb2db
Revert "first version change"
meilu-git ceceeb2
first version of decode
meilu-git 3279339
add unit test
meilu-git dad9753
unit test
meilu-git 95772d3
some code for debugging
meilu-git d48ce94
this is a working version
meilu-git 201e8f8
intermi commit
meilu-git 5253c88
take out tag and then use coset from main
meilu-git 5d932f3
fix pipleline precheck error, add Clap cll to pass bin file ot decode.
meilu-git 0bf0e92
add steps to run cli tool to decode the bins
meilu-git e47abaa
add step to call cli tool to validate bin files
meilu-git 234a995
accidently checked cargo.toml that is workign in progress, roll back
meilu-git b915d7e
use Open SSL to parse pub key instead of 509 parser
meilu-git 221d0e9
build the binary before running the cli
meilu-git 6010d6e
update the working dir
meilu-git 1ddeee2
one more try with working dir
meilu-git 5979f07
code review feedback
meilu-git 0484956
chamge the to add verify as a subcommand
meilu-git 1630e41
code review feedback
meilu-git 15f07bf
clean up
meilu-git 94f16cd
code review feedback
meilu-git 13944f7
update the cli due to foramt change
meilu-git 668bbfd
fmt in yaml
meilu-git be1458f
code review feedback
meilu-git 9cb5be1
code review feedback
meilu-git 29d1200
Merge branch 'main' of https://github.com/chipsalliance/caliptra-mcu-…
f2c4774
address review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /target*/ | ||
| *target*/ | ||
| **/target/ | ||
| test_key | ||
|
|
||
| # By default, ignore Cargo.lock files in non-workspace directories. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Licensed under the Apache-2.0 license | ||
|
|
||
| [workspace] | ||
| members = [ | ||
| "ocptoken-rs", | ||
swenson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
| resolver = "2" | ||
|
|
||
| [workspace.package] | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| authors = ["Caliptra contributors"] | ||
|
|
||
| [workspace.dependencies] | ||
| coset = { git = "https://github.com/google/coset",rev = "3ebd2d7d0dafe2b6856934ea2b4fa28ea3d9a373"} | ||
| hex = "0.4" | ||
| thiserror = "2.0" | ||
| openssl = { version = "0.10", features = ["vendored"] } | ||
| clap = { version = "4", features = ["derive"] } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Licensed under the Apache-2.0 license | ||
|
|
||
| [package] | ||
| name = "ocptoken" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| authors = ["Caliptra Contributors"] | ||
|
|
||
| [dependencies] | ||
| coset.workspace = true | ||
| hex.workspace = true | ||
| thiserror.workspace = true | ||
| openssl.workspace = true | ||
| clap.workspace = true | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Licensed under the Apache-2.0 license | ||
|
|
||
| use thiserror::Error; | ||
| /// Errors that can occur when working with OCP EAT tokens | ||
| #[derive(Error, Debug)] | ||
| pub enum OcpEatError { | ||
| /// COSE parsing or validation error | ||
| #[error("COSE error: {0:?}")] | ||
| CoseSign1(coset::CoseError), | ||
|
|
||
| #[error("Invalid token: {0}")] | ||
| InvalidToken(&'static str), | ||
|
|
||
| /// Certificate parsing error | ||
| #[error("Certificate error: {0}")] | ||
| Certificate(String), | ||
|
|
||
| /// Signature verification failure | ||
| #[error("Signature verification failed")] | ||
| SignatureVerification, | ||
|
|
||
| /// Crypto backend error | ||
| #[error("Crypto error: {0}")] | ||
| Crypto(String), | ||
| } | ||
|
|
||
| impl From<coset::CoseError> for OcpEatError { | ||
| fn from(err: coset::CoseError) -> Self { | ||
| OcpEatError::CoseSign1(err) | ||
| } | ||
| } | ||
|
|
||
| /// Result type for OCP EAT operations | ||
| pub type OcpEatResult<T> = std::result::Result<T, OcpEatError>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Licensed under the Apache-2.0 license | ||
|
|
||
| pub mod token; | ||
| pub mod error; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Licensed under the Apache-2.0 license | ||
|
|
||
| use clap::{Parser, Subcommand}; | ||
| use std::fs; | ||
| use std::path::PathBuf; | ||
|
|
||
| use ocptoken::token::evidence::Evidence; | ||
|
|
||
| #[derive(Parser, Debug)] | ||
| #[command( | ||
| name = "ocptoken", | ||
| author, | ||
| version, | ||
| about = "Verify an OCP TOKEN COSE_Sign1 token", | ||
| long_about = None | ||
| )] | ||
| struct Cli { | ||
| #[command(subcommand)] | ||
| command: Commands, | ||
| } | ||
|
|
||
| #[derive(Subcommand, Debug)] | ||
| enum Commands { | ||
| /// Cryptographically verify the supplied OCP token using the EAT attestation key | ||
| Verify(VerifyArgs), | ||
| } | ||
|
|
||
| #[derive(Parser, Debug)] | ||
| #[command( | ||
| author, | ||
| version, | ||
| about = "Cryptographically verify the supplied OCP token using the EAT attestation key" | ||
| )] | ||
| struct VerifyArgs { | ||
| #[arg( | ||
| short = 'e', | ||
| long = "evidence", | ||
| value_name = "EVIDENCE", | ||
| default_value = "ocp_eat.cbor" | ||
| )] | ||
| evidence: PathBuf, | ||
| } | ||
|
|
||
| fn main() { | ||
swenson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let cli = Cli::parse(); | ||
|
|
||
| match cli.command { | ||
| Commands::Verify(args) => run_verify(&args), | ||
| } | ||
| } | ||
|
|
||
| fn run_verify(args: &VerifyArgs) { | ||
| // 1. Load the binary file | ||
| let encoded = match fs::read(&args.evidence) { | ||
| Ok(b) => b, | ||
| Err(e) => { | ||
| eprintln!( | ||
| "Failed to read evidence file '{}': {}", | ||
| args.evidence.display(), | ||
| e | ||
| ); | ||
| std::process::exit(1); | ||
| } | ||
| }; | ||
|
|
||
| println!( | ||
| "Loaded evidence file '{}' ({} bytes)", | ||
| args.evidence.display(), | ||
| encoded.len() | ||
| ); | ||
|
|
||
| // 2. Decode the evidence | ||
| let ev = match Evidence::decode(&encoded) { | ||
| Ok(ev) => { | ||
| println!("Decode successful"); | ||
| ev | ||
| } | ||
| Err(e) => { | ||
| eprintln!("Evidence::decode failed: {:?}", e); | ||
|
|
||
| // Optional debug dump | ||
| let prefix_len = encoded.len().min(32); | ||
| eprintln!( | ||
| "First {} bytes of input: {:02x?}", | ||
| prefix_len, | ||
| &encoded[..prefix_len] | ||
| ); | ||
|
|
||
| std::process::exit(1); | ||
| } | ||
| }; | ||
|
|
||
| // 3. Cryptographically verify | ||
| match ev.verify() { | ||
| Ok(()) => { | ||
| println!("Signature verification successful"); | ||
| } | ||
| Err(e) => { | ||
| eprintln!("Evidence::verify failed: {:?}", e); | ||
| std::process::exit(1); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.