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

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

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

Powered by Google App Engine
This is Rietveld 408576698