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

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

Issue 1741783002: Add disabled origin trial feature list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ef-finch
Patch Set: Rebase 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/common/origin_trials/chrome_origin_trial_policy.h" 5 #include "chrome/common/origin_trials/chrome_origin_trial_policy.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <vector>
10
9 #include "base/base64.h" 11 #include "base/base64.h"
10 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/strings/string_split.h"
11 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
12 15
13 // This is the default public key used for validating signatures. 16 // This is the default public key used for validating signatures.
14 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys. 17 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys.
15 // https://crbug.com/584737 18 // https://crbug.com/584737
16 static const uint8_t kDefaultPublicKey[] = { 19 static const uint8_t kDefaultPublicKey[] = {
17 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03, 20 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03,
18 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07, 21 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07,
19 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15, 22 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15,
20 }; 23 };
21 24
22 ChromeOriginTrialPolicy::ChromeOriginTrialPolicy() 25 ChromeOriginTrialPolicy::ChromeOriginTrialPolicy()
23 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey), 26 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey),
24 arraysize(kDefaultPublicKey))) { 27 arraysize(kDefaultPublicKey))) {
25 // Set the public key for the origin trial key manager, based on the command 28 // Set the public key and disabled feature list for the origin trial key
26 // line flags which were passed to this process. If the flag is not present, 29 // manager, based on the command line flags which were passed to this process.
27 // or is incorrectly formatted, the default key will remain active. 30 // If the flags are not present, or are incorrectly formatted, the defaults
31 // will remain active.
28 if (base::CommandLine::InitializedForCurrentProcess()) { 32 if (base::CommandLine::InitializedForCurrentProcess()) {
29 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 33 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
30 if (command_line->HasSwitch(switches::kOriginTrialPublicKey)) { 34 if (command_line->HasSwitch(switches::kOriginTrialPublicKey)) {
31 SetPublicKeyFromASCIIString( 35 SetPublicKeyFromASCIIString(
32 command_line->GetSwitchValueASCII(switches::kOriginTrialPublicKey)); 36 command_line->GetSwitchValueASCII(switches::kOriginTrialPublicKey));
33 } 37 }
38 if (command_line->HasSwitch(switches::kOriginTrialDisabledFeatures)) {
39 SetDisabledFeatures(command_line->GetSwitchValueASCII(
40 switches::kOriginTrialDisabledFeatures));
41 }
34 } 42 }
35 } 43 }
36 44
37 ChromeOriginTrialPolicy::~ChromeOriginTrialPolicy() {} 45 ChromeOriginTrialPolicy::~ChromeOriginTrialPolicy() {}
38 46
39 base::StringPiece ChromeOriginTrialPolicy::GetPublicKey() const { 47 base::StringPiece ChromeOriginTrialPolicy::GetPublicKey() const {
40 return base::StringPiece(public_key_); 48 return base::StringPiece(public_key_);
41 } 49 }
42 50
51 bool ChromeOriginTrialPolicy::IsFeatureDisabled(
52 base::StringPiece feature) const {
53 return disabled_features_.count(feature.as_string()) > 0;
54 }
55
43 bool ChromeOriginTrialPolicy::SetPublicKeyFromASCIIString( 56 bool ChromeOriginTrialPolicy::SetPublicKeyFromASCIIString(
44 const std::string& ascii_public_key) { 57 const std::string& ascii_public_key) {
45 // Base64-decode the incoming string. Set the key if it is correctly formatted 58 // Base64-decode the incoming string. Set the key if it is correctly formatted
46 std::string new_public_key; 59 std::string new_public_key;
47 if (!base::Base64Decode(ascii_public_key, &new_public_key)) 60 if (!base::Base64Decode(ascii_public_key, &new_public_key))
48 return false; 61 return false;
49 if (new_public_key.size() != 32) 62 if (new_public_key.size() != 32)
50 return false; 63 return false;
51 public_key_.swap(new_public_key); 64 public_key_.swap(new_public_key);
52 return true; 65 return true;
53 } 66 }
67
68 bool ChromeOriginTrialPolicy::SetDisabledFeatures(
69 const std::string& disabled_feature_list) {
70 std::set<std::string> new_disabled_features;
71 const std::vector<std::string> features =
72 base::SplitString(disabled_feature_list, "|", base::TRIM_WHITESPACE,
73 base::SPLIT_WANT_NONEMPTY);
74 for (const std::string& feature : features)
75 new_disabled_features.insert(feature);
76 disabled_features_.swap(new_disabled_features);
77 return true;
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698