diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-06 07:18:49 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-06 07:18:49 +0000 |
commit | bc4e551b1f94caa915997d6394f44da58ec146f1 (patch) | |
tree | ec15edbeb6271797e16ab5ce5116786641fe1e46 | |
parent | 7eb83af2e35620d049902eb114fd1960f4acae69 (diff) | |
download | chromium_src-bc4e551b1f94caa915997d6394f44da58ec146f1.zip chromium_src-bc4e551b1f94caa915997d6394f44da58ec146f1.tar.gz chromium_src-bc4e551b1f94caa915997d6394f44da58ec146f1.tar.bz2 |
Cleanup: Do not use wide strings in http auth code.
BUG=23581
Review URL: https://codereview.chromium.org/83203005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239129 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/http/http_auth_gssapi_posix.cc | 6 | ||||
-rw-r--r-- | net/http/http_auth_gssapi_posix.h | 4 | ||||
-rw-r--r-- | net/http/http_auth_gssapi_posix_unittest.cc | 6 | ||||
-rw-r--r-- | net/http/http_auth_handler_negotiate.cc | 11 | ||||
-rw-r--r-- | net/http/http_auth_handler_negotiate.h | 6 | ||||
-rw-r--r-- | net/http/http_auth_handler_negotiate_unittest.cc | 20 | ||||
-rw-r--r-- | net/http/http_auth_handler_ntlm.cc | 6 | ||||
-rw-r--r-- | net/http/http_auth_handler_ntlm.h | 2 | ||||
-rw-r--r-- | net/http/http_auth_sspi_win.cc | 7 | ||||
-rw-r--r-- | net/http/http_auth_sspi_win.h | 4 | ||||
-rw-r--r-- | net/http/http_auth_sspi_win_unittest.cc | 6 |
11 files changed, 38 insertions, 40 deletions
diff --git a/net/http/http_auth_gssapi_posix.cc b/net/http/http_auth_gssapi_posix.cc index 4d7bf07..4ea4bb9 100644 --- a/net/http/http_auth_gssapi_posix.cc +++ b/net/http/http_auth_gssapi_posix.cc @@ -715,7 +715,7 @@ HttpAuth::AuthorizationResult HttpAuthGSSAPI::ParseChallenge( } int HttpAuthGSSAPI::GenerateAuthToken(const AuthCredentials* credentials, - const std::wstring& spn, + const std::string& spn, std::string* auth_token) { DCHECK(auth_token); @@ -837,12 +837,12 @@ int MapInitSecContextStatusToError(OM_uint32 major_status) { } -int HttpAuthGSSAPI::GetNextSecurityToken(const std::wstring& spn, +int HttpAuthGSSAPI::GetNextSecurityToken(const std::string& spn, gss_buffer_t in_token, gss_buffer_t out_token) { // Create a name for the principal // TODO(cbentzel): Just do this on the first pass? - std::string spn_principal = WideToASCII(spn); + std::string spn_principal = spn; gss_buffer_desc spn_buffer = GSS_C_EMPTY_BUFFER; spn_buffer.value = const_cast<char*>(spn_principal.c_str()); spn_buffer.length = spn_principal.size() + 1; diff --git a/net/http/http_auth_gssapi_posix.h b/net/http/http_auth_gssapi_posix.h index afa50a0..db603f65 100644 --- a/net/http/http_auth_gssapi_posix.h +++ b/net/http/http_auth_gssapi_posix.h @@ -251,7 +251,7 @@ class NET_EXPORT_PRIVATE HttpAuthGSSAPI { // obtained using |*credentials|. If |credentials| is NULL, the default // credentials are used instead. int GenerateAuthToken(const AuthCredentials* credentials, - const std::wstring& spn, + const std::string& spn, std::string* auth_token); // Delegation is allowed on the Kerberos ticket. This allows certain servers @@ -260,7 +260,7 @@ class NET_EXPORT_PRIVATE HttpAuthGSSAPI { void Delegate(); private: - int GetNextSecurityToken(const std::wstring& spn, + int GetNextSecurityToken(const std::string& spn, gss_buffer_t in_token, gss_buffer_t out_token); diff --git a/net/http/http_auth_gssapi_posix_unittest.cc b/net/http/http_auth_gssapi_posix_unittest.cc index 1c3d12b..48d17a3 100644 --- a/net/http/http_auth_gssapi_posix_unittest.cc +++ b/net/http/http_auth_gssapi_posix_unittest.cc @@ -202,7 +202,7 @@ TEST(HttpAuthGSSAPITest, ParseChallenge_TwoRounds) { // Generate an auth token and create another thing. EstablishInitialContext(&mock_library); std::string auth_token; - EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", + EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", &auth_token)); std::string second_challenge_text = "Negotiate Zm9vYmFy"; @@ -239,7 +239,7 @@ TEST(HttpAuthGSSAPITest, ParseChallenge_MissingTokenSecondRound) { EstablishInitialContext(&mock_library); std::string auth_token; - EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", + EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", &auth_token)); std::string second_challenge_text = "Negotiate"; HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), @@ -262,7 +262,7 @@ TEST(HttpAuthGSSAPITest, ParseChallenge_NonBase64EncodedToken) { EstablishInitialContext(&mock_library); std::string auth_token; - EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", + EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", &auth_token)); std::string second_challenge_text = "Negotiate =happyjoy="; HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), diff --git a/net/http/http_auth_handler_negotiate.cc b/net/http/http_auth_handler_negotiate.cc index 13b1069..788b067 100644 --- a/net/http/http_auth_handler_negotiate.cc +++ b/net/http/http_auth_handler_negotiate.cc @@ -7,9 +7,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/logging.h" -#include "base/strings/string_util.h" #include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" #include "net/base/address_family.h" #include "net/base/net_errors.h" #include "net/dns/host_resolver.h" @@ -114,7 +112,7 @@ HttpAuthHandlerNegotiate::HttpAuthHandlerNegotiate( HttpAuthHandlerNegotiate::~HttpAuthHandlerNegotiate() { } -std::wstring HttpAuthHandlerNegotiate::CreateSPN( +std::string HttpAuthHandlerNegotiate::CreateSPN( const AddressList& address_list, const GURL& origin) { // Kerberos Web Server SPNs are in the form HTTP/<host>:<port> through SSPI, // and in the form HTTP@<host>:<port> through GSSAPI @@ -155,11 +153,10 @@ std::wstring HttpAuthHandlerNegotiate::CreateSPN( static const char kSpnSeparator = '@'; #endif if (port != 80 && port != 443 && use_port_) { - return ASCIIToWide(base::StringPrintf("HTTP%c%s:%d", kSpnSeparator, - server.c_str(), port)); + return base::StringPrintf("HTTP%c%s:%d", kSpnSeparator, server.c_str(), + port); } else { - return ASCIIToWide(base::StringPrintf("HTTP%c%s", kSpnSeparator, - server.c_str())); + return base::StringPrintf("HTTP%c%s", kSpnSeparator, server.c_str()); } } diff --git a/net/http/http_auth_handler_negotiate.h b/net/http/http_auth_handler_negotiate.h index 6fd7aa9..d028178 100644 --- a/net/http/http_auth_handler_negotiate.h +++ b/net/http/http_auth_handler_negotiate.h @@ -102,8 +102,8 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerNegotiate : public HttpAuthHandler { virtual ~HttpAuthHandlerNegotiate(); // These are public for unit tests - std::wstring CreateSPN(const AddressList& address_list, const GURL& orign); - const std::wstring& spn() const { return spn_; } + std::string CreateSPN(const AddressList& address_list, const GURL& orign); + const std::string& spn() const { return spn_; } // HttpAuthHandler: virtual HttpAuth::AuthorizationResult HandleAnotherChallenge( @@ -152,7 +152,7 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerNegotiate : public HttpAuthHandler { bool already_called_; bool has_credentials_; AuthCredentials credentials_; - std::wstring spn_; + std::string spn_; // Things which vary each round. CompletionCallback callback_; diff --git a/net/http/http_auth_handler_negotiate_unittest.cc b/net/http/http_auth_handler_negotiate_unittest.cc index 809f58e..64521a6 100644 --- a/net/http/http_auth_handler_negotiate_unittest.cc +++ b/net/http/http_auth_handler_negotiate_unittest.cc @@ -226,9 +226,9 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) { EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, callback.callback(), &token)); #if defined(OS_WIN) - EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); + EXPECT_EQ("HTTP/alias", auth_handler->spn()); #elif defined(OS_POSIX) - EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); + EXPECT_EQ("HTTP@alias", auth_handler->spn()); #endif } @@ -244,9 +244,9 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, callback.callback(), &token)); #if defined(OS_WIN) - EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); + EXPECT_EQ("HTTP/alias", auth_handler->spn()); #elif defined(OS_POSIX) - EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); + EXPECT_EQ("HTTP@alias", auth_handler->spn()); #endif } @@ -262,9 +262,9 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, callback.callback(), &token)); #if defined(OS_WIN) - EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); + EXPECT_EQ("HTTP/alias:500", auth_handler->spn()); #elif defined(OS_POSIX) - EXPECT_EQ(L"HTTP@alias:500", auth_handler->spn()); + EXPECT_EQ("HTTP@alias:500", auth_handler->spn()); #endif } @@ -280,9 +280,9 @@ TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, callback.callback(), &token)); #if defined(OS_WIN) - EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); + EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); #elif defined(OS_POSIX) - EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); + EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); #endif } @@ -299,9 +299,9 @@ TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { NULL, &request_info, callback.callback(), &token)); EXPECT_EQ(OK, callback.WaitForResult()); #if defined(OS_WIN) - EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); + EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); #elif defined(OS_POSIX) - EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); + EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); #endif } diff --git a/net/http/http_auth_handler_ntlm.cc b/net/http/http_auth_handler_ntlm.cc index 4c04234..c0387d8 100644 --- a/net/http/http_auth_handler_ntlm.cc +++ b/net/http/http_auth_handler_ntlm.cc @@ -136,11 +136,11 @@ HttpAuth::AuthorizationResult HttpAuthHandlerNTLM::ParseChallenge( } // static -std::wstring HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { +std::string HttpAuthHandlerNTLM::CreateSPN(const GURL& origin) { // The service principal name of the destination server. See // http://msdn.microsoft.com/en-us/library/ms677949%28VS.85%29.aspx - std::wstring target(L"HTTP/"); - target.append(ASCIIToWide(GetHostAndPort(origin))); + std::string target("HTTP/"); + target.append(GetHostAndPort(origin)); return target; } diff --git a/net/http/http_auth_handler_ntlm.h b/net/http/http_auth_handler_ntlm.h index 971dd1f..98bd362 100644 --- a/net/http/http_auth_handler_ntlm.h +++ b/net/http/http_auth_handler_ntlm.h @@ -145,7 +145,7 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerNTLM : public HttpAuthHandler { uint32* out_token_len); // Create an NTLM SPN to identify the |origin| server. - static std::wstring CreateSPN(const GURL& origin); + static std::string CreateSPN(const GURL& origin); #if defined(NTLM_SSPI) HttpAuthSSPI auth_sspi_; diff --git a/net/http/http_auth_sspi_win.cc b/net/http/http_auth_sspi_win.cc index abc8050..11d64dc 100644 --- a/net/http/http_auth_sspi_win.cc +++ b/net/http/http_auth_sspi_win.cc @@ -255,7 +255,7 @@ HttpAuth::AuthorizationResult HttpAuthSSPI::ParseChallenge( } int HttpAuthSSPI::GenerateAuthToken(const AuthCredentials* credentials, - const std::wstring& spn, + const std::string& spn, std::string* auth_token) { // Initial challenge. if (!SecIsValidHandle(&cred_)) { @@ -312,7 +312,7 @@ int HttpAuthSSPI::OnFirstRound(const AuthCredentials* credentials) { } int HttpAuthSSPI::GetNextSecurityToken( - const std::wstring& spn, + const std::string& spn, const void* in_token, int in_token_len, void** out_token, @@ -362,10 +362,11 @@ int HttpAuthSSPI::GetNextSecurityToken( // This returns a token that is passed to the remote server. DWORD context_attribute; + std::wstring spn_wide = base::ASCIIToWide(spn); SECURITY_STATUS status = library_->InitializeSecurityContext( &cred_, // phCredential ctxt_ptr, // phContext - const_cast<wchar_t *>(spn.c_str()), // pszTargetName + const_cast<wchar_t *>(spn_wide.c_str()), // pszTargetName context_flags, // fContextReq 0, // Reserved1 (must be 0) SECURITY_NATIVE_DREP, // TargetDataRep diff --git a/net/http/http_auth_sspi_win.h b/net/http/http_auth_sspi_win.h index 57a3daa..bc7da46 100644 --- a/net/http/http_auth_sspi_win.h +++ b/net/http/http_auth_sspi_win.h @@ -144,7 +144,7 @@ class NET_EXPORT_PRIVATE HttpAuthSSPI { // obtained using |*credentials|. If |credentials| is NULL, the credentials // for the currently logged in user are used instead. int GenerateAuthToken(const AuthCredentials* credentials, - const std::wstring& spn, + const std::string& spn, std::string* auth_token); // Delegation is allowed on the Kerberos ticket. This allows certain servers @@ -156,7 +156,7 @@ class NET_EXPORT_PRIVATE HttpAuthSSPI { int OnFirstRound(const AuthCredentials* credentials); int GetNextSecurityToken( - const std::wstring& spn, + const std::string& spn, const void* in_token, int in_token_len, void** out_token, diff --git a/net/http/http_auth_sspi_win_unittest.cc b/net/http/http_auth_sspi_win_unittest.cc index d852137..09fe6fa 100644 --- a/net/http/http_auth_sspi_win_unittest.cc +++ b/net/http/http_auth_sspi_win_unittest.cc @@ -82,7 +82,7 @@ TEST(HttpAuthSSPITest, ParseChallenge_TwoRounds) { // Generate an auth token and create another thing. std::string auth_token; - EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", + EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", &auth_token)); std::string second_challenge_text = "Negotiate Zm9vYmFy"; @@ -118,7 +118,7 @@ TEST(HttpAuthSSPITest, ParseChallenge_MissingTokenSecondRound) { auth_sspi.ParseChallenge(&first_challenge)); std::string auth_token; - EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", + EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", &auth_token)); std::string second_challenge_text = "Negotiate"; HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), @@ -140,7 +140,7 @@ TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { auth_sspi.ParseChallenge(&first_challenge)); std::string auth_token; - EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", + EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", &auth_token)); std::string second_challenge_text = "Negotiate =happyjoy="; HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), |