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

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

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 #ifndef CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_ 5 #ifndef CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_
6 #define CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_ 6 #define CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "url/origin.h" 14 #include "url/origin.h"
15 15
16 namespace blink { 16 namespace blink {
17 enum class WebOriginTrialTokenStatus; 17 enum class WebOriginTrialTokenStatus;
18 } 18 }
19 19
20 namespace content { 20 namespace content {
21 21
22 // The Experimental Framework (EF) provides limited access to experimental 22 // The Origin Trials Framework (OT) provides limited access to experimental
23 // features, on a per-origin basis (origin trials). This class defines the trial 23 // features, on a per-origin basis. This class defines the trial token data
24 // token data structure, used to securely provide access to an experimental 24 // structure, used to securely provide access to an experimental feature.
25 // feature.
26 // 25 //
27 // Features are defined by string names, provided by the implementers. The EF 26 // Features are defined by string names, provided by the implementers. The OT
28 // code does not maintain an enum or constant list for feature names. Instead, 27 // code does not maintain an enum or constant list for feature names. Instead,
29 // the EF validates the name provided by the feature implementation against any 28 // it validates the name provided by the feature implementation against any
30 // provided tokens. 29 // provided tokens.
31 // 30 //
32 // More documentation on the token format can be found at 31 // More documentation on the token format can be found at
33 // https://docs.google.com/document/d/1v5fi0EUV_QHckVHVF2K4P72iNywnrJtNhNZ6i2NPt 0M 32 // https://docs.google.com/document/d/1v5fi0EUV_QHckVHVF2K4P72iNywnrJtNhNZ6i2NPt 0M
34 33
35 class CONTENT_EXPORT TrialToken { 34 class CONTENT_EXPORT TrialToken {
36 public: 35 public:
37 ~TrialToken(); 36 ~TrialToken();
38 37
39 // If the string represents a signed well-formed token, a token object is 38 // If the string represents a signed well-formed token, a token object is
40 // returned, and success is returned in the |out_status| parameter. Otherwise, 39 // returned, and success is returned in the |out_status| parameter. Otherwise,
41 // the |out_status| parameter indicates what was wrong with the string, and 40 // the |out_status| parameter indicates what was wrong with the string, and
42 // nullptr is returned. 41 // nullptr is returned.
43 // Note that success does not mean that the token is currently valid, or 42 // Note that success does not mean that the token is currently valid, or
44 // appropriate for a given origin / feature. It only means that it is 43 // appropriate for a given origin / feature. It only means that it is
45 // correctly formatted and signed by the supplied public key, and can be 44 // correctly formatted and signed by the supplied public key, and can be
46 // parsed. 45 // parsed.
47 static std::unique_ptr<TrialToken> From( 46 static std::unique_ptr<TrialToken> From(
48 const std::string& token_text, 47 const std::string& token_text,
49 base::StringPiece public_key, 48 base::StringPiece public_key,
50 blink::WebOriginTrialTokenStatus* out_status); 49 blink::WebOriginTrialTokenStatus* out_status);
51 50
52 // Returns success if this token is appropriate for use by the given origin 51 // Returns success if this token is appropriate for use by the given origin
53 // and has not yet expired. Otherwise, the return value indicates why the 52 // and has not yet expired. Otherwise, the return value indicates why the
54 // token is not valid. 53 // token is not valid.
55 blink::WebOriginTrialTokenStatus IsValid(const url::Origin& origin, 54 blink::WebOriginTrialTokenStatus IsValid(const url::Origin& origin,
56 const base::Time& now) const; 55 const base::Time& now) const;
57 56
58 url::Origin origin() { return origin_; } 57 url::Origin origin() { return origin_; }
58 bool is_wildcard_origin() const { return is_wildcard_origin_; }
59 std::string feature_name() { return feature_name_; } 59 std::string feature_name() { return feature_name_; }
60 base::Time expiry_time() { return expiry_time_; } 60 base::Time expiry_time() { return expiry_time_; }
61 61
62 protected: 62 protected:
63 friend class TrialTokenTest; 63 friend class TrialTokenTest;
64 64
65 // If the string represents a properly signed and well-formed token, the token 65 // If the string represents a properly signed and well-formed token, the token
66 // payload is returned in the |out_token_payload| parameter and success is 66 // payload is returned in the |out_token_payload| parameter and success is
67 // returned. Otherwise,the return code indicates what was wrong with the 67 // returned. Otherwise,the return code indicates what was wrong with the
68 // string, and |out_token_payload| is unchanged. 68 // string, and |out_token_payload| is unchanged.
69 static blink::WebOriginTrialTokenStatus Extract( 69 static blink::WebOriginTrialTokenStatus Extract(
70 const std::string& token_text, 70 const std::string& token_text,
71 base::StringPiece public_key, 71 base::StringPiece public_key,
72 std::string* out_token_payload); 72 std::string* out_token_payload);
73 73
74 // Returns a token object if the string represents a well-formed JSON token 74 // Returns a token object if the string represents a well-formed JSON token
75 // payload, or nullptr otherwise. 75 // payload, or nullptr otherwise.
76 static std::unique_ptr<TrialToken> Parse(const std::string& token_payload); 76 static std::unique_ptr<TrialToken> Parse(const std::string& token_payload);
77 77
78 bool ValidateOrigin(const url::Origin& origin) const; 78 bool ValidateOrigin(const url::Origin& origin) const;
79 bool ValidateFeatureName(base::StringPiece feature_name) const; 79 bool ValidateFeatureName(base::StringPiece feature_name) const;
80 bool ValidateDate(const base::Time& now) const; 80 bool ValidateDate(const base::Time& now) const;
81 81
82 static bool ValidateSignature(base::StringPiece signature_text, 82 static bool ValidateSignature(base::StringPiece signature_text,
83 const std::string& data, 83 const std::string& data,
84 base::StringPiece public_key); 84 base::StringPiece public_key);
85 85
86 private: 86 private:
87 TrialToken(const url::Origin& origin, 87 TrialToken(const url::Origin& origin,
88 bool is_wildcard_origin,
88 const std::string& feature_name, 89 const std::string& feature_name,
89 uint64_t expiry_timestamp); 90 uint64_t expiry_timestamp);
90 91
91 // The origin for which this token is valid. Must be a secure origin. 92 // The origin for which this token is valid. Must be a secure origin.
92 url::Origin origin_; 93 url::Origin origin_;
93 94
95 // Indicates if the origin should use wildcard matching, to enable subdomains.
96 bool is_wildcard_origin_;
iclelland 2016/10/12 04:18:15 Bikeshed: Would this be better named something lik
97
94 // The name of the experimental feature which this token enables. 98 // The name of the experimental feature which this token enables.
95 std::string feature_name_; 99 std::string feature_name_;
96 100
97 // The time until which this token should be considered valid. 101 // The time until which this token should be considered valid.
98 base::Time expiry_time_; 102 base::Time expiry_time_;
99 }; 103 };
100 104
101 } // namespace content 105 } // namespace content
102 106
103 #endif // CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_ 107 #endif // CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/origin_trials/trial_token.cc » ('j') | content/common/origin_trials/trial_token_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698