tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CTLogVerifier.h (3369B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef CTLogVerifier_h
      8 #define CTLogVerifier_h
      9 
     10 #include "CTKnownLogs.h"
     11 #include "CTLog.h"
     12 #include "CTUtils.h"
     13 #include "SignedCertificateTimestamp.h"
     14 #include "mozpkix/Input.h"
     15 #include "mozpkix/Result.h"
     16 #include "mozpkix/pkix.h"
     17 #include "signature_cache_ffi.h"
     18 
     19 namespace mozilla {
     20 namespace ct {
     21 
     22 // Verifies Signed Certificate Timestamps (SCTs) provided by a specific log
     23 // using the public key of that log. Assumes the SCT being verified
     24 // matches the log by log key ID and signature parameters (an error is returned
     25 // otherwise).
     26 // The verification functions return Success if the provided SCT has passed
     27 // verification, ERROR_BAD_SIGNATURE if failed verification, or other result
     28 // on error.
     29 class CTLogVerifier {
     30 public:
     31  // |operatorId| The numeric ID of the log operator.
     32  // |logState| "Qualified", "Usable", "ReadOnly", or "Retired".
     33  // |logFormat| "RFC6962" or "Tiled"
     34  // |timestamp| timestamp associated with logState.
     35  CTLogVerifier(CTLogOperatorId operatorId, CTLogState logState,
     36                CTLogFormat logFormat, uint64_t timestamp);
     37 
     38  // Initializes the verifier with the given subjectPublicKeyInfo.
     39  // |subjectPublicKeyInfo| is a DER-encoded SubjectPublicKeyInfo.
     40  // An error is returned if |subjectPublicKeyInfo| refers to an unsupported
     41  // public key.
     42  pkix::Result Init(pkix::Input subjectPublicKeyInfo);
     43 
     44  // Returns the log's key ID, which is a SHA256 hash of its public key.
     45  // See RFC 6962, Section 3.2.
     46  const Buffer& keyId() const { return mKeyId; }
     47 
     48  CTLogOperatorId operatorId() const { return mOperatorId; }
     49  CTLogState state() const { return mState; }
     50  CTLogFormat format() const { return mFormat; }
     51  uint64_t timestamp() const { return mTimestamp; }
     52 
     53  // Verifies that |sct| contains a valid signature for |entry|.
     54  // |sct| must be signed by the verifier's log.
     55  pkix::Result Verify(const LogEntry& entry,
     56                      const SignedCertificateTimestamp& sct,
     57                      SignatureCache* signatureCache);
     58 
     59  // Returns true if the signature and hash algorithms in |signature|
     60  // match those of the log.
     61  bool SignatureParametersMatch(const DigitallySigned& signature);
     62 
     63 private:
     64  // Performs the underlying verification using the log's public key. Note
     65  // that |signature| contains the raw signature data (i.e. without any
     66  // DigitallySigned struct encoding).
     67  // Returns Success if passed verification, ERROR_BAD_SIGNATURE if failed
     68  // verification, or other result on error.
     69  pkix::Result VerifySignature(pkix::Input data, pkix::Input signature,
     70                               SignatureCache* signatureCache);
     71  pkix::Result VerifySignature(const Buffer& data, const Buffer& signature,
     72                               SignatureCache* signatureCache);
     73 
     74  Buffer mSubjectPublicKeyInfo;
     75  Buffer mKeyId;
     76  DigitallySigned::SignatureAlgorithm mSignatureAlgorithm;
     77  CTLogOperatorId mOperatorId;
     78  CTLogState mState;
     79  CTLogFormat mFormat;
     80  uint64_t mTimestamp;
     81 };
     82 
     83 }  // namespace ct
     84 }  // namespace mozilla
     85 
     86 #endif  // CTLogVerifier_h