OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 NET_HTTP_MAC_SIGNATURE_H_ | 5 #ifndef NET_HTTP_MAC_SIGNATURE_H_ |
6 #define NET_HTTP_MAC_SIGNATURE_H_ | 6 #define NET_HTTP_MAC_SIGNATURE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/time.h" |
13 #include "crypto/hmac.h" | 14 #include "crypto/hmac.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 // This class represents an HTTP MAC signature for use in the HTTP MAC | 18 // This class represents an HTTP MAC signature for use in the HTTP MAC |
18 // Authentication scheme. The current draft specification of this | 19 // Authentication scheme. The current draft specification of this |
19 // authentication scheme is located at the following URL: | 20 // authentication scheme is located at the following URL: |
20 // | 21 // |
21 // http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token | 22 // http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token |
22 // | 23 // |
23 class HttpMacSignature { | 24 class HttpMacSignature { |
24 public: | 25 public: |
25 HttpMacSignature(); | 26 HttpMacSignature(); |
26 ~HttpMacSignature(); | 27 ~HttpMacSignature(); |
27 | 28 |
28 // Returns whether this information is valid. | 29 // Returns whether this information is valid. |
29 bool AddStateInfo(const std::string& id, | 30 bool AddStateInfo(const std::string& id, |
| 31 const base::Time& creation_date, |
30 const std::string& mac_key, | 32 const std::string& mac_key, |
31 const std::string& mac_algorithm); | 33 const std::string& mac_algorithm); |
32 | 34 |
33 // Returns whether this information is valid. | 35 // Returns whether this information is valid. |
34 bool AddHttpInfo(const std::string& method, | 36 bool AddHttpInfo(const std::string& method, |
35 const std::string& request_uri, | 37 const std::string& request_uri, |
36 const std::string& host, | 38 const std::string& host, |
37 int port); | 39 int port); |
38 | 40 |
39 // Returns the value of the Authorization header for use in an HTTP request. | 41 // Returns the value of the Authorization header for use in an HTTP request. |
40 std::string GenerateAuthorizationHeader(); | 42 std::string GenerateAuthorizationHeader(); |
41 | 43 |
42 private: | 44 private: |
43 FRIEND_TEST_ALL_PREFIXES(HttpMacSignatureTest, GenerateHeaderString); | 45 FRIEND_TEST_ALL_PREFIXES(HttpMacSignatureTest, GenerateHeaderString); |
44 FRIEND_TEST_ALL_PREFIXES(HttpMacSignatureTest, GenerateNormalizedRequest); | 46 FRIEND_TEST_ALL_PREFIXES(HttpMacSignatureTest, GenerateNormalizedRequest); |
45 FRIEND_TEST_ALL_PREFIXES(HttpMacSignatureTest, GenerateMAC); | 47 FRIEND_TEST_ALL_PREFIXES(HttpMacSignatureTest, GenerateMAC); |
46 | 48 |
47 std::string GenerateHeaderString(const std::string& timestamp, | 49 std::string GenerateHeaderString(const std::string& age, |
48 const std::string& nonce); | 50 const std::string& nonce); |
49 std::string GenerateNormalizedRequest(const std::string& timestamp, | 51 std::string GenerateNormalizedRequest(const std::string& age, |
50 const std::string& nonce); | 52 const std::string& nonce); |
51 std::string GenerateMAC(const std::string& timestamp, | 53 std::string GenerateMAC(const std::string& age, |
52 const std::string& nonce); | 54 const std::string& nonce); |
53 | 55 |
54 std::string id_; | 56 std::string id_; |
| 57 base::Time creation_date_; |
55 std::string mac_key_; | 58 std::string mac_key_; |
56 crypto::HMAC::HashAlgorithm mac_algorithm_; | 59 crypto::HMAC::HashAlgorithm mac_algorithm_; |
57 | 60 |
58 std::string method_; | 61 std::string method_; |
59 std::string request_uri_; | 62 std::string request_uri_; |
60 std::string host_; | 63 std::string host_; |
61 std::string port_; | 64 std::string port_; |
62 // TODO(abarth): body_hash_ | 65 // TODO(abarth): body_hash_ |
63 | 66 |
64 DISALLOW_COPY_AND_ASSIGN(HttpMacSignature); | 67 DISALLOW_COPY_AND_ASSIGN(HttpMacSignature); |
65 }; | 68 }; |
66 | 69 |
67 } // namespace net | 70 } // namespace net |
68 | 71 |
69 #endif // NET_HTTP_MAC_SIGNATURE_H_ | 72 #endif // NET_HTTP_MAC_SIGNATURE_H_ |
OLD | NEW |