OLD | NEW |
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 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); | 16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 enum class WebOriginTrialTokenStatus; | 19 enum class WebOriginTrialTokenStatus; |
20 } | 20 } |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 // The Experimental Framework (EF) provides limited access to experimental | 24 // The Origin Trials Framework (OT) provides limited access to experimental |
25 // features, on a per-origin basis (origin trials). This class defines the trial | 25 // features, on a per-origin basis. This class defines the trial token data |
26 // token data structure, used to securely provide access to an experimental | 26 // structure, used to securely provide access to an experimental feature. |
27 // feature. | |
28 // | 27 // |
29 // Features are defined by string names, provided by the implementers. The EF | 28 // Features are defined by string names, provided by the implementers. The OT |
30 // code does not maintain an enum or constant list for feature names. Instead, | 29 // code does not maintain an enum or constant list for feature names. Instead, |
31 // the EF validates the name provided by the feature implementation against any | 30 // it validates the name provided by the feature implementation against any |
32 // provided tokens. | 31 // provided tokens. |
33 // | 32 // |
34 // More documentation on the token format can be found at | 33 // More documentation on the token format can be found at |
35 // https://docs.google.com/document/d/1v5fi0EUV_QHckVHVF2K4P72iNywnrJtNhNZ6i2NPt
0M | 34 // https://docs.google.com/document/d/1v5fi0EUV_QHckVHVF2K4P72iNywnrJtNhNZ6i2NPt
0M |
36 | 35 |
37 class CONTENT_EXPORT TrialToken { | 36 class CONTENT_EXPORT TrialToken { |
38 public: | 37 public: |
39 ~TrialToken(); | 38 ~TrialToken(); |
40 | 39 |
41 // If the string represents a signed well-formed token, a token object is | 40 // If the string represents a signed well-formed token, a token object is |
42 // returned, and success is returned in the |out_status| parameter. Otherwise, | 41 // returned, and success is returned in the |out_status| parameter. Otherwise, |
43 // the |out_status| parameter indicates what was wrong with the string, and | 42 // the |out_status| parameter indicates what was wrong with the string, and |
44 // nullptr is returned. | 43 // nullptr is returned. |
45 // Note that success does not mean that the token is currently valid, or | 44 // Note that success does not mean that the token is currently valid, or |
46 // appropriate for a given origin / feature. It only means that it is | 45 // appropriate for a given origin / feature. It only means that it is |
47 // correctly formatted and signed by the supplied public key, and can be | 46 // correctly formatted and signed by the supplied public key, and can be |
48 // parsed. | 47 // parsed. |
49 static std::unique_ptr<TrialToken> From( | 48 static std::unique_ptr<TrialToken> From( |
50 const std::string& token_text, | 49 const std::string& token_text, |
51 base::StringPiece public_key, | 50 base::StringPiece public_key, |
52 blink::WebOriginTrialTokenStatus* out_status); | 51 blink::WebOriginTrialTokenStatus* out_status); |
53 | 52 |
54 // Returns success if this token is appropriate for use by the given origin | 53 // Returns success if this token is appropriate for use by the given origin |
55 // and has not yet expired. Otherwise, the return value indicates why the | 54 // and has not yet expired. Otherwise, the return value indicates why the |
56 // token is not valid. | 55 // token is not valid. |
57 blink::WebOriginTrialTokenStatus IsValid(const url::Origin& origin, | 56 blink::WebOriginTrialTokenStatus IsValid(const url::Origin& origin, |
58 const base::Time& now) const; | 57 const base::Time& now) const; |
59 | 58 |
60 url::Origin origin() { return origin_; } | 59 url::Origin origin() { return origin_; } |
| 60 bool match_subdomains() const { return match_subdomains_; } |
61 std::string feature_name() { return feature_name_; } | 61 std::string feature_name() { return feature_name_; } |
62 base::Time expiry_time() { return expiry_time_; } | 62 base::Time expiry_time() { return expiry_time_; } |
63 | 63 |
64 protected: | 64 protected: |
65 // Tests can access the Parse method directly to validate it, and so are | 65 // Tests can access the Parse method directly to validate it, and so are |
66 // declared as friends here. All other access to Parse should be made through | 66 // declared as friends here. All other access to Parse should be made through |
67 // TrialToken::From, which will always also ensure that there is a valid | 67 // TrialToken::From, which will always also ensure that there is a valid |
68 // signature attached to the token. | 68 // signature attached to the token. |
69 friend class TrialTokenTest; | 69 friend class TrialTokenTest; |
70 friend int ::LLVMFuzzerTestOneInput(const uint8_t*, size_t); | 70 friend int ::LLVMFuzzerTestOneInput(const uint8_t*, size_t); |
(...skipping 14 matching lines...) Expand all Loading... |
85 bool ValidateOrigin(const url::Origin& origin) const; | 85 bool ValidateOrigin(const url::Origin& origin) const; |
86 bool ValidateFeatureName(base::StringPiece feature_name) const; | 86 bool ValidateFeatureName(base::StringPiece feature_name) const; |
87 bool ValidateDate(const base::Time& now) const; | 87 bool ValidateDate(const base::Time& now) const; |
88 | 88 |
89 static bool ValidateSignature(base::StringPiece signature_text, | 89 static bool ValidateSignature(base::StringPiece signature_text, |
90 const std::string& data, | 90 const std::string& data, |
91 base::StringPiece public_key); | 91 base::StringPiece public_key); |
92 | 92 |
93 private: | 93 private: |
94 TrialToken(const url::Origin& origin, | 94 TrialToken(const url::Origin& origin, |
| 95 bool match_subdomains, |
95 const std::string& feature_name, | 96 const std::string& feature_name, |
96 uint64_t expiry_timestamp); | 97 uint64_t expiry_timestamp); |
97 | 98 |
98 // The origin for which this token is valid. Must be a secure origin. | 99 // The origin for which this token is valid. Must be a secure origin. |
99 url::Origin origin_; | 100 url::Origin origin_; |
100 | 101 |
| 102 // Indicates if the token should match all subdomains of the origin. |
| 103 bool match_subdomains_; |
| 104 |
101 // The name of the experimental feature which this token enables. | 105 // The name of the experimental feature which this token enables. |
102 std::string feature_name_; | 106 std::string feature_name_; |
103 | 107 |
104 // The time until which this token should be considered valid. | 108 // The time until which this token should be considered valid. |
105 base::Time expiry_time_; | 109 base::Time expiry_time_; |
106 }; | 110 }; |
107 | 111 |
108 } // namespace content | 112 } // namespace content |
109 | 113 |
110 #endif // CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_ | 114 #endif // CONTENT_COMMON_ORIGIN_TRIALS_TRIAL_TOKEN_H_ |
OLD | NEW |