CTLogVerifier.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef CTLogVerifier_h
  6. #define CTLogVerifier_h
  7. #include "pkix/Input.h"
  8. #include "pkix/pkix.h"
  9. #include "SignedCertificateTimestamp.h"
  10. #include "SignedTreeHead.h"
  11. namespace mozilla { namespace ct {
  12. // Verifies Signed Certificate Timestamps (SCTs) provided by a specific log
  13. // using the public key of that log. Assumes the SCT being verified
  14. // matches the log by log key ID and signature parameters (an error is returned
  15. // otherwise).
  16. // The verification functions return Success if the provided SCT has passed
  17. // verification, ERROR_BAD_SIGNATURE if failed verification, or other result
  18. // on error.
  19. class CTLogVerifier
  20. {
  21. public:
  22. CTLogVerifier();
  23. // Initializes the verifier with log-specific information.
  24. // |subjectPublicKeyInfo| is a DER-encoded SubjectPublicKeyInfo.
  25. // An error is returned if |subjectPublicKeyInfo| refers to an unsupported
  26. // public key.
  27. pkix::Result Init(pkix::Input subjectPublicKeyInfo);
  28. // Returns the log's key ID, which is a SHA256 hash of its public key.
  29. // See RFC 6962, Section 3.2.
  30. const Buffer& keyId() const { return mKeyId; }
  31. // Verifies that |sct| contains a valid signature for |entry|.
  32. // |sct| must be signed by the verifier's log.
  33. pkix::Result Verify(const LogEntry& entry,
  34. const SignedCertificateTimestamp& sct);
  35. // Verifies the signature in |sth|.
  36. // |sth| must be signed by the verifier's log.
  37. pkix::Result VerifySignedTreeHead(const SignedTreeHead& sth);
  38. // Returns true if the signature and hash algorithms in |signature|
  39. // match those of the log.
  40. bool SignatureParametersMatch(const DigitallySigned& signature);
  41. private:
  42. // Performs the underlying verification using the log's public key. Note
  43. // that |signature| contains the raw signature data (i.e. without any
  44. // DigitallySigned struct encoding).
  45. // Returns Success if passed verification, ERROR_BAD_SIGNATURE if failed
  46. // verification, or other result on error.
  47. pkix::Result VerifySignature(pkix::Input data, pkix::Input signature);
  48. pkix::Result VerifySignature(const Buffer& data, const Buffer& signature);
  49. Buffer mSubjectPublicKeyInfo;
  50. Buffer mKeyId;
  51. DigitallySigned::SignatureAlgorithm mSignatureAlgorithm;
  52. };
  53. } } // namespace mozilla::ct
  54. #endif // CTLogVerifier_h