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

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

Issue 148183013: Use per-user nssdb in onc certificate importer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser_tests compile Created 6 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 | Annotate | Revision Log
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #include "net/proxy/proxy_service.h" 76 #include "net/proxy/proxy_service.h"
77 #include "net/url_request/url_request_context.h" 77 #include "net/url_request/url_request_context.h"
78 #include "net/url_request/url_request_context_getter.h" 78 #include "net/url_request/url_request_context_getter.h"
79 #include "ui/base/resource/resource_bundle.h" 79 #include "ui/base/resource/resource_bundle.h"
80 80
81 #if defined(OS_CHROMEOS) 81 #if defined(OS_CHROMEOS)
82 #include "chrome/browser/chromeos/login/user.h" 82 #include "chrome/browser/chromeos/login/user.h"
83 #include "chrome/browser/chromeos/login/user_manager.h" 83 #include "chrome/browser/chromeos/login/user_manager.h"
84 #include "chrome/browser/chromeos/net/onc_utils.h" 84 #include "chrome/browser/chromeos/net/onc_utils.h"
85 #include "chrome/browser/chromeos/system/syslogs_provider.h" 85 #include "chrome/browser/chromeos/system/syslogs_provider.h"
86 #include "chrome/browser/net/nss_context.h"
86 #include "chromeos/dbus/dbus_thread_manager.h" 87 #include "chromeos/dbus/dbus_thread_manager.h"
87 #include "chromeos/dbus/debug_daemon_client.h" 88 #include "chromeos/dbus/debug_daemon_client.h"
88 #include "chromeos/network/onc/onc_certificate_importer_impl.h" 89 #include "chromeos/network/onc/onc_certificate_importer_impl.h"
89 #include "chromeos/network/onc/onc_utils.h" 90 #include "chromeos/network/onc/onc_utils.h"
90 #endif 91 #endif
91 #if defined(OS_WIN) 92 #if defined(OS_WIN)
92 #include "chrome/browser/net/service_providers_win.h" 93 #include "chrome/browser/net/service_providers_win.h"
93 #endif 94 #endif
94 95
95 using base::PassPlatformFile; 96 using base::PassPlatformFile;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 #if defined(OS_CHROMEOS) 383 #if defined(OS_CHROMEOS)
383 void OnRefreshSystemLogs(const base::ListValue* list); 384 void OnRefreshSystemLogs(const base::ListValue* list);
384 void OnGetSystemLog(const base::ListValue* list); 385 void OnGetSystemLog(const base::ListValue* list);
385 void OnImportONCFile(const base::ListValue* list); 386 void OnImportONCFile(const base::ListValue* list);
386 void OnStoreDebugLogs(const base::ListValue* list); 387 void OnStoreDebugLogs(const base::ListValue* list);
387 void OnStoreDebugLogsCompleted(const base::FilePath& log_path, 388 void OnStoreDebugLogsCompleted(const base::FilePath& log_path,
388 bool succeeded); 389 bool succeeded);
389 void OnSetNetworkDebugMode(const base::ListValue* list); 390 void OnSetNetworkDebugMode(const base::ListValue* list);
390 void OnSetNetworkDebugModeCompleted(const std::string& subsystem, 391 void OnSetNetworkDebugModeCompleted(const std::string& subsystem,
391 bool succeeded); 392 bool succeeded);
393
394 // Callback to |GetNSSCertDatabaseForProfile| used to retrieve the database
395 // to which user's ONC defined certificates should be imported.
396 // It parses and imports |onc_blob|.
397 void ImportONCFileToNSSDB(const std::string& onc_blob,
398 const std::string& passcode,
399 net::NSSCertDatabase* nssdb);
392 #endif 400 #endif
393 401
394 private: 402 private:
395 class IOThreadImpl; 403 class IOThreadImpl;
396 404
397 #if defined(OS_CHROMEOS) 405 #if defined(OS_CHROMEOS)
398 // Class that is used for getting network related ChromeOS logs. 406 // Class that is used for getting network related ChromeOS logs.
399 // Logs are fetched from ChromeOS libcros on user request, and only when we 407 // Logs are fetched from ChromeOS libcros on user request, and only when we
400 // don't yet have a copy of logs. If a copy is present, we send back data from 408 // don't yet have a copy of logs. If a copy is present, we send back data from
401 // it, else we save request and answer to it when we get logs from libcros. 409 // it, else we save request and answer to it when we get logs from libcros.
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 syslogs_getter_->DeleteSystemLogs(); 1504 syslogs_getter_->DeleteSystemLogs();
1497 syslogs_getter_->LoadSystemLogs(); 1505 syslogs_getter_->LoadSystemLogs();
1498 } 1506 }
1499 1507
1500 void NetInternalsMessageHandler::OnGetSystemLog( 1508 void NetInternalsMessageHandler::OnGetSystemLog(
1501 const base::ListValue* list) { 1509 const base::ListValue* list) {
1502 DCHECK(syslogs_getter_.get()); 1510 DCHECK(syslogs_getter_.get());
1503 syslogs_getter_->RequestSystemLog(list); 1511 syslogs_getter_->RequestSystemLog(list);
1504 } 1512 }
1505 1513
1506 void NetInternalsMessageHandler::OnImportONCFile( 1514 void NetInternalsMessageHandler::ImportONCFileToNSSDB(
1507 const base::ListValue* list) { 1515 const std::string& onc_blob,
1508 std::string onc_blob; 1516 const std::string& passcode,
1509 std::string passcode; 1517 net::NSSCertDatabase* nssdb) {
1510 if (list->GetSize() != 2 || 1518 std::string error;
1511 !list->GetString(0, &onc_blob) || 1519 chromeos::User* user = chromeos::UserManager::Get()->GetUserByProfile(
1512 !list->GetString(1, &passcode)) { 1520 Profile::FromWebUI(web_ui()));
1513 NOTREACHED();
1514 }
1515 1521
1516 std::string error;
1517 const chromeos::User* user = chromeos::UserManager::Get()->GetActiveUser();
1518 if (user) { 1522 if (user) {
1519 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT; 1523 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT;
1520 1524
1521 base::ListValue network_configs; 1525 base::ListValue network_configs;
1522 base::DictionaryValue global_network_config; 1526 base::DictionaryValue global_network_config;
1523 base::ListValue certificates; 1527 base::ListValue certificates;
1524 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob, 1528 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob,
1525 onc_source, 1529 onc_source,
1526 passcode, 1530 passcode,
1527 &network_configs, 1531 &network_configs,
1528 &global_network_config, 1532 &global_network_config,
1529 &certificates)) { 1533 &certificates)) {
1530 error = "Errors occurred during the ONC parsing. "; 1534 error = "Errors occurred during the ONC parsing. ";
1531 } 1535 }
1532 1536
1533 chromeos::onc::CertificateImporterImpl cert_importer; 1537 chromeos::onc::CertificateImporterImpl cert_importer(nssdb);
1534 if (!cert_importer.ImportCertificates(certificates, onc_source, NULL)) 1538 if (!cert_importer.ImportCertificates(certificates, onc_source, NULL))
1535 error += "Some certificates couldn't be imported. "; 1539 error += "Some certificates couldn't be imported. ";
1536 1540
1537 std::string network_error; 1541 std::string network_error;
1538 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error); 1542 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error);
1539 if (!network_error.empty()) 1543 if (!network_error.empty())
1540 error += network_error; 1544 error += network_error;
1541 } else { 1545 } else {
1542 error = "No active user."; 1546 error = "User not found.";
1543 } 1547 }
1544 1548
1545 LOG_IF(ERROR, !error.empty()) << error; 1549 LOG_IF(ERROR, !error.empty()) << error;
1546 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error)); 1550 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error));
1547 } 1551 }
1548 1552
1553 void NetInternalsMessageHandler::OnImportONCFile(
1554 const base::ListValue* list) {
1555 std::string onc_blob;
1556 std::string passcode;
1557 if (list->GetSize() != 2 ||
1558 !list->GetString(0, &onc_blob) ||
1559 !list->GetString(1, &passcode)) {
1560 NOTREACHED();
1561 }
1562
1563 GetNSSCertDatabaseForProfile(
1564 Profile::FromWebUI(web_ui()),
1565 base::Bind(&NetInternalsMessageHandler::ImportONCFileToNSSDB, AsWeakPtr(),
1566 onc_blob, passcode));
1567 }
1568
1549 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) { 1569 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) {
1550 DCHECK(list); 1570 DCHECK(list);
1551 1571
1552 SendJavascriptCommand("receivedStoreDebugLogs", 1572 SendJavascriptCommand("receivedStoreDebugLogs",
1553 new base::StringValue("Creating log file...")); 1573 new base::StringValue("Creating log file..."));
1554 const DownloadPrefs* const prefs = 1574 const DownloadPrefs* const prefs =
1555 DownloadPrefs::FromBrowserContext(Profile::FromWebUI(web_ui())); 1575 DownloadPrefs::FromBrowserContext(Profile::FromWebUI(web_ui()));
1556 StoreDebugLogs(prefs->DownloadPath(), 1576 StoreDebugLogs(prefs->DownloadPath(),
1557 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted, 1577 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted,
1558 AsWeakPtr())); 1578 AsWeakPtr()));
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 } 1869 }
1850 1870
1851 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1871 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1852 : WebUIController(web_ui) { 1872 : WebUIController(web_ui) {
1853 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1873 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1854 1874
1855 // Set up the chrome://net-internals/ source. 1875 // Set up the chrome://net-internals/ source.
1856 Profile* profile = Profile::FromWebUI(web_ui); 1876 Profile* profile = Profile::FromWebUI(web_ui);
1857 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); 1877 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource());
1858 } 1878 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698