diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 16:52:20 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 16:52:20 +0000 |
commit | fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25 (patch) | |
tree | e12b53330014fbd6ab0aab857d373c2b7e65a1c6 /net/http/http_auth_handler_ntlm.h | |
parent | 16868d3c01d84271ec55efde52b2ed82c430a454 (diff) | |
download | chromium_src-fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25.zip chromium_src-fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25.tar.gz chromium_src-fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25.tar.bz2 |
Make GetHostNameProc return a std::string.
Add the ScopedProcSetter helper class so that unit tests
restore the original GenerateRandom and GetHostName
functions on completion.
Merge NTLMAuthModule into HttpAuthHandlerNTLM. The data
members domain_, username_, and password_ are moved. The
Init method is inlined at its only call site. The
GetNextToken method is moved.
Make generate_random_proc_ and get_host_name_proc_ static
members of the HttpAuthHandlerNTLM class.
R=eroman
BUG=6567,6824
Review URL: http://codereview.chromium.org/43113
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth_handler_ntlm.h')
-rw-r--r-- | net/http/http_auth_handler_ntlm.h | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/net/http/http_auth_handler_ntlm.h b/net/http/http_auth_handler_ntlm.h index 00c246a..9b8a3b1 100644 --- a/net/http/http_auth_handler_ntlm.h +++ b/net/http/http_auth_handler_ntlm.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "net/http/http_auth_handler.h" namespace net { @@ -21,11 +22,29 @@ class HttpAuthHandlerNTLM : public HttpAuthHandler { // A function that generates n random bytes in the output buffer. typedef void (*GenerateRandomProc)(uint8* output, size_t n); - // A function that returns the local host name as a null-terminated string - // in the output buffer. Returns an empty string if the local host name is - // not available. - // TODO(wtc): return a std::string instead. - typedef void (*HostNameProc)(char* name, size_t namelen); + // A function that returns the local host name. Returns an empty string if + // the local host name is not available. + typedef std::string (*HostNameProc)(); + + // For unit tests to override and restore the GenerateRandom and + // GetHostName functions. + class ScopedProcSetter { + public: + ScopedProcSetter(GenerateRandomProc random_proc, + HostNameProc host_name_proc) { + old_random_proc_ = SetGenerateRandomProc(random_proc); + old_host_name_proc_ = SetHostNameProc(host_name_proc); + } + + ~ScopedProcSetter() { + SetGenerateRandomProc(old_random_proc_); + SetHostNameProc(old_host_name_proc_); + } + + private: + GenerateRandomProc old_random_proc_; + HostNameProc old_host_name_proc_; + }; HttpAuthHandlerNTLM(); @@ -38,10 +57,6 @@ class HttpAuthHandlerNTLM : public HttpAuthHandler { const HttpRequestInfo* request, const ProxyInfo* proxy); - // For unit tests to override the GenerateRandom and GetHostName functions. - static void SetGenerateRandomProc(GenerateRandomProc proc); - static void SetHostNameProc(HostNameProc proc); - protected: virtual bool Init(std::string::const_iterator challenge_begin, std::string::const_iterator challenge_end) { @@ -49,20 +64,29 @@ class HttpAuthHandlerNTLM : public HttpAuthHandler { } private: + // For unit tests to override the GenerateRandom and GetHostName functions. + // Returns the old function. + static GenerateRandomProc SetGenerateRandomProc(GenerateRandomProc proc); + static HostNameProc SetHostNameProc(HostNameProc proc); + // Parse the challenge, saving the results into this instance. // Returns true on success. bool ParseChallenge(std::string::const_iterator challenge_begin, std::string::const_iterator challenge_end); - // The actual implementation of NTLM. - // - // TODO(wtc): This artificial separation of the NTLM auth module from the - // NTLM auth handler comes from the Mozilla code. It is due to an - // architecture constraint of Mozilla's (all crypto code must reside in the - // "PSM" component), so that the NTLM code, which does crypto, must be - // separated from the "netwerk" component. Our source tree doesn't have - // this constraint, so we may want to merge NTLMAuthModule into this class. - scoped_ptr<NTLMAuthModule> ntlm_module_; + // Given an input token received from the server, generate the next output + // token to be sent to the server. + int GetNextToken(const void* in_token, + uint32 in_token_len, + void** out_token, + uint32* out_token_len); + + static GenerateRandomProc generate_random_proc_; + static HostNameProc get_host_name_proc_; + + string16 domain_; + string16 username_; + string16 password_; // The base64-encoded string following "NTLM" in the "WWW-Authenticate" or // "Proxy-Authenticate" response header. |