| 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> |
| 10 |
| 11 #include "base/string16.h" |
| 9 #include "net/http/http_auth_handler.h" | 12 #include "net/http/http_auth_handler.h" |
| 10 #include "net/http/http_auth_handler_factory.h" | 13 #include "net/http/http_auth_handler_factory.h" |
| 11 | 14 |
| 12 // This is needed for the FRIEND_TEST() macro. | 15 // This is needed for the FRIEND_TEST() macro. |
| 13 #include "testing/gtest/include/gtest/gtest_prod.h" | 16 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 14 | 17 |
| 15 namespace net { | 18 namespace net { |
| 16 | 19 |
| 17 // Code for handling http digest authentication. | 20 // Code for handling http digest authentication. |
| 18 class HttpAuthHandlerDigest : public HttpAuthHandler { | 21 class HttpAuthHandlerDigest : public HttpAuthHandler { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 int digest_nonce_count, | 32 int digest_nonce_count, |
| 30 const BoundNetLog& net_log, | 33 const BoundNetLog& net_log, |
| 31 scoped_ptr<HttpAuthHandler>* handler); | 34 scoped_ptr<HttpAuthHandler>* handler); |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 protected: | 37 protected: |
| 35 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) { | 38 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) { |
| 36 return ParseChallenge(challenge); | 39 return ParseChallenge(challenge); |
| 37 } | 40 } |
| 38 | 41 |
| 39 virtual int GenerateAuthTokenImpl(const std::wstring* username, | 42 virtual int GenerateAuthTokenImpl(const string16* username, |
| 40 const std::wstring* password, | 43 const string16* password, |
| 41 const HttpRequestInfo* request, | 44 const HttpRequestInfo* request, |
| 42 CompletionCallback* callback, | 45 CompletionCallback* callback, |
| 43 std::string* auth_token); | 46 std::string* auth_token); |
| 44 | 47 |
| 45 private: | 48 private: |
| 46 FRIEND_TEST(HttpAuthHandlerDigestTest, ParseChallenge); | 49 FRIEND_TEST(HttpAuthHandlerDigestTest, ParseChallenge); |
| 47 FRIEND_TEST(HttpAuthHandlerDigestTest, AssembleCredentials); | 50 FRIEND_TEST(HttpAuthHandlerDigestTest, AssembleCredentials); |
| 48 FRIEND_TEST(HttpNetworkTransactionTest, DigestPreAuthNonceCount); | 51 FRIEND_TEST(HttpNetworkTransactionTest, DigestPreAuthNonceCount); |
| 49 | 52 |
| 50 // Possible values for the "algorithm" property. | 53 // Possible values for the "algorithm" property. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 93 |
| 91 // Extract the method and path of the request, as needed by | 94 // Extract the method and path of the request, as needed by |
| 92 // the 'A2' production. (path may be a hostname for proxy). | 95 // the 'A2' production. (path may be a hostname for proxy). |
| 93 void GetRequestMethodAndPath(const HttpRequestInfo* request, | 96 void GetRequestMethodAndPath(const HttpRequestInfo* request, |
| 94 std::string* method, | 97 std::string* method, |
| 95 std::string* path) const; | 98 std::string* path) const; |
| 96 | 99 |
| 97 // Build up the 'response' production. | 100 // Build up the 'response' production. |
| 98 std::string AssembleResponseDigest(const std::string& method, | 101 std::string AssembleResponseDigest(const std::string& method, |
| 99 const std::string& path, | 102 const std::string& path, |
| 100 const std::string& username, | 103 const string16& username, |
| 101 const std::string& password, | 104 const string16& password, |
| 102 const std::string& cnonce, | 105 const std::string& cnonce, |
| 103 const std::string& nc) const; | 106 const std::string& nc) const; |
| 104 | 107 |
| 105 // Build up the value for (Authorization/Proxy-Authorization). | 108 // Build up the value for (Authorization/Proxy-Authorization). |
| 106 std::string AssembleCredentials(const std::string& method, | 109 std::string AssembleCredentials(const std::string& method, |
| 107 const std::string& path, | 110 const std::string& path, |
| 108 const std::string& username, | 111 const string16& username, |
| 109 const std::string& password, | 112 const string16& password, |
| 110 const std::string& cnonce, | 113 const std::string& cnonce, |
| 111 int nonce_count) const; | 114 int nonce_count) const; |
| 112 | 115 |
| 113 // Forces cnonce to be the same each time. This is used for unit tests. | 116 // Forces cnonce to be the same each time. This is used for unit tests. |
| 114 static void SetFixedCnonce(bool fixed_cnonce) { | 117 static void SetFixedCnonce(bool fixed_cnonce) { |
| 115 fixed_cnonce_ = fixed_cnonce; | 118 fixed_cnonce_ = fixed_cnonce; |
| 116 } | 119 } |
| 117 | 120 |
| 118 // Information parsed from the challenge. | 121 // Information parsed from the challenge. |
| 119 std::string nonce_; | 122 std::string nonce_; |
| 120 std::string domain_; | 123 std::string domain_; |
| 121 std::string opaque_; | 124 std::string opaque_; |
| 122 bool stale_; | 125 bool stale_; |
| 123 DigestAlgorithm algorithm_; | 126 DigestAlgorithm algorithm_; |
| 124 int qop_; // Bitfield of QualityOfProtection | 127 int qop_; // Bitfield of QualityOfProtection |
| 125 | 128 |
| 126 int nonce_count_; | 129 int nonce_count_; |
| 127 | 130 |
| 128 // Forces the cnonce to be the same each time, for unit tests. | 131 // Forces the cnonce to be the same each time, for unit tests. |
| 129 static bool fixed_cnonce_; | 132 static bool fixed_cnonce_; |
| 130 }; | 133 }; |
| 131 | 134 |
| 132 } // namespace net | 135 } // namespace net |
| 133 | 136 |
| 134 #endif // NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ | 137 #endif // NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ |
| OLD | NEW |