Index: chrome/browser/protector/protector.cc |
diff --git a/chrome/browser/protector/protector.cc b/chrome/browser/protector/protector.cc |
index e26fe18b8eea59a542401231c2675f1164139366..1b2d04185146a018f23401506752200f674e3f3b 100644 |
--- a/chrome/browser/protector/protector.cc |
+++ b/chrome/browser/protector/protector.cc |
@@ -69,12 +69,27 @@ void Protector::OnChangesAction(SettingChangeAction action) { |
std::string SignSetting(const std::string& value) { |
crypto::HMAC hmac(crypto::HMAC::SHA256); |
- DCHECK(hmac.Init(kProtectorSigningKey)); |
+ if (!hmac.Init(kProtectorSigningKey)) { |
+ 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
|
+ return std::string(); |
+ } |
std::vector<unsigned char> digest(hmac.DigestLength()); |
- DCHECK(hmac.Sign(value, &digest[0], digest.size())); |
+ if (!hmac.Sign(value, &digest[0], digest.size())) { |
+ LOG(WARNING) << "Failed to sign setting"; |
+ return std::string(); |
+ } |
return std::string(&digest[0], &digest[0] + digest.size()); |
} |
+bool IsSettingValid(const std::string& value, const std::string& signature) { |
+ crypto::HMAC hmac(crypto::HMAC::SHA256); |
+ if (!hmac.Init(kProtectorSigningKey)) { |
+ LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; |
+ return false; |
+ } |
+ return hmac.Verify(value, signature); |
+} |
+ |
} // namespace protector |