| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/protector/protector_utils.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/protector/keys.h" | |
| 13 #include "chrome/common/chrome_switches.h" | |
| 14 #include "crypto/hmac.h" | |
| 15 | |
| 16 namespace protector { | |
| 17 | |
| 18 std::string SignSetting(const std::string& value) { | |
| 19 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
| 20 if (!hmac.Init(kProtectorSigningKey)) { | |
| 21 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing"; | |
| 22 return std::string(); | |
| 23 } | |
| 24 | |
| 25 std::vector<unsigned char> digest(hmac.DigestLength()); | |
| 26 if (!hmac.Sign(value, &digest[0], digest.size())) { | |
| 27 LOG(WARNING) << "Failed to sign setting"; | |
| 28 return std::string(); | |
| 29 } | |
| 30 | |
| 31 return std::string(&digest[0], &digest[0] + digest.size()); | |
| 32 } | |
| 33 | |
| 34 bool IsSettingValid(const std::string& value, const std::string& signature) { | |
| 35 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
| 36 if (!hmac.Init(kProtectorSigningKey)) { | |
| 37 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; | |
| 38 return false; | |
| 39 } | |
| 40 return hmac.Verify(value, signature); | |
| 41 } | |
| 42 | |
| 43 bool IsEnabled() { | |
| 44 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kProtector); | |
| 45 } | |
| 46 | |
| 47 } // namespace protector | |
| OLD | NEW |