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

Side by Side Diff: content/renderer/origin_trials/trial_token.cc

Issue 1653263005: [Experimental Framework] Move the trial token public key out of content and into the embedder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, and update for recent token changes Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/renderer/origin_trials/trial_token.h" 5 #include "content/renderer/origin_trials/trial_token.h"
6 6
7 #include <openssl/curve25519.h> 7 #include <openssl/curve25519.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "url/origin.h" 18 #include "url/origin.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 namespace { 22 namespace {
23 23
24 // Version 1 is the only token version currently supported 24 // Version 1 is the only token version currently supported
25 const uint8_t kVersion1 = 1; 25 const uint8_t kVersion1 = 1;
26 26
27 // This is the default public key used for validating signatures.
28 // TODO(iclelland): Move this to the embedder, and provide a mechanism to allow
29 // for multiple signing keys. https://crbug.com/543220
30 static const uint8_t kPublicKey[] = {
31 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03,
32 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07,
33 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15,
34 };
35
36 const char* kFieldSeparator = "|"; 27 const char* kFieldSeparator = "|";
37 28
38 } // namespace 29 } // namespace
39 30
40 TrialToken::~TrialToken() {} 31 TrialToken::~TrialToken() {}
41 32
42 scoped_ptr<TrialToken> TrialToken::Parse(const std::string& token_text) { 33 scoped_ptr<TrialToken> TrialToken::Parse(const std::string& token_text) {
43 if (token_text.empty()) { 34 if (token_text.empty()) {
44 return nullptr; 35 return nullptr;
45 } 36 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 data_(data), 100 data_(data),
110 origin_(origin), 101 origin_(origin),
111 feature_name_(feature_name), 102 feature_name_(feature_name),
112 expiry_timestamp_(expiry_timestamp) {} 103 expiry_timestamp_(expiry_timestamp) {}
113 104
114 bool TrialToken::IsAppropriate(const std::string& origin, 105 bool TrialToken::IsAppropriate(const std::string& origin,
115 const std::string& feature_name) const { 106 const std::string& feature_name) const {
116 return ValidateOrigin(origin) && ValidateFeatureName(feature_name); 107 return ValidateOrigin(origin) && ValidateFeatureName(feature_name);
117 } 108 }
118 109
119 bool TrialToken::IsValid(const base::Time& now) const { 110 bool TrialToken::IsValid(const base::Time& now,
111 const base::StringPiece& public_key) const {
120 // TODO(iclelland): Allow for multiple signing keys, and iterate over all 112 // TODO(iclelland): Allow for multiple signing keys, and iterate over all
121 // active keys here. https://crbug.com/543220 113 // active keys here. https://crbug.com/543220
122 return ValidateDate(now) && 114 return ValidateDate(now) && ValidateSignature(public_key);
123 ValidateSignature(base::StringPiece(
124 reinterpret_cast<const char*>(kPublicKey), arraysize(kPublicKey)));
125 } 115 }
126 116
127 bool TrialToken::ValidateOrigin(const std::string& origin) const { 117 bool TrialToken::ValidateOrigin(const std::string& origin) const {
128 return GURL(origin) == origin_; 118 return GURL(origin) == origin_;
129 } 119 }
130 120
131 bool TrialToken::ValidateFeatureName(const std::string& feature_name) const { 121 bool TrialToken::ValidateFeatureName(const std::string& feature_name) const {
132 return feature_name == feature_name_; 122 return feature_name == feature_name_;
133 } 123 }
134 124
(...skipping 25 matching lines...) Expand all
160 } 150 }
161 151
162 int result = ED25519_verify( 152 int result = ED25519_verify(
163 reinterpret_cast<const uint8_t*>(data.data()), data.length(), 153 reinterpret_cast<const uint8_t*>(data.data()), data.length(),
164 reinterpret_cast<const uint8_t*>(signature.data()), 154 reinterpret_cast<const uint8_t*>(signature.data()),
165 reinterpret_cast<const uint8_t*>(public_key.data())); 155 reinterpret_cast<const uint8_t*>(public_key.data()));
166 return (result != 0); 156 return (result != 0);
167 } 157 }
168 158
169 } // namespace content 159 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/origin_trials/trial_token.h ('k') | content/renderer/origin_trials/trial_token_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698