OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_HTTP_AUTH_HANDLER_DIGEST_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ |
6 #define NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ALGORITHM_UNSPECIFIED, | 56 ALGORITHM_UNSPECIFIED, |
57 | 57 |
58 // Hashes are run for every request. | 58 // Hashes are run for every request. |
59 ALGORITHM_MD5, | 59 ALGORITHM_MD5, |
60 | 60 |
61 // Hash is run only once during the first WWW-Authenticate handshake. | 61 // Hash is run only once during the first WWW-Authenticate handshake. |
62 // (SESS means session). | 62 // (SESS means session). |
63 ALGORITHM_MD5_SESS, | 63 ALGORITHM_MD5_SESS, |
64 }; | 64 }; |
65 | 65 |
66 // Possible values for "qop" -- may be or-ed together if there were | 66 // Possible values for QualityOfProtection. |
67 // multiple comma separated values. | 67 // auth-int is not supported, see http://crbug.com/62890 for justification. |
68 enum QualityOfProtection { | 68 enum QualityOfProtection { |
69 QOP_UNSPECIFIED = 0, | 69 QOP_UNSPECIFIED, |
70 QOP_AUTH = 1 << 0, | 70 QOP_AUTH, |
71 QOP_AUTH_INT = 1 << 1, | |
72 }; | 71 }; |
73 | 72 |
74 explicit HttpAuthHandlerDigest(int nonce_count); | 73 explicit HttpAuthHandlerDigest(int nonce_count); |
75 ~HttpAuthHandlerDigest(); | 74 ~HttpAuthHandlerDigest(); |
76 | 75 |
77 // Parse the challenge, saving the results into this instance. | 76 // Parse the challenge, saving the results into this instance. |
78 // Returns true on success. | 77 // Returns true on success. |
79 bool ParseChallenge(HttpAuth::ChallengeTokenizer* challenge); | 78 bool ParseChallenge(HttpAuth::ChallengeTokenizer* challenge); |
80 | 79 |
81 // Parse an individual property. Returns true on success. | 80 // Parse an individual property. Returns true on success. |
82 bool ParseChallengeProperty(const std::string& name, | 81 bool ParseChallengeProperty(const std::string& name, |
83 const std::string& value); | 82 const std::string& value); |
84 | 83 |
85 // Generates a random string, to be used for client-nonce. | 84 // Generates a random string, to be used for client-nonce. |
86 static std::string GenerateNonce(); | 85 static std::string GenerateNonce(); |
87 | 86 |
88 // Convert enum value back to string. | 87 // Convert enum value back to string. |
89 static std::string QopToString(int qop); | 88 static std::string QopToString(QualityOfProtection qop); |
90 static std::string AlgorithmToString(int algorithm); | 89 static std::string AlgorithmToString(DigestAlgorithm algorithm); |
91 | 90 |
92 // Extract the method and path of the request, as needed by | 91 // Extract the method and path of the request, as needed by |
93 // the 'A2' production. (path may be a hostname for proxy). | 92 // the 'A2' production. (path may be a hostname for proxy). |
94 void GetRequestMethodAndPath(const HttpRequestInfo* request, | 93 void GetRequestMethodAndPath(const HttpRequestInfo* request, |
95 std::string* method, | 94 std::string* method, |
96 std::string* path) const; | 95 std::string* path) const; |
97 | 96 |
98 // Build up the 'response' production. | 97 // Build up the 'response' production. |
99 std::string AssembleResponseDigest(const std::string& method, | 98 std::string AssembleResponseDigest(const std::string& method, |
100 const std::string& path, | 99 const std::string& path, |
(...skipping 14 matching lines...) Expand all Loading... |
115 static void SetFixedCnonce(bool fixed_cnonce) { | 114 static void SetFixedCnonce(bool fixed_cnonce) { |
116 fixed_cnonce_ = fixed_cnonce; | 115 fixed_cnonce_ = fixed_cnonce; |
117 } | 116 } |
118 | 117 |
119 // Information parsed from the challenge. | 118 // Information parsed from the challenge. |
120 std::string nonce_; | 119 std::string nonce_; |
121 std::string domain_; | 120 std::string domain_; |
122 std::string opaque_; | 121 std::string opaque_; |
123 bool stale_; | 122 bool stale_; |
124 DigestAlgorithm algorithm_; | 123 DigestAlgorithm algorithm_; |
125 int qop_; // Bitfield of QualityOfProtection | 124 QualityOfProtection qop_; |
126 | 125 |
127 int nonce_count_; | 126 int nonce_count_; |
128 | 127 |
129 // Forces the cnonce to be the same each time, for unit tests. | 128 // Forces the cnonce to be the same each time, for unit tests. |
130 static bool fixed_cnonce_; | 129 static bool fixed_cnonce_; |
131 }; | 130 }; |
132 | 131 |
133 } // namespace net | 132 } // namespace net |
134 | 133 |
135 #endif // NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ | 134 #endif // NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ |
OLD | NEW |