| OLD | NEW |
| 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/protector/protector_service.h" | 5 #include "chrome/browser/protector/protector_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/protector/settings_change_global_error.h" | 9 #include "chrome/browser/protector/settings_change_global_error.h" |
| 12 #include "chrome/browser/protector/keys.h" | |
| 13 #include "chrome/browser/protector/protected_prefs_watcher.h" | 10 #include "chrome/browser/protector/protected_prefs_watcher.h" |
| 14 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_switches.h" | |
| 17 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 19 #include "crypto/hmac.h" | |
| 20 | 15 |
| 21 namespace protector { | 16 namespace protector { |
| 22 | 17 |
| 23 ProtectorService::ProtectorService(Profile* profile) | 18 ProtectorService::ProtectorService(Profile* profile) |
| 24 : profile_(profile), | 19 : profile_(profile), |
| 25 has_active_change_(false) { | 20 has_active_change_(false) { |
| 26 // Start observing pref changes. | 21 // Start observing pref changes. |
| 27 prefs_watcher_.reset(new ProtectedPrefsWatcher(profile)); | 22 prefs_watcher_.reset(new ProtectedPrefsWatcher(profile)); |
| 28 } | 23 } |
| 29 | 24 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 139 |
| 145 ProtectorService::MatchItemByError::MatchItemByError( | 140 ProtectorService::MatchItemByError::MatchItemByError( |
| 146 const SettingsChangeGlobalError* other) : other_(other) { | 141 const SettingsChangeGlobalError* other) : other_(other) { |
| 147 } | 142 } |
| 148 | 143 |
| 149 bool ProtectorService::MatchItemByError::operator()( | 144 bool ProtectorService::MatchItemByError::operator()( |
| 150 const ProtectorService::Item& item) { | 145 const ProtectorService::Item& item) { |
| 151 return other_ == item.error.get(); | 146 return other_ == item.error.get(); |
| 152 } | 147 } |
| 153 | 148 |
| 154 | |
| 155 std::string SignSetting(const std::string& value) { | |
| 156 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
| 157 if (!hmac.Init(kProtectorSigningKey)) { | |
| 158 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing"; | |
| 159 return std::string(); | |
| 160 } | |
| 161 | |
| 162 std::vector<unsigned char> digest(hmac.DigestLength()); | |
| 163 if (!hmac.Sign(value, &digest[0], digest.size())) { | |
| 164 LOG(WARNING) << "Failed to sign setting"; | |
| 165 return std::string(); | |
| 166 } | |
| 167 | |
| 168 return std::string(&digest[0], &digest[0] + digest.size()); | |
| 169 } | |
| 170 | |
| 171 bool IsSettingValid(const std::string& value, const std::string& signature) { | |
| 172 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
| 173 if (!hmac.Init(kProtectorSigningKey)) { | |
| 174 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; | |
| 175 return false; | |
| 176 } | |
| 177 return hmac.Verify(value, signature); | |
| 178 } | |
| 179 | |
| 180 bool IsEnabled() { | |
| 181 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoProtector); | |
| 182 } | |
| 183 | |
| 184 } // namespace protector | 149 } // namespace protector |
| OLD | NEW |