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

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

Issue 117263002: Prevent ONC-pushed certificates from being used with multiprofiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/policy_cert_service_factory.h" 5 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/login/user_manager.h"
8 #include "chrome/browser/chromeos/policy/policy_cert_service.h" 13 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
9 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" 14 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
10 #include "chrome/browser/chromeos/policy/user_network_configuration_updater_fact ory.h" 15 #include "chrome/browser/chromeos/policy/user_network_configuration_updater_fact ory.h"
11 #include "chrome/browser/profiles/incognito_helpers.h" 16 #include "chrome/browser/profiles/incognito_helpers.h"
12 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
14 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 19 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
15 #include "components/user_prefs/pref_registry_syncable.h" 20 #include "components/user_prefs/pref_registry_syncable.h"
16 21
17 namespace policy { 22 namespace policy {
(...skipping 13 matching lines...) Expand all
31 if (!service) 36 if (!service)
32 return scoped_ptr<PolicyCertVerifier>(); 37 return scoped_ptr<PolicyCertVerifier>();
33 return service->CreatePolicyCertVerifier(); 38 return service->CreatePolicyCertVerifier();
34 } 39 }
35 40
36 // static 41 // static
37 PolicyCertServiceFactory* PolicyCertServiceFactory::GetInstance() { 42 PolicyCertServiceFactory* PolicyCertServiceFactory::GetInstance() {
38 return Singleton<PolicyCertServiceFactory>::get(); 43 return Singleton<PolicyCertServiceFactory>::get();
39 } 44 }
40 45
46 // static
47 void PolicyCertServiceFactory::SetUsedPolicyCertificates(
48 const std::string& user_id) {
49 if (!UsedPolicyCertificates(user_id)) {
pneubeck (no reviews) 2013/12/17 15:25:31 if (Used...) return; to remove indentation, if
Joao da Silva 2013/12/17 16:36:41 Done.
50 ListPrefUpdate update(g_browser_process->local_state(),
51 prefs::kUsedPolicyCertificates);
pneubeck (no reviews) 2013/12/17 15:25:31 is it safe to use local_state implicitly in static
Joao da Silva 2013/12/17 16:36:41 That's a good point. This call is made from the se
pneubeck (no reviews) 2013/12/17 17:57:00 Yeah, in case of this function. The other to funct
52 update->AppendString(user_id);
53 }
54 }
55
56 // static
57 void PolicyCertServiceFactory::ClearUsedPolicyCertificates(
58 const std::string& user_id) {
pneubeck (no reviews) 2013/12/17 15:25:31 not sure whether we consistently use "user_id" as
Joao da Silva 2013/12/17 16:36:41 This comes from UserManager, which uses user_id.
59 ListPrefUpdate update(g_browser_process->local_state(),
60 prefs::kUsedPolicyCertificates);
61 update->Remove(base::StringValue(user_id), NULL);
62 }
63
64 // static
65 bool PolicyCertServiceFactory::UsedPolicyCertificates(
66 const std::string& user_id) {
67 base::StringValue value(user_id);
68 const base::ListValue* list =
69 g_browser_process->local_state()->GetList(prefs::kUsedPolicyCertificates);
70 return list && list->Find(value) != list->end();
pneubeck (no reviews) 2013/12/17 15:25:31 !list is an error so logging or DCHECK should be m
Joao da Silva 2013/12/17 16:36:41 Done.
71 }
72
73 // static
74 void PolicyCertServiceFactory::RegisterPrefs(PrefRegistrySimple* local_state) {
75 local_state->RegisterListPref(prefs::kUsedPolicyCertificates);
76 }
77
41 PolicyCertServiceFactory::PolicyCertServiceFactory() 78 PolicyCertServiceFactory::PolicyCertServiceFactory()
42 : BrowserContextKeyedServiceFactory( 79 : BrowserContextKeyedServiceFactory(
43 "PolicyCertService", 80 "PolicyCertService",
44 BrowserContextDependencyManager::GetInstance()) { 81 BrowserContextDependencyManager::GetInstance()) {
45 DependsOn(UserNetworkConfigurationUpdaterFactory::GetInstance()); 82 DependsOn(UserNetworkConfigurationUpdaterFactory::GetInstance());
46 } 83 }
47 84
48 PolicyCertServiceFactory::~PolicyCertServiceFactory() {} 85 PolicyCertServiceFactory::~PolicyCertServiceFactory() {}
49 86
50 BrowserContextKeyedService* PolicyCertServiceFactory::BuildServiceInstanceFor( 87 BrowserContextKeyedService* PolicyCertServiceFactory::BuildServiceInstanceFor(
51 content::BrowserContext* context) const { 88 content::BrowserContext* context) const {
52 Profile* profile = static_cast<Profile*>(context); 89 Profile* profile = static_cast<Profile*>(context);
90
91 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
92 chromeos::User* user =
93 user_manager->GetUserByProfile(profile->GetOriginalProfile());
94 if (!user)
95 return NULL;
96
97 // Backwards compatibility: profiles that used policy-pushed certificates used
98 // to have this condition marked in their prefs. This signal has moved to
99 // local_state though, to support checking it before the profile is loaded.
100 // Check the profile here and update the local_state, if appropriate.
101 // TODO(joaodasilva): remove this, eventually.
102 PrefService* prefs = profile->GetOriginalProfile()->GetPrefs();
103 if (prefs->GetBoolean(prefs::kUsedPolicyCertificatesOnce)) {
pneubeck (no reviews) 2013/12/17 15:25:31 is a UMA metric necessary, to decide when to remov
Joao da Silva 2013/12/17 16:36:41 This is mostly used by schools, and IIRC they disa
104 prefs->ClearPref(prefs::kUsedPolicyCertificatesOnce);
105 SetUsedPolicyCertificates(user->email());
106 }
107
53 UserNetworkConfigurationUpdater* net_conf_updater = 108 UserNetworkConfigurationUpdater* net_conf_updater =
54 UserNetworkConfigurationUpdaterFactory::GetForProfile(profile); 109 UserNetworkConfigurationUpdaterFactory::GetForProfile(profile);
55 if (!net_conf_updater) 110 if (!net_conf_updater)
56 return NULL; 111 return NULL;
57 112
58 // In case of usage of additional trust anchors from an incognito profile, the 113 return new PolicyCertService(net_conf_updater, user->email(), user_manager);
59 // prefs of the original profile have to be marked.
60 return new PolicyCertService(net_conf_updater,
61 profile->GetOriginalProfile()->GetPrefs());
62 } 114 }
63 115
64 content::BrowserContext* PolicyCertServiceFactory::GetBrowserContextToUse( 116 content::BrowserContext* PolicyCertServiceFactory::GetBrowserContextToUse(
65 content::BrowserContext* context) const { 117 content::BrowserContext* context) const {
66 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 118 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
67 } 119 }
68 120
69 void PolicyCertServiceFactory::RegisterProfilePrefs( 121 void PolicyCertServiceFactory::RegisterProfilePrefs(
70 user_prefs::PrefRegistrySyncable* registry) { 122 user_prefs::PrefRegistrySyncable* registry) {
71 registry->RegisterBooleanPref( 123 registry->RegisterBooleanPref(
pneubeck (no reviews) 2013/12/17 15:25:31 add a comment that it's still here for backwards c
Joao da Silva 2013/12/17 16:36:41 Done.
72 prefs::kUsedPolicyCertificatesOnce, 124 prefs::kUsedPolicyCertificatesOnce,
73 false, 125 false,
74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 126 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
75 } 127 }
76 128
77 bool PolicyCertServiceFactory::ServiceIsNULLWhileTesting() const { 129 bool PolicyCertServiceFactory::ServiceIsNULLWhileTesting() const {
78 return true; 130 return true;
79 } 131 }
80 132
81 } // namespace policy 133 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698