blob: 5b31fbfc897aa1fea57bb622c5a53227bf312cec [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.
//
// Support for RFC 3161 TimestampToken verification.
#ifndef THIRD_PARTY_CREDENTIO_CRYPTO_DEFAULT_TIMESTAMP_VERIFIER_H_
#define THIRD_PARTY_CREDENTIO_CRYPTO_DEFAULT_TIMESTAMP_VERIFIER_H_
#include "absl/base/attributes.h"
#include "absl/base/nullability.h"
#include "absl/status/statusor.h"
#include "openssl/pki/verify.h"
#include "tsp/parsed_timestamp_token.h"
#include "tsp/verified_timestamp.h"
namespace credentio {
// Verifier for RFC 3161 TimestampTokens.
class TimestampVerifier {
public:
// If `tsa_roots` is `nullptr`, the verifier will skip trust checks (only for
// use in tests).
explicit TimestampVerifier(const bssl::VerifyTrustStore* absl_nullable
tsa_roots ABSL_ATTRIBUTE_LIFETIME_BOUND)
: tsa_roots_(tsa_roots) {}
// Verifies the signature of an RFC 3161 TimestampToken, and
// checks that the TSA is trusted. Error codes reported include
// kInvalidArgument: Malformed timestamp token
// kUnauthenticated: Signature verification errors, missing/untrusted certs
// kOutOfRange: A certificate was not within its validity period
absl::StatusOr<VerifiedTimestamp> VerifyTimestampToken(
const ParsedTimestampToken& parsed_token) const;
private:
const bssl::VerifyTrustStore* tsa_roots_;
};
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_CRYPTO_DEFAULT_TIMESTAMP_VERIFIER_H_