blob: ba7b04e39ab9872a49c46ed02990dcd46d4e32fd [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_VERIFIER_H_
#define THIRD_PARTY_CREDENTIO_COSE_VERIFIER_H_
#include <memory>
#include "absl/base/nullability.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock_interface.h"
#include "crypto/crypto_read_handler.h"
#include "proto/cose_verification_result.pb.h"
#include "proto/signature_info.pb.h"
namespace credentio {
class CoseVerifier {
public:
virtual ~CoseVerifier() = default;
// Validates the provided COSE_SIGN1 signature (`signature`) against the
// provided expected data (`data`).
// Returns a CoseVerificationResult, which contains the SignatureInfo
// if the signature is valid, and the validation statuses encountered
// during verification.
virtual CoseVerificationResult Verify(absl::string_view signature,
absl::string_view data) const = 0;
};
// Whether claim signatures (by the leaf certificate holder) are checked.
// This does not affect trust chain validation.
enum class CoseVerifierSignatureChecks { kDisabledForTest, kEnabled };
// Whether OCSP revocation checks are performed.
// This does not affect trust chain validation.
enum class CoseVerifierRevocationChecks { kDisabledForTest, kEnabled };
struct CoseVerifierOptions {
std::unique_ptr<CryptoReadHandler> absl_nonnull crypto_read_handler;
// Clock to use by the verifier.
absl::Clock* clock = &absl::Clock::GetRealClock();
// Option to enable/disable signature checks.
CoseVerifierSignatureChecks signature_checks =
CoseVerifierSignatureChecks::kEnabled;
// Option to enable/disable OCSP revocation checks.
CoseVerifierRevocationChecks revocation_checks =
CoseVerifierRevocationChecks::kEnabled;
};
// Creates a COSE verifier.
std::unique_ptr<CoseVerifier> CreateCoseVerifier(
CoseVerifierOptions options = {});
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_COSE_VERIFIER_H_