blob: 3f1afc58cb94ead5beaa0e0dff13e731f39aa734 [file] [edit]
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef THIRD_PARTY_CREDENTIO_COSE_COSE_SIGN1_H_
#define THIRD_PARTY_CREDENTIO_COSE_COSE_SIGN1_H_
#include <memory>
#include <optional>
#include <utility>
#include "absl/base/nullability.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock_interface.h"
#include "cose/sig_structure.h"
#include "crypto/crypto_read_handler.h"
#include "crypto/hash.h"
#include "google/protobuf/timestamp.pb.h"
#include "proto/signature_info.pb.h"
#include "proto/validation_status.pb.h"
namespace credentio {
// CoseSign1 verifier for C2PA use cases.
//
// This class does not support multiple signers. Do not use this for non-C2PA
// use cases.
class CoseSign1Verifier {
public:
struct Options {
// Whether to check OCSP responses.
bool check_ocsp_responses = true;
// Whether to verify the signature.
// NOTE: signer's certificate chain trust checks are always performed.
bool verify_signature = true;
};
// Creates a CoseSign1Verifier instance.
static std::unique_ptr<CoseSign1Verifier> Create(
const CryptoReadHandler* absl_nonnull crypto_read_handler,
const HashCheckerFactory* absl_nonnull hash_checker_factory,
absl::Clock* absl_nonnull clock, Options options);
// Validates a COSE_Sign1 structure and returns a SignatureInfo on success,
// or std::nullopt if the signature is invalid.
std::optional<SignatureInfo> Verify(
const CoseSign1TaggedStructure& cose_sign1,
absl::string_view external_payload,
ValidationStatusSet* status_set) const;
private:
CoseSign1Verifier(const CryptoReadHandler* absl_nonnull crypto_read_handler,
const HashCheckerFactory* absl_nonnull hash_checker_factory,
absl::Clock* absl_nonnull clock, Options options)
: crypto_read_handler_(*crypto_read_handler),
hash_checker_factory_(*hash_checker_factory),
clock_(*clock),
options_(std::move(options)) {}
const CryptoReadHandler& crypto_read_handler_;
const HashCheckerFactory& hash_checker_factory_;
absl::Clock& clock_;
Options options_;
};
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_COSE_COSE_SIGN1_H_