| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 std::string b64_value; | 30 std::string b64_value; |
| 31 base::Base64Encode(value, &b64_value); | 31 base::Base64Encode(value, &b64_value); |
| 32 | 32 |
| 33 dict->SetString(key, b64_value); | 33 dict->SetString(key, b64_value); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Returns a dictionary where each key is a field of the SCT and its value | 36 // Returns a dictionary where each key is a field of the SCT and its value |
| 37 // is this field's value in the SCT. This dictionary is meant to be used for | 37 // is this field's value in the SCT. This dictionary is meant to be used for |
| 38 // outputting a de-serialized SCT to the NetLog. | 38 // outputting a de-serialized SCT to the NetLog. |
| 39 std::unique_ptr<base::DictionaryValue> SCTToDictionary( | 39 std::unique_ptr<base::DictionaryValue> SCTToDictionary( |
| 40 const ct::SignedCertificateTimestamp& sct) { | 40 const ct::SignedCertificateTimestamp& sct, |
| 41 ct::SCTVerifyStatus status) { |
| 41 std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue()); | 42 std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue()); |
| 42 | 43 |
| 43 out->SetString("origin", OriginToString(sct.origin)); | 44 out->SetString("origin", OriginToString(sct.origin)); |
| 45 out->SetString("verification_status", StatusToString(status)); |
| 44 out->SetInteger("version", sct.version); | 46 out->SetInteger("version", sct.version); |
| 45 | 47 |
| 46 SetBinaryData("log_id", sct.log_id, out.get()); | 48 SetBinaryData("log_id", sct.log_id, out.get()); |
| 47 base::TimeDelta time_since_unix_epoch = | 49 base::TimeDelta time_since_unix_epoch = |
| 48 sct.timestamp - base::Time::UnixEpoch(); | 50 sct.timestamp - base::Time::UnixEpoch(); |
| 49 out->SetString("timestamp", | 51 out->SetString("timestamp", |
| 50 base::Int64ToString(time_since_unix_epoch.InMilliseconds())); | 52 base::Int64ToString(time_since_unix_epoch.InMilliseconds())); |
| 51 SetBinaryData("extensions", sct.extensions, out.get()); | 53 SetBinaryData("extensions", sct.extensions, out.get()); |
| 52 | 54 |
| 53 out->SetString("hash_algorithm", | 55 out->SetString("hash_algorithm", |
| 54 HashAlgorithmToString(sct.signature.hash_algorithm)); | 56 HashAlgorithmToString(sct.signature.hash_algorithm)); |
| 55 out->SetString("signature_algorithm", | 57 out->SetString("signature_algorithm", |
| 56 SignatureAlgorithmToString(sct.signature.signature_algorithm)); | 58 SignatureAlgorithmToString(sct.signature.signature_algorithm)); |
| 57 SetBinaryData("signature_data", sct.signature.signature_data, out.get()); | 59 SetBinaryData("signature_data", sct.signature.signature_data, out.get()); |
| 58 | 60 |
| 59 return out; | 61 return out; |
| 60 } | 62 } |
| 61 | 63 |
| 62 // Given a list of SCTs, return a ListValue instance where each item in the | 64 // Given a list of SCTs and their statuses, return a ListValue instance where |
| 63 // list is a dictionary created by SCTToDictionary. | 65 // each item in the list is a dictionary created by SCTToDictionary. |
| 64 std::unique_ptr<base::ListValue> SCTListToPrintableValues( | 66 std::unique_ptr<base::ListValue> SCTListToPrintableValues( |
| 65 const ct::SCTList& sct_list) { | 67 const SignedCertificateTimestampAndStatusList& sct_and_status_list) { |
| 66 std::unique_ptr<base::ListValue> output_scts(new base::ListValue()); | 68 std::unique_ptr<base::ListValue> output_scts(new base::ListValue()); |
| 67 for (const auto& sct : sct_list) | 69 for (const auto& sct_and_status : sct_and_status_list) |
| 68 output_scts->Append(SCTToDictionary(*(sct.get()))); | 70 output_scts->Append( |
| 71 SCTToDictionary(*(sct_and_status.sct.get()), sct_and_status.status)); |
| 69 | 72 |
| 70 return output_scts; | 73 return output_scts; |
| 71 } | 74 } |
| 72 | 75 |
| 73 } // namespace | 76 } // namespace |
| 74 | 77 |
| 75 std::unique_ptr<base::Value> NetLogSignedCertificateTimestampCallback( | 78 std::unique_ptr<base::Value> NetLogSignedCertificateTimestampCallback( |
| 76 const ct::CTVerifyResult* ct_result, | 79 const ct::CTVerifyResult* ct_result, |
| 77 NetLogCaptureMode capture_mode) { | 80 NetLogCaptureMode capture_mode) { |
| 78 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 81 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 79 | 82 |
| 80 dict->Set("verified_scts", | 83 dict->Set("scts", SCTListToPrintableValues(ct_result->scts)); |
| 81 SCTListToPrintableValues(ct_result->verified_scts)); | |
| 82 | |
| 83 dict->Set("invalid_scts", | |
| 84 SCTListToPrintableValues(ct_result->invalid_scts)); | |
| 85 | |
| 86 dict->Set("unknown_logs_scts", | |
| 87 SCTListToPrintableValues(ct_result->unknown_logs_scts)); | |
| 88 | 84 |
| 89 return std::move(dict); | 85 return std::move(dict); |
| 90 } | 86 } |
| 91 | 87 |
| 92 std::unique_ptr<base::Value> NetLogRawSignedCertificateTimestampCallback( | 88 std::unique_ptr<base::Value> NetLogRawSignedCertificateTimestampCallback( |
| 93 const std::string* embedded_scts, | 89 const std::string* embedded_scts, |
| 94 const std::string* sct_list_from_ocsp, | 90 const std::string* sct_list_from_ocsp, |
| 95 const std::string* sct_list_from_tls_extension, | 91 const std::string* sct_list_from_tls_extension, |
| 96 NetLogCaptureMode capture_mode) { | 92 NetLogCaptureMode capture_mode) { |
| 97 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 93 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 98 | 94 |
| 99 SetBinaryData("embedded_scts", *embedded_scts, dict.get()); | 95 SetBinaryData("embedded_scts", *embedded_scts, dict.get()); |
| 100 SetBinaryData("scts_from_ocsp_response", *sct_list_from_ocsp, dict.get()); | 96 SetBinaryData("scts_from_ocsp_response", *sct_list_from_ocsp, dict.get()); |
| 101 SetBinaryData("scts_from_tls_extension", *sct_list_from_tls_extension, | 97 SetBinaryData("scts_from_tls_extension", *sct_list_from_tls_extension, |
| 102 dict.get()); | 98 dict.get()); |
| 103 | 99 |
| 104 return std::move(dict); | 100 return std::move(dict); |
| 105 } | 101 } |
| 106 | 102 |
| 107 } // namespace net | 103 } // namespace net |
| OLD | NEW |