File: log_verifier.h

package info (click to toggle)
golang-github-google-certificate-transparency 0.0~git20160709.0.0f6e3d1~ds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 5,676 kB
  • sloc: cpp: 35,278; python: 11,838; java: 1,911; sh: 1,885; makefile: 950; xml: 520; ansic: 225
file content (124 lines) | stat: -rw-r--r-- 4,190 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef CERT_TRANS_LOG_LOG_VERIFIER_H_
#define CERT_TRANS_LOG_LOG_VERIFIER_H_

#include <glog/logging.h>
#include <stdint.h>

#include "base/macros.h"
#include "log/log_signer.h"
#include "proto/ct.pb.h"

class MerkleVerifier;

// A verifier for verifying signed statements of the log.
// TODO(ekasper): unit tests.
class LogVerifier {
 public:
  LogVerifier(LogSigVerifier* sig_verifier, MerkleVerifier* tree_verifier);
  ~LogVerifier();

  enum LogVerifyResult {
    VERIFY_OK,
    // Invalid format
    INVALID_FORMAT,
    // Invalid timestamp
    INVALID_TIMESTAMP,
    // Timestamps differ.
    INCONSISTENT_TIMESTAMPS,
    // The signature does not verify.
    INVALID_SIGNATURE,
    // The Merkle path is not valid for the given index
    // and tree size
    INVALID_MERKLE_PATH,
  };

  static std::string VerifyResultString(LogVerifyResult result) {
    switch (result) {
      case VERIFY_OK:
        return "Verify OK.";
      case INVALID_FORMAT:
        return "Invalid format.";
      case INVALID_TIMESTAMP:
        return "Invalid timestamp.";
      case INCONSISTENT_TIMESTAMPS:
        return "Inconsistent timestamps.";
      case INVALID_SIGNATURE:
        return "Invalid signature.";
      case INVALID_MERKLE_PATH:
        return "Invalid Merkle path.";
    }

    LOG(FATAL) << "unknown value for LogVerifyResult enum: " << result;
    // It should not be possible for control to reach this point but this
    // avoids a compilation warning on some platforms.
    abort();
  }

  std::string KeyID() const {
    return sig_verifier_->KeyID();
  }

  // Verify that the timestamp is in the given range,
  // and the signature is valid.
  // Timestamps are given in milliseconds, since January 1, 1970,
  // 00:00 UTC time.
  LogVerifyResult VerifySignedCertificateTimestamp(
      const ct::LogEntry& entry, const ct::SignedCertificateTimestamp& sct,
      uint64_t begin_range, uint64_t end_range,
      std::string* merkle_leaf_hash) const;

  // Verify that the timestamp is not in the future, and the signature is
  // valid.
  LogVerifyResult VerifySignedCertificateTimestamp(
      const ct::LogEntry& entry, const ct::SignedCertificateTimestamp& sct,
      std::string* merkle_leaf_hash) const;

  LogVerifyResult VerifySignedCertificateTimestamp(
      const ct::LogEntry& entry, const ct::SignedCertificateTimestamp& sct,
      uint64_t begin_range, uint64_t end_range) const {
    return VerifySignedCertificateTimestamp(entry, sct, begin_range, end_range,
                                            NULL);
  }
  // Verify that the timestamp is not in the future, and the signature is
  // valid.
  LogVerifyResult VerifySignedCertificateTimestamp(
      const ct::LogEntry& entry,
      const ct::SignedCertificateTimestamp& sct) const {
    return VerifySignedCertificateTimestamp(entry, sct, NULL);
  }

  // Verify that the timestamp is in the given range,
  // and the signature is valid.
  // Timestamps are given in milliseconds, since January 1, 1970,
  // 00:00 UTC time.
  LogVerifyResult VerifySignedTreeHead(const ct::SignedTreeHead& sth,
                                       uint64_t begin_range,
                                       uint64_t end_range) const;

  // Verify that the timestamp is not in the future, and the signature is
  // valid.
  LogVerifyResult VerifySignedTreeHead(const ct::SignedTreeHead& sth) const;

  // Verify that
  // (1) The audit proof signature is valid
  // (2) sct timestamp <= audit proof timestamp <= now
  // Does not verify the SCT signature (or even require one).
  LogVerifyResult VerifyMerkleAuditProof(
      const ct::LogEntry& entry, const ct::SignedCertificateTimestamp& sct,
      const ct::MerkleAuditProof& merkle_proof) const;

  bool VerifyConsistency(const ct::SignedTreeHead& sth1,
                         const ct::SignedTreeHead& sth2,
                         const std::vector<std::string>& proof) const;

 private:
  LogSigVerifier* sig_verifier_;
  MerkleVerifier* merkle_verifier_;

  static bool IsBetween(uint64_t timestamp, uint64_t earliest,
                        uint64_t latest);

  DISALLOW_COPY_AND_ASSIGN(LogVerifier);
};

#endif  // CERT_TRANS_LOG_LOG_VERIFIER_H_