Skip to content

Commit

Permalink
feat: Claim v2 (contentauth#707)
Browse files Browse the repository at this point in the history
* Initial Claim_v2 work

* feat: 24 API enabled and v1_api disabled by default

* feat: v2 claims enabled for early testing by setting the claim_version field

* Support data hash

* More features

* sigTst2 fixes

* Support for Ingredient.V3 assertions

* Support for Ingredient.V3

* More checks

* signature box support

* Add version check for ingredient add

* feat: Support v2 claims in 24 API
Ingredient title and format now Options.
Manifest claim_generator and format now Options.
Removed claim_generator_hints support.
Changed Actions validation
make_test_images update for v2 claims.

* feat: Support v2 claims
feat: Ingredient.v3 support
ValidationResults in ingredients and ManifestStore
Always use action.parameters.ingredients instead of ingredient.
Adds string parameter to AssertionEncoding error.

* fix: c2patool upgrades to API change in Ingredient.title()

* chore: PR comment cleanup

* feat: Add ingredient_url tracking for status.
Adds default support for LogItem

* feat: add validation_results to Reader debug output

* fix: c2patool sidecar not written

* feat: 24 API enabled and v1_api disabled by default
public manifest writing only under v1 api
schema now based on Reader instead of manifest store

* fix(c2patool) assortment of bug fixes
adds status_results to detailed report.
fixes force flag
removes invalid sample certs
no more local target test folder
restores most missing integration tests
repair support for different case extensions

* fix(c2patool): do not write instanceId named generated thumbnail file

* feat: Remove the unstable_api feature (always available now)

* feat: rename ValidationResults to not use Map
Add validation_results method to reader.
Add some ValidationResults docs

* feat: Adds Reader. validation_results() method
processes informational status (when we have them)

* Remove function `ts_token_from_time_stamp_response`. No longer used anywhere.

* Fix Markdown syntax

* chore: Release notes and review fixes

* Proofreading

* feat: handle validation results and status together
Add some integration tests
  • Loading branch information
mauricefisher64 authored Jan 27, 2025
1 parent 0a22601 commit ff17cf3
Show file tree
Hide file tree
Showing 71 changed files with 4,477 additions and 677 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion cawg_identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
async-trait = "0.1.78"
base64 = "0.22.1"
c2pa = { path = "../sdk", version = "0.43.0", features = ["openssl", "unstable_api"] }
c2pa = { path = "../sdk", version = "0.43.0", features = ["openssl"] }
c2pa-crypto = { path = "../internal/crypto", version = "0.5.0" }
c2pa-status-tracker = { path = "../internal/status-tracker", version = "0.3.0" }
chrono = { version = "0.4.38", features = ["serde"] }
Expand Down
3 changes: 1 addition & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ c2pa = { path = "../sdk", version = "0.43.0", features = [
"fetch_remote_manifests",
"file_io",
"add_thumbnails",
"pdf",
"unstable_api",
"pdf"
] }
c2pa-crypto = { path = "../internal/crypto", version = "0.5.0" }
clap = { version = "4.5.10", features = ["derive", "env"] }
Expand Down
9 changes: 5 additions & 4 deletions cli/sample/test.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"alg": "ps256",
"private_key": "ps256.pem",
"sign_cert": "ps256.pub",
"claim_version": 1,
"ta_url": "http://timestamp.digicert.com",
"claim_generator": "TestApp",
"claim_generator_info":[{
"name": "TestApp",
"version": "1.0.0"
}],
"title": "My Title",
"assertions": [
{
Expand Down
5 changes: 3 additions & 2 deletions cli/src/callback_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ impl CallbackSignerConfig {
pub fn new(sign_config: &SignConfig, reserve_size: usize) -> anyhow::Result<Self> {
let alg = sign_config
.alg
.clone()
.and_then(|alg| alg.parse::<SigningAlg>().ok())
.as_deref()
.map_or_else(|| "es256".to_string(), |alg| alg.to_lowercase())
.parse::<SigningAlg>()
.context("Invalid signing algorithm provided")?;

let sign_cert_path = sign_config
Expand Down
2 changes: 1 addition & 1 deletion cli/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn info(path: &Path) -> Result<()> {
}
}
let ingredient = c2pa::Ingredient::from_file_with_options(path, &Options {})?;
println!("Information for {}", ingredient.title());
println!("Information for {}", ingredient.title().unwrap_or_default());
let mut is_cloud_manifest = false;
//println!("instanceID = {}", ingredient.instance_id());
if let Some(provenance) = ingredient.provenance() {
Expand Down
30 changes: 19 additions & 11 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// in that file. If a manifest definition JSON file is specified,
/// the claim will be added to any existing claims.
use std::{
fs::{create_dir_all, remove_dir_all, File},
fs::{create_dir_all, remove_dir_all, remove_file, File},
io::Write,
path::{Path, PathBuf},
str::FromStr,
Expand Down Expand Up @@ -469,7 +469,7 @@ fn main() -> Result<()> {
// match args.output {
// Some(output) => {
// if output.exists() && !args.force {
// bail!("Output already exists, use -f/force to force write");
// bail!("Output already exists; use -f/force to force write");
// }
// if path != &output {
// std::fs::copy(path, &output)?;
Expand Down Expand Up @@ -517,7 +517,7 @@ fn main() -> Result<()> {
} else {
manifest.claim_generator_info.insert(1, tool_generator);
}
println!("claim generator {:?}", manifest.claim_generator_info);

// set manifest base path before ingredients so ingredients can override it
if let Some(base) = base_path.as_ref() {
builder.base_path = Some(base.clone());
Expand Down Expand Up @@ -596,8 +596,12 @@ fn main() -> Result<()> {
if ext_normal(&output) != ext_normal(&args.path) {
bail!("Output type must match source type");
}
if output.exists() && !args.force {
bail!("Output already exists, use -f/force to force write");
if output.exists() {
if args.force {
remove_file(&output)?;
} else {
bail!("Output already exists; use -f/force to force write");
}
}

if output.file_name().is_none() {
Expand All @@ -607,11 +611,16 @@ fn main() -> Result<()> {
bail!("Missing extension output");
}

#[allow(deprecated)] // todo: remove when we can
builder
let manifest_data = builder
.sign_file(signer.as_ref(), &args.path, &output)
.context("embedding manifest")?;

if args.sidecar {
let sidecar = output.with_extension("c2pa");
let mut file = File::create(&sidecar)?;
file.write_all(&manifest_data)?;
}

// generate a report on the output file
let reader = Reader::from_file(&output).map_err(special_errs)?;
if args.detailed {
Expand All @@ -633,7 +642,7 @@ fn main() -> Result<()> {
if args.force {
remove_dir_all(&output)?;
} else {
bail!("Output already exists, use -f/force to force write");
bail!("Output already exists; use -f/force to force write");
}
}
create_dir_all(&output)?;
Expand Down Expand Up @@ -708,8 +717,8 @@ pub mod tests {
#[test]
fn test_manifest_config() {
const SOURCE_PATH: &str = "tests/fixtures/earth_apollo17.jpg";
const OUTPUT_PATH: &str = "target/tmp/unit_out.jpg";
create_dir_all("target/tmp").expect("create_dir");
const OUTPUT_PATH: &str = "../target/tmp/unit_out.jpg";
create_dir_all("../target/tmp").expect("create_dir");
std::fs::remove_file(OUTPUT_PATH).ok(); // remove output file if it exists
let mut builder = Builder::from_json(CONFIG).expect("from_json");

Expand All @@ -719,7 +728,6 @@ pub mod tests {
.signer()
.expect("get_signer");

#[allow(deprecated)] // todo: remove when we can
let _result = builder
.sign_file(signer.as_ref(), SOURCE_PATH, OUTPUT_PATH)
.expect("embed");
Expand Down
10 changes: 5 additions & 5 deletions cli/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ fn populate_node(
}

for ingredient in manifest.ingredients().iter() {
let title = ingredient.title().unwrap_or("Untitled");
if let Some(label) = ingredient.active_manifest() {
// create new node
let data = if name_only {
format!("{}_{}", ingredient.title(), label)
format!("{}_{}", title, label)
} else {
format!("Asset:{}, Manifest:{}", ingredient.title(), label)
format!("Asset:{}, Manifest:{}", title, label)
};

let new_token = current_token.append(tree, data);

populate_node(tree, reader, label, &new_token, name_only)?;
} else {
let asset_name = ingredient.title();
let data = if name_only {
asset_name.to_string()
title.to_string()
} else {
format!("Asset:{asset_name}")
format!("Asset:{title}")
};
current_token.append(tree, data);
}
Expand Down
Loading

0 comments on commit ff17cf3

Please sign in to comment.