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

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 8 years 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
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 <list> 7 #include <list>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // encounters a new version. This should be incremented when significant 99 // encounters a new version. This should be incremented when significant
100 // changes are made that will invalidate the old loading code. 100 // changes are made that will invalidate the old loading code.
101 const int kLogFormatVersion = 1; 101 const int kLogFormatVersion = 1;
102 102
103 // Returns the HostCache for |context|'s primary HostResolver, or NULL if 103 // Returns the HostCache for |context|'s primary HostResolver, or NULL if
104 // there is none. 104 // there is none.
105 net::HostCache* GetHostResolverCache(net::URLRequestContext* context) { 105 net::HostCache* GetHostResolverCache(net::URLRequestContext* context) {
106 return context->host_resolver()->GetHostCache(); 106 return context->host_resolver()->GetHostCache();
107 } 107 }
108 108
109 std::string HashesToBase64String(const net::HashValueVector& hashes) {
110 std::string str;
111 for (size_t i = 0; i != hashes.size(); ++i) {
112 if (i != 0)
113 str += ",";
114 str += hashes[i].ToString();
115 }
116 return str;
117 }
118
119 bool Base64StringToHashes(const std::string& hashes_str,
120 net::HashValueVector* hashes) {
121 hashes->clear();
122 std::vector<std::string> vector_hash_str;
123 base::SplitString(hashes_str, ',', &vector_hash_str);
124
125 for (size_t i = 0; i != vector_hash_str.size(); ++i) {
126 std::string hash_str;
127 RemoveChars(vector_hash_str[i], " \t\r\n", &hash_str);
128 net::HashValue hash;
129 // Skip past unrecognized hash algos
130 if (hash_str.substr(0, 4) != "sha1" && hash_str.substr(0, 6) != "sha256")
agl 2012/12/10 17:13:44 I fear this crashes if |hash_str| is empty (and th
unsafe 2012/12/10 20:59:18 Done.
131 continue;
132 if (!hash.FromString(hash_str))
133 return false;
134 hashes->push_back(hash);
135 }
136 return true;
137 }
138
109 // Returns the disk cache backend for |context| if there is one, or NULL. 139 // Returns the disk cache backend for |context| if there is one, or NULL.
110 disk_cache::Backend* GetDiskCacheBackend(net::URLRequestContext* context) { 140 disk_cache::Backend* GetDiskCacheBackend(net::URLRequestContext* context) {
111 if (!context->http_transaction_factory()) 141 if (!context->http_transaction_factory())
112 return NULL; 142 return NULL;
113 143
114 net::HttpCache* http_cache = context->http_transaction_factory()->GetCache(); 144 net::HttpCache* http_cache = context->http_transaction_factory()->GetCache();
115 if (!http_cache) 145 if (!http_cache)
116 return NULL; 146 return NULL;
117 147
118 return http_cache->GetCurrentBackend(); 148 return http_cache->GetCurrentBackend();
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 // For example, turn "www.google.com" into "http://www.google.com". 1123 // For example, turn "www.google.com" into "http://www.google.com".
1094 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); 1124 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string()));
1095 1125
1096 connection_tester_.reset(new ConnectionTester( 1126 connection_tester_.reset(new ConnectionTester(
1097 this, 1127 this,
1098 io_thread_->globals()->proxy_script_fetcher_context.get(), 1128 io_thread_->globals()->proxy_script_fetcher_context.get(),
1099 net_log())); 1129 net_log()));
1100 connection_tester_->RunAllTests(url); 1130 connection_tester_->RunAllTests(url);
1101 } 1131 }
1102 1132
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( 1133 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSQuery(
1119 const ListValue* list) { 1134 const ListValue* list) {
1120 // |list| should be: [<domain to query>]. 1135 // |list| should be: [<domain to query>].
1121 std::string domain; 1136 std::string domain;
1122 CHECK(list->GetString(0, &domain)); 1137 CHECK(list->GetString(0, &domain));
1123 DictionaryValue* result = new DictionaryValue(); 1138 DictionaryValue* result = new DictionaryValue();
1124 1139
1125 if (!IsStringASCII(domain)) { 1140 if (!IsStringASCII(domain)) {
1126 result->SetString("error", "non-ASCII domain name"); 1141 result->SetString("error", "non-ASCII domain name");
1127 } else { 1142 } else {
1128 net::TransportSecurityState* transport_security_state = 1143 net::TransportSecurityState* transport_security_state =
1129 context_getter_->GetURLRequestContext()->transport_security_state(); 1144 context_getter_->GetURLRequestContext()->transport_security_state();
1130 if (!transport_security_state) { 1145 if (!transport_security_state) {
1131 result->SetString("error", "no TransportSecurityState active"); 1146 result->SetString("error", "no TransportSecurityState active");
1132 } else { 1147 } else {
1133 net::TransportSecurityState::DomainState state; 1148 net::TransportSecurityState::DomainState state;
1134 const bool found = transport_security_state->GetDomainState( 1149 const bool found = transport_security_state->GetDomainState(
1135 domain, true, &state); 1150 domain, true, &state);
1136 1151
1137 result->SetBoolean("result", found); 1152 result->SetBoolean("result", found);
1138 if (found) { 1153 if (found) {
1139 result->SetInteger("mode", static_cast<int>(state.upgrade_mode)); 1154 result->SetInteger("mode", static_cast<int>(state.upgrade_mode));
1140 result->SetBoolean("subdomains", state.include_subdomains); 1155 result->SetBoolean("subdomains", state.include_subdomains);
1141 result->SetString("domain", state.domain); 1156 result->SetString("domain", state.domain);
1142 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT()); 1157 result->SetDouble("expiry", state.upgrade_expiry.ToDoubleT());
1143 result->SetDouble("dynamic_spki_hashes_expiry", 1158 result->SetDouble("dynamic_spki_hashes_expiry",
1144 state.dynamic_spki_hashes_expiry.ToDoubleT()); 1159 state.dynamic_spki_hashes_expiry.ToDoubleT());
1145 1160
1146 std::string hashes; 1161 result->SetString("static_spki_hashes",
1147 SPKIHashesToString(state.static_spki_hashes, &hashes); 1162 HashesToBase64String(state.static_spki_hashes));
1148 result->SetString("static_spki_hashes", hashes); 1163 result->SetString("dynamic_spki_hashes",
1149 1164 HashesToBase64String(state.dynamic_spki_hashes));
1150 hashes.clear();
1151 SPKIHashesToString(state.dynamic_spki_hashes, &hashes);
1152 result->SetString("dynamic_spki_hashes", hashes);
1153 } 1165 }
1154 } 1166 }
1155 } 1167 }
1156 1168
1157 SendJavascriptCommand("receivedHSTSResult", result); 1169 SendJavascriptCommand("receivedHSTSResult", result);
1158 } 1170 }
1159 1171
1160 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd( 1172 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSAdd(
1161 const ListValue* list) { 1173 const ListValue* list) {
1162 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>]. 1174 // |list| should be: [<domain to query>, <include subdomains>, <cert pins>].
(...skipping 11 matching lines...) Expand all
1174 1186
1175 net::TransportSecurityState* transport_security_state = 1187 net::TransportSecurityState* transport_security_state =
1176 context_getter_->GetURLRequestContext()->transport_security_state(); 1188 context_getter_->GetURLRequestContext()->transport_security_state();
1177 if (!transport_security_state) 1189 if (!transport_security_state)
1178 return; 1190 return;
1179 1191
1180 net::TransportSecurityState::DomainState state; 1192 net::TransportSecurityState::DomainState state;
1181 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000); 1193 state.upgrade_expiry = state.created + base::TimeDelta::FromDays(1000);
1182 state.include_subdomains = include_subdomains; 1194 state.include_subdomains = include_subdomains;
1183 if (!hashes_str.empty()) { 1195 if (!hashes_str.empty()) {
1184 std::vector<std::string> type_and_b64s; 1196 if (!Base64StringToHashes(hashes_str, &state.dynamic_spki_hashes))
1185 base::SplitString(hashes_str, ',', &type_and_b64s); 1197 return;
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 } 1198 }
1197
1198 transport_security_state->EnableHost(domain, state); 1199 transport_security_state->EnableHost(domain, state);
1199 } 1200 }
1200 1201
1201 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete( 1202 void NetInternalsMessageHandler::IOThreadImpl::OnHSTSDelete(
1202 const ListValue* list) { 1203 const ListValue* list) {
1203 // |list| should be: [<domain to query>]. 1204 // |list| should be: [<domain to query>].
1204 std::string domain; 1205 std::string domain;
1205 CHECK(list->GetString(0, &domain)); 1206 CHECK(list->GetString(0, &domain));
1206 if (!IsStringASCII(domain)) { 1207 if (!IsStringASCII(domain)) {
1207 // There cannot be a unicode entry in the HSTS set. 1208 // There cannot be a unicode entry in the HSTS set.
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 } 1776 }
1776 1777
1777 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1778 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1778 : WebUIController(web_ui) { 1779 : WebUIController(web_ui) {
1779 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1780 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1780 1781
1781 // Set up the chrome://net-internals/ source. 1782 // Set up the chrome://net-internals/ source.
1782 Profile* profile = Profile::FromWebUI(web_ui); 1783 Profile* profile = Profile::FromWebUI(web_ui);
1783 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); 1784 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource());
1784 } 1785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698