Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 16 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 11 #include "chrome/browser/profiles/incognito_helpers.h" | 17 #include "chrome/browser/profiles/incognito_helpers.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 14 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 20 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
| 15 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
| 16 | 22 |
| 17 namespace policy { | 23 namespace policy { |
| 18 | 24 |
| 19 // static | 25 // static |
| 20 PolicyCertService* PolicyCertServiceFactory::GetForProfile(Profile* profile) { | 26 PolicyCertService* PolicyCertServiceFactory::GetForProfile(Profile* profile) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 31 if (!service) | 37 if (!service) |
| 32 return scoped_ptr<PolicyCertVerifier>(); | 38 return scoped_ptr<PolicyCertVerifier>(); |
| 33 return service->CreatePolicyCertVerifier(); | 39 return service->CreatePolicyCertVerifier(); |
| 34 } | 40 } |
| 35 | 41 |
| 36 // static | 42 // static |
| 37 PolicyCertServiceFactory* PolicyCertServiceFactory::GetInstance() { | 43 PolicyCertServiceFactory* PolicyCertServiceFactory::GetInstance() { |
| 38 return Singleton<PolicyCertServiceFactory>::get(); | 44 return Singleton<PolicyCertServiceFactory>::get(); |
| 39 } | 45 } |
| 40 | 46 |
| 47 // static | |
| 48 void PolicyCertServiceFactory::SetUsedPolicyCertificates( | |
| 49 const std::string& user_id) { | |
| 50 if (UsedPolicyCertificates(user_id)) | |
| 51 return; | |
| 52 ListPrefUpdate update(g_browser_process->local_state(), | |
| 53 prefs::kUsedPolicyCertificates); | |
| 54 update->AppendString(user_id); | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 void PolicyCertServiceFactory::ClearUsedPolicyCertificates( | |
| 59 const std::string& user_id) { | |
| 60 ListPrefUpdate update(g_browser_process->local_state(), | |
| 61 prefs::kUsedPolicyCertificates); | |
| 62 update->Remove(base::StringValue(user_id), NULL); | |
| 63 } | |
| 64 | |
| 65 // static | |
| 66 bool PolicyCertServiceFactory::UsedPolicyCertificates( | |
| 67 const std::string& user_id) { | |
| 68 base::StringValue value(user_id); | |
| 69 const base::ListValue* list = | |
| 70 g_browser_process->local_state()->GetList(prefs::kUsedPolicyCertificates); | |
| 71 if (!list) { | |
| 72 NOTREACHED(); | |
| 73 return false; | |
| 74 } | |
| 75 return list->Find(value) != list->end(); | |
| 76 } | |
| 77 | |
| 78 // static | |
| 79 void PolicyCertServiceFactory::RegisterPrefs(PrefRegistrySimple* local_state) { | |
| 80 local_state->RegisterListPref(prefs::kUsedPolicyCertificates); | |
| 81 } | |
| 82 | |
| 41 PolicyCertServiceFactory::PolicyCertServiceFactory() | 83 PolicyCertServiceFactory::PolicyCertServiceFactory() |
| 42 : BrowserContextKeyedServiceFactory( | 84 : BrowserContextKeyedServiceFactory( |
| 43 "PolicyCertService", | 85 "PolicyCertService", |
| 44 BrowserContextDependencyManager::GetInstance()) { | 86 BrowserContextDependencyManager::GetInstance()) { |
| 45 DependsOn(UserNetworkConfigurationUpdaterFactory::GetInstance()); | 87 DependsOn(UserNetworkConfigurationUpdaterFactory::GetInstance()); |
| 46 } | 88 } |
| 47 | 89 |
| 48 PolicyCertServiceFactory::~PolicyCertServiceFactory() {} | 90 PolicyCertServiceFactory::~PolicyCertServiceFactory() {} |
| 49 | 91 |
| 50 BrowserContextKeyedService* PolicyCertServiceFactory::BuildServiceInstanceFor( | 92 BrowserContextKeyedService* PolicyCertServiceFactory::BuildServiceInstanceFor( |
| 51 content::BrowserContext* context) const { | 93 content::BrowserContext* context) const { |
| 52 Profile* profile = static_cast<Profile*>(context); | 94 Profile* profile = static_cast<Profile*>(context); |
| 95 | |
| 96 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | |
| 97 chromeos::User* user = | |
| 98 user_manager->GetUserByProfile(profile->GetOriginalProfile()); | |
| 99 if (!user) | |
| 100 return NULL; | |
| 101 | |
| 102 // Backwards compatibility: profiles that used policy-pushed certificates used | |
| 103 // to have this condition marked in their prefs. This signal has moved to | |
| 104 // local_state though, to support checking it before the profile is loaded. | |
| 105 // Check the profile here and update the local_state, if appropriate. | |
| 106 // TODO(joaodasilva): remove this, eventually. | |
| 107 PrefService* prefs = profile->GetOriginalProfile()->GetPrefs(); | |
| 108 if (prefs->GetBoolean(prefs::kUsedPolicyCertificatesOnce)) { | |
| 109 prefs->ClearPref(prefs::kUsedPolicyCertificatesOnce); | |
| 110 SetUsedPolicyCertificates(user->email()); | |
| 111 | |
| 112 if (user_manager->GetLoggedInUsers().size() > 1u) { | |
| 113 // This login should not have been allowed. After rebooting, local_state | |
| 114 // will contain the updated list of users that used policy-pushed | |
| 115 // certificates and this won't happen again. | |
| 116 // Note that a user becomes logged in before his profile is created. | |
| 117 LOG(ERROR) << "Shutdown session because a tainted profile was added."; | |
| 118 prefs->CommitPendingWrite(); | |
| 119 g_browser_process->local_state()->CommitPendingWrite(); | |
| 120 chrome::AttemptUserExit(); | |
| 121 } | |
|
Joao da Silva
2013/12/17 16:36:41
This block handles the case of a pre-M33 tainted p
| |
| 122 } | |
| 123 | |
| 53 UserNetworkConfigurationUpdater* net_conf_updater = | 124 UserNetworkConfigurationUpdater* net_conf_updater = |
| 54 UserNetworkConfigurationUpdaterFactory::GetForProfile(profile); | 125 UserNetworkConfigurationUpdaterFactory::GetForProfile(profile); |
| 55 if (!net_conf_updater) | 126 if (!net_conf_updater) |
| 56 return NULL; | 127 return NULL; |
| 57 | 128 |
| 58 // In case of usage of additional trust anchors from an incognito profile, the | 129 return new PolicyCertService(user->email(), net_conf_updater, user_manager); |
| 59 // prefs of the original profile have to be marked. | |
| 60 return new PolicyCertService(net_conf_updater, | |
| 61 profile->GetOriginalProfile()->GetPrefs()); | |
| 62 } | 130 } |
| 63 | 131 |
| 64 content::BrowserContext* PolicyCertServiceFactory::GetBrowserContextToUse( | 132 content::BrowserContext* PolicyCertServiceFactory::GetBrowserContextToUse( |
| 65 content::BrowserContext* context) const { | 133 content::BrowserContext* context) const { |
| 66 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 134 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 67 } | 135 } |
| 68 | 136 |
| 69 void PolicyCertServiceFactory::RegisterProfilePrefs( | 137 void PolicyCertServiceFactory::RegisterProfilePrefs( |
| 70 user_prefs::PrefRegistrySyncable* registry) { | 138 user_prefs::PrefRegistrySyncable* registry) { |
| 139 // TODO(joaodasilva): this is used for backwards compatibility. | |
| 140 // Remove once it's not necessary anymore. | |
| 71 registry->RegisterBooleanPref( | 141 registry->RegisterBooleanPref( |
| 72 prefs::kUsedPolicyCertificatesOnce, | 142 prefs::kUsedPolicyCertificatesOnce, |
| 73 false, | 143 false, |
| 74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 144 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 75 } | 145 } |
| 76 | 146 |
| 77 bool PolicyCertServiceFactory::ServiceIsNULLWhileTesting() const { | 147 bool PolicyCertServiceFactory::ServiceIsNULLWhileTesting() const { |
| 78 return true; | 148 return true; |
| 79 } | 149 } |
| 80 | 150 |
| 81 } // namespace policy | 151 } // namespace policy |
| OLD | NEW |