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

Side by Side Diff: net/cert/ct_signed_certificate_timestamp_log_param.cc

Issue 86503002: Certificate Transparency: Logging SCTs to the NetLog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing review comments Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 "net/cert/ct_signed_certificate_timestamp_log_param.h"
6
7 #include <algorithm>
8 #include <string>
9
10 #include "base/base64.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/values.h"
14 #include "net/cert/ct_verify_result.h"
15 #include "net/cert/signed_certificate_timestamp.h"
16
17 namespace net {
18
19 namespace ct {
20
21 namespace {
22
23 base::DictionaryValue* GetSCTFieldsAsStrings(
wtc 2013/11/27 16:00:58 Nit: it is rare to see a file with no comments :-)
eroman 2013/11/27 20:39:55 Please rename this function; the "AsStrings" part
Eran M. (Google) 2013/11/27 22:08:50 Done.
Eran M. (Google) 2013/11/27 22:08:50 Done.
24 const SignedCertificateTimestamp& sct) {
25 base::DictionaryValue* out = new base::DictionaryValue();
26
27 std::string origin_string;
eroman 2013/11/27 20:39:55 [Optional] Stylistically I recommend splitting thi
Eran M. (Google) 2013/11/27 22:08:50 Done, done and done.
28 switch (sct.origin) {
29 case SignedCertificateTimestamp::SCT_EMBEDDED:
30 origin_string = "embedded_in_certificate";
31 break;
32 case SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION:
33 origin_string = "tls_extension";
34 break;
35 case SignedCertificateTimestamp::SCT_FROM_OCSP_RESPONSE:
36 origin_string = "ocsp";
37 break;
38 }
39
40 out->SetString("origin", origin_string);
41 out->SetInteger("version", sct.version);
wtc 2013/11/27 16:00:58 Nit: the function name says "get SCT fields as str
Eran M. (Google) 2013/11/27 22:08:50 Renamed function as suggested.
42 std::string log_id_b64;
wtc 2013/11/27 16:00:58 Nit: consider reusing the same std::string local v
Eran M. (Google) 2013/11/27 22:08:50 Done - calling AddBase64EncodedStringToDictionary
43 base::Base64Encode(sct.log_id, &log_id_b64);
wtc 2013/11/27 16:00:58 Nit: it may be a good idea to check the return val
eroman 2013/11/27 20:39:55 You already have a helper which abstracts the base
Eran M. (Google) 2013/11/27 22:08:50 Base64Encode promises not to change the output par
Eran M. (Google) 2013/11/27 22:08:50 Done.
44
45 out->SetString("log_id", log_id_b64);
46 base::TimeDelta time_since_epoch = sct.timestamp - base::Time::UnixEpoch();
47 out->SetString("timestamp",
48 base::Int64ToString(time_since_epoch.InMilliseconds()));
49
50 std::string extensions_b64;
51 base::Base64Encode(sct.extensions, &extensions_b64);
eroman 2013/11/27 20:39:55 SetBinaryData("extensions", sct.extensions, out);
Eran M. (Google) 2013/11/27 22:08:50 Done.
52 out->SetString("extensions", extensions_b64);
53
54 out->SetInteger("hash_algorithm", sct.signature.hash_algorithm);
55 out->SetInteger("signature_algorithm", sct.signature.signature_algorithm);
56 std::string signature_data_b64;
57 base::Base64Encode(sct.signature.signature_data, &signature_data_b64);
eroman 2013/11/27 20:39:55 SetBinaryData("extensions", sct.extensions, out);
Eran M. (Google) 2013/11/27 22:08:50 Done.
58 out->SetString("signature_data", signature_data_b64);
59
60 return out;
61 }
62
63 base::ListValue* SCTListToPrintableValues(
64 const ct::SCTList& sct_list) {
65
wtc 2013/11/27 16:00:58 Nit: delete this blank line and line 79.
Eran M. (Google) 2013/11/27 22:08:50 Done.
66 base::ListValue* output_scts = new base::ListValue();
67 for (ct::SCTList::const_iterator it = sct_list.begin();
68 it != sct_list.end();
69 ++it)
wtc 2013/11/27 16:00:58 Nit: I think people usually align these with the f
Eran M. (Google) 2013/11/27 22:08:50 It almost fits... I've indented as you suggested.
70 output_scts->Append(GetSCTFieldsAsStrings(*(it->get())));
71
72 return output_scts;
73 }
74
75 void AddBase64EncodedStringToDictionary(
eroman 2013/11/27 20:39:55 I recommend calling this: SetBinaryData(const c
Eran M. (Google) 2013/11/27 22:08:50 Done.
76 base::DictionaryValue* dict,
77 const char* description,
78 const std::string& data) {
79
80 std::string b64_data;
81 base::Base64Encode(data, &b64_data);
82
83 dict->SetString(description, b64_data);
84 }
85
86 } // namespace
87
88 } // namespace ct
89
90 base::Value* NetLogSignedCertificateTimestampCallback(
91 const ct::CTVerifyResult* ct_result, NetLog::LogLevel log_level) {
wtc 2013/11/27 16:00:58 IMPORTANT: the |log_level| parameter is not used i
eroman 2013/11/27 20:39:55 The parameter is required, hence this is needed to
92 base::DictionaryValue* dict = new base::DictionaryValue();
93
94 dict->Set("verified_scts",
95 ct::SCTListToPrintableValues(ct_result->verified_scts));
wtc 2013/11/27 16:00:58 Nit: it is strange to see these internal functions
Eran M. (Google) 2013/11/27 22:08:50 Done.
96
97 dict->Set("failed_to_verify_scts",
wtc 2013/11/27 16:00:58 Nit: just wondering why the name string doesn't ma
Eran M. (Google) 2013/11/27 22:08:50 For no good reason, really. Changed.
98 ct::SCTListToPrintableValues(ct_result->unverified_scts));
99
100 dict->Set("scts_from_unknown_logs",
101 ct::SCTListToPrintableValues(ct_result->unknown_logs_scts));
wtc 2013/11/27 16:00:58 Nit: in these three dict->Set() calls, the second
Eran M. (Google) 2013/11/27 22:08:50 Done.
102
103 return dict;
104 }
105
106 base::Value* NetLogRawSignedCertificateTimestampCallback(
107 const std::string* embedded_scts,
108 const std::string* sct_list_from_ocsp,
109 const std::string* sct_list_from_tls_extension,
110 NetLog::LogLevel log_level) {
111 base::DictionaryValue* dict = new base::DictionaryValue();
112
113 ct::AddBase64EncodedStringToDictionary(dict, "embedded_scts", *embedded_scts);
114 ct::AddBase64EncodedStringToDictionary(
115 dict, "scts_from_ocsp_response", *sct_list_from_ocsp);
116 ct::AddBase64EncodedStringToDictionary(
117 dict, "scts_from_tls_extension", *sct_list_from_tls_extension);
118
119 return dict;
120 }
121
122 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698