commit 550226f212fe45c4f1029dff497b425469dde512
parent 65658b420d51a9d5a28de9de35c30c236158cfb2
Author: Gavin Peacock <gpeacock@adobe.com>
Date: Thu, 28 Mar 2024 19:53:39 -0700
Remove verify after signing when compiling without openssl (#404)
* Adds a no_cose_verify feature
* enable signing with no openssl
fix send_timeout_request for wasm
(no default impl in the Signer traits) for wasm
* change no_cose_verify feature to no_verify_on_sign
* remove extra verify in bogus signer
* remove no_verify_on_sign feature and skip sign verify if no openssl
* verify_after_sign only happens when openssl is enabled
Diffstat:
5 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/sdk/src/cose_sign.rs b/sdk/src/cose_sign.rs
@@ -405,6 +405,10 @@ mod tests {
fn reserve_size(&self) -> usize {
1024
}
+
+ fn send_timestamp_request(&self, _message: &[u8]) -> Option<crate::error::Result<Vec<u8>>> {
+ Some(Ok(Vec::new()))
+ }
}
#[test]
@@ -418,8 +422,9 @@ mod tests {
let signer = BogusSigner::new();
- let cose_sign1 = sign_claim(&claim_bytes, &signer, box_size);
+ let _cose_sign1 = sign_claim(&claim_bytes, &signer, box_size);
- assert!(cose_sign1.is_err());
+ #[cfg(feature = "openssl")] // there is no verify on sign when openssl is disabled
+ assert!(_cose_sign1.is_err());
}
}
diff --git a/sdk/src/signer.rs b/sdk/src/signer.rs
@@ -49,12 +49,15 @@ pub trait Signer {
///
/// The default implementation will send the request to the URL
/// provided by [`Self::time_authority_url()`], if any.
+ #[cfg(not(target_arch = "wasm32"))]
fn send_timestamp_request(&self, message: &[u8]) -> Option<Result<Vec<u8>>> {
let headers: Option<Vec<(String, String)>> = self.timestamp_request_headers();
self.time_authority_url()
.map(|url| crate::time_stamp::default_rfc3161_request(&url, headers, message))
}
+ #[cfg(target_arch = "wasm32")]
+ fn send_timestamp_request(&self, message: &[u8]) -> Option<Result<Vec<u8>>>;
/// OCSP response for the signing cert if available
/// This is the only C2PA supported cert revocation method.
@@ -136,6 +139,7 @@ pub trait AsyncSigner: Sync {
///
/// The default implementation will send the request to the URL
/// provided by [`Self::time_authority_url()`], if any.
+ #[cfg(not(target_arch = "wasm32"))]
async fn send_timestamp_request(&self, message: &[u8]) -> Option<Result<Vec<u8>>> {
// NOTE: This is currently synchronous, but may become
// async in the future.
@@ -144,6 +148,8 @@ pub trait AsyncSigner: Sync {
self.time_authority_url()
.map(|url| crate::time_stamp::default_rfc3161_request(&url, headers, message))
}
+ #[cfg(target_arch = "wasm32")]
+ async fn send_timestamp_request(&self, message: &[u8]) -> Option<Result<Vec<u8>>>;
/// OCSP response for the signing cert if available
/// This is the only C2PA supported cert revocation method.
diff --git a/sdk/src/store.rs b/sdk/src/store.rs
@@ -20,6 +20,8 @@ use std::{fs, path::Path};
use log::error;
+#[cfg(feature = "openssl")]
+use crate::cose_validator::{verify_cose, verify_cose_async};
use crate::{
assertion::{
Assertion, AssertionBase, AssertionData, AssertionDecodeError, AssertionDecodeErrorCause,
@@ -32,8 +34,8 @@ use crate::{
CAIRead, CAIReadWrite, HashBlockObjectType, HashObjectPositions, RemoteRefEmbedType,
},
claim::{Claim, ClaimAssertion, ClaimAssetData},
- cose_sign::cose_sign,
- cose_validator::{check_ocsp_status, verify_cose},
+ cose_sign::{cose_sign, cose_sign_async},
+ cose_validator::check_ocsp_status,
error::{Error, Result},
hash_utils::{hash_by_alg, vec_compare, verify_by_alg},
jumbf::{
@@ -501,6 +503,7 @@ impl Store {
cose_sign(signer, &claim_bytes, box_size).and_then(|sig| {
// Sanity check: Ensure that this signature is valid.
+ #[cfg(feature = "openssl")]
if let Ok(verify_after_sign) = get_settings_value::<bool>("verify.verify_after_sign") {
if verify_after_sign {
let mut cose_log = OneShotStatusTracker::new();
@@ -531,13 +534,12 @@ impl Store {
signer: &dyn AsyncSigner,
box_size: usize,
) -> Result<Vec<u8>> {
- use crate::{cose_sign::cose_sign_async, cose_validator::verify_cose_async};
-
let claim_bytes = claim.data()?;
match cose_sign_async(signer, &claim_bytes, box_size).await {
// Sanity check: Ensure that this signature is valid.
Ok(sig) => {
+ #[cfg(feature = "openssl")]
if let Ok(verify_after_sign) =
get_settings_value::<bool>("verify.verify_after_sign")
{
diff --git a/sdk/src/time_stamp.rs b/sdk/src/time_stamp.rs
@@ -96,7 +96,7 @@ pub(crate) fn cose_sigtst_to_tstinfos(
/// internal only function to work around bug in serialization of TimeStampResponse
/// so we just return the data directly
-#[cfg(feature = "openssl_sign")]
+#[cfg(not(target_arch = "wasm32"))]
fn time_stamp_request_http(
url: &str,
headers: Option<Vec<(String, String)>>,
@@ -173,7 +173,7 @@ fn time_stamp_request_http(
/// This is a wrapper around [time_stamp_request_http] that constructs the low-level
/// ASN.1 request object with reasonable defaults.
-#[cfg(feature = "openssl_sign")]
+#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn time_stamp_message_http(
url: &str,
headers: Option<Vec<(String, String)>>,
@@ -218,7 +218,7 @@ impl std::ops::Deref for TimeStampResponse {
impl TimeStampResponse {
/// Whether the time stamp request was successful.
- #[cfg(feature = "openssl_sign")]
+ #[cfg(not(target_arch = "wasm32"))]
pub fn is_success(&self) -> bool {
matches!(
self.0.status.status,
@@ -279,13 +279,12 @@ pub fn timestamp_data(signer: &dyn Signer, data: &[u8]) -> Option<Result<Vec<u8>
}
}
-#[allow(unused_variables)]
+#[cfg(not(target_arch = "wasm32"))]
pub fn default_rfc3161_request(
url: &str,
headers: Option<Vec<(String, String)>>,
data: &[u8],
) -> Result<Vec<u8>> {
- #[cfg(feature = "openssl_sign")]
{
let ts = time_stamp_message_http(
url,
@@ -299,10 +298,6 @@ pub fn default_rfc3161_request(
Ok(ts)
}
- #[cfg(not(feature = "openssl_sign"))]
- {
- Err(Error::WasmNoCrypto)
- }
}
pub fn gt_to_datetime(
diff --git a/sdk/src/utils/test.rs b/sdk/src/utils/test.rs
@@ -284,6 +284,10 @@ impl crate::Signer for TestGoodSigner {
fn reserve_size(&self) -> usize {
1024
}
+
+ fn send_timestamp_request(&self, _message: &[u8]) -> Option<crate::error::Result<Vec<u8>>> {
+ Some(Ok(Vec::new()))
+ }
}
pub(crate) struct AsyncTestGoodSigner {}
@@ -306,6 +310,13 @@ impl crate::AsyncSigner for AsyncTestGoodSigner {
fn reserve_size(&self) -> usize {
1024
}
+
+ async fn send_timestamp_request(
+ &self,
+ _message: &[u8],
+ ) -> Option<crate::error::Result<Vec<u8>>> {
+ Some(Ok(Vec::new()))
+ }
}
/// Create a [`Signer`] instance that can be used for testing purposes using ps256 alg.