From dc323866af80e81e6c207d2266bad39851d4ef36 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Tue, 21 Jan 2025 16:02:43 -0800 Subject: [PATCH 1/9] Add deps --- Cargo.toml | 3 ++- src/callback_signer.rs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 70b82d0f..f0c16f09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,8 @@ crate-type = ["lib", "cdylib"] normal = ["openssl-src"] [dependencies] -c2pa = {version = "0.40.0", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} +c2pa = {version = "0.41.0", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} +c2pa-crypto = {version = "0.3.0" } thiserror = "1.0.49" uniffi = "0.28.2" openssl-src = "=300.3.1" # Required for openssl-sys diff --git a/src/callback_signer.rs b/src/callback_signer.rs index 4be2d3ea..a0ade42c 100644 --- a/src/callback_signer.rs +++ b/src/callback_signer.rs @@ -11,6 +11,7 @@ // each license. use c2pa::{Signer, SigningAlg}; +use c2pa_crypto::raw_signature::RawSigner; use log::debug; use crate::Result; @@ -57,6 +58,10 @@ impl Signer for RemoteSigner { fn direct_cose_handling(&self) -> bool { true } + + fn raw_signer(&self) -> Box<&dyn RawSigner> { + todo!() + } } impl CallbackSigner { From 5b52d707e715332fbd7daf6155ee611bae067b2c Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Tue, 21 Jan 2025 16:31:43 -0800 Subject: [PATCH 2/9] WIP --- Cargo.toml | 2 +- src/callback_signer.rs | 45 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f0c16f09..9bcaa66c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["lib", "cdylib"] normal = ["openssl-src"] [dependencies] -c2pa = {version = "0.41.0", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} +c2pa = { git = "https://github.com/contentauth/c2pa-rs.git", branch="mathern/python-tradeoffs", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} c2pa-crypto = {version = "0.3.0" } thiserror = "1.0.49" uniffi = "0.28.2" diff --git a/src/callback_signer.rs b/src/callback_signer.rs index a0ade42c..47140d04 100644 --- a/src/callback_signer.rs +++ b/src/callback_signer.rs @@ -11,7 +11,10 @@ // each license. use c2pa::{Signer, SigningAlg}; -use c2pa_crypto::raw_signature::RawSigner; +use c2pa_crypto::{ + raw_signature::{RawSigner, RawSignerError}, + time_stamp::TimeStampProvider, +}; use log::debug; use crate::Result; @@ -35,6 +38,46 @@ pub struct RemoteSigner { reserve_size: u32, } +impl TimeStampProvider for RemoteSigner {} + +impl c2pa_crypto::raw_signature::RawSigner for RemoteSigner { + fn sign( + &self, + data: &[u8], + ) -> std::result::Result, RawSignerError> { + let signature_result = self.signer_callback.sign(data.to_vec()); + + match signature_result { + Ok(signature) => Ok(signature), + Err(e) => Err(c2pa_crypto::raw_signature::RawSignerError::IoError( + e.to_string(), + )), + } + } + + fn alg(&self) -> c2pa_crypto::raw_signature::SigningAlg { + match self.alg { + SigningAlg::Es256 => c2pa_crypto::raw_signature::SigningAlg::Es256, + SigningAlg::Es384 => c2pa_crypto::raw_signature::SigningAlg::Es384, + SigningAlg::Es512 => c2pa_crypto::raw_signature::SigningAlg::Es512, + SigningAlg::Ps256 => c2pa_crypto::raw_signature::SigningAlg::Ps256, + SigningAlg::Ps384 => c2pa_crypto::raw_signature::SigningAlg::Ps384, + SigningAlg::Ps512 => c2pa_crypto::raw_signature::SigningAlg::Ps512, + SigningAlg::Ed25519 => c2pa_crypto::raw_signature::SigningAlg::Ed25519, + } + } + + fn cert_chain( + &self, + ) -> std::result::Result>, RawSignerError> { + Ok(Vec::new()) + } + + fn reserve_size(&self) -> usize { + self.reserve_size as usize + } +} + impl Signer for RemoteSigner { fn sign(&self, data: &[u8]) -> c2pa::Result> { self.signer_callback From 0d954c869146594404087da18e53f6ccc4011ffc Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Tue, 21 Jan 2025 22:09:15 -0800 Subject: [PATCH 3/9] WIP --- Cargo.toml | 2 +- src/callback_signer.rs | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9bcaa66c..3e981eca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["lib", "cdylib"] normal = ["openssl-src"] [dependencies] -c2pa = { git = "https://github.com/contentauth/c2pa-rs.git", branch="mathern/python-tradeoffs", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} +c2pa = { version = "0.41.0", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} c2pa-crypto = {version = "0.3.0" } thiserror = "1.0.49" uniffi = "0.28.2" diff --git a/src/callback_signer.rs b/src/callback_signer.rs index 47140d04..4a4558c3 100644 --- a/src/callback_signer.rs +++ b/src/callback_signer.rs @@ -12,8 +12,8 @@ use c2pa::{Signer, SigningAlg}; use c2pa_crypto::{ - raw_signature::{RawSigner, RawSignerError}, - time_stamp::TimeStampProvider, + raw_signature::{RawSigner, RawSignerError}, + time_stamp::TimeStampProvider, }; use log::debug; @@ -38,13 +38,16 @@ pub struct RemoteSigner { reserve_size: u32, } +pub struct RawRemoteSigner { + signer_callback: Box, + alg: SigningAlg, + reserve_size: u32, +} + impl TimeStampProvider for RemoteSigner {} impl c2pa_crypto::raw_signature::RawSigner for RemoteSigner { - fn sign( - &self, - data: &[u8], - ) -> std::result::Result, RawSignerError> { + fn sign(&self, data: &[u8]) -> std::result::Result, RawSignerError> { let signature_result = self.signer_callback.sign(data.to_vec()); match signature_result { @@ -64,12 +67,11 @@ impl c2pa_crypto::raw_signature::RawSigner for RemoteSigner { SigningAlg::Ps384 => c2pa_crypto::raw_signature::SigningAlg::Ps384, SigningAlg::Ps512 => c2pa_crypto::raw_signature::SigningAlg::Ps512, SigningAlg::Ed25519 => c2pa_crypto::raw_signature::SigningAlg::Ed25519, + _ => c2pa_crypto::raw_signature::SigningAlg::Es256, } } - fn cert_chain( - &self, - ) -> std::result::Result>, RawSignerError> { + fn cert_chain(&self) -> std::result::Result>, RawSignerError> { Ok(Vec::new()) } @@ -102,8 +104,8 @@ impl Signer for RemoteSigner { true } - fn raw_signer(&self) -> Box<&dyn RawSigner> { - todo!() + fn raw_signer(&self) -> Box<&dyn c2pa_crypto::raw_signature::RawSigner> { + Box::new(self) } } From 6176bc50d6c6fb3cc8d965c7f083a191864969ce Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Tue, 21 Jan 2025 22:18:17 -0800 Subject: [PATCH 4/9] WIP --- Cargo.toml | 2 +- src/callback_signer.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e981eca..9bcaa66c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["lib", "cdylib"] normal = ["openssl-src"] [dependencies] -c2pa = { version = "0.41.0", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} +c2pa = { git = "https://github.com/contentauth/c2pa-rs.git", branch="mathern/python-tradeoffs", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} c2pa-crypto = {version = "0.3.0" } thiserror = "1.0.49" uniffi = "0.28.2" diff --git a/src/callback_signer.rs b/src/callback_signer.rs index 4a4558c3..db36df15 100644 --- a/src/callback_signer.rs +++ b/src/callback_signer.rs @@ -11,6 +11,7 @@ // each license. use c2pa::{Signer, SigningAlg}; +// RawSigner is currently used only fully qualified use c2pa_crypto::{ raw_signature::{RawSigner, RawSignerError}, time_stamp::TimeStampProvider, @@ -60,14 +61,13 @@ impl c2pa_crypto::raw_signature::RawSigner for RemoteSigner { fn alg(&self) -> c2pa_crypto::raw_signature::SigningAlg { match self.alg { - SigningAlg::Es256 => c2pa_crypto::raw_signature::SigningAlg::Es256, SigningAlg::Es384 => c2pa_crypto::raw_signature::SigningAlg::Es384, SigningAlg::Es512 => c2pa_crypto::raw_signature::SigningAlg::Es512, SigningAlg::Ps256 => c2pa_crypto::raw_signature::SigningAlg::Ps256, SigningAlg::Ps384 => c2pa_crypto::raw_signature::SigningAlg::Ps384, SigningAlg::Ps512 => c2pa_crypto::raw_signature::SigningAlg::Ps512, SigningAlg::Ed25519 => c2pa_crypto::raw_signature::SigningAlg::Ed25519, - _ => c2pa_crypto::raw_signature::SigningAlg::Es256, + SigningAlg::Es256 => c2pa_crypto::raw_signature::SigningAlg::Es256, } } From 9dac4cc037063d04942dae9194bef188d48639fc Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 22 Jan 2025 10:07:31 -0800 Subject: [PATCH 5/9] chore: FInish update --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9bcaa66c..d5638ad5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,8 @@ crate-type = ["lib", "cdylib"] normal = ["openssl-src"] [dependencies] -c2pa = { git = "https://github.com/contentauth/c2pa-rs.git", branch="mathern/python-tradeoffs", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} -c2pa-crypto = {version = "0.3.0" } +c2pa = { version = "0.41.1", features = ["unstable_api", "file_io", "openssl", "pdf", "fetch_remote_manifests"]} +c2pa-crypto = {version = "0.3.1" } thiserror = "1.0.49" uniffi = "0.28.2" openssl-src = "=300.3.1" # Required for openssl-sys From d287c81af946cb48c5eea3b7b0a43dc99cb605f9 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 22 Jan 2025 10:15:41 -0800 Subject: [PATCH 6/9] fix: update c2pa-rs --- requirements.txt | 3 ++- src/callback_signer.rs | 8 +------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index c4f07d43..b854b3b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ maturin==1.7.4 uniffi-bindgen==0.28.0 -cryptography==43.0.1 \ No newline at end of file +cryptography==43.0.1 +pytest=8.3.4 \ No newline at end of file diff --git a/src/callback_signer.rs b/src/callback_signer.rs index db36df15..d7bc209b 100644 --- a/src/callback_signer.rs +++ b/src/callback_signer.rs @@ -13,7 +13,7 @@ use c2pa::{Signer, SigningAlg}; // RawSigner is currently used only fully qualified use c2pa_crypto::{ - raw_signature::{RawSigner, RawSignerError}, + raw_signature::RawSignerError, time_stamp::TimeStampProvider, }; use log::debug; @@ -39,12 +39,6 @@ pub struct RemoteSigner { reserve_size: u32, } -pub struct RawRemoteSigner { - signer_callback: Box, - alg: SigningAlg, - reserve_size: u32, -} - impl TimeStampProvider for RemoteSigner {} impl c2pa_crypto::raw_signature::RawSigner for RemoteSigner { From 55a3348bbd2c0f921c63f417010034e3b54ee21e Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 22 Jan 2025 10:21:29 -0800 Subject: [PATCH 7/9] chore: format --- src/callback_signer.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/callback_signer.rs b/src/callback_signer.rs index d7bc209b..a033dc02 100644 --- a/src/callback_signer.rs +++ b/src/callback_signer.rs @@ -12,10 +12,7 @@ use c2pa::{Signer, SigningAlg}; // RawSigner is currently used only fully qualified -use c2pa_crypto::{ - raw_signature::RawSignerError, - time_stamp::TimeStampProvider, -}; +use c2pa_crypto::{raw_signature::RawSignerError, time_stamp::TimeStampProvider}; use log::debug; use crate::Result; From 3354c8c29001c673b55faf6874a68ed848950d47 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 22 Jan 2025 10:21:51 -0800 Subject: [PATCH 8/9] chore: format --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b854b3b8..ce808263 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ maturin==1.7.4 uniffi-bindgen==0.28.0 cryptography==43.0.1 -pytest=8.3.4 \ No newline at end of file +pytest==8.3.4 \ No newline at end of file From 5b0103ea716a957fe5846183ea87a0cf6728041a Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 22 Jan 2025 10:24:01 -0800 Subject: [PATCH 9/9] chore: up crypto --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ce808263..c5eb6d9a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ maturin==1.7.4 uniffi-bindgen==0.28.0 -cryptography==43.0.1 +cryptography==44.0.0 pytest==8.3.4 \ No newline at end of file