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 #include "net/http/http_auth_handler_digest.h" | 5 #include "net/http/http_auth_handler_digest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/md5.h" | 10 #include "base/md5.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 handler->swap(tmp_handler); | 106 handler->swap(tmp_handler); |
107 return OK; | 107 return OK; |
108 } | 108 } |
109 | 109 |
110 HttpAuth::AuthorizationResult HttpAuthHandlerDigest::HandleAnotherChallenge( | 110 HttpAuth::AuthorizationResult HttpAuthHandlerDigest::HandleAnotherChallenge( |
111 HttpAuthChallengeTokenizer* challenge) { | 111 HttpAuthChallengeTokenizer* challenge) { |
112 // Even though Digest is not connection based, a "second round" is parsed | 112 // Even though Digest is not connection based, a "second round" is parsed |
113 // to differentiate between stale and rejected responses. | 113 // to differentiate between stale and rejected responses. |
114 // Note that the state of the current handler is not mutated - this way if | 114 // Note that the state of the current handler is not mutated - this way if |
115 // there is a rejection the realm hasn't changed. | 115 // there is a rejection the realm hasn't changed. |
116 if (!base::LowerCaseEqualsASCII(challenge->scheme(), "digest")) | 116 if (!base::LowerCaseEqualsASCII(challenge->scheme(), kDigestAuthScheme)) |
117 return HttpAuth::AUTHORIZATION_RESULT_INVALID; | 117 return HttpAuth::AUTHORIZATION_RESULT_INVALID; |
118 | 118 |
119 HttpUtil::NameValuePairsIterator parameters = challenge->param_pairs(); | 119 HttpUtil::NameValuePairsIterator parameters = challenge->param_pairs(); |
120 | 120 |
121 // Try to find the "stale" value, and also keep track of the realm | 121 // Try to find the "stale" value, and also keep track of the realm |
122 // for the new challenge. | 122 // for the new challenge. |
123 std::string original_realm; | 123 std::string original_realm; |
124 while (parameters.GetNext()) { | 124 while (parameters.GetNext()) { |
125 if (base::LowerCaseEqualsASCII(parameters.name(), "stale")) { | 125 if (base::LowerCaseEqualsASCII(parameters.name(), "stale")) { |
126 if (base::LowerCaseEqualsASCII(parameters.value(), "true")) | 126 if (base::LowerCaseEqualsASCII(parameters.value(), "true")) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 score_ = 2; | 192 score_ = 2; |
193 properties_ = ENCRYPTS_IDENTITY; | 193 properties_ = ENCRYPTS_IDENTITY; |
194 | 194 |
195 // Initialize to defaults. | 195 // Initialize to defaults. |
196 stale_ = false; | 196 stale_ = false; |
197 algorithm_ = ALGORITHM_UNSPECIFIED; | 197 algorithm_ = ALGORITHM_UNSPECIFIED; |
198 qop_ = QOP_UNSPECIFIED; | 198 qop_ = QOP_UNSPECIFIED; |
199 realm_ = original_realm_ = nonce_ = domain_ = opaque_ = std::string(); | 199 realm_ = original_realm_ = nonce_ = domain_ = opaque_ = std::string(); |
200 | 200 |
201 // FAIL -- Couldn't match auth-scheme. | 201 // FAIL -- Couldn't match auth-scheme. |
202 if (!base::LowerCaseEqualsASCII(challenge->scheme(), "digest")) | 202 if (!base::LowerCaseEqualsASCII(challenge->scheme(), kDigestAuthScheme)) |
203 return false; | 203 return false; |
204 | 204 |
205 HttpUtil::NameValuePairsIterator parameters = challenge->param_pairs(); | 205 HttpUtil::NameValuePairsIterator parameters = challenge->param_pairs(); |
206 | 206 |
207 // Loop through all the properties. | 207 // Loop through all the properties. |
208 while (parameters.GetNext()) { | 208 while (parameters.GetNext()) { |
209 // FAIL -- couldn't parse a property. | 209 // FAIL -- couldn't parse a property. |
210 if (!ParseChallengeProperty(parameters.name(), | 210 if (!ParseChallengeProperty(parameters.name(), |
211 parameters.value())) | 211 parameters.value())) |
212 return false; | 212 return false; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 // TODO(eroman): Supposedly IIS server requires quotes surrounding qop. | 374 // TODO(eroman): Supposedly IIS server requires quotes surrounding qop. |
375 authorization += ", qop=" + QopToString(qop_); | 375 authorization += ", qop=" + QopToString(qop_); |
376 authorization += ", nc=" + nc; | 376 authorization += ", nc=" + nc; |
377 authorization += ", cnonce=" + HttpUtil::Quote(cnonce); | 377 authorization += ", cnonce=" + HttpUtil::Quote(cnonce); |
378 } | 378 } |
379 | 379 |
380 return authorization; | 380 return authorization; |
381 } | 381 } |
382 | 382 |
383 } // namespace net | 383 } // namespace net |
OLD | NEW |