OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/protector/protector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/protector/settings_change_global_error.h" | 9 #include "chrome/browser/protector/settings_change_global_error.h" |
10 #include "chrome/browser/protector/keys.h" | 10 #include "chrome/browser/protector/keys.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 SettingChangeVector* changes = error_->mutable_changes(); | 62 SettingChangeVector* changes = error_->mutable_changes(); |
63 for (SettingChangeVector::iterator it = changes->begin(); | 63 for (SettingChangeVector::iterator it = changes->begin(); |
64 it != changes->end(); ++it) | 64 it != changes->end(); ++it) |
65 ((*it)->*action)(this); | 65 ((*it)->*action)(this); |
66 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 66 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
67 } | 67 } |
68 | 68 |
69 | 69 |
70 std::string SignSetting(const std::string& value) { | 70 std::string SignSetting(const std::string& value) { |
71 crypto::HMAC hmac(crypto::HMAC::SHA256); | 71 crypto::HMAC hmac(crypto::HMAC::SHA256); |
72 DCHECK(hmac.Init(kProtectorSigningKey)); | 72 if (!hmac.Init(kProtectorSigningKey)) { |
73 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing"; | |
Ilya Sherman
2011/11/01 18:19:11
Are you sure you want LOG(WARNING) here rather tha
whywhat
2011/11/02 08:14:29
HMAC implementation is platform dependent so may c
| |
74 return std::string(); | |
75 } | |
73 | 76 |
74 std::vector<unsigned char> digest(hmac.DigestLength()); | 77 std::vector<unsigned char> digest(hmac.DigestLength()); |
75 DCHECK(hmac.Sign(value, &digest[0], digest.size())); | 78 if (!hmac.Sign(value, &digest[0], digest.size())) { |
79 LOG(WARNING) << "Failed to sign setting"; | |
80 return std::string(); | |
81 } | |
76 | 82 |
77 return std::string(&digest[0], &digest[0] + digest.size()); | 83 return std::string(&digest[0], &digest[0] + digest.size()); |
78 } | 84 } |
79 | 85 |
86 bool IsSettingValid(const std::string& value, const std::string& signature) { | |
87 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
88 if (!hmac.Init(kProtectorSigningKey)) { | |
89 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; | |
90 return false; | |
91 } | |
92 return hmac.Verify(value, signature); | |
93 } | |
94 | |
80 } // namespace protector | 95 } // namespace protector |
OLD | NEW |