| OLD | NEW |
| 1 // Copyright (c) 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/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 "base/base64.h" | 9 #include "base/base64.h" |
| 10 | 10 |
| 11 // This is the default public key used for validating signatures. | 11 // This is the default public key used for validating signatures. |
| 12 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys. | 12 // TODO(iclelland): Provide a mechanism to allow for multiple signing keys. |
| 13 // https://crbug.com/584737 | 13 // https://crbug.com/584737 |
| 14 static const uint8_t kDefaultPublicKey[] = { | 14 static const uint8_t kDefaultPublicKey[] = { |
| 15 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03, | 15 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03, |
| 16 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07, | 16 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07, |
| 17 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15, | 17 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15, |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 OriginTrialKeyManager::OriginTrialKeyManager() | 20 ChromeOriginTrialPolicy::ChromeOriginTrialPolicy() |
| 21 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey), | 21 : public_key_(std::string(reinterpret_cast<const char*>(kDefaultPublicKey), |
| 22 arraysize(kDefaultPublicKey))) {} | 22 arraysize(kDefaultPublicKey))) {} |
| 23 | 23 |
| 24 OriginTrialKeyManager::~OriginTrialKeyManager() {} | 24 ChromeOriginTrialPolicy::~ChromeOriginTrialPolicy() {} |
| 25 | 25 |
| 26 bool OriginTrialKeyManager::SetPublicKeyFromASCIIString( | 26 base::StringPiece ChromeOriginTrialPolicy::GetPublicKey() const { |
| 27 return base::StringPiece(public_key_); |
| 28 } |
| 29 |
| 30 bool ChromeOriginTrialPolicy::SetPublicKeyFromASCIIString( |
| 27 const std::string& ascii_public_key) { | 31 const std::string& ascii_public_key) { |
| 28 // Base64-decode the incoming string. Set the key if it is correctly formatted | 32 // Base64-decode the incoming string. Set the key if it is correctly formatted |
| 29 std::string new_public_key; | 33 std::string new_public_key; |
| 30 if (!base::Base64Decode(ascii_public_key, &new_public_key)) | 34 if (!base::Base64Decode(ascii_public_key, &new_public_key)) |
| 31 return false; | 35 return false; |
| 32 if (new_public_key.size() != 32) | 36 if (new_public_key.size() != 32) |
| 33 return false; | 37 return false; |
| 34 public_key_.swap(new_public_key); | 38 public_key_.swap(new_public_key); |
| 35 return true; | 39 return true; |
| 36 } | 40 } |
| 37 | |
| 38 base::StringPiece OriginTrialKeyManager::GetPublicKey() const { | |
| 39 return base::StringPiece(public_key_); | |
| 40 } | |
| OLD | NEW |