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

Side by Side Diff: extensions/browser/api/web_request/web_request_api_helpers.cc

Issue 2156763003: Extend the webRequest.onCompleted event details object with TLS/SSL information Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Consistently use key constants for dict fields and simplify validation error reporting Created 3 years, 10 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
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 "extensions/browser/api/web_request/web_request_api_helpers.h" 5 #include "extensions/browser/api/web_request/web_request_api_helpers.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 10 matching lines...) Expand all
21 #include "components/web_cache/browser/web_cache_manager.h" 21 #include "components/web_cache/browser/web_cache_manager.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
24 #include "extensions/browser/api/web_request/web_request_api_constants.h" 24 #include "extensions/browser/api/web_request/web_request_api_constants.h"
25 #include "extensions/browser/extension_registry.h" 25 #include "extensions/browser/extension_registry.h"
26 #include "extensions/browser/extension_system.h" 26 #include "extensions/browser/extension_system.h"
27 #include "extensions/browser/extensions_browser_client.h" 27 #include "extensions/browser/extensions_browser_client.h"
28 #include "extensions/browser/runtime_data.h" 28 #include "extensions/browser/runtime_data.h"
29 #include "extensions/browser/warning_set.h" 29 #include "extensions/browser/warning_set.h"
30 #include "extensions/common/extension_messages.h" 30 #include "extensions/common/extension_messages.h"
31 #include "net/cert/x509_certificate.h"
31 #include "net/cookies/cookie_util.h" 32 #include "net/cookies/cookie_util.h"
32 #include "net/cookies/parsed_cookie.h" 33 #include "net/cookies/parsed_cookie.h"
33 #include "net/http/http_util.h" 34 #include "net/http/http_util.h"
34 #include "net/log/net_log.h" 35 #include "net/log/net_log.h"
35 #include "net/log/net_log_capture_mode.h" 36 #include "net/log/net_log_capture_mode.h"
36 #include "net/log/net_log_event_type.h" 37 #include "net/log/net_log_event_type.h"
37 #include "net/log/net_log_parameters_callback.h" 38 #include "net/log/net_log_parameters_callback.h"
38 #include "net/log/net_log_with_source.h" 39 #include "net/log/net_log_with_source.h"
40 #include "net/ssl/ssl_info.h"
39 #include "net/url_request/url_request.h" 41 #include "net/url_request/url_request.h"
40 #include "url/url_constants.h" 42 #include "url/url_constants.h"
41 43
42 // TODO(battre): move all static functions into an anonymous namespace at the 44 // TODO(battre): move all static functions into an anonymous namespace at the
43 // top of this file. 45 // top of this file.
44 46
45 using base::Time; 47 using base::Time;
46 using content::ResourceType; 48 using content::ResourceType;
47 using net::cookie_util::ParsedRequestCookie; 49 using net::cookie_util::ParsedRequestCookie;
48 using net::cookie_util::ParsedRequestCookies; 50 using net::cookie_util::ParsedRequestCookies;
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 bool found = false; 1274 bool found = false;
1273 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) { 1275 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) {
1274 if (type_str == kResourceTypeStrings[i]) { 1276 if (type_str == kResourceTypeStrings[i]) {
1275 found = true; 1277 found = true;
1276 types->push_back(kResourceTypeValues[i]); 1278 types->push_back(kResourceTypeValues[i]);
1277 } 1279 }
1278 } 1280 }
1279 return found; 1281 return found;
1280 } 1282 }
1281 1283
1284 static base::DictionaryValue* ExtractDN(const net::CertPrincipal& dn) {
palmer 2017/01/31 05:42:31 Are |ExtractDN| and |ExtractCertificateInfo| part
Ryan Sleevi 2017/01/31 21:37:56 I'm not supportive of exposing this information at
1285 auto* dn_dict = new base::DictionaryValue();
1286 if (!dn.common_name.empty()) {
1287 dn_dict->SetString(keys::kCommonNameKey, dn.common_name);
1288 }
1289 if (!dn.locality_name.empty()) {
1290 dn_dict->SetString(keys::kLocalityNameKey, dn.locality_name);
1291 }
1292 if (!dn.state_or_province_name.empty()) {
1293 dn_dict->SetString(keys::kStateOrProvinceNameKey,
1294 dn.state_or_province_name);
1295 }
1296 if (!dn.country_name.empty()) {
1297 dn_dict->SetString(keys::kCountryNameKey, dn.country_name);
1298 }
1299 if (dn.street_addresses.size() > 0) {
1300 base::ListValue* addrs = new base::ListValue();
palmer 2017/01/31 05:42:31 I'd say it's best to be consistent about using/not
1301 addrs->AppendStrings(dn.street_addresses);
1302 dn_dict->Set(keys::kStreetAddressesKey, addrs);
1303 }
1304 if (dn.organization_names.size() > 0) {
1305 base::ListValue* names = new base::ListValue();
1306 names->AppendStrings(dn.organization_names);
1307 dn_dict->Set(keys::kOrganizationNamesKey, names);
1308 }
1309 if (dn.organization_unit_names.size() > 0) {
1310 base::ListValue* names = new base::ListValue();
1311 names->AppendStrings(dn.organization_unit_names);
1312 dn_dict->Set(keys::kOrganizationUnitNamesKey, names);
1313 }
1314 return dn_dict;
1315 }
1316
1317 std::unique_ptr<base::DictionaryValue> ExtractCertificateInfo(
palmer 2017/01/31 05:42:31 I'm not sure if it's correct to use smart pointers
1318 scoped_refptr<net::X509Certificate> cert) {
1319 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue);
1320 info->SetString(keys::kSerialNumberKey,
1321 base::HexEncode(cert->serial_number().data(),
1322 cert->serial_number().size()));
1323 info->Set(keys::kSubjectKey, ExtractDN(cert->subject()));
1324 info->Set(keys::kIssuerKey, ExtractDN(cert->issuer()));
1325
1326 std::vector<std::string> dns_names;
1327 std::vector<std::string> ip_addrs;
1328 cert->GetSubjectAltName(&dns_names, &ip_addrs);
1329 if (dns_names.size() > 0) {
1330 base::ListValue* names = new base::ListValue();
palmer 2017/01/31 05:42:31 Could use auto here, too, and elsewhere.
1331 names->AppendStrings(dns_names);
1332 info->Set(keys::kDNSNamesKey, names);
1333 }
1334 if (ip_addrs.size() > 0) {
1335 base::ListValue* addrs = new base::ListValue();
1336 addrs->AppendStrings(ip_addrs);
1337 info->Set(keys::kIPAddressesKey, addrs);
1338 }
1339
1340 info->SetBoolean(keys::kExpiredKey, cert->HasExpired());
1341 info->SetDouble(keys::kNotBeforeKey, cert->valid_start().ToJsTime());
1342 info->SetDouble(keys::kNotAfterKey, cert->valid_expiry().ToJsTime());
1343
1344 std::string der_holder;
1345 if (!cert->GetDEREncoded(cert->os_cert_handle(), &der_holder))
1346 return info;
1347 info->Set(keys::kRawKey, base::BinaryValue::CreateWithCopiedBuffer(
1348 der_holder.c_str(), der_holder.size()));
palmer 2017/01/31 05:42:31 Is this formatting the result of `git cl format`?
Ryan Sleevi 2017/01/31 21:37:56 The only field I'm supportive of exposing is the r
1349
1350 return info;
1351 }
1352
1353 base::ListValue* ExtractCertificateChain(
1354 scoped_refptr<net::X509Certificate> cert) {
1355 auto* chain = new base::ListValue();
1356 if (cert) {
1357 chain->Append(ExtractCertificateInfo(cert));
1358 const net::X509Certificate::OSCertHandles cert_handles =
1359 cert->GetIntermediateCertificates();
1360 const net::X509Certificate::OSCertHandles empty_handle;
1361 for (size_t i = 0; i < cert_handles.size(); i++) {
1362 scoped_refptr<net::X509Certificate> interCert;
1363 interCert =
1364 net::X509Certificate::CreateFromHandle(cert_handles[i], empty_handle);
1365 chain->Append(ExtractCertificateInfo(interCert));
Ryan Sleevi 2017/01/31 21:37:56 This is a pattern that we've explicitly tried to d
1366 }
1367 }
1368 return chain;
1369 }
1370
1282 } // namespace extension_web_request_api_helpers 1371 } // namespace extension_web_request_api_helpers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698