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

Side by Side Diff: chrome/browser/protector/protector.cc

Issue 9863047: Exclude ProtectorService code from Android build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 <vector>
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/protector/keys.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "crypto/hmac.h"
13
14 namespace protector {
15
16 std::string SignSetting(const std::string& value) {
17 crypto::HMAC hmac(crypto::HMAC::SHA256);
18 if (!hmac.Init(kProtectorSigningKey)) {
19 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing";
20 return std::string();
21 }
22
23 std::vector<unsigned char> digest(hmac.DigestLength());
24 if (!hmac.Sign(value, &digest[0], digest.size())) {
25 LOG(WARNING) << "Failed to sign setting";
26 return std::string();
27 }
28
29 return std::string(&digest[0], &digest[0] + digest.size());
30 }
31
32 bool IsSettingValid(const std::string& value, const std::string& signature) {
33 crypto::HMAC hmac(crypto::HMAC::SHA256);
34 if (!hmac.Init(kProtectorSigningKey)) {
35 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification.";
36 return false;
37 }
38 return hmac.Verify(value, signature);
39 }
40
41 bool IsEnabled() {
42 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoProtector);
43 }
44
45 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698