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

Side by Side Diff: chrome/browser/ui/webui/net_internals/net_internals_ui.cc

Issue 11274032: Separate http_security_headers from transport_security_state (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 months 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
« no previous file with comments | « chrome/browser/net/transport_security_persister.cc ('k') | net/base/hash_value.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // encounters a new version. This should be incremented when significant 103 // encounters a new version. This should be incremented when significant
104 // changes are made that will invalidate the old loading code. 104 // changes are made that will invalidate the old loading code.
105 const int kLogFormatVersion = 1; 105 const int kLogFormatVersion = 1;
106 106
107 // Returns the HostCache for |context|'s primary HostResolver, or NULL if 107 // Returns the HostCache for |context|'s primary HostResolver, or NULL if
108 // there is none. 108 // there is none.
109 net::HostCache* GetHostResolverCache(net::URLRequestContext* context) { 109 net::HostCache* GetHostResolverCache(net::URLRequestContext* context) {
110 return context->host_resolver()->GetHostCache(); 110 return context->host_resolver()->GetHostCache();
111 } 111 }
112 112
113 std::string HashesToBase64String(const net::HashValueVector& hashes) {
114 std::string str;
115 for (size_t i = 0; i != hashes.size(); ++i) {
116 if (i != 0)
117 str += ",";
118 str += hashes[i].ToString();
119 }
120 return str;
121 }
122
123 bool Base64StringToHashes(const std::string& hashes_str,
124 net::HashValueVector* hashes) {
125 hashes->clear();
126 std::vector<std::string> vector_hash_str;
127 base::SplitString(hashes_str, ',', &vector_hash_str);
128
129 for (size_t i = 0; i != vector_hash_str.size(); ++i) {
130 std::string hash_str;
131 RemoveChars(vector_hash_str[i], " \t\r\n", &hash_str);
132 net::HashValue hash;
133 // Skip past unrecognized hash algos
134 // But return false on malformatted input
135 if (hash_str.empty())
136 return false;
137 if (hash_str.compare(0, 5, "sha1/") != 0 &&
eroman 2013/01/08 00:18:09 See also StartsWithASCII()
138 hash_str.compare(0, 7, "sha256/") != 0) {
139 continue;
140 }
141 if (!hash.FromString(hash_str))
142 return false;
143 hashes->push_back(hash);
144 }
145 return true;
146 }
147
113 // Returns a Value representing the state of a pre-existing URLRequest when 148 // Returns a Value representing the state of a pre-existing URLRequest when
114 // net-internals was opened. 149 // net-internals was opened.
115 Value* RequestStateToValue(const net::URLRequest* request, 150 Value* RequestStateToValue(const net::URLRequest* request,
116 net::NetLog::LogLevel log_level) { 151 net::NetLog::LogLevel log_level) {
117 DictionaryValue* dict = new DictionaryValue(); 152 DictionaryValue* dict = new DictionaryValue();
118 dict->SetString("url", request->original_url().possibly_invalid_spec()); 153 dict->SetString("url", request->original_url().possibly_invalid_spec());
119 154
120 const std::vector<GURL>& url_chain = request->url_chain(); 155 const std::vector<GURL>& url_chain = request->url_chain();
121 if (url_chain.size() > 1) { 156 if (url_chain.size() > 1) {
122 ListValue* list = new ListValue(); 157 ListValue* list = new ListValue();
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 // For example, turn "www.google.com" into "http://www.google.com". 1199 // For example, turn "www.google.com" into "http://www.google.com".
1165 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); 1200 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string()));
1166 1201
1167 connection_tester_.reset(new ConnectionTester( 1202 connection_tester_.reset(new ConnectionTester(
1168 this, 1203 this,
1169 io_thread_->globals()->proxy_script_fetcher_context.get(), 1204 io_thread_->globals()->proxy_script_fetcher_context.get(),
1170 net_log())); 1205 net_log()));
1171 connection_tester_->RunAllTests(url); 1206 connection_tester_->RunAllTests(url);
1172 } 1207 }
1173 1208
1174 void SPKIHashesToString(const net::HashValueVector& hashes,
1175 std::string* string) {
1176 for (net::HashValueVector::const_iterator
1177 i = hashes.begin(); i != hashes.end(); ++i) {
1178 base::StringPiece hash_str(reinterpret_cast<const char*>(i->data()),
1179 i->size());
1180 std::string encoded;
1181 base::Base64Encode(hash_str, &encoded);
1182
1183 if (i != hashes.begin())
1184 *string += ",";
1185 *string += net::TransportSecurityState::HashValueLabel(*i) + encoded;
1186 }
1187 }
1188
1189 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery( 1209 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery(
1190 const ListValue* list) { 1210 const ListValue* list) {
1191 // |list| should be: [<domain to query>]. 1211 // |list| should be: [<domain to query>].
1192 std::string domain; 1212 std::string domain;
1193 CHECK(list->GetString(0, &domain)); 1213 CHECK(list->GetString(0, &domain));
1194 DictionaryValue* result = new DictionaryValue(); 1214 DictionaryValue* result = new DictionaryValue();
1195 1215
1196 if (!IsStringASCII(domain)) { 1216 if (!IsStringASCII(domain)) {
1197 result->SetString("error", "non-ASCII domain name"); 1217 result->SetString("error", "non-ASCII domain name");
1198 } else { 1218 } else {
1199 net::TransportSecurityState* transport_security_state = 1219 net::TransportSecurityState* transport_security_state =
1200 GetMainContext()->transport_security_state(); 1220 GetMainContext()->transport_security_state();
1201 if (!transport_security_state) { 1221 if (!transport_security_state) {
1202 result->SetString("error", "no TransportSecurityState active"); 1222 result->SetString("error", "no TransportSecurityState active");
1203 } else { 1223 } else {
1204 net::TransportSecurityState::DomainState state; 1224 net::TransportSecurityState::DomainState state;
1205 const bool found = transport_security_state->GetDomainState( 1225 const bool found = transport_security_state->GetDomainState(
1206 domain, true, &state); 1226 domain, true, &state);
1207 1227
1208 result->SetBoolean("result", found); 1228 result->SetBoolean("result", found);
1209 if (found) { 1229 if (found) {
1210 result->SetInteger("mode", static_cast<int>(state.upgrade_mode)); 1230 result->SetInteger("mode", static_cast<int>(state.upgrade_mode));
1211 result->SetBoolean("subdomains", state.include_subdomains); 1231 result->SetBoolean("subdomains", state.include_subdomains);
1212 result->SetString("domain", state.domain); 1232 result->SetString("domain", state.domain);
1213 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT()); 1233 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT());
1214 result->SetDouble("dynamic_spki_hashes_expiry", 1234 result->SetDouble("dynamic_spki_hashes_expiry",
1215 state.dynamic_spki_hashes_expiry.ToDoubleT()); 1235 state.dynamic_spki_hashes_expiry.ToDoubleT());
1216 1236
1217 std::string hashes; 1237 result->SetString("static_spki_hashes",
1218 SPKIHashesToString(state.static_spki_hashes, &hashes); 1238 HashesToBase64String(state.static_spki_hashes));
1219 result->SetString("static_spki_hashes", hashes); 1239 result->SetString("dynamic_spki_hashes",
1220 1240 HashesToBase64String(state.dynamic_spki_hashes));
1221 hashes.clear();
1222 SPKIHashesToString(state.dynamic_spki_hashes, &hashes);
1223 result->SetString("dynamic_spki_hashes", hashes);
1224 } 1241 }
1225 } 1242 }
1226 } 1243 }
1227 1244
1228 SendJavascriptCommand("receivedHSTSResult", result); 1245 SendJavascriptCommand("receivedHSTSResult", result);
1229 } 1246 }
1230 1247
1231 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( 1248 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd(
1232 const ListValue* list) { 1249 const ListValue* list) {
1233 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>]. 1250 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>].
(...skipping 11 matching lines...) Expand all
1245 1262
1246 net::TransportSecurityState* transport_security_state = 1263 net::TransportSecurityState* transport_security_state =
1247 GetMainContext()->transport_security_state(); 1264 GetMainContext()->transport_security_state();
1248 if (!transport_security_state) 1265 if (!transport_security_state)
1249 return; 1266 return;
1250 1267
1251 net::TransportSecurityState::DomainState state; 1268 net::TransportSecurityState::DomainState state;
1252 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000); 1269 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000);
1253 state.include_subdomains = include_subdomains; 1270 state.include_subdomains = include_subdomains;
1254 if (!hashes_str.empty()) { 1271 if (!hashes_str.empty()) {
1255 std::vector<std::string> type_and_b64s; 1272 if (!Base64StringToHashes(hashes_str, &state.dynamic_spki_hashes))
1256 base::SplitString(hashes_str, ',', &type_and_b64s); 1273 return;
1257 for (std::vector<std::string>::const_iterator
1258 i = type_and_b64s.begin(); i != type_and_b64s.end(); ++i) {
1259 std::string type_and_b64;
1260 RemoveChars(*i, " \t\r\n", &type_and_b64);
1261 net::HashValue hash;
1262 if (!net::TransportSecurityState::ParsePin(type_and_b64, &hash))
1263 continue;
1264
1265 state.dynamic_spki_hashes.push_back(hash);
1266 }
1267 } 1274 }
1268
1269 transport_security_state->EnableHost(domain, state); 1275 transport_security_state->EnableHost(domain, state);
1270 } 1276 }
1271 1277
1272 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( 1278 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete(
1273 const ListValue* list) { 1279 const ListValue* list) {
1274 // |list| should be: [<domain to query>]. 1280 // |list| should be: [<domain to query>].
1275 std::string domain; 1281 std::string domain;
1276 CHECK(list->GetString(0, &domain)); 1282 CHECK(list->GetString(0, &domain));
1277 if (!IsStringASCII(domain)) { 1283 if (!IsStringASCII(domain)) {
1278 // There cannot be a unicode entry in the HSTS set. 1284 // There cannot be a unicode entry in the HSTS set.
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 } 1919 }
1914 1920
1915 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1921 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1916 : WebUIController(web_ui) { 1922 : WebUIController(web_ui) {
1917 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1923 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1918 1924
1919 // Set up the chrome://net-internals/ source. 1925 // Set up the chrome://net-internals/ source.
1920 Profile* profile = Profile::FromWebUI(web_ui); 1926 Profile* profile = Profile::FromWebUI(web_ui);
1921 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); 1927 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource());
1922 } 1928 }
OLDNEW
« no previous file with comments | « chrome/browser/net/transport_security_persister.cc ('k') | net/base/hash_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698