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 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 // For example, turn "www.google.com" into "http://www.google.com". | 1074 // For example, turn "www.google.com" into "http://www.google.com". |
1076 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); | 1075 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); |
1077 | 1076 |
1078 connection_tester_.reset(new ConnectionTester( | 1077 connection_tester_.reset(new ConnectionTester( |
1079 this, | 1078 this, |
1080 io_thread_->globals()->proxy_script_fetcher_context.get(), | 1079 io_thread_->globals()->proxy_script_fetcher_context.get(), |
1081 net_log())); | 1080 net_log())); |
1082 connection_tester_->RunAllTests(url); | 1081 connection_tester_->RunAllTests(url); |
1083 } | 1082 } |
1084 | 1083 |
1085 void SPKIHashesToString(const net::HashValueVector& hashes, | |
1086 std::string* string) { | |
1087 for (net::HashValueVector::const_iterator | |
1088 i = hashes.begin(); i != hashes.end(); ++i) { | |
1089 base::StringPiece hash_str(reinterpret_cast<const char*>(i->data()), | |
1090 i->size()); | |
1091 std::string encoded; | |
1092 base::Base64Encode(hash_str, &encoded); | |
1093 | |
1094 if (i != hashes.begin()) | |
1095 *string += ","; | |
1096 *string += net::TransportSecurityState::HashValueLabel(*i) + encoded; | |
1097 } | |
1098 } | |
1099 | |
1100 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery( | 1084 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery( |
1101 const ListValue* list) { | 1085 const ListValue* list) { |
1102 // |list| should be: [<domain to query>]. | 1086 // |list| should be: [<domain to query>]. |
1103 std::string domain; | 1087 std::string domain; |
1104 CHECK(list->GetString(0, &domain)); | 1088 CHECK(list->GetString(0, &domain)); |
1105 DictionaryValue* result = new DictionaryValue(); | 1089 DictionaryValue* result = new DictionaryValue(); |
1106 | 1090 |
1107 if (!IsStringASCII(domain)) { | 1091 if (!IsStringASCII(domain)) { |
1108 result->SetString("error", "non-ASCII domain name"); | 1092 result->SetString("error", "non-ASCII domain name"); |
1109 } else { | 1093 } else { |
1110 net::TransportSecurityState* transport_security_state = | 1094 net::TransportSecurityState* transport_security_state = |
1111 context_getter_->GetURLRequestContext()->transport_security_state(); | 1095 context_getter_->GetURLRequestContext()->transport_security_state(); |
1112 if (!transport_security_state) { | 1096 if (!transport_security_state) { |
1113 result->SetString("error", "no TransportSecurityState active"); | 1097 result->SetString("error", "no TransportSecurityState active"); |
1114 } else { | 1098 } else { |
1115 net::TransportSecurityState::DomainState state; | 1099 net::TransportSecurityState::DomainState state; |
1116 const bool found = transport_security_state->GetDomainState( | 1100 const bool found = transport_security_state->GetDomainState( |
1117 domain, true, &state); | 1101 domain, true, &state); |
1118 | 1102 |
1119 result->SetBoolean("result", found); | 1103 result->SetBoolean("result", found); |
1120 if (found) { | 1104 if (found) { |
1121 result->SetInteger("mode", static_cast<int>(state.upgrade_mode)); | 1105 result->SetInteger("mode", static_cast<int>(state.upgrade_mode)); |
1122 result->SetBoolean("subdomains", state.include_subdomains); | 1106 result->SetBoolean("subdomains", state.include_subdomains); |
1123 result->SetString("domain", state.domain); | 1107 result->SetString("domain", state.domain); |
1124 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT()); | 1108 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT()); |
1125 result->SetDouble("dynamic_spki_hashes_expiry", | 1109 result->SetDouble("dynamic_spki_hashes_expiry", |
1126 state.dynamic_spki_hashes_expiry.ToDoubleT()); | 1110 state.dynamic_spki_hashes_expiry.ToDoubleT()); |
1127 | 1111 |
1128 std::string hashes; | 1112 std::string hashes_str; |
1129 SPKIHashesToString(state.static_spki_hashes, &hashes); | 1113 hashes_str = net::HashesToBase64String(state.static_spki_hashes); |
1130 result->SetString("static_spki_hashes", hashes); | 1114 result->SetString("static_spki_hashes", hashes_str); |
1131 | 1115 |
1132 hashes.clear(); | 1116 hashes_str = net::HashesToBase64String(state.dynamic_spki_hashes); |
1133 SPKIHashesToString(state.dynamic_spki_hashes, &hashes); | 1117 result->SetString("dynamic_spki_hashes", hashes_str); |
1134 result->SetString("dynamic_spki_hashes", hashes); | |
1135 } | 1118 } |
1136 } | 1119 } |
1137 } | 1120 } |
1138 | 1121 |
1139 SendJavascriptCommand("receivedHSTSResult", result); | 1122 SendJavascriptCommand("receivedHSTSResult", result); |
1140 } | 1123 } |
1141 | 1124 |
1142 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( | 1125 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( |
1143 const ListValue* list) { | 1126 const ListValue* list) { |
1144 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>]. | 1127 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>]. |
(...skipping 10 matching lines...) Expand all Loading... |
1155 CHECK(list->GetString(2, &hashes_str)); | 1138 CHECK(list->GetString(2, &hashes_str)); |
1156 | 1139 |
1157 net::TransportSecurityState* transport_security_state = | 1140 net::TransportSecurityState* transport_security_state = |
1158 context_getter_->GetURLRequestContext()->transport_security_state(); | 1141 context_getter_->GetURLRequestContext()->transport_security_state(); |
1159 if (!transport_security_state) | 1142 if (!transport_security_state) |
1160 return; | 1143 return; |
1161 | 1144 |
1162 net::TransportSecurityState::DomainState state; | 1145 net::TransportSecurityState::DomainState state; |
1163 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000); | 1146 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000); |
1164 state.include_subdomains = include_subdomains; | 1147 state.include_subdomains = include_subdomains; |
1165 if (!hashes_str.empty()) { | 1148 net::Base64StringToHashes(hashes_str, &state.dynamic_spki_hashes); |
1166 std::vector<std::string> type_and_b64s; | |
1167 base::SplitString(hashes_str, ',', &type_and_b64s); | |
1168 for (std::vector<std::string>::const_iterator | |
1169 i = type_and_b64s.begin(); i != type_and_b64s.end(); ++i) { | |
1170 std::string type_and_b64; | |
1171 RemoveChars(*i, " \t\r\n", &type_and_b64); | |
1172 net::HashValue hash; | |
1173 if (!net::TransportSecurityState::ParsePin(type_and_b64, &hash)) | |
1174 continue; | |
1175 | |
1176 state.dynamic_spki_hashes.push_back(hash); | |
1177 } | |
1178 } | |
1179 | |
1180 transport_security_state->EnableHost(domain, state); | 1149 transport_security_state->EnableHost(domain, state); |
1181 } | 1150 } |
1182 | 1151 |
1183 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( | 1152 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( |
1184 const ListValue* list) { | 1153 const ListValue* list) { |
1185 // |list| should be: [<domain to query>]. | 1154 // |list| should be: [<domain to query>]. |
1186 std::string domain; | 1155 std::string domain; |
1187 CHECK(list->GetString(0, &domain)); | 1156 CHECK(list->GetString(0, &domain)); |
1188 if (!IsStringASCII(domain)) { | 1157 if (!IsStringASCII(domain)) { |
1189 // There cannot be a unicode entry in the HSTS set. | 1158 // There cannot be a unicode entry in the HSTS set. |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1740 } | 1709 } |
1741 | 1710 |
1742 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1711 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1743 : WebUIController(web_ui) { | 1712 : WebUIController(web_ui) { |
1744 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1713 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
1745 | 1714 |
1746 // Set up the chrome://net-internals/ source. | 1715 // Set up the chrome://net-internals/ source. |
1747 Profile* profile = Profile::FromWebUI(web_ui); | 1716 Profile* profile = Profile::FromWebUI(web_ui); |
1748 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); | 1717 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); |
1749 } | 1718 } |
OLD | NEW |