| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/cert/merkle_tree_leaf.h" | 5 #include "net/cert/merkle_tree_leaf.h" |
| 6 | 6 |
| 7 #include "crypto/sha2.h" | 7 #include "crypto/sha2.h" |
| 8 #include "net/cert/ct_objects_extractor.h" | 8 #include "net/cert/ct_objects_extractor.h" |
| 9 #include "net/cert/ct_serialization.h" | 9 #include "net/cert/ct_serialization.h" |
| 10 #include "net/cert/x509_certificate.h" | 10 #include "net/cert/x509_certificate.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 namespace ct { | 14 namespace ct { |
| 15 | 15 |
| 16 MerkleTreeLeaf::MerkleTreeLeaf() {} | 16 MerkleTreeLeaf::MerkleTreeLeaf() {} |
| 17 | 17 |
| 18 MerkleTreeLeaf::~MerkleTreeLeaf() {} | 18 MerkleTreeLeaf::MerkleTreeLeaf(const MerkleTreeLeaf& other) = default; |
| 19 | 19 |
| 20 bool Hash(const MerkleTreeLeaf& tree_leaf, std::string* out) { | 20 MerkleTreeLeaf::MerkleTreeLeaf(MerkleTreeLeaf&&) = default; |
| 21 |
| 22 MerkleTreeLeaf::~MerkleTreeLeaf() = default; |
| 23 |
| 24 bool HashMerkleTreeLeaf(const MerkleTreeLeaf& tree_leaf, std::string* out) { |
| 21 // Prepend 0 byte as per RFC 6962, section-2.1 | 25 // Prepend 0 byte as per RFC 6962, section-2.1 |
| 22 std::string leaf_in_tls_format("\x00", 1); | 26 std::string leaf_in_tls_format("\x00", 1); |
| 23 if (!EncodeTreeLeaf(tree_leaf, &leaf_in_tls_format)) | 27 if (!EncodeTreeLeaf(tree_leaf, &leaf_in_tls_format)) |
| 24 return false; | 28 return false; |
| 25 | 29 |
| 26 *out = crypto::SHA256HashString(leaf_in_tls_format); | 30 *out = crypto::SHA256HashString(leaf_in_tls_format); |
| 27 return true; | 31 return true; |
| 28 } | 32 } |
| 29 | 33 |
| 30 bool GetMerkleTreeLeaf(const X509Certificate* cert, | 34 bool GetMerkleTreeLeaf(const X509Certificate* cert, |
| 31 const SignedCertificateTimestamp* sct, | 35 const SignedCertificateTimestamp* sct, |
| 32 MerkleTreeLeaf* merkle_tree_leaf) { | 36 MerkleTreeLeaf* merkle_tree_leaf) { |
| 33 if (sct->origin == SignedCertificateTimestamp::SCT_EMBEDDED) { | 37 if (sct->origin == SignedCertificateTimestamp::SCT_EMBEDDED) { |
| 34 if (cert->GetIntermediateCertificates().empty() || | 38 if (cert->GetIntermediateCertificates().empty() || |
| 35 !GetPrecertLogEntry(cert->os_cert_handle(), | 39 !GetPrecertLogEntry(cert->os_cert_handle(), |
| 36 cert->GetIntermediateCertificates().front(), | 40 cert->GetIntermediateCertificates().front(), |
| 37 &merkle_tree_leaf->log_entry)) { | 41 &merkle_tree_leaf->log_entry)) { |
| 38 return false; | 42 return false; |
| 39 } | 43 } |
| 40 } else { | 44 } else { |
| 41 if (!GetX509LogEntry(cert->os_cert_handle(), | 45 if (!GetX509LogEntry(cert->os_cert_handle(), |
| 42 &merkle_tree_leaf->log_entry)) { | 46 &merkle_tree_leaf->log_entry)) { |
| 43 return false; | 47 return false; |
| 44 } | 48 } |
| 45 } | 49 } |
| 46 | 50 |
| 47 merkle_tree_leaf->log_id = sct->log_id; | |
| 48 merkle_tree_leaf->timestamp = sct->timestamp; | 51 merkle_tree_leaf->timestamp = sct->timestamp; |
| 49 merkle_tree_leaf->extensions = sct->extensions; | 52 merkle_tree_leaf->extensions = sct->extensions; |
| 50 return true; | 53 return true; |
| 51 } | 54 } |
| 52 | 55 |
| 53 } // namespace ct | 56 } // namespace ct |
| 54 | 57 |
| 55 } // namespace net | 58 } // namespace net |
| OLD | NEW |