| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 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/origin_trial_key_manager.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> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 | 13 |
| 14 // This is the default public key used for validating signatures. | 14 // This is the default public key used for validating signatures. |
| 15 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys. | 15 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys. |
| 16 // https://crbug.com/584737 | 16 // https://crbug.com/584737 |
| 17 static const uint8_t kDefaultPublicKey[] = { | 17 static const uint8_t kDefaultPublicKey[] = { |
| 18 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03, | 18 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03, |
| 19 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07, | 19 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07, |
| 20 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15, | 20 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15, |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 OriginTrialKeyManager::OriginTrialKeyManager() | 23 ChromeOriginTrialPolicy::ChromeOriginTrialPolicy() |
| 24 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey), | 24 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey), |
| 25 arraysize(kDefaultPublicKey))) {} | 25 arraysize(kDefaultPublicKey))) {} |
| 26 | 26 |
| 27 OriginTrialKeyManager::~OriginTrialKeyManager() {} | 27 ChromeOriginTrialPolicy::~ChromeOriginTrialPolicy() {} |
| 28 | 28 |
| 29 bool OriginTrialKeyManager::SetPublicKeyFromASCIIString( | 29 base::StringPiece ChromeOriginTrialPolicy::GetPublicKey() const { |
| 30 return base::StringPiece(public_key_); |
| 31 } |
| 32 |
| 33 bool ChromeOriginTrialPolicy::IsFeatureDisabled( |
| 34 base::StringPiece feature) const { |
| 35 return disabled_features_.count(feature.as_string()) > 0; |
| 36 } |
| 37 |
| 38 bool ChromeOriginTrialPolicy::SetPublicKeyFromASCIIString( |
| 30 const std::string& ascii_public_key) { | 39 const std::string& ascii_public_key) { |
| 31 // Base64-decode the incoming string. Set the key if it is correctly formatted | 40 // Base64-decode the incoming string. Set the key if it is correctly formatted |
| 32 std::string new_public_key; | 41 std::string new_public_key; |
| 33 if (!base::Base64Decode(ascii_public_key, &new_public_key)) | 42 if (!base::Base64Decode(ascii_public_key, &new_public_key)) |
| 34 return false; | 43 return false; |
| 35 if (new_public_key.size() != 32) | 44 if (new_public_key.size() != 32) |
| 36 return false; | 45 return false; |
| 37 public_key_.swap(new_public_key); | 46 public_key_.swap(new_public_key); |
| 38 return true; | 47 return true; |
| 39 } | 48 } |
| 40 | 49 |
| 41 base::StringPiece OriginTrialKeyManager::GetPublicKey() const { | 50 bool ChromeOriginTrialPolicy::SetDisabledFeatures( |
| 42 return base::StringPiece(public_key_); | |
| 43 } | |
| 44 | |
| 45 bool OriginTrialKeyManager::SetDisabledFeatures( | |
| 46 const std::string& disabled_feature_list) { | 51 const std::string& disabled_feature_list) { |
| 47 std::set<std::string> new_disabled_features; | 52 std::set<std::string> new_disabled_features; |
| 48 const std::vector<std::string> features = | 53 const std::vector<std::string> features = |
| 49 base::SplitString(disabled_feature_list, "|", base::TRIM_WHITESPACE, | 54 base::SplitString(disabled_feature_list, "|", base::TRIM_WHITESPACE, |
| 50 base::SPLIT_WANT_NONEMPTY); | 55 base::SPLIT_WANT_NONEMPTY); |
| 51 for (const std::string& feature : features) | 56 for (const std::string& feature : features) |
| 52 new_disabled_features.insert(feature); | 57 new_disabled_features.insert(feature); |
| 53 disabled_features_.swap(new_disabled_features); | 58 disabled_features_.swap(new_disabled_features); |
| 54 return true; | 59 return true; |
| 55 } | 60 } |
| 56 | |
| 57 bool OriginTrialKeyManager::IsFeatureDisabled(base::StringPiece feature) const { | |
| 58 return disabled_features_.count(feature.as_string()) > 0; | |
| 59 } | |
| OLD | NEW |