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_EXPERIMENTS_API_KEY_H_ | 5 #ifndef CONTENT_COMMON_EXPERIMENTS_API_KEY_H_ |
6 #define CONTENT_COMMON_EXPERIMENTS_API_KEY_H_ | 6 #define CONTENT_COMMON_EXPERIMENTS_API_KEY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string_piece.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 // The Experimental Framework (EF) provides limited access to experimental APIs, | 18 // 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 // on a per-origin basis. This class defines the API key data structure, used |
19 // to securely provide access to an experimental API. | 20 // to securely provide access to an experimental API. |
20 // | 21 // |
(...skipping 28 matching lines...) Expand all Loading... |
49 GURL origin() { return origin_; } | 50 GURL origin() { return origin_; } |
50 std::string api_name() { return api_name_; } | 51 std::string api_name() { return api_name_; } |
51 uint64_t expiry_timestamp() { return expiry_timestamp_; } | 52 uint64_t expiry_timestamp() { return expiry_timestamp_; } |
52 | 53 |
53 protected: | 54 protected: |
54 friend class ApiKeyTest; | 55 friend class ApiKeyTest; |
55 | 56 |
56 bool ValidateOrigin(const std::string& origin) const; | 57 bool ValidateOrigin(const std::string& origin) const; |
57 bool ValidateApiName(const std::string& api_name) const; | 58 bool ValidateApiName(const std::string& api_name) const; |
58 bool ValidateDate(const base::Time& now) 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); |
59 | 65 |
60 private: | 66 private: |
61 ApiKey(const std::string& signature, | 67 ApiKey(const std::string& signature, |
62 const std::string& data, | 68 const std::string& data, |
63 const GURL& origin, | 69 const GURL& origin, |
64 const std::string& api_name, | 70 const std::string& api_name, |
65 uint64_t expiry_timestamp); | 71 uint64_t expiry_timestamp); |
66 | 72 |
67 // The base64-encoded-signature portion of the key. For the key to be valid, | 73 // 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 | 74 // this must be a valid signature for the data portion of the key, as verified |
(...skipping 11 matching lines...) Expand all Loading... |
80 std::string api_name_; | 86 std::string api_name_; |
81 | 87 |
82 // The time until which this key should be considered valid, in UTC, as | 88 // The time until which this key should be considered valid, in UTC, as |
83 // seconds since the Unix epoch. | 89 // seconds since the Unix epoch. |
84 uint64_t expiry_timestamp_; | 90 uint64_t expiry_timestamp_; |
85 }; | 91 }; |
86 | 92 |
87 } // namespace content | 93 } // namespace content |
88 | 94 |
89 #endif // CONTENT_COMMON_EXPERIMENTS_API_KEY_H_ | 95 #endif // CONTENT_COMMON_EXPERIMENTS_API_KEY_H_ |
OLD | NEW |