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

Side by Side Diff: chrome/common/origin_trials/origin_trial_key_manager.cc

Issue 2049783002: Refactor OriginTrialPolicy to be an abstract interface in content/public/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ef-add-revoked-feature-list
Patch Set: Remove (c) from copyright headers on new files Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 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/common/origin_trials/origin_trial_key_manager.h"
6
7 #include <stdint.h>
8
9 #include <vector>
10
11 #include "base/base64.h"
12 #include "base/strings/string_split.h"
13
14 // This is the default public key used for validating signatures.
15 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys.
16 // https://crbug.com/584737
17 static const uint8_t kDefaultPublicKey[] = {
18 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03,
19 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07,
20 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15,
21 };
22
23 OriginTrialKeyManager::OriginTrialKeyManager()
24 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey),
25 arraysize(kDefaultPublicKey))) {}
26
27 OriginTrialKeyManager::~OriginTrialKeyManager() {}
28
29 bool OriginTrialKeyManager::SetPublicKeyFromASCIIString(
30 const std::string& ascii_public_key) {
31 // Base64-decode the incoming string. Set the key if it is correctly formatted
32 std::string new_public_key;
33 if (!base::Base64Decode(ascii_public_key, &new_public_key))
34 return false;
35 if (new_public_key.size() != 32)
36 return false;
37 public_key_.swap(new_public_key);
38 return true;
39 }
40
41 base::StringPiece OriginTrialKeyManager::GetPublicKey() const {
42 return base::StringPiece(public_key_);
43 }
44
45 bool OriginTrialKeyManager::SetDisabledFeatures(
46 const std::string& disabled_feature_list) {
47 std::set<std::string> new_disabled_features;
48 const std::vector<std::string> features =
49 base::SplitString(disabled_feature_list, "|", base::TRIM_WHITESPACE,
50 base::SPLIT_WANT_NONEMPTY);
51 for (const std::string& feature : features)
52 new_disabled_features.insert(feature);
53 disabled_features_.swap(new_disabled_features);
54 return true;
55 }
56
57 bool OriginTrialKeyManager::IsFeatureDisabled(base::StringPiece feature) const {
58 return disabled_features_.count(feature.as_string()) > 0;
59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698