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 Hash(const MerkleTreeLeaf& tree_leaf, std::string* out) { | |
| 21 std::string leaf_in_tls_format; | |
| 22 if (!EncodeTreeLeaf(tree_leaf, &leaf_in_tls_format)) | |
| 23 return false; | |
| 24 | |
| 25 // Prepend 0 byte as per RFC 6962, section-2.1 | |
| 26 *out = crypto::SHA256HashString("\x00" + leaf_in_tls_format); | |
|
eroman
2016/05/06 23:51:22
This does not behave as described -- no 0 byte is
Rob Percival
2016/05/09 12:36:05
Done.
| |
| 27 return true; | |
| 28 } | |
| 29 | |
| 18 bool GetMerkleTreeLeaf(const X509Certificate* cert, | 30 bool GetMerkleTreeLeaf(const X509Certificate* cert, |
| 19 const SignedCertificateTimestamp* sct, | 31 const SignedCertificateTimestamp* sct, |
| 20 MerkleTreeLeaf* merkle_tree_leaf) { | 32 MerkleTreeLeaf* merkle_tree_leaf) { |
| 21 if (sct->origin == SignedCertificateTimestamp::SCT_EMBEDDED) { | 33 if (sct->origin == SignedCertificateTimestamp::SCT_EMBEDDED) { |
| 22 if (cert->GetIntermediateCertificates().empty() || | 34 if (cert->GetIntermediateCertificates().empty() || |
| 23 !GetPrecertLogEntry(cert->os_cert_handle(), | 35 !GetPrecertLogEntry(cert->os_cert_handle(), |
| 24 cert->GetIntermediateCertificates().front(), | 36 cert->GetIntermediateCertificates().front(), |
| 25 &merkle_tree_leaf->log_entry)) { | 37 &merkle_tree_leaf->log_entry)) { |
| 26 return false; | 38 return false; |
| 27 } | 39 } |
| 28 } else { | 40 } else { |
| 29 if (!GetX509LogEntry(cert->os_cert_handle(), | 41 if (!GetX509LogEntry(cert->os_cert_handle(), |
| 30 &merkle_tree_leaf->log_entry)) { | 42 &merkle_tree_leaf->log_entry)) { |
| 31 return false; | 43 return false; |
| 32 } | 44 } |
| 33 } | 45 } |
| 34 | 46 |
| 35 merkle_tree_leaf->log_id = sct->log_id; | 47 merkle_tree_leaf->log_id = sct->log_id; |
| 36 merkle_tree_leaf->timestamp = sct->timestamp; | 48 merkle_tree_leaf->timestamp = sct->timestamp; |
| 37 merkle_tree_leaf->extensions = sct->extensions; | 49 merkle_tree_leaf->extensions = sct->extensions; |
| 38 return true; | 50 return true; |
| 39 } | 51 } |
| 40 | 52 |
| 41 } // namespace ct | 53 } // namespace ct |
| 42 | 54 |
| 43 } // namespace net | 55 } // namespace net |
| OLD | NEW |