Chromium Code Reviews| 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 "net/cert/ct_objects_extractor.h" | 8 #include "net/cert/ct_objects_extractor.h" |
| 9 #include "net/cert/ct_serialization.h" | |
| 8 #include "net/cert/x509_certificate.h" | 10 #include "net/cert/x509_certificate.h" |
| 9 | 11 |
| 10 namespace net { | 12 namespace net { |
| 11 | 13 |
| 12 namespace ct { | 14 namespace ct { |
| 13 | 15 |
| 14 MerkleTreeLeaf::MerkleTreeLeaf() {} | 16 MerkleTreeLeaf::MerkleTreeLeaf() {} |
| 15 | 17 |
| 16 MerkleTreeLeaf::~MerkleTreeLeaf() {} | 18 MerkleTreeLeaf::~MerkleTreeLeaf() {} |
| 17 | 19 |
| 20 bool MerkleTreeLeaf::Hash(std::string* out) const { | |
| 21 std::string leaf_in_tls_format; | |
| 22 if (!EncodeTreeLeaf(*this, &leaf_in_tls_format)) | |
| 23 return false; | |
| 24 | |
| 25 *out = crypto::SHA256HashString("\x00" + leaf_in_tls_format); | |
|
Eran Messeri
2016/05/05 16:03:26
Nit: Link to the section of RFC6962 detailing the
Rob Percival
2016/05/05 16:26:36
Done.
| |
| 26 return true; | |
| 27 } | |
| 28 | |
| 18 bool GetMerkleTreeLeaf(const X509Certificate* cert, | 29 bool GetMerkleTreeLeaf(const X509Certificate* cert, |
| 19 const SignedCertificateTimestamp* sct, | 30 const SignedCertificateTimestamp* sct, |
| 20 MerkleTreeLeaf* merkle_tree_leaf) { | 31 MerkleTreeLeaf* merkle_tree_leaf) { |
| 21 if (sct->origin == SignedCertificateTimestamp::SCT_EMBEDDED) { | 32 if (sct->origin == SignedCertificateTimestamp::SCT_EMBEDDED) { |
| 22 if (cert->GetIntermediateCertificates().empty() || | 33 if (cert->GetIntermediateCertificates().empty() || |
| 23 !GetPrecertLogEntry(cert->os_cert_handle(), | 34 !GetPrecertLogEntry(cert->os_cert_handle(), |
| 24 cert->GetIntermediateCertificates().front(), | 35 cert->GetIntermediateCertificates().front(), |
| 25 &merkle_tree_leaf->log_entry)) { | 36 &merkle_tree_leaf->log_entry)) { |
| 26 return false; | 37 return false; |
| 27 } | 38 } |
| 28 } else { | 39 } else { |
| 29 if (!GetX509LogEntry(cert->os_cert_handle(), | 40 if (!GetX509LogEntry(cert->os_cert_handle(), |
| 30 &merkle_tree_leaf->log_entry)) { | 41 &merkle_tree_leaf->log_entry)) { |
| 31 return false; | 42 return false; |
| 32 } | 43 } |
| 33 } | 44 } |
| 34 | 45 |
| 35 merkle_tree_leaf->log_id = sct->log_id; | 46 merkle_tree_leaf->log_id = sct->log_id; |
| 36 merkle_tree_leaf->timestamp = sct->timestamp; | 47 merkle_tree_leaf->timestamp = sct->timestamp; |
| 37 merkle_tree_leaf->extensions = sct->extensions; | 48 merkle_tree_leaf->extensions = sct->extensions; |
| 38 return true; | 49 return true; |
| 39 } | 50 } |
| 40 | 51 |
| 41 } // namespace ct | 52 } // namespace ct |
| 42 | 53 |
| 43 } // namespace net | 54 } // namespace net |
| OLD | NEW |