-
Couldn't load subscription status.
- Fork 100
feat: Add StatusTracker to IdentityAssertion parsing and validation APIs
#943
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
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6a4a7cc
Add StatusTracker to the IdentityAssertion entry points
scouten-adobe ef95c5f
Signal invalid CBOR through new status tracking path
scouten-adobe 674bbd6
Merge branch 'main' into cawg-validate+status-tracker
scouten-adobe 1592e18
Add links from tests to spec
scouten-adobe ced18a0
cargo fmt
scouten-adobe 3e4164c
Move fixtures into validation_method folder for consistency
scouten-adobe aa51d6f
Use doc comments to cite the section of spec we're testing
scouten-adobe 481223c
Ensure we don't balk at extra fields in identity assertion CBOR
scouten-adobe da65cc2
Add test case for referenced_assertion not found in C2PA claim V1's a…
scouten-adobe 4a2cb04
Merge branch 'main' into cawg-validate+status-tracker
scouten-adobe 1378f7b
Merge branch 'main' into cawg-validate+status-tracker
scouten-adobe 63cacdb
Placeholder for test case for referenced_assertion not found in C2PA …
scouten-adobe 433a41d
Properly handle duplicate assertion reference
scouten-adobe 5dcfaa5
Properly handle missing reference to hard binding assertion
scouten-adobe 6cdc7c9
Properly handle unknown signature type
scouten-adobe b5a417a
Properly handle invalid pad values
scouten-adobe a4169c6
Properly handle pad2 invalid case
scouten-adobe 09de9f1
Add test cases for `StatusTracker` configured to stop on first error
scouten-adobe 2009d6a
Fix WASM build
scouten-adobe 6599646
Fix WASI build
scouten-adobe 01e3b7d
Fix WASI builds
scouten-adobe 148456c
Notes from design review last week
scouten-adobe 2663ff7
Note from subsequent conversation with Gavin
scouten-adobe 7c41f30
Merge branch 'main' into cawg-validate+status-tracker
scouten-adobe 957bc12
Merge branch 'main' into cawg-validate+status-tracker
scouten-adobe 098b311
Looks like we can't #[ignore] a test on WASI
scouten-adobe cbb8b59
Clippy doesn't like doc comments for commented-out functions
scouten-adobe 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
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| }; | ||
|
|
||
| use c2pa::{Manifest, Reader}; | ||
| use c2pa_status_tracker::{log_item, StatusTracker}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use serde_bytes::ByteBuf; | ||
|
|
||
|
|
@@ -63,14 +64,31 @@ | |
| /// Iterator returns a [`Result`] because each assertion may fail to parse. | ||
| /// | ||
| /// Aside from CBOR parsing, no further validation is performed. | ||
| pub fn from_manifest( | ||
| manifest: &Manifest, | ||
| ) -> impl Iterator<Item = Result<Self, c2pa::Error>> + use<'_> { | ||
| pub fn from_manifest<'a>( | ||
| manifest: &'a Manifest, | ||
| status_tracker: &'a mut StatusTracker, | ||
| ) -> impl Iterator<Item = Result<Self, c2pa::Error>> + use<'a> { | ||
| manifest | ||
| .assertions() | ||
| .iter() | ||
| .filter(|a| a.label().starts_with("cawg.identity")) | ||
| .map(|a| a.to_assertion()) | ||
| .map(|a| (a.label().to_owned(), a.to_assertion())) | ||
| .inspect(|(label, r)| { | ||
| if let Err(err) = r { | ||
| // TO DO: a.label() is probably wrong (not a full JUMBF URI) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gpeacock is there a way I can get from |
||
| log_item!( | ||
| label.clone(), | ||
| "invalid CBOR", | ||
| "IdentityAssertion::from_manifest" | ||
| ) | ||
| .validation_status("cawg.identity.cbor.invalid") | ||
| .failure_no_throw( | ||
| status_tracker, | ||
| c2pa::Error::AssertionSpecificError(err.to_string()), | ||
| ); | ||
| } | ||
| }) | ||
| .map(move |(_label, r)| r) | ||
| } | ||
|
|
||
| /// Create a summary report from this `IdentityAssertion`. | ||
|
|
@@ -83,25 +101,28 @@ | |
| pub async fn to_summary<SV: SignatureVerifier>( | ||
| &self, | ||
| manifest: &Manifest, | ||
| status_tracker: &mut StatusTracker, | ||
| verifier: &SV, | ||
| ) -> impl Serialize | ||
| where | ||
| <SV as SignatureVerifier>::Output: 'static, | ||
| { | ||
| self.to_summary_impl(manifest, verifier).await | ||
| self.to_summary_impl(manifest, status_tracker, verifier) | ||
| .await | ||
| } | ||
|
|
||
| pub(crate) async fn to_summary_impl<SV: SignatureVerifier>( | ||
| &self, | ||
| manifest: &Manifest, | ||
| status_tracker: &mut StatusTracker, | ||
| verifier: &SV, | ||
| ) -> IdentityAssertionReport< | ||
| <<SV as SignatureVerifier>::Output as ToCredentialSummary>::CredentialSummary, | ||
| > | ||
| where | ||
| <SV as SignatureVerifier>::Output: 'static, | ||
| { | ||
| match self.validate(manifest, verifier).await { | ||
| match self.validate(manifest, status_tracker, verifier).await { | ||
| Ok(named_actor) => { | ||
| let summary = named_actor.to_summary(); | ||
|
|
||
|
|
@@ -120,13 +141,15 @@ | |
| /// Summarize all of the identity assertions found for a [`Manifest`]. | ||
| pub async fn summarize_all<SV: SignatureVerifier>( | ||
| manifest: &Manifest, | ||
| status_tracker: &mut StatusTracker, | ||
| verifier: &SV, | ||
| ) -> impl Serialize { | ||
| Self::summarize_all_impl(manifest, verifier).await | ||
| Self::summarize_all_impl(manifest, status_tracker, verifier).await | ||
| } | ||
|
|
||
| pub(crate) async fn summarize_all_impl<SV: SignatureVerifier>( | ||
| manifest: &Manifest, | ||
| status_tracker: &mut StatusTracker, | ||
| verifier: &SV, | ||
| ) -> IdentityAssertionsForManifest< | ||
| <<SV as SignatureVerifier>::Output as ToCredentialSummary>::CredentialSummary, | ||
|
|
@@ -139,9 +162,16 @@ | |
| >, | ||
| > = vec![]; | ||
|
|
||
| for assertion in Self::from_manifest(manifest) { | ||
| let assertion_results: Vec<Result<IdentityAssertion, c2pa::Error>> = | ||
| Self::from_manifest(manifest, status_tracker).collect(); | ||
|
|
||
| for assertion in assertion_results { | ||
| let report = match assertion { | ||
| Ok(assertion) => assertion.to_summary_impl(manifest, verifier).await, | ||
| Ok(assertion) => { | ||
| assertion | ||
| .to_summary_impl(manifest, status_tracker, verifier) | ||
| .await | ||
| } | ||
| Err(_) => { | ||
| todo!("Handle assertion failed to parse case"); | ||
| } | ||
|
|
@@ -163,6 +193,7 @@ | |
| #[cfg(feature = "v1_api")] | ||
| pub async fn summarize_manifest_store<SV: SignatureVerifier>( | ||
| store: &c2pa::ManifestStore, | ||
| status_tracker: &mut StatusTracker, | ||
| verifier: &SV, | ||
| ) -> impl Serialize { | ||
| // NOTE: We can't write this using .map(...).collect() because there are async | ||
|
|
@@ -175,7 +206,7 @@ | |
| > = BTreeMap::new(); | ||
|
|
||
| for (id, manifest) in store.manifests() { | ||
| let report = Self::summarize_all_impl(manifest, verifier).await; | ||
| let report = Self::summarize_all_impl(manifest, status_tracker, verifier).await; | ||
| reports.insert(id.clone(), report); | ||
| } | ||
|
|
||
|
|
@@ -189,6 +220,7 @@ | |
| /// Summarize all of the identity assertions found for a [`Reader`]. | ||
| pub async fn summarize_from_reader<SV: SignatureVerifier>( | ||
| reader: &Reader, | ||
| status_tracker: &mut StatusTracker, | ||
| verifier: &SV, | ||
| ) -> impl Serialize { | ||
| // NOTE: We can't write this using .map(...).collect() because there are async | ||
|
|
@@ -201,7 +233,7 @@ | |
| > = BTreeMap::new(); | ||
|
|
||
| for (id, manifest) in reader.manifests() { | ||
| let report = Self::summarize_all_impl(manifest, verifier).await; | ||
| let report = Self::summarize_all_impl(manifest, status_tracker, verifier).await; | ||
| reports.insert(id.clone(), report); | ||
| } | ||
|
|
||
|
|
@@ -222,25 +254,55 @@ | |
| pub async fn validate<SV: SignatureVerifier>( | ||
| &self, | ||
| manifest: &Manifest, | ||
| status_tracker: &mut StatusTracker, | ||
| verifier: &SV, | ||
| ) -> Result<SV::Output, ValidationError<SV::Error>> { | ||
| self.check_padding()?; | ||
| // TO DO: Create new status tracker here and pass it through | ||
| // the rest of this code. Then we can rewrite the log with | ||
| // assertion label at the end of this process. | ||
|
|
||
| // UPDATED TO DO: Hold off until Gavin lands the post-validate branch. | ||
| // Then we'll get the assertion label handed to us nicely. | ||
| self.check_padding(status_tracker)?; | ||
|
|
||
| self.signer_payload.check_against_manifest(manifest)?; | ||
| self.signer_payload | ||
| .check_against_manifest(manifest, status_tracker)?; | ||
|
|
||
| verifier | ||
| .check_signature(&self.signer_payload, &self.signature) | ||
| .check_signature(&self.signer_payload, &self.signature, status_tracker) | ||
| .await | ||
| } | ||
|
|
||
| fn check_padding<E>(&self) -> Result<(), ValidationError<E>> { | ||
| fn check_padding<E: Debug>( | ||
| &self, | ||
| status_tracker: &mut StatusTracker, | ||
| ) -> Result<(), ValidationError<E>> { | ||
| if !self.pad1.iter().all(|b| *b == 0) { | ||
| return Err(ValidationError::InvalidPadding); | ||
| // TO DO: Where would we get assertion label? | ||
| log_item!( | ||
| "NEED TO FIND LABEL".to_owned(), | ||
| "invalid value in pad fields", | ||
| "SignerPayload::check_padding" | ||
| ) | ||
| .validation_status("cawg.identity.pad.invalid") | ||
| .failure(status_tracker, ValidationError::<E>::InvalidPadding)?; | ||
|
|
||
| // We'll only get to this line if `pad1` is invalid and the status tracker is | ||
| // configured to continue through recoverable errors. In that case, we want to | ||
| // avoid logging a second "invalid padding" warning if `pad2` is also invalid. | ||
| return Ok(()); | ||
| } | ||
|
|
||
| if let Some(pad2) = self.pad2.as_ref() { | ||
| if !pad2.iter().all(|b| *b == 0) { | ||
| return Err(ValidationError::InvalidPadding); | ||
| // TO DO: Where would we get assertion label? | ||
| log_item!( | ||
| "NEED TO FIND LABEL".to_owned(), | ||
| "invalid value in pad fields", | ||
| "SignerPayload::check_padding" | ||
| ) | ||
| .validation_status("cawg.identity.pad.invalid") | ||
| .failure(status_tracker, ValidationError::<E>::InvalidPadding)?; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.