Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: net/cert/ct_serialization.cc

Issue 230713002: Certificate Transparency: Parse Signed Tree Heads and validate them (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing more of Ryan's comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cert/ct_serialization.h ('k') | net/cert/ct_serialization_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/ct_serialization.cc
diff --git a/net/cert/ct_serialization.cc b/net/cert/ct_serialization.cc
index 3de512c81813386fa14cdc38ab315aa4899f56ec..489717a9686088c9c41262bfcd8b4ce97058e0d8 100644
--- a/net/cert/ct_serialization.cc
+++ b/net/cert/ct_serialization.cc
@@ -34,6 +34,9 @@ const size_t kTbsCertificateLengthBytes = 3;
const size_t kSCTListLengthBytes = 2;
const size_t kSerializedSCTLengthBytes = 2;
+// Members of digitally-signed struct of a STH
+const size_t kTreeSizeLength = 8;
+
enum SignatureType {
SIGNATURE_TYPE_CERTIFICATE_TIMESTAMP = 0,
TREE_HASH = 1,
@@ -285,6 +288,12 @@ bool EncodeLogEntry(const LogEntry& input, std::string* output) {
return false;
}
+static void WriteTimeSinceEpoch(const base::Time& timestamp,
+ std::string* output) {
+ base::TimeDelta time_since_epoch = timestamp - base::Time::UnixEpoch();
+ WriteUint(kTimestampLength, time_since_epoch.InMilliseconds(), output);
+}
+
bool EncodeV1SCTSignedData(const base::Time& timestamp,
const std::string& serialized_log_entry,
const std::string& extensions,
@@ -293,15 +302,24 @@ bool EncodeV1SCTSignedData(const base::Time& timestamp,
output);
WriteUint(kSignatureTypeLength, SIGNATURE_TYPE_CERTIFICATE_TIMESTAMP,
output);
- base::TimeDelta time_since_epoch = timestamp - base::Time::UnixEpoch();
- WriteUint(kTimestampLength, time_since_epoch.InMilliseconds(),
- output);
+ WriteTimeSinceEpoch(timestamp, output);
// NOTE: serialized_log_entry must already be serialized and contain the
// length as the prefix.
WriteEncodedBytes(serialized_log_entry, output);
return WriteVariableBytes(kExtensionsLengthBytes, extensions, output);
}
+void EncodeTreeHeadSignature(const SignedTreeHead& signed_tree_head,
+ std::string* output) {
+ WriteUint(kVersionLength, signed_tree_head.version, output);
+ WriteUint(kSignatureTypeLength, TREE_HASH, output);
+ WriteTimeSinceEpoch(signed_tree_head.timestamp, output);
+ WriteUint(kTreeSizeLength, signed_tree_head.tree_size, output);
+ WriteEncodedBytes(
+ base::StringPiece(signed_tree_head.sha256_root_hash, kSthRootHashLength),
+ output);
+}
+
bool DecodeSCTList(base::StringPiece* input,
std::vector<base::StringPiece>* output) {
std::vector<base::StringPiece> result;
« no previous file with comments | « net/cert/ct_serialization.h ('k') | net/cert/ct_serialization_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698