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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/origin_trials/chrome_origin_trial_policy.cc
diff --git a/chrome/common/origin_trials/chrome_origin_trial_policy.cc b/chrome/common/origin_trials/chrome_origin_trial_policy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a4dbcc3a57015432aac543081342a8532aa4cbc4
--- /dev/null
+++ b/chrome/common/origin_trials/chrome_origin_trial_policy.cc
@@ -0,0 +1,53 @@
+// Copyright 2016 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/common/origin_trials/chrome_origin_trial_policy.h"
+
+#include <stdint.h>
+
+#include "base/base64.h"
+#include "base/command_line.h"
+#include "chrome/common/chrome_switches.h"
+
+// This is the default public key used for validating signatures.
+// TODO(iclelland): Provide a mechanism to allow for multiple signing keys.
+// https://crbug.com/584737
+static const uint8_t kDefaultPublicKey[] = {
+ 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03,
+ 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07,
+ 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15,
+};
+
+ChromeOriginTrialPolicy::ChromeOriginTrialPolicy()
+ : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey),
+ arraysize(kDefaultPublicKey))) {
+ // Set the public key for the origin trial key manager, based on the command
+ // line flags which were passed to this process. If the flag is not present,
+ // or is incorrectly formatted, the default key will remain active.
+ if (base::CommandLine::InitializedForCurrentProcess()) {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kOriginTrialPublicKey)) {
+ SetPublicKeyFromASCIIString(
+ command_line->GetSwitchValueASCII(switches::kOriginTrialPublicKey));
+ }
+ }
+}
+
+ChromeOriginTrialPolicy::~ChromeOriginTrialPolicy() {}
+
+base::StringPiece ChromeOriginTrialPolicy::GetPublicKey() const {
+ return base::StringPiece(public_key_);
+}
+
+bool ChromeOriginTrialPolicy::SetPublicKeyFromASCIIString(
+ const std::string& ascii_public_key) {
+ // Base64-decode the incoming string. Set the key if it is correctly formatted
+ std::string new_public_key;
+ if (!base::Base64Decode(ascii_public_key, &new_public_key))
+ return false;
+ if (new_public_key.size() != 32)
+ return false;
+ public_key_.swap(new_public_key);
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698