c2pa-rs

A fork of https://github.com/contentauth/c2pa-rs/
git clone git://archive.git.mtrnord.blog/mtrnords-photography-manager/c2pa-rs.git
Log | Files | Refs | README

commit f48cb7d282ce4e7f43d8b72f11e4f5179bdb6503
parent 503e637da0ce599f54e31ff588dd66b8b0640ff8
Author: mauricefisher64 <92736594+mauricefisher64@users.noreply.github.com>
Date:   Wed, 21 Jun 2023 12:22:42 -0400

Generate old COSE headers for temporary backwards support (#269)

* Generate old Cose headers.

Diffstat:
Msdk/src/cose_sign.rs | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/sdk/src/cose_sign.rs b/sdk/src/cose_sign.rs @@ -17,7 +17,7 @@ use ciborium::value::Value; use coset::{ - iana::{self, EnumI64}, + iana::{self}, CoseSign1, CoseSign1Builder, Header, HeaderBuilder, Label, ProtectedHeader, TaggedCborSerializable, }; @@ -197,7 +197,7 @@ fn build_headers( ta_url: Option<String>, ocsp_val: Option<Vec<u8>>, ) -> Result<(Header, Header)> { - let mut protected_h = match alg { + let protected_h = match alg { SigningAlg::Ps256 => HeaderBuilder::new().algorithm(iana::Algorithm::PS256), SigningAlg::Ps384 => HeaderBuilder::new().algorithm(iana::Algorithm::PS384), SigningAlg::Ps512 => HeaderBuilder::new().algorithm(iana::Algorithm::PS512), @@ -218,11 +218,15 @@ fn build_headers( } }; + // enable this block of code when we want to switch to 1.3 headers + /* // add certs to protected header (spec 1.3 now requires integer 33(X5Chain) in favor of string "x5chain" going forward) protected_h = protected_h.value( iana::HeaderParameter::X5Chain.to_i64(), - sc_der_array_or_bytes, + sc_der_array_or_bytes.clone(), ); + */ + let protected_header = protected_h.build(); let mut unprotected_h = if let Some(url) = ta_url { @@ -242,6 +246,9 @@ fn build_headers( HeaderBuilder::new() }; + // generate old Cose header todo: remove this line when protected headers are enabled + unprotected_h = unprotected_h.text_value("x5chain".to_string(), sc_der_array_or_bytes); + // set the ocsp responder response if available if let Some(ocsp) = ocsp_val { let mut ocsp_vec: Vec<Value> = Vec::new();