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

Side by Side Diff: chrome/common/origin_trials/chrome_origin_trial_policy.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: Switch to lazy initialization in ChromeContentClient 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 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/chrome_origin_trial_policy.h"
6
7 #include <stdint.h>
8
9 #include "base/base64.h"
10 #include "base/command_line.h"
11 #include "chrome/common/chrome_switches.h"
12
13 // This is the default public key used for validating signatures.
14 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys.
15 // https://crbug.com/584737
16 static const uint8_t kDefaultPublicKey[] = {
17 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03,
18 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07,
19 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15,
20 };
21
22 ChromeOriginTrialPolicy::ChromeOriginTrialPolicy()
23 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey),
24 arraysize(kDefaultPublicKey))) {
25 // Set the public key for the origin trial key manager, based on the command
26 // line flags which were passed to this process. If the flag is not present,
27 // or is incorrectly formatted, the default key will remain active.
28 if (base::CommandLine::InitializedForCurrentProcess()) {
29 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
30 if (command_line->HasSwitch(switches::kOriginTrialPublicKey)) {
31 SetPublicKeyFromASCIIString(
32 command_line->GetSwitchValueASCII(switches::kOriginTrialPublicKey));
33 }
34 }
35 }
36
37 ChromeOriginTrialPolicy::~ChromeOriginTrialPolicy() {}
38
39 base::StringPiece ChromeOriginTrialPolicy::GetPublicKey() const {
40 return base::StringPiece(public_key_);
41 }
42
43 bool ChromeOriginTrialPolicy::SetPublicKeyFromASCIIString(
44 const std::string& ascii_public_key) {
45 // Base64-decode the incoming string. Set the key if it is correctly formatted
46 std::string new_public_key;
47 if (!base::Base64Decode(ascii_public_key, &new_public_key))
48 return false;
49 if (new_public_key.size() != 32)
50 return false;
51 public_key_.swap(new_public_key);
52 return true;
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698