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

Side by Side Diff: content/common/experiments/api_key.h

Issue 1521063003: Add API Key parsing for experimental APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 11 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
« no previous file with comments | « no previous file | content/common/experiments/api_key.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_COMMON_EXPERIMENTS_API_KEY_H_
6 #define CONTENT_COMMON_EXPERIMENTS_API_KEY_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "content/common/content_export.h"
13 #include "url/gurl.h"
14
15 namespace content {
16
17 // The Experimental Framework (EF) provides limited access to experimental APIs,
18 // on a per-origin basis. This class defines the API key data structure, used
19 // to securely provide access to an experimental API.
20 //
21 // Experimental APIs are defined by string names, provided by the implementers.
22 // The EF code does not maintain an enum or constant list for experiment names.
23 // Instead, the EF validates the name provided by the API implementation against
24 // any provided API keys.
25 //
26 // More documentation on the key format can be found at
27 // https://docs.google.com/document/d/1v5fi0EUV_QHckVHVF2K4P72iNywnrJtNhNZ6i2NPt 0M
28
29 class CONTENT_EXPORT ApiKey {
30 public:
31 ~ApiKey();
32
33 // Returns a key object if the string represents a well-formed key, or
34 // nullptr otherwise. (This does not mean that the key is valid, just that it
35 // can be parsed.)
36 static scoped_ptr<ApiKey> Parse(const std::string& key_text);
37
38 // Returns true if this API is appropriate for use by the given origin, for
39 // the given API name. This does not check whether the signature is valid, or
40 // whether the key itself has expired.
41 bool IsAppropriate(const std::string& origin,
42 const std::string& apiName) const;
43
44 // Returns true if this API key has a valid signature, and has not expired.
45 bool IsValid(const base::Time& now) const;
46
47 std::string signature() { return signature_; }
48 std::string data() { return data_; }
49 GURL origin() { return origin_; }
50 std::string api_name() { return api_name_; }
51 uint64_t expiry_timestamp() { return expiry_timestamp_; }
52
53 protected:
54 friend class ApiKeyTest;
55
56 bool ValidateOrigin(const std::string& origin) const;
57 bool ValidateApiName(const std::string& api_name) const;
58 bool ValidateDate(const base::Time& now) const;
59
60 private:
61 ApiKey(const std::string& signature,
62 const std::string& data,
63 const GURL& origin,
64 const std::string& api_name,
65 uint64_t expiry_timestamp);
66
67 // The base64-encoded-signature portion of the key. For the key to be valid,
68 // this must be a valid signature for the data portion of the key, as verified
69 // by the public key in api_key.cc.
70 std::string signature_;
71
72 // The portion of the key string which is signed, and whose signature is
73 // contained in the signature_ member.
74 std::string data_;
75
76 // The origin for which this key is valid. Must be a secure origin.
77 GURL origin_;
78
79 // The name of the API experiment which this key enables.
80 std::string api_name_;
81
82 // The time until which this key should be considered valid, in UTC, as
83 // seconds since the Unix epoch.
84 uint64_t expiry_timestamp_;
85 };
86
87 } // namespace content
88
89 #endif // CONTENT_COMMON_EXPERIMENTS_API_KEY_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/experiments/api_key.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698