From f2ee9e39970f90c66e095716b8833503f242f29c Mon Sep 17 00:00:00 2001 From: Eli Mensch Date: Mon, 9 Dec 2024 16:08:46 -0500 Subject: [PATCH] chore: Move `ValidationInfo` to `c2pa-crypto` (#721) * Extract ValidationInfo into c2pa-status-tracker * Move ValidationInfo into c2pa-crypto * Format --- internal/crypto/src/lib.rs | 3 +++ .../crypto/src/validation_info.rs | 21 ++++++++++++++----- sdk/src/claim.rs | 6 ++---- sdk/src/cose_validator.rs | 3 +-- sdk/src/lib.rs | 2 -- 5 files changed, 22 insertions(+), 13 deletions(-) rename sdk/src/validator.rs => internal/crypto/src/validation_info.rs (60%) diff --git a/internal/crypto/src/lib.rs b/internal/crypto/src/lib.rs index c41173434..178d07ff4 100644 --- a/internal/crypto/src/lib.rs +++ b/internal/crypto/src/lib.rs @@ -42,6 +42,9 @@ pub use signing_alg::{SigningAlg, UnknownAlgorithmError}; pub mod time_stamp; +mod validation_info; +pub use validation_info::ValidationInfo; + #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] pub mod webcrypto; diff --git a/sdk/src/validator.rs b/internal/crypto/src/validation_info.rs similarity index 60% rename from sdk/src/validator.rs rename to internal/crypto/src/validation_info.rs index dc06bc551..ac121670e 100644 --- a/sdk/src/validator.rs +++ b/internal/crypto/src/validation_info.rs @@ -1,4 +1,4 @@ -// Copyright 2022 Adobe. All rights reserved. +// Copyright 2024 Adobe. All rights reserved. // This file is licensed to you under the Apache License, // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) // or the MIT license (http://opensource.org/licenses/MIT), @@ -11,17 +11,28 @@ // specific language governing permissions and limitations under // each license. -use c2pa_crypto::SigningAlg; +//! Signature validation info. + use chrono::{DateTime, Utc}; use x509_parser::num_bigint::BigUint; +use crate::SigningAlg; + +/// Describes a signature's validation data and status. #[derive(Debug, Default)] pub struct ValidationInfo { - pub alg: Option, // validation algorithm + /// Algorithm used to validate the signature + pub alg: Option, + /// Date the signature was created pub date: Option>, + /// Certificate serial number pub cert_serial_number: Option, + /// Certificate issuer organization pub issuer_org: Option, - pub validated: bool, // claim signature is valid - pub cert_chain: Vec, // certificate chain used to validate signature + /// Signature validity + pub validated: bool, + /// Certificate chain used to validate the signature + pub cert_chain: Vec, + /// Signature revocation status pub revocation_status: Option, } diff --git a/sdk/src/claim.rs b/sdk/src/claim.rs index bb5e0f0eb..5b8341bb5 100644 --- a/sdk/src/claim.rs +++ b/sdk/src/claim.rs @@ -16,7 +16,7 @@ use std::path::Path; use std::{collections::HashMap, fmt}; use async_generic::async_generic; -use c2pa_crypto::base64; +use c2pa_crypto::{base64, ValidationInfo}; use c2pa_status_tracker::{log_item, OneShotStatusTracker, StatusTracker}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -54,9 +54,7 @@ use crate::{ salt::{DefaultSalt, SaltGenerator, NO_SALT}, trust_handler::TrustHandlerConfig, utils::hash_utils::{hash_by_alg, vec_compare, verify_by_alg}, - validation_status, - validator::ValidationInfo, - ClaimGeneratorInfo, + validation_status, ClaimGeneratorInfo, }; const BUILD_HASH_ALG: &str = "sha256"; diff --git a/sdk/src/cose_validator.rs b/sdk/src/cose_validator.rs index 8ef312a95..30f5767a1 100644 --- a/sdk/src/cose_validator.rs +++ b/sdk/src/cose_validator.rs @@ -22,7 +22,7 @@ use c2pa_crypto::{ p1363::parse_ec_der_sig, raw_signature::{validator_for_signing_alg, RawSignatureValidator}, time_stamp::TimeStampError, - SigningAlg, + SigningAlg, ValidationInfo, }; use c2pa_status_tracker::{log_item, validation_codes::*, StatusTracker}; use ciborium::value::Value; @@ -47,7 +47,6 @@ use crate::{ error::{Error, Result}, // DON'T MOVE settings::get_settings_value, // DON'T MOVE trust_handler::{has_allowed_oid, TrustHandlerConfig}, // Eli to move to c2pa-crypto - validator::ValidationInfo, // Eli to move to c2pa-status-tracker }; pub(crate) const RSA_OID: Oid<'static> = oid!(1.2.840 .113549 .1 .1 .1); diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 08bd59d0e..3cc2d730a 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -177,5 +177,3 @@ pub(crate) mod trust_handler; pub(crate) mod utils; pub(crate) use utils::{cbor_types, hash_utils}; - -pub(crate) mod validator;