Skip to content

Commit 8eed862

Browse files
authored
fix: Allow C2PA archives to be unsigned (#1560)
Change to unsigned c2pa archives We must read without validation Note that you can still sign a builder as application/c2pa if desired but to_archive will not sign archives.
1 parent cfd374a commit 8eed862

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

sdk/src/builder.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,24 @@ impl Builder {
871871
let mut stream = stream;
872872
Self::old_from_archive(&mut stream).or_else(|_| {
873873
// if the old method fails, try the new method
874-
stream.rewind()?;
875-
crate::Reader::from_stream("application/c2pa", stream).and_then(|r| r.into_builder())
874+
// we should be able to call Reader::from_stream and then convert to Builder
875+
// but we need to disable validation since we are not signing yet
876+
// so we will read the store directly here
877+
//crate::Reader::from_stream("application/c2pa", stream).and_then(|r| r.into_builder())
878+
let settings = crate::settings::get_settings().unwrap_or_default();
879+
880+
let mut validation_log = crate::status_tracker::StatusTracker::default();
881+
stream.rewind()?; // Ensure stream is at the start
882+
883+
let store = Store::from_stream(
884+
"application/c2pa",
885+
&mut stream,
886+
false,
887+
&mut validation_log,
888+
&settings,
889+
)?;
890+
let reader = Reader::from_store(store, &mut validation_log, &settings)?;
891+
reader.into_builder()
876892
})
877893
}
878894

@@ -1753,21 +1769,6 @@ impl Builder {
17531769
.ok_or(Error::IngredientNotFound)
17541770
}
17551771

1756-
/// We use this signer to generate working store manifests
1757-
pub(crate) fn working_store_signer() -> Result<Box<dyn Signer>> {
1758-
let cert_chain = include_bytes!("../tests/fixtures/certs/ed25519.pub");
1759-
let private_key = include_bytes!("../tests/fixtures/certs/ed25519.pem");
1760-
1761-
Ok(Box::new(crate::signer::RawSignerWrapper(
1762-
crate::crypto::raw_signature::signer_from_cert_chain_and_private_key(
1763-
cert_chain,
1764-
private_key,
1765-
crate::SigningAlg::Ed25519,
1766-
None,
1767-
)?,
1768-
)))
1769-
}
1770-
17711772
/// This creates a working store from the builder
17721773
/// The working store is signed with a BoxHash over an empty string
17731774
/// And is returned as a Vec<u8> of the c2pa_manifest bytes
@@ -1790,8 +1791,9 @@ impl Builder {
17901791
let mut store = Store::new();
17911792
store.commit_claim(claim)?;
17921793

1793-
let signer = Self::working_store_signer()?;
1794-
store.get_box_hashed_embeddable_manifest(signer.as_ref(), settings)
1794+
//store.to_jumbf_internal(1000)
1795+
store.get_data_hashed_manifest_placeholder(100, "application/c2pa")
1796+
//store.get_box_hashed_embeddable_manifest(signer.as_ref(), settings)
17951797
}
17961798
}
17971799

@@ -2696,7 +2698,7 @@ mod tests {
26962698

26972699
#[test]
26982700
fn test_builder_data_hashed_embeddable_min() -> Result<()> {
2699-
let signer = Builder::working_store_signer().unwrap();
2701+
let signer = Settings::signer().unwrap();
27002702

27012703
let mut builder = Builder::from_json(&simple_manifest_json()).unwrap();
27022704

@@ -2745,7 +2747,7 @@ mod tests {
27452747
let mut builder = Builder::from_json(&simple_manifest_json()).unwrap();
27462748
builder.add_assertion(labels::BOX_HASH, &bh).unwrap();
27472749

2748-
let signer = Builder::working_store_signer().unwrap();
2750+
let signer = Settings::signer().unwrap();
27492751

27502752
let manifest_bytes = builder
27512753
.sign_box_hashed_embeddable(signer.as_ref(), "application/c2pa")

sdk/src/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl Reader {
688688
}
689689

690690
#[async_generic()]
691-
fn from_store(
691+
pub(crate) fn from_store(
692692
store: Store,
693693
validation_log: &mut StatusTracker,
694694
settings: &Settings,

0 commit comments

Comments
 (0)