OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_NTLM_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_NTLM_H_ |
6 #define NET_HTTP_HTTP_AUTH_HANDLER_NTLM_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_NTLM_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/basictypes.h" |
10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
11 #include "net/http/http_auth_handler.h" | 12 #include "net/http/http_auth_handler.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 class NTLMAuthModule; | 16 class NTLMAuthModule; |
16 | 17 |
17 // Code for handling HTTP NTLM authentication. | 18 // Code for handling HTTP NTLM authentication. |
18 class HttpAuthHandlerNTLM : public HttpAuthHandler { | 19 class HttpAuthHandlerNTLM : public HttpAuthHandler { |
19 public: | 20 public: |
| 21 // A function that generates n random bytes in the output buffer. |
| 22 typedef void (*GenerateRandomProc)(uint8* output, size_t n); |
| 23 |
| 24 // A function that returns the local host name as a null-terminated string |
| 25 // in the output buffer. Returns an empty string if the local host name is |
| 26 // not available. |
| 27 // TODO(wtc): return a std::string instead. |
| 28 typedef void (*HostNameProc)(char* name, size_t namelen); |
| 29 |
20 HttpAuthHandlerNTLM(); | 30 HttpAuthHandlerNTLM(); |
21 | 31 |
22 virtual ~HttpAuthHandlerNTLM(); | 32 virtual ~HttpAuthHandlerNTLM(); |
23 | 33 |
24 virtual bool NeedsIdentity(); | 34 virtual bool NeedsIdentity(); |
25 | 35 |
26 virtual std::string GenerateCredentials(const std::wstring& username, | 36 virtual std::string GenerateCredentials(const std::wstring& username, |
27 const std::wstring& password, | 37 const std::wstring& password, |
28 const HttpRequestInfo* request, | 38 const HttpRequestInfo* request, |
29 const ProxyInfo* proxy); | 39 const ProxyInfo* proxy); |
30 | 40 |
| 41 // For unit tests to override the GenerateRandom and GetHostName functions. |
| 42 static void SetGenerateRandomProc(GenerateRandomProc proc); |
| 43 static void SetHostNameProc(HostNameProc proc); |
| 44 |
31 protected: | 45 protected: |
32 virtual bool Init(std::string::const_iterator challenge_begin, | 46 virtual bool Init(std::string::const_iterator challenge_begin, |
33 std::string::const_iterator challenge_end) { | 47 std::string::const_iterator challenge_end) { |
34 return ParseChallenge(challenge_begin, challenge_end); | 48 return ParseChallenge(challenge_begin, challenge_end); |
35 } | 49 } |
36 | 50 |
37 private: | 51 private: |
38 // Parse the challenge, saving the results into this instance. | 52 // Parse the challenge, saving the results into this instance. |
39 // Returns true on success. | 53 // Returns true on success. |
40 bool ParseChallenge(std::string::const_iterator challenge_begin, | 54 bool ParseChallenge(std::string::const_iterator challenge_begin, |
(...skipping 10 matching lines...) Expand all Loading... |
51 scoped_ptr<NTLMAuthModule> ntlm_module_; | 65 scoped_ptr<NTLMAuthModule> ntlm_module_; |
52 | 66 |
53 // The base64-encoded string following "NTLM" in the "WWW-Authenticate" or | 67 // The base64-encoded string following "NTLM" in the "WWW-Authenticate" or |
54 // "Proxy-Authenticate" response header. | 68 // "Proxy-Authenticate" response header. |
55 std::string auth_data_; | 69 std::string auth_data_; |
56 }; | 70 }; |
57 | 71 |
58 } // namespace net | 72 } // namespace net |
59 | 73 |
60 #endif // NET_HTTP_HTTP_AUTH_HANDLER_NTLM_H_ | 74 #endif // NET_HTTP_HTTP_AUTH_HANDLER_NTLM_H_ |
OLD | NEW |