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

Side by Side Diff: content/common/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; fix DLL export error in VS compile 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/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
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 // This is the default public key used for validating signatures.
25 // TODO(iclelland): Move this to the embedder, and provide a mechanism to allow
26 // for multiple signing keys. https://crbug.com/543220
27 static const uint8_t kPublicKey[] = {
28 0x7c, 0xc4, 0xb8, 0x9a, 0x93, 0xba, 0x6e, 0xe2, 0xd0, 0xfd, 0x03,
29 0x1d, 0xfb, 0x32, 0x66, 0xc7, 0x3b, 0x72, 0xfd, 0x54, 0x3a, 0x07,
30 0x51, 0x14, 0x66, 0xaa, 0x02, 0x53, 0x4e, 0x33, 0xa1, 0x15,
31 };
32
33 const char* kFieldSeparator = "|"; 24 const char* kFieldSeparator = "|";
34 25
35 } // namespace 26 } // namespace
36 27
37 TrialToken::~TrialToken() {} 28 TrialToken::~TrialToken() {}
38 29
39 scoped_ptr<TrialToken> TrialToken::Parse(const std::string& token_text) { 30 scoped_ptr<TrialToken> TrialToken::Parse(const std::string& token_text) {
40 if (token_text.empty()) { 31 if (token_text.empty()) {
41 return nullptr; 32 return nullptr;
42 } 33 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 data_(data), 74 data_(data),
84 origin_(origin), 75 origin_(origin),
85 feature_name_(feature_name), 76 feature_name_(feature_name),
86 expiry_timestamp_(expiry_timestamp) {} 77 expiry_timestamp_(expiry_timestamp) {}
87 78
88 bool TrialToken::IsAppropriate(const std::string& origin, 79 bool TrialToken::IsAppropriate(const std::string& origin,
89 const std::string& feature_name) const { 80 const std::string& feature_name) const {
90 return ValidateOrigin(origin) && ValidateFeatureName(feature_name); 81 return ValidateOrigin(origin) && ValidateFeatureName(feature_name);
91 } 82 }
92 83
93 bool TrialToken::IsValid(const base::Time& now) const { 84 bool TrialToken::IsValid(const base::Time& now,
85 const base::StringPiece& public_key) const {
94 // TODO(iclelland): Allow for multiple signing keys, and iterate over all 86 // TODO(iclelland): Allow for multiple signing keys, and iterate over all
95 // active keys here. https://crbug.com/543220 87 // active keys here. https://crbug.com/543220
chasej 2016/02/05 19:35:28 Nit: This is the wrong bug number (543220 is for s
iclelland 2016/02/05 20:18:09 Thanks! Done.
96 return ValidateDate(now) && 88 return ValidateDate(now) && ValidateSignature(public_key);
97 ValidateSignature(base::StringPiece(
98 reinterpret_cast<const char*>(kPublicKey), arraysize(kPublicKey)));
99 } 89 }
100 90
101 bool TrialToken::ValidateOrigin(const std::string& origin) const { 91 bool TrialToken::ValidateOrigin(const std::string& origin) const {
102 return GURL(origin) == origin_; 92 return GURL(origin) == origin_;
103 } 93 }
104 94
105 bool TrialToken::ValidateFeatureName(const std::string& feature_name) const { 95 bool TrialToken::ValidateFeatureName(const std::string& feature_name) const {
106 return base::EqualsCaseInsensitiveASCII(feature_name, feature_name_); 96 return base::EqualsCaseInsensitiveASCII(feature_name, feature_name_);
107 } 97 }
108 98
(...skipping 25 matching lines...) Expand all
134 } 124 }
135 125
136 int result = ED25519_verify( 126 int result = ED25519_verify(
137 reinterpret_cast<const uint8_t*>(data.data()), data.length(), 127 reinterpret_cast<const uint8_t*>(data.data()), data.length(),
138 reinterpret_cast<const uint8_t*>(signature.data()), 128 reinterpret_cast<const uint8_t*>(signature.data()),
139 reinterpret_cast<const uint8_t*>(public_key.data())); 129 reinterpret_cast<const uint8_t*>(public_key.data()));
140 return (result != 0); 130 return (result != 0);
141 } 131 }
142 132
143 } // namespace content 133 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698