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

Side by Side Diff: chrome/browser/chromeos/policy/network_configuration_updater_impl.cc

Issue 14192017: Extract certificate policy application from NetworkLibrary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/chromeos/policy/network_configuration_updater_impl.h" 5 #include "chrome/browser/chromeos/policy/network_configuration_updater_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/debug/stack_trace.h" 11 #include "base/logging.h"
12 #include "base/values.h"
12 #include "chrome/browser/policy/policy_map.h" 13 #include "chrome/browser/policy/policy_map.h"
14 #include "chromeos/network/certificate_handler.h"
13 #include "chromeos/network/managed_network_configuration_handler.h" 15 #include "chromeos/network/managed_network_configuration_handler.h"
16 #include "chromeos/network/onc/onc_constants.h"
14 #include "chromeos/network/onc/onc_utils.h" 17 #include "chromeos/network/onc/onc_utils.h"
15 #include "policy/policy_constants.h" 18 #include "policy/policy_constants.h"
16 19
17 namespace policy { 20 namespace policy {
18 21
19 NetworkConfigurationUpdaterImpl::NetworkConfigurationUpdaterImpl( 22 NetworkConfigurationUpdaterImpl::NetworkConfigurationUpdaterImpl(
20 PolicyService* policy_service) 23 PolicyService* policy_service,
24 chromeos::ManagedNetworkConfigurationHandler* network_config_handler,
25 scoped_ptr<chromeos::CertificateHandler> certificate_handler)
21 : user_policy_initialized_(false), 26 : user_policy_initialized_(false),
22 policy_change_registrar_( 27 policy_change_registrar_(
23 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), 28 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())),
24 policy_service_(policy_service) { 29 policy_service_(policy_service),
30 network_config_handler_(network_config_handler),
31 certificate_handler_(certificate_handler.Pass()) {
25 policy_change_registrar_.Observe( 32 policy_change_registrar_.Observe(
26 key::kDeviceOpenNetworkConfiguration, 33 key::kDeviceOpenNetworkConfiguration,
27 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged, 34 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged,
28 base::Unretained(this), 35 base::Unretained(this),
29 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); 36 chromeos::onc::ONC_SOURCE_DEVICE_POLICY));
30 policy_change_registrar_.Observe( 37 policy_change_registrar_.Observe(
31 key::kOpenNetworkConfiguration, 38 key::kOpenNetworkConfiguration,
32 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged, 39 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged,
33 base::Unretained(this), 40 base::Unretained(this),
34 chromeos::onc::ONC_SOURCE_USER_POLICY)); 41 chromeos::onc::ONC_SOURCE_USER_POLICY));
35 42
43 // Apply the current device policies immediately.
36 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_DEVICE_POLICY); 44 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_DEVICE_POLICY);
37 } 45 }
38 46
39 NetworkConfigurationUpdaterImpl::~NetworkConfigurationUpdaterImpl() { 47 NetworkConfigurationUpdaterImpl::~NetworkConfigurationUpdaterImpl() {
40 } 48 }
41 49
42 void NetworkConfigurationUpdaterImpl::OnUserPolicyInitialized() { 50 void NetworkConfigurationUpdaterImpl::OnUserPolicyInitialized() {
43 VLOG(1) << "User policy initialized."; 51 VLOG(1) << "User policy initialized.";
44 user_policy_initialized_ = true; 52 user_policy_initialized_ = true;
45 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_USER_POLICY); 53 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_USER_POLICY);
46 } 54 }
47 55
48 net::CertTrustAnchorProvider*
49 NetworkConfigurationUpdaterImpl::GetCertTrustAnchorProvider() {
50 return NULL;
51 }
52
53 void NetworkConfigurationUpdaterImpl::OnPolicyChanged( 56 void NetworkConfigurationUpdaterImpl::OnPolicyChanged(
54 chromeos::onc::ONCSource onc_source, 57 chromeos::onc::ONCSource onc_source,
55 const base::Value* previous, 58 const base::Value* previous,
56 const base::Value* current) { 59 const base::Value* current) {
57 VLOG(1) << "Policy for ONC source " 60 VLOG(1) << "Policy for ONC source "
58 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; 61 << chromeos::onc::GetSourceAsString(onc_source) << " changed.";
59 VLOG(2) << "User policy is " << (user_policy_initialized_ ? "" : "not ") 62 VLOG(2) << "User policy is " << (user_policy_initialized_ ? "" : "not ")
60 << "initialized."; 63 << "initialized.";
61 ApplyNetworkConfiguration(onc_source); 64 ApplyNetworkConfiguration(onc_source);
62 } 65 }
(...skipping 15 matching lines...) Expand all
78 81
79 std::string onc_blob; 82 std::string onc_blob;
80 if (policy_value) { 83 if (policy_value) {
81 if (!policy_value->GetAsString(&onc_blob)) 84 if (!policy_value->GetAsString(&onc_blob))
82 LOG(ERROR) << "ONC policy " << policy_key << " is not a string value."; 85 LOG(ERROR) << "ONC policy " << policy_key << " is not a string value.";
83 } else { 86 } else {
84 VLOG(2) << "The policy is not set."; 87 VLOG(2) << "The policy is not set.";
85 } 88 }
86 VLOG(2) << "The policy contains this ONC: " << onc_blob; 89 VLOG(2) << "The policy contains this ONC: " << onc_blob;
87 90
88 if (onc_blob.empty()) 91 base::ListValue network_configs;
89 onc_blob = chromeos::onc::kEmptyUnencryptedConfiguration; 92 base::ListValue certificates;
93 ParseAndValidateOncForImport(
94 onc_blob, onc_source, "", &network_configs, &certificates);
90 95
91 scoped_ptr<base::DictionaryValue> onc_dict = 96 network_config_handler_->SetPolicy(onc_source, network_configs);
92 chromeos::onc::ReadDictionaryFromJson(onc_blob);
93 if (!onc_dict) {
94 LOG(ERROR) << "ONC loaded from policy " << policy_key
95 << " is not a valid JSON dictionary.";
96 return;
97 }
98 97
99 chromeos::ManagedNetworkConfigurationHandler::Get()->SetPolicy(onc_source, 98 scoped_ptr<net::CertificateList> web_trust_certs(new net::CertificateList);
100 *onc_dict); 99 certificate_handler_->ImportCertificates(
100 certificates, onc_source, web_trust_certs.get());
101
102 if (onc_source == chromeos::onc::ONC_SOURCE_USER_POLICY)
103 SetTrustAnchors(web_trust_certs.Pass());
101 } 104 }
102 105
103 } // namespace policy 106 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698