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

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

Issue 2411803002: Support subdomain matching in trial tokens (Closed)
Patch Set: Created 4 years, 2 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/common/origin_trials/trial_token.h" 5 #include "content/common/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
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 datadict->GetString("origin", &origin_string); 150 datadict->GetString("origin", &origin_string);
151 datadict->GetString("feature", &feature_name); 151 datadict->GetString("feature", &feature_name);
152 datadict->GetInteger("expiry", &expiry_timestamp); 152 datadict->GetInteger("expiry", &expiry_timestamp);
153 153
154 // Ensure that the origin is a valid (non-unique) origin URL. 154 // Ensure that the origin is a valid (non-unique) origin URL.
155 url::Origin origin = url::Origin(GURL(origin_string)); 155 url::Origin origin = url::Origin(GURL(origin_string));
156 if (origin.unique()) { 156 if (origin.unique()) {
157 return nullptr; 157 return nullptr;
158 } 158 }
159 159
160 // The |isWildcard| flag is optional. If found, ensure it is a valid boolean.
161 bool is_wildcard = false;
162 if (datadict->HasKey("isWildcard")) {
163 if (!datadict->GetBoolean("isWildcard", &is_wildcard)) {
164 return nullptr;
165 }
166 }
167
160 // Ensure that the feature name is a valid string. 168 // Ensure that the feature name is a valid string.
161 if (feature_name.empty()) { 169 if (feature_name.empty()) {
162 return nullptr; 170 return nullptr;
163 } 171 }
164 172
165 // Ensure that the expiry timestamp is a valid (positive) integer. 173 // Ensure that the expiry timestamp is a valid (positive) integer.
166 if (expiry_timestamp <= 0) { 174 if (expiry_timestamp <= 0) {
167 return nullptr; 175 return nullptr;
168 } 176 }
169 177
170 return base::WrapUnique( 178 return base::WrapUnique(
171 new TrialToken(origin, feature_name, expiry_timestamp)); 179 new TrialToken(origin, is_wildcard, feature_name, expiry_timestamp));
172 } 180 }
173 181
174 bool TrialToken::ValidateOrigin(const url::Origin& origin) const { 182 bool TrialToken::ValidateOrigin(const url::Origin& origin) const {
183 if (is_wildcard_origin_) {
184 return origin.scheme() == origin_.scheme() &&
185 origin.DomainIs(origin_.host()) &&
186 origin.port() == origin_.port();
187 }
175 return origin == origin_; 188 return origin == origin_;
176 } 189 }
177 190
178 bool TrialToken::ValidateFeatureName(base::StringPiece feature_name) const { 191 bool TrialToken::ValidateFeatureName(base::StringPiece feature_name) const {
179 return feature_name == feature_name_; 192 return feature_name == feature_name_;
180 } 193 }
181 194
182 bool TrialToken::ValidateDate(const base::Time& now) const { 195 bool TrialToken::ValidateDate(const base::Time& now) const {
183 return expiry_time_ > now; 196 return expiry_time_ > now;
184 } 197 }
(...skipping 11 matching lines...) Expand all
196 } 209 }
197 210
198 int result = ED25519_verify( 211 int result = ED25519_verify(
199 reinterpret_cast<const uint8_t*>(data.data()), data.length(), 212 reinterpret_cast<const uint8_t*>(data.data()), data.length(),
200 reinterpret_cast<const uint8_t*>(signature.data()), 213 reinterpret_cast<const uint8_t*>(signature.data()),
201 reinterpret_cast<const uint8_t*>(public_key.data())); 214 reinterpret_cast<const uint8_t*>(public_key.data()));
202 return (result != 0); 215 return (result != 0);
203 } 216 }
204 217
205 TrialToken::TrialToken(const url::Origin& origin, 218 TrialToken::TrialToken(const url::Origin& origin,
219 bool is_wildcard_origin,
206 const std::string& feature_name, 220 const std::string& feature_name,
207 uint64_t expiry_timestamp) 221 uint64_t expiry_timestamp)
208 : origin_(origin), 222 : origin_(origin),
223 is_wildcard_origin_(is_wildcard_origin),
209 feature_name_(feature_name), 224 feature_name_(feature_name),
210 expiry_time_(base::Time::FromDoubleT(expiry_timestamp)) {} 225 expiry_time_(base::Time::FromDoubleT(expiry_timestamp)) {}
211 226
212 } // namespace content 227 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698