Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3078)

Unified Diff: chrome/browser/protector/protector_utils.cc

Issue 9863047: Exclude ProtectorService code from Android build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/protector/protector_utils.h ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/protector/protector_utils.cc
diff --git a/chrome/browser/protector/protector_utils.cc b/chrome/browser/protector/protector_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8ffe61e79ecc10f90a24976f111350c70f03e09
--- /dev/null
+++ b/chrome/browser/protector/protector_utils.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/protector/protector_utils.h"
+
+#include <vector>
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/protector/keys.h"
+#include "chrome/common/chrome_switches.h"
+#include "crypto/hmac.h"
+
+namespace protector {
+
+std::string SignSetting(const std::string& value) {
+ crypto::HMAC hmac(crypto::HMAC::SHA256);
+ if (!hmac.Init(kProtectorSigningKey)) {
+ LOG(WARNING) << "Failed to initialize HMAC algorithm for signing";
+ return std::string();
+ }
+
+ std::vector<unsigned char> digest(hmac.DigestLength());
+ 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);
+}
+
+bool IsEnabled() {
+ return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoProtector);
+}
+
+} // namespace protector
« no previous file with comments | « chrome/browser/protector/protector_utils.h ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698