OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/net_internals/net_internals_ui.h" | 5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
17 #include "base/file_util.h" | 17 #include "base/file_util.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
20 #include "base/platform_file.h" | 20 #include "base/platform_file.h" |
21 #include "base/sequenced_task_runner_helpers.h" | 21 #include "base/sequenced_task_runner_helpers.h" |
22 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
23 #include "base/string_piece.h" | 23 #include "base/string_piece.h" |
24 #include "base/string_split.h" | |
25 #include "base/string_util.h" | 24 #include "base/string_util.h" |
26 #include "base/threading/worker_pool.h" | 25 #include "base/threading/worker_pool.h" |
27 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
28 #include "base/values.h" | 27 #include "base/values.h" |
29 #include "chrome/browser/api/prefs/pref_member.h" | 28 #include "chrome/browser/api/prefs/pref_member.h" |
30 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 30 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
32 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 31 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
33 #include "chrome/browser/download/download_util.h" | 32 #include "chrome/browser/download/download_util.h" |
34 #include "chrome/browser/io_thread.h" | 33 #include "chrome/browser/io_thread.h" |
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 // For example, turn "www.google.com" into "http://www.google.com". | 1092 // For example, turn "www.google.com" into "http://www.google.com". |
1094 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); | 1093 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); |
1095 | 1094 |
1096 connection_tester_.reset(new ConnectionTester( | 1095 connection_tester_.reset(new ConnectionTester( |
1097 this, | 1096 this, |
1098 io_thread_->globals()->proxy_script_fetcher_context.get(), | 1097 io_thread_->globals()->proxy_script_fetcher_context.get(), |
1099 net_log())); | 1098 net_log())); |
1100 connection_tester_->RunAllTests(url); | 1099 connection_tester_->RunAllTests(url); |
1101 } | 1100 } |
1102 | 1101 |
1103 void SPKIHashesToString(const net::HashValueVector& hashes, | |
1104 std::string* string) { | |
1105 for (net::HashValueVector::const_iterator | |
1106 i = hashes.begin(); i != hashes.end(); ++i) { | |
1107 base::StringPiece hash_str(reinterpret_cast<const char*>(i->data()), | |
1108 i->size()); | |
1109 std::string encoded; | |
1110 base::Base64Encode(hash_str, &encoded); | |
1111 | |
1112 if (i != hashes.begin()) | |
1113 *string += ","; | |
1114 *string += net::TransportSecurityState::HashValueLabel(*i) + encoded; | |
1115 } | |
1116 } | |
1117 | |
1118 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery( | 1102 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery( |
1119 const ListValue* list) { | 1103 const ListValue* list) { |
1120 // |list| should be: [<domain to query>]. | 1104 // |list| should be: [<domain to query>]. |
1121 std::string domain; | 1105 std::string domain; |
1122 CHECK(list->GetString(0, &domain)); | 1106 CHECK(list->GetString(0, &domain)); |
1123 DictionaryValue* result = new DictionaryValue(); | 1107 DictionaryValue* result = new DictionaryValue(); |
1124 | 1108 |
1125 if (!IsStringASCII(domain)) { | 1109 if (!IsStringASCII(domain)) { |
1126 result->SetString("error", "non-ASCII domain name"); | 1110 result->SetString("error", "non-ASCII domain name"); |
1127 } else { | 1111 } else { |
1128 net::TransportSecurityState* transport_security_state = | 1112 net::TransportSecurityState* transport_security_state = |
1129 context_getter_->GetURLRequestContext()->transport_security_state(); | 1113 context_getter_->GetURLRequestContext()->transport_security_state(); |
1130 if (!transport_security_state) { | 1114 if (!transport_security_state) { |
1131 result->SetString("error", "no TransportSecurityState active"); | 1115 result->SetString("error", "no TransportSecurityState active"); |
1132 } else { | 1116 } else { |
1133 net::TransportSecurityState::DomainState state; | 1117 net::TransportSecurityState::DomainState state; |
1134 const bool found = transport_security_state->GetDomainState( | 1118 const bool found = transport_security_state->GetDomainState( |
1135 domain, true, &state); | 1119 domain, true, &state); |
1136 | 1120 |
1137 result->SetBoolean("result", found); | 1121 result->SetBoolean("result", found); |
1138 if (found) { | 1122 if (found) { |
1139 result->SetInteger("mode", static_cast<int>(state.upgrade_mode)); | 1123 result->SetInteger("mode", static_cast<int>(state.upgrade_mode)); |
1140 result->SetBoolean("subdomains", state.include_subdomains); | 1124 result->SetBoolean("subdomains", state.include_subdomains); |
1141 result->SetString("domain", state.domain); | 1125 result->SetString("domain", state.domain); |
1142 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT()); | 1126 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT()); |
1143 result->SetDouble("dynamic_spki_hashes_expiry", | 1127 result->SetDouble("dynamic_spki_hashes_expiry", |
1144 state.dynamic_spki_hashes_expiry.ToDoubleT()); | 1128 state.dynamic_spki_hashes_expiry.ToDoubleT()); |
1145 | 1129 |
1146 std::string hashes; | 1130 std::string hashes_str; |
1147 SPKIHashesToString(state.static_spki_hashes, &hashes); | 1131 hashes_str = net::HashesToBase64String(state.static_spki_hashes); |
1148 result->SetString("static_spki_hashes", hashes); | 1132 result->SetString("static_spki_hashes", hashes_str); |
1149 | 1133 |
1150 hashes.clear(); | 1134 hashes_str = net::HashesToBase64String(state.dynamic_spki_hashes); |
1151 SPKIHashesToString(state.dynamic_spki_hashes, &hashes); | 1135 result->SetString("dynamic_spki_hashes", hashes_str); |
1152 result->SetString("dynamic_spki_hashes", hashes); | |
1153 } | 1136 } |
1154 } | 1137 } |
1155 } | 1138 } |
1156 | 1139 |
1157 SendJavascriptCommand("receivedHSTSResult", result); | 1140 SendJavascriptCommand("receivedHSTSResult", result); |
1158 } | 1141 } |
1159 | 1142 |
1160 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( | 1143 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( |
1161 const ListValue* list) { | 1144 const ListValue* list) { |
1162 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>]. | 1145 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>]. |
(...skipping 10 matching lines...) Expand all Loading... |
1173 CHECK(list->GetString(2, &hashes_str)); | 1156 CHECK(list->GetString(2, &hashes_str)); |
1174 | 1157 |
1175 net::TransportSecurityState* transport_security_state = | 1158 net::TransportSecurityState* transport_security_state = |
1176 context_getter_->GetURLRequestContext()->transport_security_state(); | 1159 context_getter_->GetURLRequestContext()->transport_security_state(); |
1177 if (!transport_security_state) | 1160 if (!transport_security_state) |
1178 return; | 1161 return; |
1179 | 1162 |
1180 net::TransportSecurityState::DomainState state; | 1163 net::TransportSecurityState::DomainState state; |
1181 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000); | 1164 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000); |
1182 state.include_subdomains = include_subdomains; | 1165 state.include_subdomains = include_subdomains; |
1183 if (!hashes_str.empty()) { | 1166 net::Base64StringToHashes(hashes_str, &state.dynamic_spki_hashes); |
1184 std::vector<std::string> type_and_b64s; | |
1185 base::SplitString(hashes_str, ',', &type_and_b64s); | |
1186 for (std::vector<std::string>::const_iterator | |
1187 i = type_and_b64s.begin(); i != type_and_b64s.end(); ++i) { | |
1188 std::string type_and_b64; | |
1189 RemoveChars(*i, " \t\r\n", &type_and_b64); | |
1190 net::HashValue hash; | |
1191 if (!net::TransportSecurityState::ParsePin(type_and_b64, &hash)) | |
1192 continue; | |
1193 | |
1194 state.dynamic_spki_hashes.push_back(hash); | |
1195 } | |
1196 } | |
1197 | |
1198 transport_security_state->EnableHost(domain, state); | 1167 transport_security_state->EnableHost(domain, state); |
1199 } | 1168 } |
1200 | 1169 |
1201 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( | 1170 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( |
1202 const ListValue* list) { | 1171 const ListValue* list) { |
1203 // |list| should be: [<domain to query>]. | 1172 // |list| should be: [<domain to query>]. |
1204 std::string domain; | 1173 std::string domain; |
1205 CHECK(list->GetString(0, &domain)); | 1174 CHECK(list->GetString(0, &domain)); |
1206 if (!IsStringASCII(domain)) { | 1175 if (!IsStringASCII(domain)) { |
1207 // There cannot be a unicode entry in the HSTS set. | 1176 // There cannot be a unicode entry in the HSTS set. |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 } | 1744 } |
1776 | 1745 |
1777 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1746 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1778 : WebUIController(web_ui) { | 1747 : WebUIController(web_ui) { |
1779 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1748 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
1780 | 1749 |
1781 // Set up the chrome://net-internals/ source. | 1750 // Set up the chrome://net-internals/ source. |
1782 Profile* profile = Profile::FromWebUI(web_ui); | 1751 Profile* profile = Profile::FromWebUI(web_ui); |
1783 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); | 1752 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); |
1784 } | 1753 } |
OLD | NEW |