| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/ct_signed_certificate_timestamp_log_param.h" | 5 #include "net/cert/ct_signed_certificate_timestamp_log_param.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 return "DSA"; | 69 return "DSA"; |
| 70 case ct::DigitallySigned::SIG_ALGO_ECDSA: | 70 case ct::DigitallySigned::SIG_ALGO_ECDSA: |
| 71 return "ECDSA"; | 71 return "ECDSA"; |
| 72 } | 72 } |
| 73 | 73 |
| 74 return "unknown"; | 74 return "unknown"; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Base64 encode the given |value| string and put it in |dict| with the | 77 // Base64 encode the given |value| string and put it in |dict| with the |
| 78 // description |key|. | 78 // description |key|. |
| 79 void SetBinaryData( | 79 void SetBinaryData(const char* key, |
| 80 const char* key, | 80 const std::string& value, |
| 81 const std::string& value, | 81 base::DictionaryValue* dict) { |
| 82 base::DictionaryValue* dict) { | |
| 83 std::string b64_value; | 82 std::string b64_value; |
| 84 base::Base64Encode(value, &b64_value); | 83 base::Base64Encode(value, &b64_value); |
| 85 | 84 |
| 86 dict->SetString(key, b64_value); | 85 dict->SetString(key, b64_value); |
| 87 } | 86 } |
| 88 | 87 |
| 89 // Returns a dictionary where each key is a field of the SCT and its value | 88 // Returns a dictionary where each key is a field of the SCT and its value |
| 90 // is this field's value in the SCT. This dictionary is meant to be used for | 89 // is this field's value in the SCT. This dictionary is meant to be used for |
| 91 // outputting a de-serialized SCT to the NetLog. | 90 // outputting a de-serialized SCT to the NetLog. |
| 92 base::DictionaryValue* SCTToDictionary( | 91 base::DictionaryValue* SCTToDictionary( |
| 93 const ct::SignedCertificateTimestamp& sct) { | 92 const ct::SignedCertificateTimestamp& sct) { |
| 94 base::DictionaryValue* out = new base::DictionaryValue(); | 93 base::DictionaryValue* out = new base::DictionaryValue(); |
| 95 | 94 |
| 96 out->SetString("origin", OriginToString(sct.origin)); | 95 out->SetString("origin", OriginToString(sct.origin)); |
| 97 out->SetInteger("version", sct.version); | 96 out->SetInteger("version", sct.version); |
| 98 | 97 |
| 99 SetBinaryData("log_id", sct.log_id, out); | 98 SetBinaryData("log_id", sct.log_id, out); |
| 100 base::TimeDelta time_since_unix_epoch = | 99 base::TimeDelta time_since_unix_epoch = |
| 101 sct.timestamp - base::Time::UnixEpoch(); | 100 sct.timestamp - base::Time::UnixEpoch(); |
| 102 out->SetString("timestamp", | 101 out->SetString("timestamp", |
| 103 base::Int64ToString(time_since_unix_epoch.InMilliseconds())); | 102 base::Int64ToString(time_since_unix_epoch.InMilliseconds())); |
| 104 SetBinaryData("extensions", sct.extensions, out); | 103 SetBinaryData("extensions", sct.extensions, out); |
| 105 | 104 |
| 106 out->SetString("hash_algorithm", | 105 out->SetString("hash_algorithm", |
| 107 HashAlgorithmToString(sct.signature.hash_algorithm)); | 106 HashAlgorithmToString(sct.signature.hash_algorithm)); |
| 108 out->SetString("signature_algorithm", | 107 out->SetString("signature_algorithm", |
| 109 SignatureAlgorithmToString(sct.signature.signature_algorithm)); | 108 SignatureAlgorithmToString(sct.signature.signature_algorithm)); |
| 110 SetBinaryData( | 109 SetBinaryData("signature_data", sct.signature.signature_data, out); |
| 111 "signature_data", sct.signature.signature_data, out); | |
| 112 | 110 |
| 113 return out; | 111 return out; |
| 114 } | 112 } |
| 115 | 113 |
| 116 // Given a list of SCTs, return a ListValue instance where each item in the | 114 // Given a list of SCTs, return a ListValue instance where each item in the |
| 117 // list is a dictionary created by SCTToDictionary. | 115 // list is a dictionary created by SCTToDictionary. |
| 118 base::ListValue* SCTListToPrintableValues( | 116 base::ListValue* SCTListToPrintableValues(const ct::SCTList& sct_list) { |
| 119 const ct::SCTList& sct_list) { | |
| 120 base::ListValue* output_scts = new base::ListValue(); | 117 base::ListValue* output_scts = new base::ListValue(); |
| 121 for (ct::SCTList::const_iterator it = sct_list.begin(); | 118 for (ct::SCTList::const_iterator it = sct_list.begin(); it != sct_list.end(); |
| 122 it != sct_list.end(); | |
| 123 ++it) | 119 ++it) |
| 124 output_scts->Append(SCTToDictionary(*(it->get()))); | 120 output_scts->Append(SCTToDictionary(*(it->get()))); |
| 125 | 121 |
| 126 return output_scts; | 122 return output_scts; |
| 127 } | 123 } |
| 128 | 124 |
| 129 } // namespace | 125 } // namespace |
| 130 | 126 |
| 131 base::Value* NetLogSignedCertificateTimestampCallback( | 127 base::Value* NetLogSignedCertificateTimestampCallback( |
| 132 const ct::CTVerifyResult* ct_result, NetLog::LogLevel log_level) { | 128 const ct::CTVerifyResult* ct_result, |
| 129 NetLog::LogLevel log_level) { |
| 133 base::DictionaryValue* dict = new base::DictionaryValue(); | 130 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 134 | 131 |
| 135 dict->Set("verified_scts", | 132 dict->Set("verified_scts", |
| 136 SCTListToPrintableValues(ct_result->verified_scts)); | 133 SCTListToPrintableValues(ct_result->verified_scts)); |
| 137 | 134 |
| 138 dict->Set("invalid_scts", | 135 dict->Set("invalid_scts", SCTListToPrintableValues(ct_result->invalid_scts)); |
| 139 SCTListToPrintableValues(ct_result->invalid_scts)); | |
| 140 | 136 |
| 141 dict->Set("unknown_logs_scts", | 137 dict->Set("unknown_logs_scts", |
| 142 SCTListToPrintableValues(ct_result->unknown_logs_scts)); | 138 SCTListToPrintableValues(ct_result->unknown_logs_scts)); |
| 143 | 139 |
| 144 return dict; | 140 return dict; |
| 145 } | 141 } |
| 146 | 142 |
| 147 base::Value* NetLogRawSignedCertificateTimestampCallback( | 143 base::Value* NetLogRawSignedCertificateTimestampCallback( |
| 148 const std::string* embedded_scts, | 144 const std::string* embedded_scts, |
| 149 const std::string* sct_list_from_ocsp, | 145 const std::string* sct_list_from_ocsp, |
| 150 const std::string* sct_list_from_tls_extension, | 146 const std::string* sct_list_from_tls_extension, |
| 151 NetLog::LogLevel log_level) { | 147 NetLog::LogLevel log_level) { |
| 152 base::DictionaryValue* dict = new base::DictionaryValue(); | 148 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 153 | 149 |
| 154 SetBinaryData("embedded_scts", *embedded_scts, dict); | 150 SetBinaryData("embedded_scts", *embedded_scts, dict); |
| 155 SetBinaryData("scts_from_ocsp_response", *sct_list_from_ocsp, dict); | 151 SetBinaryData("scts_from_ocsp_response", *sct_list_from_ocsp, dict); |
| 156 SetBinaryData("scts_from_tls_extension", *sct_list_from_tls_extension, dict); | 152 SetBinaryData("scts_from_tls_extension", *sct_list_from_tls_extension, dict); |
| 157 | 153 |
| 158 return dict; | 154 return dict; |
| 159 } | 155 } |
| 160 | 156 |
| 161 } // namespace net | 157 } // namespace net |
| OLD | NEW |