diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-11 22:21:29 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-11 22:21:29 +0000 |
commit | 385a467616a675d979514c64bda2fa5ddddb70c0 (patch) | |
tree | a50ec11679303302d305c5dffb700847ce6c93da /net/http/http_auth_handler_ntlm.cc | |
parent | 5203a4f3fc6bd8bcb2d521db09bc2625bf48c2cc (diff) | |
download | chromium_src-385a467616a675d979514c64bda2fa5ddddb70c0.zip chromium_src-385a467616a675d979514c64bda2fa5ddddb70c0.tar.gz chromium_src-385a467616a675d979514c64bda2fa5ddddb70c0.tar.bz2 |
Add unit tests for NTLM authentication. This requires
overriding the functions that generate random bytes or get
the local host name, so that the generated NTLM messages are
reproducible.
R=eroman
BUG=6567,6824
Review URL: http://codereview.chromium.org/42052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth_handler_ntlm.cc')
-rw-r--r-- | net/http/http_auth_handler_ntlm.cc | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/net/http/http_auth_handler_ntlm.cc b/net/http/http_auth_handler_ntlm.cc index 5dbec24..533b484 100644 --- a/net/http/http_auth_handler_ntlm.cc +++ b/net/http/http_auth_handler_ntlm.cc @@ -434,6 +434,25 @@ static int ParseType2Msg(const void* in_buf, uint32 in_len, Type2Msg* msg) { return OK; } +static void GenerateRandom(uint8* output, size_t n) { + for (size_t i = 0; i < n; ++i) + output[i] = base::RandInt(0, 255); +} + +static void GetHostName(char* name, size_t namelen) { + if (gethostname(name, namelen) != 0) + name[0] = '\0'; +} + +// TODO(wtc): these two function pointers should become static members of +// HttpAuthHandlerNTLM. They are file-scope static variables now so that +// GenerateType3Msg can use them without being a friend function. We should +// have HttpAuthHandlerNTLM absorb NTLMAuthModule and pass the host name and +// random bytes as input arguments to GenerateType3Msg. +static HttpAuthHandlerNTLM::GenerateRandomProc generate_random_proc_ = + GenerateRandom; +static HttpAuthHandlerNTLM::HostNameProc get_host_name_proc_ = GetHostName; + // Returns OK or a network error code. static int GenerateType3Msg(const string16& domain, const string16& username, @@ -511,9 +530,10 @@ static int GenerateType3Msg(const string16& domain, // Get workstation name (use local machine's hostname). // char host_buf[256]; // Host names are limited to 255 bytes. - if (gethostname(host_buf, sizeof(host_buf)) != 0) - return ERR_UNEXPECTED; + get_host_name_proc_(host_buf, sizeof(host_buf)); host_len = strlen(host_buf); + if (host_len == 0) + return ERR_UNEXPECTED; if (unicode) { // hostname is ASCII, so we can do a simple zero-pad expansion: ucs_host_buf.assign(host_buf, host_buf + host_len); @@ -547,10 +567,7 @@ static int GenerateType3Msg(const string16& domain, MD5Digest session_hash; uint8 temp[16]; - // TODO(wtc): Add a function that generates random bytes so we can say: - // GenerateRandom(lm_resp, 8); - for (int i = 0; i < 8; ++i) - lm_resp[i] = base::RandInt(0, 255); + generate_random_proc_(lm_resp, 8); memset(lm_resp + 8, 0, LM_RESP_LEN - 8); memcpy(temp, msg.challenge, 8); @@ -757,6 +774,16 @@ std::string HttpAuthHandlerNTLM::GenerateCredentials( return std::string("NTLM ") + encode_output; } +// static +void HttpAuthHandlerNTLM::SetGenerateRandomProc(GenerateRandomProc proc) { + generate_random_proc_ = proc; +} + +// static +void HttpAuthHandlerNTLM::SetHostNameProc(HostNameProc proc) { + get_host_name_proc_ = proc; +} + // The NTLM challenge header looks like: // WWW-Authenticate: NTLM auth-data bool HttpAuthHandlerNTLM::ParseChallenge( |