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

Side by Side Diff: components/certificate_transparency/log_response_parser.cc

Issue 1100003006: Certificate Transparency: Fetching of Signed Tree Heads (DRAFT) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revised design, addressed some comments Created 5 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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
5 #include "components/certificate_transparency/log_response_parser.h"
6
7 #include "base/base64.h"
8 #include "base/logging.h"
9 #include "base/time/time.h"
10 #include "base/values.h"
11 #include "net/cert/ct_serialization.h"
12 #include "net/cert/signed_tree_head.h"
13
14 namespace certificate_transparency {
15
16 bool CTLogResponseParser::FillSignedTreeHead(scoped_ptr<base::Value> json,
17 net::ct::SignedTreeHead* sth) {
18 const base::DictionaryValue* json_dict;
19 if (!json->GetAsDictionary(&json_dict)) {
20 LOG(WARNING) << "Json value not a dictionary.";
21 return false;
22 }
23
24 int tree_size;
25 if (!json_dict->GetInteger("tree_size", &tree_size)) {
26 LOG(WARNING) << "Json dictionary does not contain tree_size";
27 return false;
28 }
29
30 double timestamp;
31 if (!json_dict->GetDouble("timestamp", &timestamp)) {
32 LOG(WARNING) << "Json dictionary does not contain timestamp";
33 return false;
34 }
35
36 std::string sha256_root_hash;
37 if (!json_dict->GetString("sha256_root_hash", &sha256_root_hash)) {
38 LOG(WARNING) << "Json dictionary does not contain sha256_root_hash";
39 return false;
40 }
41
42 std::string tree_head_signature;
43 if (!json_dict->GetString("tree_head_signature", &tree_head_signature)) {
44 LOG(WARNING) << "Json dictionary does not contain tree_head_signature";
45 return false;
46 }
47
48 std::string decoded_root_hash;
49 if (!base::Base64Decode(sha256_root_hash, &decoded_root_hash)) {
50 LOG(WARNING) << "Failed decoding sha256_root_hash";
51 return false;
52 }
53
54 if (decoded_root_hash.length() != net::ct::kSthRootHashLength) {
55 LOG(WARNING) << "sha256_root_hash must be exactly 32 bit.";
56 return false;
57 }
58
59 std::string decoded_signature;
60 if (!base::Base64Decode(tree_head_signature, &decoded_signature)) {
61 LOG(WARNING) << "Failed decoding tree_head_signature";
62 return false;
63 }
64
65 base::StringPiece sp(decoded_signature);
66 if (!DecodeDigitallySigned(&sp, &(sth->signature))) {
67 LOG(WARNING) << "Failed decoding signature to DigitallySigned";
68 return false;
69 }
70
71 sth->version = net::ct::SignedTreeHead::V1;
72 sth->tree_size = tree_size;
73 sth->timestamp =
74 base::Time::UnixEpoch() + base::TimeDelta::FromMilliseconds(timestamp);
75 memcpy(sth->sha256_root_hash, decoded_root_hash.c_str(),
76 net::ct::kSthRootHashLength);
77 return true;
78 }
79
80 } // namespace certificate_transparency
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698