merkle_tree_leaf.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_CERT_MERKLE_TREE_LEAF_H_
  5. #define NET_CERT_MERKLE_TREE_LEAF_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/time/time.h"
  9. #include "net/base/net_export.h"
  10. #include "net/cert/signed_certificate_timestamp.h"
  11. namespace net {
  12. class X509Certificate;
  13. namespace ct {
  14. // Represents a MerkleTreeLeaf as defined in RFC6962, section 3.4.
  15. // The goal of this struct is to represent the Merkle tree entry such that
  16. // all details are easily accessible and a leaf hash can be easily calculated
  17. // for the entry.
  18. //
  19. // As such, it has all the data as the MerkleTreeLeaf defined in the RFC,
  20. // but it is not identical to the structure in the RFC for the following
  21. // reasons:
  22. // * The version is implicit - it is only used for V1 leaves currently.
  23. // * the leaf_type is also implicit: There's exactly one leaf type and no
  24. // new types are planned.
  25. // * The timestamped_entry's |timestamp| and |extensions| fields are directly
  26. // accessible.
  27. // * The timestamped_entry's entry_type can be deduced from |signed_entry|.type
  28. struct NET_EXPORT MerkleTreeLeaf {
  29. MerkleTreeLeaf();
  30. MerkleTreeLeaf(const MerkleTreeLeaf& other);
  31. MerkleTreeLeaf(MerkleTreeLeaf&&);
  32. ~MerkleTreeLeaf();
  33. // Certificate / Precertificate and indication of entry type.
  34. SignedEntryData signed_entry;
  35. // Timestamp from the SCT.
  36. base::Time timestamp;
  37. // Extensions from the SCT.
  38. std::string extensions;
  39. };
  40. // Given a |cert| and an |sct| for that certificate, constructs the
  41. // representation of this entry in the Merkle tree by filling in
  42. // |merkle_tree_leaf|.
  43. // Returns false if it failed to construct the |merkle_tree_leaf|.
  44. NET_EXPORT bool GetMerkleTreeLeaf(const X509Certificate* cert,
  45. const SignedCertificateTimestamp* sct,
  46. MerkleTreeLeaf* merkle_tree_leaf);
  47. // Sets |*out| to the hash of the Merkle |tree_leaf|, as defined in RFC6962,
  48. // section 3.4. Returns true if the hash was generated, false if an error
  49. // occurred.
  50. NET_EXPORT bool HashMerkleTreeLeaf(const MerkleTreeLeaf& tree_leaf,
  51. std::string* out);
  52. } // namespace ct
  53. } // namespace net
  54. #endif // NET_CERT_MERKLE_TREE_LEAF_H_