| File: | root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp |
| Warning: | line 957, column 7 Value stored to 'identFromURI' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | // HttpLog.h should generally be included first |
| 6 | #include "nsHttpChannelAuthProvider.h" |
| 7 | |
| 8 | #include "HttpLog.h" |
| 9 | #include "MockHttpAuth.h" |
| 10 | #include "mozilla/BasePrincipal.h" |
| 11 | #include "mozilla/Components.h" |
| 12 | #include "mozilla/StoragePrincipalHelper.h" |
| 13 | #include "mozilla/Tokenizer.h" |
| 14 | #include "netCore.h" |
| 15 | #include "nsAuthInformationHolder.h" |
| 16 | #include "nsCRT.h" |
| 17 | #include "nsContentUtils.h" |
| 18 | #include "nsEscape.h" |
| 19 | #include "nsHttp.h" |
| 20 | #include "nsHttpBasicAuth.h" |
| 21 | #include "nsHttpDigestAuth.h" |
| 22 | #include "nsHttpHandler.h" |
| 23 | #include "nsIAuthPrompt2.h" |
| 24 | #include "nsIAuthPromptProvider.h" |
| 25 | #include "nsIHttpAuthenticableChannel.h" |
| 26 | #include "nsIHttpAuthenticator.h" |
| 27 | #include "nsIHttpChannelInternal.h" |
| 28 | #include "nsIInterfaceRequestor.h" |
| 29 | #include "nsIInterfaceRequestorUtils.h" |
| 30 | #include "nsIPromptService.h" |
| 31 | #include "nsIStringBundle.h" |
| 32 | #include "nsIURI.h" |
| 33 | #include "nsNetUtil.h" |
| 34 | #ifdef MOZ_AUTH_EXTENSION1 |
| 35 | # include "nsHttpNegotiateAuth.h" |
| 36 | #endif |
| 37 | #include "mozilla/StaticPrefs_network.h" |
| 38 | #include "mozilla/StaticPrefs_prompts.h" |
| 39 | #include "nsHttpNTLMAuth.h" |
| 40 | #include "nsIProxiedChannel.h" |
| 41 | #include "nsIProxyInfo.h" |
| 42 | #include "nsIURL.h" |
| 43 | #include "nsServiceManagerUtils.h" |
| 44 | |
| 45 | namespace mozilla::net { |
| 46 | |
| 47 | #define SUBRESOURCE_AUTH_DIALOG_DISALLOW_ALL0 0 |
| 48 | #define SUBRESOURCE_AUTH_DIALOG_DISALLOW_CROSS_ORIGIN1 1 |
| 49 | #define SUBRESOURCE_AUTH_DIALOG_ALLOW_ALL2 2 |
| 50 | |
| 51 | #define MAX_DISPLAYED_USER_LENGTH64 64 |
| 52 | #define MAX_DISPLAYED_HOST_LENGTH64 64 |
| 53 | |
| 54 | static void GetOriginAttributesSuffix(nsIChannel* aChan, nsACString& aSuffix) { |
| 55 | OriginAttributes oa; |
| 56 | |
| 57 | // Deliberately ignoring the result and going with defaults |
| 58 | if (aChan) { |
| 59 | StoragePrincipalHelper::GetOriginAttributesForNetworkState(aChan, oa); |
| 60 | } |
| 61 | |
| 62 | oa.CreateSuffix(aSuffix); |
| 63 | } |
| 64 | |
| 65 | nsHttpChannelAuthProvider::nsHttpChannelAuthProvider() |
| 66 | : mProxyAuth(false), |
| 67 | mTriedProxyAuth(false), |
| 68 | mTriedHostAuth(false), |
| 69 | mCrossOrigin(false), |
| 70 | mConnectionBased(false), |
| 71 | mHttpHandler(gHttpHandler) {} |
| 72 | |
| 73 | nsHttpChannelAuthProvider::~nsHttpChannelAuthProvider() { |
| 74 | MOZ_RELEASE_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()" , "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 74); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence(__null, 74); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 75 | MOZ_ASSERT(!mAuthChannel, "Disconnect wasn't called")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mAuthChannel)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mAuthChannel))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mAuthChannel" " (" "Disconnect wasn't called" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 75); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mAuthChannel" ") (" "Disconnect wasn't called" ")"); do { MOZ_CrashSequence (__null, 75); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 76 | } |
| 77 | |
| 78 | NS_IMETHODIMPnsresult |
| 79 | nsHttpChannelAuthProvider::Init(nsIHttpAuthenticableChannel* channel) { |
| 80 | MOZ_ASSERT(channel, "channel expected!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(channel)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(channel))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("channel" " (" "channel expected!" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 80); AnnotateMozCrashReason("MOZ_ASSERT" "(" "channel" ") (" "channel expected!" ")"); do { MOZ_CrashSequence(__null, 80) ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 81 | |
| 82 | mAuthChannel = channel; |
| 83 | |
| 84 | nsresult rv = mAuthChannel->GetURI(getter_AddRefs(mURI)); |
| 85 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 86 | |
| 87 | rv = mAuthChannel->GetIsSSL(&mUsingSSL); |
| 88 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 89 | |
| 90 | nsCOMPtr<nsIProxiedChannel> proxied(channel); |
| 91 | if (proxied) { |
| 92 | nsCOMPtr<nsIProxyInfo> pi; |
| 93 | rv = proxied->GetProxyInfo(getter_AddRefs(pi)); |
| 94 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 95 | |
| 96 | if (pi) { |
| 97 | nsAutoCString proxyType; |
| 98 | rv = pi->GetType(proxyType); |
| 99 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 100 | |
| 101 | mProxyUsingSSL = proxyType.EqualsLiteral("https"); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | rv = mURI->GetAsciiHost(mHost); |
| 106 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 107 | |
| 108 | // reject the URL if it doesn't specify a host |
| 109 | if (mHost.IsEmpty()) return NS_ERROR_MALFORMED_URI; |
| 110 | |
| 111 | rv = mURI->GetPort(&mPort); |
| 112 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 113 | |
| 114 | nsCOMPtr<nsIChannel> bareChannel = do_QueryInterface(channel); |
| 115 | mIsPrivate = NS_UsePrivateBrowsing(bareChannel); |
| 116 | |
| 117 | return NS_OK; |
| 118 | } |
| 119 | |
| 120 | NS_IMETHODIMPnsresult |
| 121 | nsHttpChannelAuthProvider::ProcessAuthentication(uint32_t httpStatus, |
| 122 | bool SSLConnectFailed) { |
| 123 | LOG(do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::ProcessAuthentication " "[this=%p channel=%p code=%u SSLConnectFailed=%d]\n", this, mAuthChannel , httpStatus, SSLConnectFailed); } } while (0) |
| 124 | ("nsHttpChannelAuthProvider::ProcessAuthentication "do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::ProcessAuthentication " "[this=%p channel=%p code=%u SSLConnectFailed=%d]\n", this, mAuthChannel , httpStatus, SSLConnectFailed); } } while (0) |
| 125 | "[this=%p channel=%p code=%u SSLConnectFailed=%d]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::ProcessAuthentication " "[this=%p channel=%p code=%u SSLConnectFailed=%d]\n", this, mAuthChannel , httpStatus, SSLConnectFailed); } } while (0) |
| 126 | this, mAuthChannel, httpStatus, SSLConnectFailed))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::ProcessAuthentication " "[this=%p channel=%p code=%u SSLConnectFailed=%d]\n", this, mAuthChannel , httpStatus, SSLConnectFailed); } } while (0); |
| 127 | |
| 128 | MOZ_ASSERT(mAuthChannel, "Channel not initialized")do { static_assert( mozilla::detail::AssertionConditionType< decltype(mAuthChannel)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mAuthChannel))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mAuthChannel" " (" "Channel not initialized" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 128); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAuthChannel" ") (" "Channel not initialized" ")"); do { MOZ_CrashSequence (__null, 128); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 129 | |
| 130 | nsCOMPtr<nsIProxyInfo> proxyInfo; |
| 131 | nsresult rv = mAuthChannel->GetProxyInfo(getter_AddRefs(proxyInfo)); |
| 132 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 133 | if (proxyInfo) { |
| 134 | mProxyInfo = do_QueryInterface(proxyInfo); |
| 135 | if (!mProxyInfo) return NS_ERROR_NO_INTERFACE; |
| 136 | } |
| 137 | |
| 138 | nsAutoCString challenges; |
| 139 | mProxyAuth = (httpStatus == 407); |
| 140 | |
| 141 | rv = PrepareForAuthentication(mProxyAuth); |
| 142 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 143 | |
| 144 | if (mProxyAuth) { |
| 145 | // only allow a proxy challenge if we have a proxy server configured. |
| 146 | // otherwise, we could inadvertently expose the user's proxy |
| 147 | // credentials to an origin server. We could attempt to proceed as |
| 148 | // if we had received a 401 from the server, but why risk flirting |
| 149 | // with trouble? IE similarly rejects 407s when a proxy server is |
| 150 | // not configured, so there's no reason not to do the same. |
| 151 | if (!UsingHttpProxy()) { |
| 152 | LOG(("rejecting 407 when proxy server not configured!\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "rejecting 407 when proxy server not configured!\n" ); } } while (0); |
| 153 | return NS_ERROR_UNEXPECTED; |
| 154 | } |
| 155 | if (UsingSSL() && !SSLConnectFailed) { |
| 156 | // we need to verify that this challenge came from the proxy |
| 157 | // server itself, and not some server on the other side of the |
| 158 | // SSL tunnel. |
| 159 | LOG(("rejecting 407 from origin server!\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "rejecting 407 from origin server!\n" ); } } while (0); |
| 160 | return NS_ERROR_UNEXPECTED; |
| 161 | } |
| 162 | rv = mAuthChannel->GetProxyChallenges(challenges); |
| 163 | } else { |
| 164 | rv = mAuthChannel->GetWWWChallenges(challenges); |
| 165 | } |
| 166 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 167 | |
| 168 | nsAutoCString creds; |
| 169 | rv = GetCredentials(challenges, mProxyAuth, creds); |
| 170 | if (rv == NS_ERROR_IN_PROGRESS || rv == NS_ERROR_BASIC_HTTP_AUTH_DISABLED) { |
| 171 | return rv; |
| 172 | } |
| 173 | |
| 174 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 175 | LOG(("unable to authenticate\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "unable to authenticate\n" ); } } while (0); |
| 176 | } else { |
| 177 | // set the authentication credentials |
| 178 | if (mProxyAuth) { |
| 179 | rv = mAuthChannel->SetProxyCredentials(creds); |
| 180 | } else { |
| 181 | rv = mAuthChannel->SetWWWCredentials(creds); |
| 182 | } |
| 183 | } |
| 184 | return rv; |
| 185 | } |
| 186 | |
| 187 | NS_IMETHODIMPnsresult |
| 188 | nsHttpChannelAuthProvider::AddAuthorizationHeaders( |
| 189 | bool aDontUseCachedWWWCreds) { |
| 190 | LOG(do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::AddAuthorizationHeaders? " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 191 | ("nsHttpChannelAuthProvider::AddAuthorizationHeaders? "do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::AddAuthorizationHeaders? " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 192 | "[this=%p channel=%p]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::AddAuthorizationHeaders? " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 193 | this, mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::AddAuthorizationHeaders? " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0); |
| 194 | |
| 195 | MOZ_ASSERT(mAuthChannel, "Channel not initialized")do { static_assert( mozilla::detail::AssertionConditionType< decltype(mAuthChannel)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mAuthChannel))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mAuthChannel" " (" "Channel not initialized" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 195); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAuthChannel" ") (" "Channel not initialized" ")"); do { MOZ_CrashSequence (__null, 195); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 196 | |
| 197 | nsCOMPtr<nsIProxyInfo> proxyInfo; |
| 198 | nsresult rv = mAuthChannel->GetProxyInfo(getter_AddRefs(proxyInfo)); |
| 199 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 200 | if (proxyInfo) { |
| 201 | mProxyInfo = do_QueryInterface(proxyInfo); |
| 202 | if (!mProxyInfo) return NS_ERROR_NO_INTERFACE; |
| 203 | } |
| 204 | |
| 205 | uint32_t loadFlags; |
| 206 | rv = mAuthChannel->GetLoadFlags(&loadFlags); |
| 207 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 208 | |
| 209 | // this getter never fails |
| 210 | nsHttpAuthCache* authCache = gHttpHandler->AuthCache(mIsPrivate); |
| 211 | |
| 212 | // check if proxy credentials should be sent |
| 213 | if (!ProxyHost().IsEmpty() && UsingHttpProxy()) { |
| 214 | SetAuthorizationHeader(authCache, nsHttp::Proxy_Authorization, "http"_ns, |
| 215 | ProxyHost(), ProxyPort(), |
| 216 | ""_ns, // proxy has no path |
| 217 | mProxyIdent); |
| 218 | } |
| 219 | |
| 220 | if (loadFlags & nsIRequest::LOAD_ANONYMOUS) { |
| 221 | LOG(("Skipping Authorization header for anonymous load\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Skipping Authorization header for anonymous load\n" ); } } while (0); |
| 222 | return NS_OK; |
| 223 | } |
| 224 | |
| 225 | if (aDontUseCachedWWWCreds) { |
| 226 | LOG(do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Authorization header already present:" " skipping adding auth header from cache\n"); } } while (0) |
| 227 | ("Authorization header already present:"do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Authorization header already present:" " skipping adding auth header from cache\n"); } } while (0) |
| 228 | " skipping adding auth header from cache\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Authorization header already present:" " skipping adding auth header from cache\n"); } } while (0); |
| 229 | return NS_OK; |
| 230 | } |
| 231 | |
| 232 | // check if server credentials should be sent |
| 233 | nsAutoCString path, scheme; |
| 234 | if (NS_SUCCEEDED(GetCurrentPath(path))((bool)(__builtin_expect(!!(!NS_FAILED_impl(GetCurrentPath(path ))), 1))) && |
| 235 | NS_SUCCEEDED(mURI->GetScheme(scheme))((bool)(__builtin_expect(!!(!NS_FAILED_impl(mURI->GetScheme (scheme))), 1)))) { |
| 236 | SetAuthorizationHeader(authCache, nsHttp::Authorization, scheme, Host(), |
| 237 | Port(), path, mIdent); |
| 238 | } |
| 239 | |
| 240 | return NS_OK; |
| 241 | } |
| 242 | |
| 243 | NS_IMETHODIMPnsresult |
| 244 | nsHttpChannelAuthProvider::Cancel(nsresult status) { |
| 245 | MOZ_ASSERT(mAuthChannel, "Channel not initialized")do { static_assert( mozilla::detail::AssertionConditionType< decltype(mAuthChannel)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mAuthChannel))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mAuthChannel" " (" "Channel not initialized" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 245); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAuthChannel" ") (" "Channel not initialized" ")"); do { MOZ_CrashSequence (__null, 245); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 246 | |
| 247 | if (mAsyncPromptAuthCancelable) { |
| 248 | mAsyncPromptAuthCancelable->Cancel(status); |
| 249 | mAsyncPromptAuthCancelable = nullptr; |
| 250 | } |
| 251 | |
| 252 | if (mGenerateCredentialsCancelable) { |
| 253 | mGenerateCredentialsCancelable->Cancel(status); |
| 254 | mGenerateCredentialsCancelable = nullptr; |
| 255 | } |
| 256 | return NS_OK; |
| 257 | } |
| 258 | |
| 259 | NS_IMETHODIMPnsresult |
| 260 | nsHttpChannelAuthProvider::Disconnect(nsresult status) { |
| 261 | mAuthChannel = nullptr; |
| 262 | |
| 263 | if (mAsyncPromptAuthCancelable) { |
| 264 | mAsyncPromptAuthCancelable->Cancel(status); |
| 265 | mAsyncPromptAuthCancelable = nullptr; |
| 266 | } |
| 267 | |
| 268 | if (mGenerateCredentialsCancelable) { |
| 269 | mGenerateCredentialsCancelable->Cancel(status); |
| 270 | mGenerateCredentialsCancelable = nullptr; |
| 271 | } |
| 272 | |
| 273 | NS_IF_RELEASE(mProxyAuthContinuationState)do { if (mProxyAuthContinuationState) { (mProxyAuthContinuationState )->Release(); (mProxyAuthContinuationState) = 0; } } while (0); |
| 274 | NS_IF_RELEASE(mAuthContinuationState)do { if (mAuthContinuationState) { (mAuthContinuationState)-> Release(); (mAuthContinuationState) = 0; } } while (0); |
| 275 | |
| 276 | return NS_OK; |
| 277 | } |
| 278 | |
| 279 | // helper function for getting an auth prompt from an interface requestor |
| 280 | static void GetAuthPrompt(nsIInterfaceRequestor* ifreq, bool proxyAuth, |
| 281 | nsIAuthPrompt2** result) { |
| 282 | if (!ifreq) return; |
| 283 | |
| 284 | uint32_t promptReason; |
| 285 | if (proxyAuth) { |
| 286 | promptReason = nsIAuthPromptProvider::PROMPT_PROXY; |
| 287 | } else { |
| 288 | promptReason = nsIAuthPromptProvider::PROMPT_NORMAL; |
| 289 | } |
| 290 | |
| 291 | nsCOMPtr<nsIAuthPromptProvider> promptProvider = do_GetInterface(ifreq); |
| 292 | if (promptProvider) { |
| 293 | promptProvider->GetAuthPrompt(promptReason, NS_GET_IID(nsIAuthPrompt2)(nsIAuthPrompt2::kIID), |
| 294 | reinterpret_cast<void**>(result)); |
| 295 | } else { |
| 296 | NS_QueryAuthPrompt2(ifreq, result); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | // generate credentials for the given challenge, and update the auth cache. |
| 301 | nsresult nsHttpChannelAuthProvider::GenCredsAndSetEntry( |
| 302 | nsIHttpAuthenticator* auth, bool proxyAuth, const nsACString& scheme, |
| 303 | const nsACString& host, int32_t port, const nsACString& directory, |
| 304 | const nsACString& realm, const nsACString& challenge, |
| 305 | const nsHttpAuthIdentity& ident, nsCOMPtr<nsISupports>& sessionState, |
| 306 | nsACString& result) { |
| 307 | nsresult rv; |
| 308 | nsISupports* ss = sessionState; |
| 309 | |
| 310 | // set informations that depend on whether |
| 311 | // we're authenticating against a proxy |
| 312 | // or a webserver |
| 313 | nsISupports** continuationState; |
| 314 | |
| 315 | if (proxyAuth) { |
| 316 | continuationState = &mProxyAuthContinuationState; |
| 317 | } else { |
| 318 | continuationState = &mAuthContinuationState; |
| 319 | } |
| 320 | |
| 321 | rv = auth->GenerateCredentialsAsync( |
| 322 | mAuthChannel, this, challenge, proxyAuth, ident.Domain(), ident.User(), |
| 323 | ident.Password(), ss, *continuationState, |
| 324 | getter_AddRefs(mGenerateCredentialsCancelable)); |
| 325 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 326 | // Calling generate credentials async, results will be dispatched to the |
| 327 | // main thread by calling OnCredsGenerated method |
| 328 | return NS_ERROR_IN_PROGRESS; |
| 329 | } |
| 330 | |
| 331 | uint32_t generateFlags; |
| 332 | rv = auth->GenerateCredentials( |
| 333 | mAuthChannel, challenge, proxyAuth, ident.Domain(), ident.User(), |
| 334 | ident.Password(), &ss, &*continuationState, &generateFlags, result); |
| 335 | |
| 336 | sessionState.swap(ss); |
| 337 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 338 | |
| 339 | // don't log this in release build since it could contain sensitive info. |
| 340 | #ifdef DEBUG1 |
| 341 | LOG(("generated creds: %s\n", PromiseFlatCString(result).get()))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "generated creds: %s\n" , TPromiseFlatString<char>(result).get()); } } while (0 ); |
| 342 | #endif |
| 343 | |
| 344 | return UpdateCache(auth, scheme, host, port, directory, realm, challenge, |
| 345 | ident, result, generateFlags, sessionState, proxyAuth); |
| 346 | } |
| 347 | |
| 348 | nsresult nsHttpChannelAuthProvider::UpdateCache( |
| 349 | nsIHttpAuthenticator* auth, const nsACString& scheme, |
| 350 | const nsACString& host, int32_t port, const nsACString& directory, |
| 351 | const nsACString& realm, const nsACString& challenge, |
| 352 | const nsHttpAuthIdentity& ident, const nsACString& creds, |
| 353 | uint32_t generateFlags, nsISupports* sessionState, bool aProxyAuth) { |
| 354 | nsresult rv; |
| 355 | |
| 356 | uint32_t authFlags; |
| 357 | rv = auth->GetAuthFlags(&authFlags); |
| 358 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 359 | |
| 360 | // find out if this authenticator allows reuse of credentials and/or |
| 361 | // challenge. |
| 362 | bool saveCreds = |
| 363 | 0 != (authFlags & nsIHttpAuthenticator::REUSABLE_CREDENTIALS); |
| 364 | bool saveChallenge = |
| 365 | 0 != (authFlags & nsIHttpAuthenticator::REUSABLE_CHALLENGE); |
| 366 | |
| 367 | bool saveIdentity = |
| 368 | 0 == (generateFlags & nsIHttpAuthenticator::USING_INTERNAL_IDENTITY); |
| 369 | |
| 370 | // this getter never fails |
| 371 | nsHttpAuthCache* authCache = gHttpHandler->AuthCache(mIsPrivate); |
| 372 | |
| 373 | nsAutoCString suffix; |
| 374 | if (!aProxyAuth) { |
| 375 | // We don't isolate proxy credentials cache entries with the origin suffix |
| 376 | // as it would only annoy users with authentication dialogs popping up. |
| 377 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 378 | GetOriginAttributesSuffix(chan, suffix); |
| 379 | } |
| 380 | |
| 381 | // create a cache entry. we do this even though we don't yet know that |
| 382 | // these credentials are valid b/c we need to avoid prompting the user |
| 383 | // more than once in case the credentials are valid. |
| 384 | // |
| 385 | // if the credentials are not reusable, then we don't bother sticking |
| 386 | // them in the auth cache. |
| 387 | rv = authCache->SetAuthEntry(scheme, host, port, directory, realm, |
| 388 | saveCreds ? creds : ""_ns, |
| 389 | saveChallenge ? challenge : ""_ns, suffix, |
| 390 | saveIdentity ? &ident : nullptr, sessionState); |
| 391 | return rv; |
| 392 | } |
| 393 | |
| 394 | NS_IMETHODIMPnsresult nsHttpChannelAuthProvider::ClearProxyIdent() { |
| 395 | LOG(("nsHttpChannelAuthProvider::ClearProxyIdent [this=%p]\n", this))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::ClearProxyIdent [this=%p]\n" , this); } } while (0); |
| 396 | |
| 397 | mProxyIdent.Clear(); |
| 398 | return NS_OK; |
| 399 | } |
| 400 | |
| 401 | nsresult nsHttpChannelAuthProvider::PrepareForAuthentication(bool proxyAuth) { |
| 402 | LOG(do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::PrepareForAuthentication " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 403 | ("nsHttpChannelAuthProvider::PrepareForAuthentication "do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::PrepareForAuthentication " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 404 | "[this=%p channel=%p]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::PrepareForAuthentication " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 405 | this, mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::PrepareForAuthentication " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0); |
| 406 | |
| 407 | if (!proxyAuth) { |
| 408 | // reset the current proxy continuation state because our last |
| 409 | // authentication attempt was completed successfully. |
| 410 | NS_IF_RELEASE(mProxyAuthContinuationState)do { if (mProxyAuthContinuationState) { (mProxyAuthContinuationState )->Release(); (mProxyAuthContinuationState) = 0; } } while (0); |
| 411 | LOG((" proxy continuation state has been reset"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " proxy continuation state has been reset" ); } } while (0); |
| 412 | } |
| 413 | |
| 414 | if (!UsingHttpProxy() || mProxyAuthType.IsEmpty()) return NS_OK; |
| 415 | |
| 416 | // We need to remove any Proxy_Authorization header left over from a |
| 417 | // non-request based authentication handshake (e.g., for NTLM auth). |
| 418 | |
| 419 | nsresult rv; |
| 420 | nsCOMPtr<nsIHttpAuthenticator> precedingAuth; |
| 421 | nsCString proxyAuthType; |
| 422 | rv = GetAuthenticator(mProxyAuthType, proxyAuthType, |
| 423 | getter_AddRefs(precedingAuth)); |
| 424 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 425 | |
| 426 | uint32_t precedingAuthFlags; |
| 427 | rv = precedingAuth->GetAuthFlags(&precedingAuthFlags); |
| 428 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 429 | |
| 430 | if (!(precedingAuthFlags & nsIHttpAuthenticator::REQUEST_BASED)) { |
| 431 | nsAutoCString challenges; |
| 432 | rv = mAuthChannel->GetProxyChallenges(challenges); |
| 433 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 434 | // delete the proxy authorization header because we weren't |
| 435 | // asked to authenticate |
| 436 | rv = mAuthChannel->SetProxyCredentials(""_ns); |
| 437 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 438 | LOG((" cleared proxy authorization header"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " cleared proxy authorization header" ); } } while (0); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | return NS_OK; |
| 443 | } |
| 444 | |
| 445 | class MOZ_STACK_CLASS ChallengeParser final : Tokenizer { |
| 446 | public: |
| 447 | explicit ChallengeParser(const nsACString& aChallenges) |
| 448 | : Tokenizer(aChallenges, nullptr, "") { |
| 449 | Record(); |
| 450 | } |
| 451 | |
| 452 | Maybe<nsDependentCSubstring> GetNext() { |
| 453 | Token t; |
| 454 | nsDependentCSubstring result; |
| 455 | |
| 456 | bool inQuote = false; |
| 457 | |
| 458 | while (Next(t)) { |
| 459 | if (t.Type() == TOKEN_EOL) { |
| 460 | Claim(result, ClaimInclusion::EXCLUDE_LAST); |
| 461 | SkipWhites(WhiteSkipping::INCLUDE_NEW_LINE); |
| 462 | Record(); |
| 463 | inQuote = false; |
| 464 | if (!result.IsEmpty()) { |
| 465 | return Some(result); |
| 466 | } |
| 467 | } else if (t.Equals(Token::Char(',')) && !inQuote) { |
| 468 | // Sometimes we get multiple challenges separated by a comma. |
| 469 | // This is not great, as it's slightly ambiguous. We check if something |
| 470 | // is a new challenge by matching agains <param_name> = |
| 471 | // If the , isn't followed by a word and = then most likely |
| 472 | // it is the name of an authType. |
| 473 | |
| 474 | const char* prevCursorPos = mCursor; |
| 475 | const char* prevRollbackPos = mRollback; |
| 476 | |
| 477 | auto hasWordAndEqual = [&]() { |
| 478 | SkipWhites(); |
| 479 | nsDependentCSubstring word; |
| 480 | if (!ReadWord(word)) { |
| 481 | return false; |
| 482 | } |
| 483 | SkipWhites(); |
| 484 | return Check(Token::Char('=')); |
| 485 | }; |
| 486 | if (!hasWordAndEqual()) { |
| 487 | // This is not a parameter. It means the `,` character starts a |
| 488 | // different challenge. |
| 489 | // We'll revert the cursor and return the contents so far. |
| 490 | mCursor = prevCursorPos; |
| 491 | mRollback = prevRollbackPos; |
| 492 | Claim(result, ClaimInclusion::EXCLUDE_LAST); |
| 493 | SkipWhites(); |
| 494 | Record(); |
| 495 | if (!result.IsEmpty()) { |
| 496 | return Some(result); |
| 497 | } |
| 498 | } |
| 499 | } else if (t.Equals(Token::Char('"'))) { |
| 500 | inQuote = !inQuote; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | Claim(result, Tokenizer::ClaimInclusion::INCLUDE_LAST); |
| 505 | SkipWhites(); |
| 506 | Record(); |
| 507 | if (!result.IsEmpty()) { |
| 508 | return Some(result); |
| 509 | } |
| 510 | return Nothing{}; |
| 511 | } |
| 512 | }; |
| 513 | |
| 514 | enum ChallengeRank { |
| 515 | Unknown = 0, |
| 516 | Basic = 1, |
| 517 | Digest = 2, |
| 518 | NTLM = 3, |
| 519 | Negotiate = 4, |
| 520 | }; |
| 521 | |
| 522 | ChallengeRank Rank(const nsACString& aChallenge) { |
| 523 | if (StringBeginsWith(aChallenge, "Negotiate"_ns, |
| 524 | nsCaseInsensitiveCStringComparator)) { |
| 525 | return ChallengeRank::Negotiate; |
| 526 | } |
| 527 | |
| 528 | if (StringBeginsWith(aChallenge, "NTLM"_ns, |
| 529 | nsCaseInsensitiveCStringComparator)) { |
| 530 | return ChallengeRank::NTLM; |
| 531 | } |
| 532 | |
| 533 | if (StringBeginsWith(aChallenge, "Digest"_ns, |
| 534 | nsCaseInsensitiveCStringComparator)) { |
| 535 | return ChallengeRank::Digest; |
| 536 | } |
| 537 | |
| 538 | if (StringBeginsWith(aChallenge, "Basic"_ns, |
| 539 | nsCaseInsensitiveCStringComparator)) { |
| 540 | return ChallengeRank::Basic; |
| 541 | } |
| 542 | |
| 543 | return ChallengeRank::Unknown; |
| 544 | } |
| 545 | |
| 546 | nsresult nsHttpChannelAuthProvider::GetCredentials( |
| 547 | const nsACString& aChallenges, bool proxyAuth, nsCString& creds) { |
| 548 | LOG(("nsHttpChannelAuthProvider::GetCredentials"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentials" ); } } while (0); |
| 549 | nsAutoCString challenges(aChallenges); |
| 550 | |
| 551 | using AuthChallenge = struct AuthChallenge { |
| 552 | nsDependentCSubstring challenge; |
| 553 | uint16_t algorithm = 0; |
| 554 | ChallengeRank rank = ChallengeRank::Unknown; |
| 555 | |
| 556 | void operator=(const AuthChallenge& aOther) { |
| 557 | challenge.Rebind(aOther.challenge, 0); |
| 558 | algorithm = aOther.algorithm; |
| 559 | rank = aOther.rank; |
| 560 | } |
| 561 | }; |
| 562 | |
| 563 | nsTArray<AuthChallenge> cc; |
| 564 | |
| 565 | ChallengeParser p(challenges); |
| 566 | while (true) { |
| 567 | auto next = p.GetNext(); |
| 568 | if (next.isNothing()) { |
| 569 | break; |
| 570 | } |
| 571 | AuthChallenge ac{next.ref(), 0}; |
| 572 | nsAutoCString realm, domain, nonce, opaque; |
| 573 | bool stale = false; |
| 574 | uint16_t qop = 0; |
| 575 | ac.rank = Rank(ac.challenge); |
| 576 | if (StringBeginsWith(ac.challenge, "Digest"_ns, |
| 577 | nsCaseInsensitiveCStringComparator)) { |
| 578 | (void)nsHttpDigestAuth::ParseChallenge(ac.challenge, realm, domain, nonce, |
| 579 | opaque, &stale, &ac.algorithm, |
| 580 | &qop); |
| 581 | } |
| 582 | cc.AppendElement(std::move(ac)); |
| 583 | } |
| 584 | |
| 585 | // Returns true if an authorization is in progress |
| 586 | auto authInProgress = [&]() -> bool { |
| 587 | return proxyAuth ? mProxyAuthContinuationState : mAuthContinuationState; |
| 588 | }; |
| 589 | |
| 590 | // We shouldn't sort if authorization is already in progress |
| 591 | // otherwise we might end up picking the wrong one. See bug 1805666 |
| 592 | if (!authInProgress() || |
| 593 | StaticPrefs::network_auth_sort_challenge_in_progress()) { |
| 594 | cc.StableSort([](const AuthChallenge& lhs, const AuthChallenge& rhs) { |
| 595 | // Different auth types |
| 596 | if (lhs.rank != rhs.rank) { |
| 597 | return lhs.rank < rhs.rank ? 1 : -1; |
| 598 | } |
| 599 | |
| 600 | // If they're the same auth type, and not a Digest, then we treat them |
| 601 | // as equal (don't reorder them). |
| 602 | if (lhs.rank != ChallengeRank::Digest) { |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | if (lhs.algorithm == rhs.algorithm) { |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | return lhs.algorithm < rhs.algorithm ? 1 : -1; |
| 611 | }); |
| 612 | } |
| 613 | |
| 614 | nsAutoCString scheme; |
| 615 | |
| 616 | // If a preference to enable basic HTTP Auth is unset and the scheme is HTTP, |
| 617 | // check if Basic is the sole available authentication challenge. |
| 618 | if (NS_SUCCEEDED(mURI->GetScheme(scheme))((bool)(__builtin_expect(!!(!NS_FAILED_impl(mURI->GetScheme (scheme))), 1))) && scheme == "http"_ns && |
| 619 | !StaticPrefs::network_http_basic_http_auth_enabled() && |
| 620 | cc[0].rank == ChallengeRank::Basic) { |
| 621 | // HTTP Auth and "Basic" is the sole available authentication. |
| 622 | return NS_ERROR_BASIC_HTTP_AUTH_DISABLED; |
| 623 | } |
| 624 | |
| 625 | nsCOMPtr<nsIHttpAuthenticator> auth; |
| 626 | nsCString authType; // force heap allocation to enable string sharing since |
| 627 | // we'll be assigning this value into mAuthType. |
| 628 | |
| 629 | // set informations that depend on whether we're authenticating against a |
| 630 | // proxy or a webserver |
| 631 | nsISupports** currentContinuationState; |
| 632 | nsCString* currentAuthType; |
| 633 | |
| 634 | if (proxyAuth) { |
| 635 | currentContinuationState = &mProxyAuthContinuationState; |
| 636 | currentAuthType = &mProxyAuthType; |
| 637 | } else { |
| 638 | currentContinuationState = &mAuthContinuationState; |
| 639 | currentAuthType = &mAuthType; |
| 640 | } |
| 641 | |
| 642 | nsresult rv = NS_ERROR_NOT_AVAILABLE; |
| 643 | bool gotCreds = false; |
| 644 | |
| 645 | // figure out which challenge we can handle and which authenticator to use. |
| 646 | for (size_t i = 0; i < cc.Length(); i++) { |
| 647 | rv = GetAuthenticator(cc[i].challenge, authType, getter_AddRefs(auth)); |
| 648 | LOG(("trying auth for %s", authType.get()))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "trying auth for %s" , authType.get()); } } while (0); |
| 649 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 650 | // |
| 651 | // if we've already selected an auth type from a previous challenge |
| 652 | // received while processing this channel, then skip others until |
| 653 | // we find a challenge corresponding to the previously tried auth |
| 654 | // type. |
| 655 | // |
| 656 | if (!currentAuthType->IsEmpty() && authType != *currentAuthType) continue; |
| 657 | |
| 658 | // |
| 659 | // we allow the routines to run all the way through before we |
| 660 | // decide if they are valid. |
| 661 | // |
| 662 | // we don't worry about the auth cache being altered because that |
| 663 | // would have been the last step, and if the error is from updating |
| 664 | // the authcache it wasn't really altered anyway. -CTN |
| 665 | // |
| 666 | // at this point the code is really only useful for client side |
| 667 | // errors (it will not automatically fail over to do a different |
| 668 | // auth type if the server keeps rejecting what is being sent, even |
| 669 | // if a particular auth method only knows 1 thing, like a |
| 670 | // non-identity based authentication method) |
| 671 | // |
| 672 | rv = GetCredentialsForChallenge(cc[i].challenge, authType, proxyAuth, |
| 673 | auth, creds); |
| 674 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 675 | gotCreds = true; |
| 676 | *currentAuthType = authType; |
| 677 | |
| 678 | break; |
| 679 | } |
| 680 | if (rv == NS_ERROR_IN_PROGRESS) { |
| 681 | // authentication prompt has been invoked and result is |
| 682 | // expected asynchronously, save current challenge being |
| 683 | // processed and all remaining challenges to use later in |
| 684 | // OnAuthAvailable and now immediately return |
| 685 | *currentAuthType = authType; |
| 686 | mCurrentChallenge = cc[i].challenge; |
| 687 | // imperfect; does not save server-side preference ordering. |
| 688 | // instead, continues with remaining string as provided by client |
| 689 | mRemainingChallenges.Truncate(); |
| 690 | while (i + 1 < cc.Length()) { |
| 691 | i++; |
| 692 | mRemainingChallenges.Append(cc[i].challenge); |
| 693 | mRemainingChallenges.Append("\n"_ns); |
| 694 | } |
| 695 | return rv; |
| 696 | } |
| 697 | |
| 698 | // reset the auth type and continuation state |
| 699 | NS_IF_RELEASE(*currentContinuationState)do { if (*currentContinuationState) { (*currentContinuationState )->Release(); (*currentContinuationState) = 0; } } while ( 0); |
| 700 | currentAuthType->Truncate(); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | if (!gotCreds && !currentAuthType->IsEmpty()) { |
| 705 | // looks like we never found the auth type we were looking for. |
| 706 | // reset the auth type and continuation state, and try again. |
| 707 | currentAuthType->Truncate(); |
| 708 | NS_IF_RELEASE(*currentContinuationState)do { if (*currentContinuationState) { (*currentContinuationState )->Release(); (*currentContinuationState) = 0; } } while ( 0); |
| 709 | |
| 710 | rv = GetCredentials(challenges, proxyAuth, creds); |
| 711 | } |
| 712 | |
| 713 | return rv; |
| 714 | } |
| 715 | |
| 716 | nsresult nsHttpChannelAuthProvider::GetAuthorizationMembers( |
| 717 | bool proxyAuth, nsACString& scheme, nsCString& host, int32_t& port, |
| 718 | nsACString& path, nsHttpAuthIdentity*& ident, |
| 719 | nsISupports**& continuationState) { |
| 720 | if (proxyAuth) { |
| 721 | MOZ_ASSERT(UsingHttpProxy(),do { static_assert( mozilla::detail::AssertionConditionType< decltype(UsingHttpProxy())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(UsingHttpProxy()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("UsingHttpProxy()" " (" "proxyAuth is true, but no HTTP proxy is configured!" ")" , "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 722); AnnotateMozCrashReason("MOZ_ASSERT" "(" "UsingHttpProxy()" ") (" "proxyAuth is true, but no HTTP proxy is configured!" ")" ); do { MOZ_CrashSequence(__null, 722); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 722 | "proxyAuth is true, but no HTTP proxy is configured!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(UsingHttpProxy())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(UsingHttpProxy()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("UsingHttpProxy()" " (" "proxyAuth is true, but no HTTP proxy is configured!" ")" , "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 722); AnnotateMozCrashReason("MOZ_ASSERT" "(" "UsingHttpProxy()" ") (" "proxyAuth is true, but no HTTP proxy is configured!" ")" ); do { MOZ_CrashSequence(__null, 722); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 723 | |
| 724 | host = ProxyHost(); |
| 725 | port = ProxyPort(); |
| 726 | ident = &mProxyIdent; |
| 727 | scheme.AssignLiteral("http"); |
| 728 | |
| 729 | continuationState = &mProxyAuthContinuationState; |
| 730 | } else { |
| 731 | host = Host(); |
| 732 | port = Port(); |
| 733 | ident = &mIdent; |
| 734 | |
| 735 | nsresult rv; |
| 736 | rv = GetCurrentPath(path); |
| 737 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 738 | |
| 739 | rv = mURI->GetScheme(scheme); |
| 740 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 741 | |
| 742 | continuationState = &mAuthContinuationState; |
| 743 | } |
| 744 | |
| 745 | return NS_OK; |
| 746 | } |
| 747 | |
| 748 | nsresult nsHttpChannelAuthProvider::GetCredentialsForChallenge( |
| 749 | const nsACString& aChallenge, const nsACString& aAuthType, bool proxyAuth, |
| 750 | nsIHttpAuthenticator* auth, nsCString& creds) { |
| 751 | LOG(do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge " "[this=%p channel=%p proxyAuth=%d challenges=%s]\n", this, mAuthChannel , proxyAuth, nsCString(aChallenge).get()); } } while (0) |
| 752 | ("nsHttpChannelAuthProvider::GetCredentialsForChallenge "do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge " "[this=%p channel=%p proxyAuth=%d challenges=%s]\n", this, mAuthChannel , proxyAuth, nsCString(aChallenge).get()); } } while (0) |
| 753 | "[this=%p channel=%p proxyAuth=%d challenges=%s]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge " "[this=%p channel=%p proxyAuth=%d challenges=%s]\n", this, mAuthChannel , proxyAuth, nsCString(aChallenge).get()); } } while (0) |
| 754 | this, mAuthChannel, proxyAuth, nsCString(aChallenge).get()))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge " "[this=%p channel=%p proxyAuth=%d challenges=%s]\n", this, mAuthChannel , proxyAuth, nsCString(aChallenge).get()); } } while (0); |
| 755 | |
| 756 | // this getter never fails |
| 757 | nsHttpAuthCache* authCache = gHttpHandler->AuthCache(mIsPrivate); |
| 758 | |
| 759 | uint32_t authFlags; |
| 760 | nsresult rv = auth->GetAuthFlags(&authFlags); |
| 761 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 762 | |
| 763 | nsAutoCString realm; |
| 764 | ParseRealm(aChallenge, realm); |
| 765 | |
| 766 | // if no realm, then use the auth type as the realm. ToUpperCase so the |
| 767 | // ficticious realm stands out a bit more. |
| 768 | // XXX this will cause some single signon misses! |
| 769 | // XXX this was meant to be used with NTLM, which supplies no realm. |
| 770 | /* |
| 771 | if (realm.IsEmpty()) { |
| 772 | realm = authType; |
| 773 | ToUpperCase(realm); |
| 774 | } |
| 775 | */ |
| 776 | |
| 777 | // set informations that depend on whether |
| 778 | // we're authenticating against a proxy |
| 779 | // or a webserver |
| 780 | nsAutoCString host; |
| 781 | int32_t port; |
| 782 | nsHttpAuthIdentity* ident; |
| 783 | nsAutoCString path, scheme; |
| 784 | bool identFromURI = false; |
| 785 | nsISupports** continuationState; |
| 786 | |
| 787 | rv = GetAuthorizationMembers(proxyAuth, scheme, host, port, path, ident, |
| 788 | continuationState); |
| 789 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 790 | |
| 791 | uint32_t loadFlags; |
| 792 | rv = mAuthChannel->GetLoadFlags(&loadFlags); |
| 793 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 794 | |
| 795 | // Fill only for non-proxy auth, proxy credentials are not OA-isolated. |
| 796 | nsAutoCString suffix; |
| 797 | |
| 798 | if (!proxyAuth) { |
| 799 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 800 | GetOriginAttributesSuffix(chan, suffix); |
| 801 | |
| 802 | // if this is the first challenge, then try using the identity |
| 803 | // specified in the URL. |
| 804 | if (mIdent.IsEmpty()) { |
| 805 | GetIdentityFromURI(authFlags, mIdent); |
| 806 | identFromURI = !mIdent.IsEmpty(); |
| 807 | } |
| 808 | |
| 809 | if ((loadFlags & nsIRequest::LOAD_ANONYMOUS) && !identFromURI) { |
| 810 | LOG(("Skipping authentication for anonymous non-proxy request\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Skipping authentication for anonymous non-proxy request\n" ); } } while (0); |
| 811 | return NS_ERROR_NOT_AVAILABLE; |
| 812 | } |
| 813 | |
| 814 | // Let explicit URL credentials pass |
| 815 | // regardless of the LOAD_ANONYMOUS flag |
| 816 | } else if ((loadFlags & nsIRequest::LOAD_ANONYMOUS) && !UsingHttpProxy()) { |
| 817 | LOG(("Skipping authentication for anonymous non-proxy request\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Skipping authentication for anonymous non-proxy request\n" ); } } while (0); |
| 818 | return NS_ERROR_NOT_AVAILABLE; |
| 819 | } |
| 820 | |
| 821 | // |
| 822 | // if we already tried some credentials for this transaction, then |
| 823 | // we need to possibly clear them from the cache, unless the credentials |
| 824 | // in the cache have changed, in which case we'd want to give them a |
| 825 | // try instead. |
| 826 | // |
| 827 | RefPtr<nsHttpAuthEntry> entry; |
| 828 | (void)authCache->GetAuthEntryForDomain(scheme, host, port, realm, suffix, |
| 829 | entry); |
| 830 | |
| 831 | // hold reference to the auth session state (in case we clear our |
| 832 | // reference to the entry). |
| 833 | nsCOMPtr<nsISupports> sessionStateGrip; |
| 834 | if (entry) sessionStateGrip = entry->mMetaData; |
| 835 | |
| 836 | // remember if we already had the continuation state. it means we are in |
| 837 | // the middle of the authentication exchange and the connection must be |
| 838 | // kept sticky then (and only then). |
| 839 | bool authAtProgress = !!*continuationState; |
| 840 | |
| 841 | // for digest auth, maybe our cached nonce value simply timed out... |
| 842 | bool identityInvalid; |
| 843 | nsISupports* sessionState = sessionStateGrip; |
| 844 | rv = auth->ChallengeReceived(mAuthChannel, aChallenge, proxyAuth, |
| 845 | &sessionState, &*continuationState, |
| 846 | &identityInvalid); |
| 847 | sessionStateGrip.swap(sessionState); |
| 848 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 849 | |
| 850 | LOG((" identity invalid = %d\n", identityInvalid))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " identity invalid = %d\n" , identityInvalid); } } while (0); |
| 851 | |
| 852 | if (mConnectionBased && identityInvalid) { |
| 853 | // If the flag is set and identity is invalid, it means we received the |
| 854 | // first challange for a new negotiation round after negotiating a |
| 855 | // connection based auth failed (invalid password). The mConnectionBased |
| 856 | // flag is set later for the newly received challenge, so here it reflects |
| 857 | // the previous 401/7 response schema. |
| 858 | rv = mAuthChannel->CloseStickyConnection(); |
| 859 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 859); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 859); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 860 | if (!proxyAuth) { |
| 861 | // We must clear proxy ident in the following scenario + explanation: |
| 862 | // - we are authenticating to an NTLM proxy and an NTLM server |
| 863 | // - we successfully authenticated to the proxy, mProxyIdent keeps |
| 864 | // the user name/domain and password, the identity has also been cached |
| 865 | // - we just threw away the connection because we are now asking for |
| 866 | // creds for the server (WWW auth) |
| 867 | // - hence, we will have to auth to the proxy again as well |
| 868 | // - if we didn't clear the proxy identity, it would be considered |
| 869 | // as non-valid and we would ask the user again ; clearing it forces |
| 870 | // use of the cached identity and not asking the user again |
| 871 | ClearProxyIdent(); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | mConnectionBased = !!(authFlags & nsIHttpAuthenticator::CONNECTION_BASED); |
| 876 | |
| 877 | // It's legal if the peer closes the connection after the first 401/7. |
| 878 | // Making the connection sticky will prevent its restart giving the user |
| 879 | // a 'network reset' error every time. Hence, we mark the connection |
| 880 | // as restartable. |
| 881 | mAuthChannel->ConnectionRestartable(!authAtProgress); |
| 882 | |
| 883 | if (identFromURI && |
| 884 | (authFlags & nsIHttpAuthenticator::IDENTITY_INCLUDES_DOMAIN)) { |
| 885 | LOG((" ignoring URL identity for a domain-identity scheme\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " ignoring URL identity for a domain-identity scheme\n" ); } } while (0); |
| 886 | ident->Clear(); |
| 887 | identFromURI = false; |
| 888 | } |
| 889 | |
| 890 | if (identityInvalid) { |
| 891 | if (entry) { |
| 892 | if (ident->Equals(entry->Identity())) { |
| 893 | if (!identFromURI) { |
| 894 | LOG((" clearing bad auth cache entry\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " clearing bad auth cache entry\n" ); } } while (0); |
| 895 | // ok, we've already tried this user identity, so clear the |
| 896 | // corresponding entry from the auth cache. |
| 897 | authCache->ClearAuthEntry(scheme, host, port, realm, suffix); |
| 898 | entry = nullptr; |
| 899 | ident->Clear(); |
| 900 | } |
| 901 | } else if (!identFromURI || |
| 902 | (ident->User() == entry->Identity().User() && |
| 903 | !(loadFlags & (nsIChannel::LOAD_ANONYMOUS | |
| 904 | nsIChannel::LOAD_EXPLICIT_CREDENTIALS)))) { |
| 905 | LOG((" taking identity from auth cache\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " taking identity from auth cache\n" ); } } while (0); |
| 906 | // the password from the auth cache is more likely to be |
| 907 | // correct than the one in the URL. at least, we know that it |
| 908 | // works with the given username. it is possible for a server |
| 909 | // to distinguish logons based on the supplied password alone, |
| 910 | // but that would be quite unusual... and i don't think we need |
| 911 | // to worry about such unorthodox cases. |
| 912 | *ident = entry->Identity(); |
| 913 | identFromURI = false; |
| 914 | if (entry->Creds()[0] != '\0') { |
| 915 | LOG((" using cached credentials!\n"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " using cached credentials!\n" ); } } while (0); |
| 916 | creds.Assign(entry->Creds()); |
| 917 | return entry->AddPath(path); |
| 918 | } |
| 919 | } |
| 920 | } else if (!identFromURI) { |
| 921 | // hmm... identity invalid, but no auth entry! the realm probably |
| 922 | // changed (see bug 201986). |
| 923 | ident->Clear(); |
| 924 | } |
| 925 | |
| 926 | if (!entry && ident->IsEmpty()) { |
| 927 | uint32_t level = nsIAuthPrompt2::LEVEL_NONE; |
| 928 | if ((!proxyAuth && mUsingSSL) || (proxyAuth && mProxyUsingSSL)) { |
| 929 | level = nsIAuthPrompt2::LEVEL_SECURE; |
| 930 | } else if (authFlags & nsIHttpAuthenticator::IDENTITY_ENCRYPTED) { |
| 931 | level = nsIAuthPrompt2::LEVEL_PW_ENCRYPTED; |
| 932 | } |
| 933 | |
| 934 | // Depending on the pref setting, the authentication dialog may be |
| 935 | // blocked for all sub-resources, blocked for cross-origin |
| 936 | // sub-resources, or always allowed for sub-resources. |
| 937 | // For more details look at the bug 647010. |
| 938 | // BlockPrompt will set mCrossOrigin parameter as well. |
| 939 | if (BlockPrompt(proxyAuth)) { |
| 940 | LOG((do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 941 | "nsHttpChannelAuthProvider::GetCredentialsForChallenge: "do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 942 | "Prompt is blocked [this=%p pref=%d img-pref=%d "do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 943 | "non-web-content-triggered-pref=%d]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 944 | this, StaticPrefs::network_auth_subresource_http_auth_allow(),do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 945 | StaticPrefs::do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 946 | network_auth_subresource_img_cross_origin_http_auth_allow(),do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 947 | StaticPrefs::do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0) |
| 948 | network_auth_non_web_content_triggered_resources_http_auth_allow()))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetCredentialsForChallenge: " "Prompt is blocked [this=%p pref=%d img-pref=%d " "non-web-content-triggered-pref=%d]\n" , this, StaticPrefs::network_auth_subresource_http_auth_allow (), StaticPrefs:: network_auth_subresource_img_cross_origin_http_auth_allow (), StaticPrefs:: network_auth_non_web_content_triggered_resources_http_auth_allow ()); } } while (0); |
| 949 | return NS_ERROR_ABORT; |
| 950 | } |
| 951 | |
| 952 | // at this point we are forced to interact with the user to get |
| 953 | // their username and password for this domain. |
| 954 | rv = PromptForIdentity(level, proxyAuth, realm, aAuthType, authFlags, |
| 955 | *ident); |
| 956 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 957 | identFromURI = false; |
Value stored to 'identFromURI' is never read | |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | // get credentials for the given user:pass |
| 962 | // |
| 963 | // always store the credentials we're trying now so that they will be used |
| 964 | // on subsequent links. This will potentially remove good credentials from |
| 965 | // the cache. This is ok as we don't want to use cached credentials if the |
| 966 | // user specified something on the URI or in another manner. This is so |
| 967 | // that we don't transparently authenticate as someone they're not |
| 968 | // expecting to authenticate as. |
| 969 | // |
| 970 | nsCString result; |
| 971 | rv = GenCredsAndSetEntry(auth, proxyAuth, scheme, host, port, path, realm, |
| 972 | aChallenge, *ident, sessionStateGrip, creds); |
| 973 | return rv; |
| 974 | } |
| 975 | |
| 976 | bool nsHttpChannelAuthProvider::BlockPrompt(bool proxyAuth) { |
| 977 | // Verify that it's ok to prompt for credentials here, per spec |
| 978 | // http://xhr.spec.whatwg.org/#the-send%28%29-method |
| 979 | |
| 980 | nsCOMPtr<nsIHttpChannelInternal> chanInternal = |
| 981 | do_QueryInterface(mAuthChannel); |
| 982 | MOZ_ASSERT(chanInternal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(chanInternal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(chanInternal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("chanInternal", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 982); AnnotateMozCrashReason("MOZ_ASSERT" "(" "chanInternal" ")"); do { MOZ_CrashSequence(__null, 982); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 983 | |
| 984 | if (chanInternal->GetBlockAuthPrompt()) { |
| 985 | LOG(do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::BlockPrompt: Prompt is blocked " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 986 | ("nsHttpChannelAuthProvider::BlockPrompt: Prompt is blocked "do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::BlockPrompt: Prompt is blocked " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 987 | "[this=%p channel=%p]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::BlockPrompt: Prompt is blocked " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0) |
| 988 | this, mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::BlockPrompt: Prompt is blocked " "[this=%p channel=%p]\n", this, mAuthChannel); } } while (0); |
| 989 | return true; |
| 990 | } |
| 991 | |
| 992 | if (proxyAuth) { |
| 993 | // Do not block auth-dialog if this is a proxy authentication. |
| 994 | return false; |
| 995 | } |
| 996 | |
| 997 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 998 | nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo(); |
| 999 | |
| 1000 | // We will treat loads w/o loadInfo as a top level document. |
| 1001 | bool topDoc = true; |
| 1002 | bool xhr = false; |
| 1003 | bool nonWebContent = false; |
| 1004 | |
| 1005 | if (loadInfo->GetExternalContentPolicyType() != |
| 1006 | ExtContentPolicy::TYPE_DOCUMENT) { |
| 1007 | topDoc = false; |
| 1008 | } |
| 1009 | |
| 1010 | if (!topDoc) { |
| 1011 | nsCOMPtr<nsIPrincipal> triggeringPrinc = loadInfo->TriggeringPrincipal(); |
| 1012 | if (triggeringPrinc->IsSystemPrincipal()) { |
| 1013 | nonWebContent = true; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | if (loadInfo->GetExternalContentPolicyType() == |
| 1018 | ExtContentPolicy::TYPE_XMLHTTPREQUEST) { |
| 1019 | xhr = true; |
| 1020 | } |
| 1021 | |
| 1022 | if (!topDoc && !xhr) { |
| 1023 | nsCOMPtr<nsIURI> topURI; |
| 1024 | (void)chanInternal->GetTopWindowURI(getter_AddRefs(topURI)); |
| 1025 | if (topURI) { |
| 1026 | mCrossOrigin = !NS_SecurityCompareURIs(topURI, mURI, true); |
| 1027 | } else { |
| 1028 | nsIPrincipal* loadingPrinc = loadInfo->GetLoadingPrincipal(); |
| 1029 | MOZ_ASSERT(loadingPrinc)do { static_assert( mozilla::detail::AssertionConditionType< decltype(loadingPrinc)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(loadingPrinc))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("loadingPrinc", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1029); AnnotateMozCrashReason("MOZ_ASSERT" "(" "loadingPrinc" ")"); do { MOZ_CrashSequence(__null, 1029); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1030 | mCrossOrigin = !loadingPrinc->IsSameOrigin(mURI); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | if (!topDoc && |
| 1035 | !StaticPrefs:: |
| 1036 | network_auth_non_web_content_triggered_resources_http_auth_allow() && |
| 1037 | nonWebContent) { |
| 1038 | return true; |
| 1039 | } |
| 1040 | |
| 1041 | switch (StaticPrefs::network_auth_subresource_http_auth_allow()) { |
| 1042 | case SUBRESOURCE_AUTH_DIALOG_DISALLOW_ALL0: |
| 1043 | // Do not open the http-authentication credentials dialog for |
| 1044 | // the sub-resources. |
| 1045 | return !topDoc && !xhr; |
| 1046 | case SUBRESOURCE_AUTH_DIALOG_DISALLOW_CROSS_ORIGIN1: |
| 1047 | // Open the http-authentication credentials dialog for |
| 1048 | // the sub-resources only if they are not cross-origin. |
| 1049 | return !topDoc && !xhr && mCrossOrigin; |
| 1050 | case SUBRESOURCE_AUTH_DIALOG_ALLOW_ALL2: |
| 1051 | // Allow the http-authentication dialog for subresources. |
| 1052 | // If pref network.auth.subresource-img-cross-origin-http-auth-allow |
| 1053 | // is set, http-authentication dialog for image subresources is |
| 1054 | // blocked. |
| 1055 | if (mCrossOrigin && |
| 1056 | !StaticPrefs:: |
| 1057 | network_auth_subresource_img_cross_origin_http_auth_allow() && |
| 1058 | loadInfo && |
| 1059 | ((loadInfo->GetExternalContentPolicyType() == |
| 1060 | ExtContentPolicy::TYPE_IMAGE) || |
| 1061 | (loadInfo->GetExternalContentPolicyType() == |
| 1062 | ExtContentPolicy::TYPE_IMAGESET))) { |
| 1063 | return true; |
| 1064 | } |
| 1065 | return false; |
| 1066 | default: |
| 1067 | // This is an invalid value. |
| 1068 | MOZ_ASSERT(false, "A non valid value!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "A non valid value!" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1068); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "A non valid value!" ")"); do { MOZ_CrashSequence(__null, 1068 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 1069 | } |
| 1070 | return false; |
| 1071 | } |
| 1072 | |
| 1073 | inline void GetAuthType(const nsACString& aChallenge, nsCString& authType) { |
| 1074 | auto spaceIndex = aChallenge.FindChar(' '); |
| 1075 | authType = Substring(aChallenge, 0, spaceIndex); |
| 1076 | // normalize to lowercase |
| 1077 | ToLowerCase(authType); |
| 1078 | } |
| 1079 | |
| 1080 | nsresult nsHttpChannelAuthProvider::GetAuthenticator( |
| 1081 | const nsACString& aChallenge, nsCString& authType, |
| 1082 | nsIHttpAuthenticator** auth) { |
| 1083 | LOG(("nsHttpChannelAuthProvider::GetAuthenticator [this=%p channel=%p]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetAuthenticator [this=%p channel=%p]\n" , this, mAuthChannel); } } while (0) |
| 1084 | this, mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetAuthenticator [this=%p channel=%p]\n" , this, mAuthChannel); } } while (0); |
| 1085 | |
| 1086 | GetAuthType(aChallenge, authType); |
| 1087 | |
| 1088 | nsCOMPtr<nsIHttpAuthenticator> authenticator; |
| 1089 | #ifdef MOZ_AUTH_EXTENSION1 |
| 1090 | if (authType.EqualsLiteral("negotiate")) { |
| 1091 | authenticator = nsHttpNegotiateAuth::GetOrCreate(); |
| 1092 | } else |
| 1093 | #endif |
| 1094 | if (authType.EqualsLiteral("basic")) { |
| 1095 | authenticator = nsHttpBasicAuth::GetOrCreate(); |
| 1096 | } else if (authType.EqualsLiteral("digest")) { |
| 1097 | authenticator = nsHttpDigestAuth::GetOrCreate(); |
| 1098 | } else if (authType.EqualsLiteral("ntlm")) { |
| 1099 | authenticator = nsHttpNTLMAuth::GetOrCreate(); |
| 1100 | } else if (authType.EqualsLiteral("mock_auth") && |
| 1101 | PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR")) { |
| 1102 | authenticator = MockHttpAuth::Create(); |
| 1103 | } else { |
| 1104 | return NS_ERROR_FACTORY_NOT_REGISTERED; |
| 1105 | } |
| 1106 | |
| 1107 | if (!authenticator) { |
| 1108 | // If called during shutdown it's possible that the singleton authenticator |
| 1109 | // was already cleared so we have a null one here. |
| 1110 | return NS_ERROR_NOT_AVAILABLE; |
| 1111 | } |
| 1112 | |
| 1113 | MOZ_ASSERT(authenticator)do { static_assert( mozilla::detail::AssertionConditionType< decltype(authenticator)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(authenticator))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("authenticator", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1113); AnnotateMozCrashReason("MOZ_ASSERT" "(" "authenticator" ")"); do { MOZ_CrashSequence(__null, 1113); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1114 | authenticator.forget(auth); |
| 1115 | |
| 1116 | return NS_OK; |
| 1117 | } |
| 1118 | |
| 1119 | // buf contains "domain\user" |
| 1120 | static void ParseUserDomain(const nsAString& buf, nsDependentSubstring& user, |
| 1121 | nsDependentSubstring& domain) { |
| 1122 | auto backslashPos = buf.FindChar(u'\\'); |
| 1123 | if (backslashPos != kNotFound) { |
| 1124 | domain.Rebind(buf, 0, backslashPos); |
| 1125 | user.Rebind(buf, backslashPos + 1); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | void nsHttpChannelAuthProvider::GetIdentityFromURI(uint32_t authFlags, |
| 1130 | nsHttpAuthIdentity& ident) { |
| 1131 | LOG(("nsHttpChannelAuthProvider::GetIdentityFromURI [this=%p channel=%p]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetIdentityFromURI [this=%p channel=%p]\n" , this, mAuthChannel); } } while (0) |
| 1132 | this, mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::GetIdentityFromURI [this=%p channel=%p]\n" , this, mAuthChannel); } } while (0); |
| 1133 | |
| 1134 | bool hasUserPass; |
| 1135 | if (NS_FAILED(mURI->GetHasUserPass(&hasUserPass))((bool)(__builtin_expect(!!(NS_FAILED_impl(mURI->GetHasUserPass (&hasUserPass))), 0))) || !hasUserPass) { |
| 1136 | return; |
| 1137 | } |
| 1138 | |
| 1139 | nsAutoString userBuf; |
| 1140 | nsAutoString passBuf; |
| 1141 | |
| 1142 | // XXX i18n |
| 1143 | nsAutoCString buf; |
| 1144 | nsresult rv = mURI->GetUsername(buf); |
| 1145 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1146 | return; |
| 1147 | } |
| 1148 | NS_UnescapeURL(buf); |
| 1149 | CopyUTF8toUTF16(buf, userBuf); |
| 1150 | |
| 1151 | rv = mURI->GetPassword(buf); |
| 1152 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1153 | return; |
| 1154 | } |
| 1155 | NS_UnescapeURL(buf); |
| 1156 | CopyUTF8toUTF16(buf, passBuf); |
| 1157 | |
| 1158 | nsDependentSubstring user(userBuf, 0); |
| 1159 | nsDependentSubstring domain(EmptyString(), 0); |
| 1160 | |
| 1161 | if (authFlags & nsIHttpAuthenticator::IDENTITY_INCLUDES_DOMAIN) { |
| 1162 | ParseUserDomain(userBuf, user, domain); |
| 1163 | } |
| 1164 | |
| 1165 | ident = nsHttpAuthIdentity(domain, user, passBuf); |
| 1166 | } |
| 1167 | |
| 1168 | void nsHttpChannelAuthProvider::ParseRealm(const nsACString& aChallenge, |
| 1169 | nsACString& realm) { |
| 1170 | // |
| 1171 | // From RFC2617 section 1.2, the realm value is defined as such: |
| 1172 | // |
| 1173 | // realm = "realm" "=" realm-value |
| 1174 | // realm-value = quoted-string |
| 1175 | // |
| 1176 | // but, we'll accept anything after the the "=" up to the first space, or |
| 1177 | // end-of-line, if the string is not quoted. |
| 1178 | // |
| 1179 | |
| 1180 | Tokenizer t(aChallenge); |
| 1181 | |
| 1182 | // The challenge begins with the authType. |
| 1183 | // If we can't find that something has probably gone wrong. |
| 1184 | t.SkipWhites(); |
| 1185 | nsDependentCSubstring authType; |
| 1186 | if (!t.ReadWord(authType)) { |
| 1187 | return; |
| 1188 | } |
| 1189 | |
| 1190 | // Will return true if the tokenizer advanced the cursor - false otherwise. |
| 1191 | auto readParam = [&](nsDependentCSubstring& key, nsAutoCString& value) { |
| 1192 | key.Rebind(EmptyCString(), 0); |
| 1193 | value.Truncate(); |
| 1194 | |
| 1195 | t.SkipWhites(); |
| 1196 | if (!t.ReadWord(key)) { |
| 1197 | return false; |
| 1198 | } |
| 1199 | t.SkipWhites(); |
| 1200 | if (!t.CheckChar('=')) { |
| 1201 | return true; |
| 1202 | } |
| 1203 | t.SkipWhites(); |
| 1204 | |
| 1205 | Tokenizer::Token token1; |
| 1206 | |
| 1207 | t.Record(); |
| 1208 | if (!t.Next(token1)) { |
| 1209 | return true; |
| 1210 | } |
| 1211 | nsDependentCSubstring sub; |
| 1212 | bool hasQuote = false; |
| 1213 | if (token1.Equals(Tokenizer::Token::Char('"'))) { |
| 1214 | hasQuote = true; |
| 1215 | } else { |
| 1216 | t.Claim(sub, Tokenizer::ClaimInclusion::INCLUDE_LAST); |
| 1217 | value.Append(sub); |
| 1218 | } |
| 1219 | t.Record(); |
| 1220 | Tokenizer::Token token2; |
| 1221 | while (t.Next(token2)) { |
| 1222 | if (hasQuote && token2.Equals(Tokenizer::Token::Char('"')) && |
| 1223 | !token1.Equals(Tokenizer::Token::Char('\\'))) { |
| 1224 | break; |
| 1225 | } |
| 1226 | if (!hasQuote && (token2.Type() == Tokenizer::TokenType::TOKEN_WS || |
| 1227 | token2.Type() == Tokenizer::TokenType::TOKEN_EOL)) { |
| 1228 | break; |
| 1229 | } |
| 1230 | |
| 1231 | t.Claim(sub, Tokenizer::ClaimInclusion::INCLUDE_LAST); |
| 1232 | if (!sub.Equals(R"(\)")) { |
| 1233 | value.Append(sub); |
| 1234 | } |
| 1235 | t.Record(); |
| 1236 | token1 = token2; |
| 1237 | } |
| 1238 | return true; |
| 1239 | }; |
| 1240 | |
| 1241 | while (!t.CheckEOF()) { |
| 1242 | nsDependentCSubstring key; |
| 1243 | nsAutoCString value; |
| 1244 | // If we couldn't read anything, and the input isn't followed by a , |
| 1245 | // then we exit. |
| 1246 | if (!readParam(key, value) && !t.Check(Tokenizer::Token::Char(','))) { |
| 1247 | break; |
| 1248 | } |
| 1249 | // When we find the first instance of realm we exit. |
| 1250 | // Theoretically there should be only one instance and we should fail |
| 1251 | // if there are more, but we're trying to preserve existing behaviour. |
| 1252 | if (key.Equals("realm"_ns, nsCaseInsensitiveCStringComparator)) { |
| 1253 | realm = value; |
| 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | class nsHTTPAuthInformation : public nsAuthInformationHolder { |
| 1260 | public: |
| 1261 | nsHTTPAuthInformation(uint32_t aFlags, const nsString& aRealm, |
| 1262 | const nsACString& aAuthType) |
| 1263 | : nsAuthInformationHolder(aFlags, aRealm, aAuthType) {} |
| 1264 | |
| 1265 | void SetToHttpAuthIdentity(uint32_t authFlags, nsHttpAuthIdentity& identity); |
| 1266 | }; |
| 1267 | |
| 1268 | void nsHTTPAuthInformation::SetToHttpAuthIdentity( |
| 1269 | uint32_t authFlags, nsHttpAuthIdentity& identity) { |
| 1270 | identity = nsHttpAuthIdentity(Domain(), User(), Password()); |
| 1271 | } |
| 1272 | |
| 1273 | nsresult nsHttpChannelAuthProvider::PromptForIdentity( |
| 1274 | uint32_t level, bool proxyAuth, const nsACString& realm, |
| 1275 | const nsACString& authType, uint32_t authFlags, nsHttpAuthIdentity& ident) { |
| 1276 | LOG(("nsHttpChannelAuthProvider::PromptForIdentity [this=%p channel=%p]\n",do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::PromptForIdentity [this=%p channel=%p]\n" , this, mAuthChannel); } } while (0) |
| 1277 | this, mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::PromptForIdentity [this=%p channel=%p]\n" , this, mAuthChannel); } } while (0); |
| 1278 | |
| 1279 | nsresult rv; |
| 1280 | |
| 1281 | nsCOMPtr<nsIInterfaceRequestor> callbacks; |
| 1282 | rv = mAuthChannel->GetNotificationCallbacks(getter_AddRefs(callbacks)); |
| 1283 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1284 | |
| 1285 | nsCOMPtr<nsILoadGroup> loadGroup; |
| 1286 | rv = mAuthChannel->GetLoadGroup(getter_AddRefs(loadGroup)); |
| 1287 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1288 | |
| 1289 | nsCOMPtr<nsIAuthPrompt2> authPrompt; |
| 1290 | GetAuthPrompt(callbacks, proxyAuth, getter_AddRefs(authPrompt)); |
| 1291 | if (!authPrompt && loadGroup) { |
| 1292 | nsCOMPtr<nsIInterfaceRequestor> cbs; |
| 1293 | loadGroup->GetNotificationCallbacks(getter_AddRefs(cbs)); |
| 1294 | GetAuthPrompt(cbs, proxyAuth, getter_AddRefs(authPrompt)); |
| 1295 | } |
| 1296 | if (!authPrompt) return NS_ERROR_NO_INTERFACE; |
| 1297 | |
| 1298 | // XXX i18n: need to support non-ASCII realm strings (see bug 41489) |
| 1299 | NS_ConvertASCIItoUTF16 realmU(realm); |
| 1300 | |
| 1301 | // prompt the user... |
| 1302 | uint32_t promptFlags = 0; |
| 1303 | if (proxyAuth) { |
| 1304 | promptFlags |= nsIAuthInformation::AUTH_PROXY; |
| 1305 | if (mTriedProxyAuth) promptFlags |= nsIAuthInformation::PREVIOUS_FAILED; |
| 1306 | mTriedProxyAuth = true; |
| 1307 | } else { |
| 1308 | promptFlags |= nsIAuthInformation::AUTH_HOST; |
| 1309 | if (mTriedHostAuth) promptFlags |= nsIAuthInformation::PREVIOUS_FAILED; |
| 1310 | mTriedHostAuth = true; |
| 1311 | } |
| 1312 | |
| 1313 | if (authFlags & nsIHttpAuthenticator::IDENTITY_INCLUDES_DOMAIN) { |
| 1314 | promptFlags |= nsIAuthInformation::NEED_DOMAIN; |
| 1315 | } |
| 1316 | |
| 1317 | if (mCrossOrigin) { |
| 1318 | promptFlags |= nsIAuthInformation::CROSS_ORIGIN_SUB_RESOURCE; |
| 1319 | } |
| 1320 | |
| 1321 | RefPtr<nsHTTPAuthInformation> holder = |
| 1322 | new nsHTTPAuthInformation(promptFlags, realmU, authType); |
| 1323 | if (!holder) return NS_ERROR_OUT_OF_MEMORY; |
| 1324 | |
| 1325 | nsCOMPtr<nsIChannel> channel(do_QueryInterface(mAuthChannel, &rv)); |
| 1326 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1327 | |
| 1328 | rv = authPrompt->AsyncPromptAuth(channel, this, nullptr, level, holder, |
| 1329 | getter_AddRefs(mAsyncPromptAuthCancelable)); |
| 1330 | |
| 1331 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1332 | // indicate using this error code that authentication prompt |
| 1333 | // result is expected asynchronously |
| 1334 | rv = NS_ERROR_IN_PROGRESS; |
| 1335 | } else { |
| 1336 | // Fall back to synchronous prompt |
| 1337 | bool retval = false; |
| 1338 | rv = authPrompt->PromptAuth(channel, level, holder, &retval); |
| 1339 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1340 | |
| 1341 | if (!retval) { |
| 1342 | rv = NS_ERROR_ABORT; |
| 1343 | } else { |
| 1344 | holder->SetToHttpAuthIdentity(authFlags, ident); |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (mConnectionBased) { |
| 1349 | // Connection can be reset by the server in the meantime user is entering |
| 1350 | // the credentials. Result would be just a "Connection was reset" error. |
| 1351 | // Hence, we drop the current regardless if the user would make it on time |
| 1352 | // to provide credentials. |
| 1353 | // It's OK to send the NTLM type 1 message (response to the plain "NTLM" |
| 1354 | // challenge) on a new connection. |
| 1355 | { |
| 1356 | DebugOnly<nsresult> rv = mAuthChannel->CloseStickyConnection(); |
| 1357 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1357); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1357); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | return rv; |
| 1362 | } |
| 1363 | |
| 1364 | NS_IMETHODIMPnsresult nsHttpChannelAuthProvider::OnAuthAvailable( |
| 1365 | nsISupports* aContext, nsIAuthInformation* aAuthInfo) { |
| 1366 | LOG(("nsHttpChannelAuthProvider::OnAuthAvailable [this=%p channel=%p]", this,do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::OnAuthAvailable [this=%p channel=%p]" , this, mAuthChannel); } } while (0) |
| 1367 | mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::OnAuthAvailable [this=%p channel=%p]" , this, mAuthChannel); } } while (0); |
| 1368 | |
| 1369 | mAsyncPromptAuthCancelable = nullptr; |
| 1370 | if (!mAuthChannel) return NS_OK; |
| 1371 | |
| 1372 | nsresult rv; |
| 1373 | |
| 1374 | nsAutoCString host; |
| 1375 | int32_t port; |
| 1376 | nsHttpAuthIdentity* ident; |
| 1377 | nsAutoCString path, scheme; |
| 1378 | nsISupports** continuationState; |
| 1379 | rv = GetAuthorizationMembers(mProxyAuth, scheme, host, port, path, ident, |
| 1380 | continuationState); |
| 1381 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) OnAuthCancelled(aContext, false); |
| 1382 | |
| 1383 | nsAutoCString realm; |
| 1384 | ParseRealm(mCurrentChallenge, realm); |
| 1385 | |
| 1386 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 1387 | nsAutoCString suffix; |
| 1388 | if (!mProxyAuth) { |
| 1389 | // Fill only for non-proxy auth, proxy credentials are not OA-isolated. |
| 1390 | GetOriginAttributesSuffix(chan, suffix); |
| 1391 | } |
| 1392 | |
| 1393 | nsHttpAuthCache* authCache = gHttpHandler->AuthCache(mIsPrivate); |
| 1394 | RefPtr<nsHttpAuthEntry> entry; |
| 1395 | (void)authCache->GetAuthEntryForDomain(scheme, host, port, realm, suffix, |
| 1396 | entry); |
| 1397 | |
| 1398 | nsCOMPtr<nsISupports> sessionStateGrip; |
| 1399 | if (entry) sessionStateGrip = entry->mMetaData; |
| 1400 | |
| 1401 | nsString domain, user, password; |
| 1402 | aAuthInfo->GetDomain(domain); |
| 1403 | aAuthInfo->GetUsername(user); |
| 1404 | aAuthInfo->GetPassword(password); |
| 1405 | *ident = nsHttpAuthIdentity(domain, user, password); |
| 1406 | |
| 1407 | nsAutoCString unused; |
| 1408 | nsCOMPtr<nsIHttpAuthenticator> auth; |
| 1409 | rv = GetAuthenticator(mCurrentChallenge, unused, getter_AddRefs(auth)); |
| 1410 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1411 | MOZ_ASSERT(false, "GetAuthenticator failed")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "GetAuthenticator failed" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "GetAuthenticator failed" ")"); do { MOZ_CrashSequence(__null , 1411); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 1412 | OnAuthCancelled(aContext, true); |
| 1413 | return NS_OK; |
| 1414 | } |
| 1415 | |
| 1416 | nsCString creds; |
| 1417 | rv = GenCredsAndSetEntry(auth, mProxyAuth, scheme, host, port, path, realm, |
| 1418 | mCurrentChallenge, *ident, sessionStateGrip, creds); |
| 1419 | if (rv == NS_ERROR_IN_PROGRESS) { |
| 1420 | // OnCredsGenerated will be called and needs mCurrentChallenge. |
| 1421 | return NS_OK; |
| 1422 | } |
| 1423 | |
| 1424 | mCurrentChallenge.Truncate(); |
| 1425 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1426 | OnAuthCancelled(aContext, true); |
| 1427 | return NS_OK; |
| 1428 | } |
| 1429 | |
| 1430 | return ContinueOnAuthAvailable(creds); |
| 1431 | } |
| 1432 | |
| 1433 | NS_IMETHODIMPnsresult nsHttpChannelAuthProvider::OnAuthCancelled(nsISupports* aContext, |
| 1434 | bool userCancel) { |
| 1435 | LOG(("nsHttpChannelAuthProvider::OnAuthCancelled [this=%p channel=%p]", this,do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::OnAuthCancelled [this=%p channel=%p]" , this, mAuthChannel); } } while (0) |
| 1436 | mAuthChannel))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "nsHttpChannelAuthProvider::OnAuthCancelled [this=%p channel=%p]" , this, mAuthChannel); } } while (0); |
| 1437 | |
| 1438 | mAsyncPromptAuthCancelable = nullptr; |
| 1439 | if (!mAuthChannel) return NS_OK; |
| 1440 | |
| 1441 | // When user cancels or auth fails we want to close the connection for |
| 1442 | // connection based schemes like NTLM. Some servers don't like re-negotiation |
| 1443 | // on the same connection. |
| 1444 | nsresult rv; |
| 1445 | if (mConnectionBased) { |
| 1446 | rv = mAuthChannel->CloseStickyConnection(); |
| 1447 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1447); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1447); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1448 | mConnectionBased = false; |
| 1449 | } |
| 1450 | |
| 1451 | nsCOMPtr<nsIChannel> channel = do_QueryInterface(mAuthChannel); |
| 1452 | if (channel) { |
| 1453 | nsresult status; |
| 1454 | (void)channel->GetStatus(&status); |
| 1455 | if (NS_FAILED(status)((bool)(__builtin_expect(!!(NS_FAILED_impl(status)), 0)))) { |
| 1456 | // If the channel is already cancelled, there is no need to deal with the |
| 1457 | // rest challenges. |
| 1458 | LOG((" Clear mRemainingChallenges, since mAuthChannel is cancelled"))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " Clear mRemainingChallenges, since mAuthChannel is cancelled" ); } } while (0); |
| 1459 | mRemainingChallenges.Truncate(); |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | if (userCancel) { |
| 1464 | if (!mRemainingChallenges.IsEmpty()) { |
| 1465 | // there are still some challenges to process, do so |
| 1466 | |
| 1467 | // Get rid of current continuationState to avoid reusing it in |
| 1468 | // next challenges since it is no longer relevant. |
| 1469 | if (mProxyAuth) { |
| 1470 | NS_IF_RELEASE(mProxyAuthContinuationState)do { if (mProxyAuthContinuationState) { (mProxyAuthContinuationState )->Release(); (mProxyAuthContinuationState) = 0; } } while (0); |
| 1471 | mProxyAuthType.Truncate(); |
| 1472 | } else { |
| 1473 | NS_IF_RELEASE(mAuthContinuationState)do { if (mAuthContinuationState) { (mAuthContinuationState)-> Release(); (mAuthContinuationState) = 0; } } while (0); |
| 1474 | mAuthType.Truncate(); |
| 1475 | } |
| 1476 | nsAutoCString creds; |
| 1477 | rv = GetCredentials(mRemainingChallenges, mProxyAuth, creds); |
| 1478 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1479 | // GetCredentials loaded the credentials from the cache or |
| 1480 | // some other way in a synchronous manner, process those |
| 1481 | // credentials now |
| 1482 | mRemainingChallenges.Truncate(); |
| 1483 | return ContinueOnAuthAvailable(creds); |
| 1484 | } |
| 1485 | if (rv == NS_ERROR_IN_PROGRESS) { |
| 1486 | // GetCredentials successfully queued another authprompt for |
| 1487 | // a challenge from the list, we are now waiting for the user |
| 1488 | // to provide the credentials |
| 1489 | return NS_OK; |
| 1490 | } |
| 1491 | |
| 1492 | // otherwise, we failed... |
| 1493 | } |
| 1494 | |
| 1495 | mRemainingChallenges.Truncate(); |
| 1496 | } |
| 1497 | |
| 1498 | rv = mAuthChannel->OnAuthCancelled(userCancel); |
| 1499 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1499); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1499); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1500 | |
| 1501 | return NS_OK; |
| 1502 | } |
| 1503 | |
| 1504 | NS_IMETHODIMPnsresult nsHttpChannelAuthProvider::OnCredsGenerated( |
| 1505 | const nsACString& aGeneratedCreds, uint32_t aFlags, nsresult aResult, |
| 1506 | nsISupports* aSessionState, nsISupports* aContinuationState) { |
| 1507 | nsresult rv; |
| 1508 | |
| 1509 | MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()" , "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1509); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence(__null, 1509); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1510 | |
| 1511 | // When channel is closed, do not proceed |
| 1512 | if (!mAuthChannel) { |
| 1513 | return NS_OK; |
| 1514 | } |
| 1515 | |
| 1516 | mGenerateCredentialsCancelable = nullptr; |
| 1517 | |
| 1518 | if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) { |
| 1519 | return OnAuthCancelled(nullptr, true); |
| 1520 | } |
| 1521 | |
| 1522 | // We want to update m(Proxy)AuthContinuationState in case it was changed by |
| 1523 | // nsHttpNegotiateAuth::GenerateCredentials |
| 1524 | nsCOMPtr<nsISupports> contState(aContinuationState); |
| 1525 | if (mProxyAuth) { |
| 1526 | contState.swap(mProxyAuthContinuationState); |
| 1527 | } else { |
| 1528 | contState.swap(mAuthContinuationState); |
| 1529 | } |
| 1530 | |
| 1531 | nsCOMPtr<nsIHttpAuthenticator> auth; |
| 1532 | nsAutoCString unused; |
| 1533 | rv = GetAuthenticator(mCurrentChallenge, unused, getter_AddRefs(auth)); |
| 1534 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1534); return rv; } } while (false); |
| 1535 | |
| 1536 | nsAutoCString host; |
| 1537 | int32_t port; |
| 1538 | nsHttpAuthIdentity* ident; |
| 1539 | nsAutoCString directory, scheme; |
| 1540 | nsISupports** unusedContinuationState; |
| 1541 | |
| 1542 | // Get realm from challenge |
| 1543 | nsAutoCString realm; |
| 1544 | ParseRealm(mCurrentChallenge, realm); |
| 1545 | |
| 1546 | rv = GetAuthorizationMembers(mProxyAuth, scheme, host, port, directory, ident, |
| 1547 | unusedContinuationState); |
| 1548 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1549 | |
| 1550 | rv = |
| 1551 | UpdateCache(auth, scheme, host, port, directory, realm, mCurrentChallenge, |
| 1552 | *ident, aGeneratedCreds, aFlags, aSessionState, mProxyAuth); |
| 1553 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1553); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1553); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1554 | mCurrentChallenge.Truncate(); |
| 1555 | |
| 1556 | rv = ContinueOnAuthAvailable(aGeneratedCreds); |
| 1557 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1557); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1557); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1558 | return NS_OK; |
| 1559 | } |
| 1560 | |
| 1561 | nsresult nsHttpChannelAuthProvider::ContinueOnAuthAvailable( |
| 1562 | const nsACString& creds) { |
| 1563 | nsresult rv; |
| 1564 | if (mProxyAuth) { |
| 1565 | rv = mAuthChannel->SetProxyCredentials(creds); |
| 1566 | } else { |
| 1567 | rv = mAuthChannel->SetWWWCredentials(creds); |
| 1568 | } |
| 1569 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1570 | |
| 1571 | // drop our remaining list of challenges. We don't need them, because we |
| 1572 | // have now authenticated against a challenge and will be sending that |
| 1573 | // information to the server (or proxy). If it doesn't accept our |
| 1574 | // authentication it'll respond with failure and resend the challenge list |
| 1575 | mRemainingChallenges.Truncate(); |
| 1576 | |
| 1577 | (void)mAuthChannel->OnAuthAvailable(); |
| 1578 | |
| 1579 | return NS_OK; |
| 1580 | } |
| 1581 | |
| 1582 | void nsHttpChannelAuthProvider::SetAuthorizationHeader( |
| 1583 | nsHttpAuthCache* authCache, const nsHttpAtom& header, |
| 1584 | const nsACString& scheme, const nsACString& host, int32_t port, |
| 1585 | const nsACString& path, nsHttpAuthIdentity& ident) { |
| 1586 | RefPtr<nsHttpAuthEntry> entry; |
| 1587 | nsresult rv; |
| 1588 | |
| 1589 | // set informations that depend on whether |
| 1590 | // we're authenticating against a proxy |
| 1591 | // or a webserver |
| 1592 | nsISupports** continuationState; |
| 1593 | |
| 1594 | nsAutoCString suffix; |
| 1595 | if (header == nsHttp::Proxy_Authorization) { |
| 1596 | continuationState = &mProxyAuthContinuationState; |
| 1597 | |
| 1598 | if (mProxyInfo) { |
| 1599 | nsAutoCString type; |
| 1600 | mProxyInfo->GetType(type); |
| 1601 | if (type.EqualsLiteral("https") || type.EqualsLiteral("masque")) { |
| 1602 | // Let this be overriden by anything from the cache. |
| 1603 | auto const& pa = mProxyInfo->ProxyAuthorizationHeader(); |
| 1604 | if (!pa.IsEmpty()) { |
| 1605 | rv = mAuthChannel->SetProxyCredentials(pa); |
| 1606 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1606); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1606); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | } else { |
| 1611 | continuationState = &mAuthContinuationState; |
| 1612 | |
| 1613 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 1614 | GetOriginAttributesSuffix(chan, suffix); |
| 1615 | } |
| 1616 | |
| 1617 | rv = authCache->GetAuthEntryForPath(scheme, host, port, path, suffix, entry); |
| 1618 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1619 | // if we are trying to add a header for origin server auth and if the |
| 1620 | // URL contains an explicit username, then try the given username first. |
| 1621 | // we only want to do this, however, if we know the URL requires auth |
| 1622 | // based on the presence of an auth cache entry for this URL (which is |
| 1623 | // true since we are here). but, if the username from the URL matches |
| 1624 | // the username from the cache, then we should prefer the password |
| 1625 | // stored in the cache since that is most likely to be valid. |
| 1626 | if (header == nsHttp::Authorization && entry->Domain()[0] == '\0') { |
| 1627 | GetIdentityFromURI(0, ident); |
| 1628 | // if the usernames match, then clear the ident so we will pick |
| 1629 | // up the one from the auth cache instead. |
| 1630 | // when this is undesired, specify LOAD_EXPLICIT_CREDENTIALS load |
| 1631 | // flag. |
| 1632 | if (ident.User() == entry->User()) { |
| 1633 | uint32_t loadFlags; |
| 1634 | if (NS_SUCCEEDED(mAuthChannel->GetLoadFlags(&loadFlags))((bool)(__builtin_expect(!!(!NS_FAILED_impl(mAuthChannel-> GetLoadFlags(&loadFlags))), 1))) && |
| 1635 | !(loadFlags & nsIChannel::LOAD_EXPLICIT_CREDENTIALS)) { |
| 1636 | ident.Clear(); |
| 1637 | } |
| 1638 | } |
| 1639 | } |
| 1640 | bool identFromURI; |
| 1641 | if (ident.IsEmpty()) { |
| 1642 | ident = entry->Identity(); |
| 1643 | identFromURI = false; |
| 1644 | } else { |
| 1645 | identFromURI = true; |
| 1646 | } |
| 1647 | |
| 1648 | nsCString temp; // this must have the same lifetime as creds |
| 1649 | nsAutoCString creds(entry->Creds()); |
| 1650 | // we can only send a preemptive Authorization header if we have either |
| 1651 | // stored credentials or a stored challenge from which to derive |
| 1652 | // credentials. if the identity is from the URI, then we cannot use |
| 1653 | // the stored credentials. |
| 1654 | if ((creds.IsEmpty() || identFromURI) && !entry->Challenge().IsEmpty()) { |
| 1655 | nsCOMPtr<nsIHttpAuthenticator> auth; |
| 1656 | nsAutoCString unused; |
| 1657 | rv = GetAuthenticator(entry->Challenge(), unused, getter_AddRefs(auth)); |
| 1658 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1659 | bool proxyAuth = (header == nsHttp::Proxy_Authorization); |
| 1660 | rv = GenCredsAndSetEntry(auth, proxyAuth, scheme, host, port, path, |
| 1661 | entry->Realm(), entry->Challenge(), ident, |
| 1662 | entry->mMetaData, temp); |
| 1663 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) creds = temp; |
| 1664 | |
| 1665 | // make sure the continuation state is null since we do not |
| 1666 | // support mixing preemptive and 'multirequest' authentication. |
| 1667 | NS_IF_RELEASE(*continuationState)do { if (*continuationState) { (*continuationState)->Release (); (*continuationState) = 0; } } while (0); |
| 1668 | } |
| 1669 | } |
| 1670 | if (!creds.IsEmpty()) { |
| 1671 | LOG((" adding \"%s\" request header\n", header.get()))do { const ::mozilla::LogModule* moz_real_module = mozilla::net ::gHttpLog; if ((__builtin_expect(!!(mozilla::detail::log_test (moz_real_module, mozilla::LogLevel::Debug)), 0))) { mozilla:: detail::log_print(moz_real_module, mozilla::LogLevel::Debug, " adding \"%s\" request header\n" , header.get()); } } while (0); |
| 1672 | if (header == nsHttp::Proxy_Authorization) { |
| 1673 | rv = mAuthChannel->SetProxyCredentials(creds); |
| 1674 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1674); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1674); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1675 | } else { |
| 1676 | rv = mAuthChannel->SetWWWCredentials(creds); |
| 1677 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1677); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1677); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1678 | } |
| 1679 | } else { |
| 1680 | ident.Clear(); // don't remember the identity |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | nsresult nsHttpChannelAuthProvider::GetCurrentPath(nsACString& path) { |
| 1686 | nsresult rv; |
| 1687 | nsCOMPtr<nsIURL> url = do_QueryInterface(mURI); |
| 1688 | if (url) { |
| 1689 | rv = url->GetDirectory(path); |
| 1690 | } else { |
| 1691 | rv = mURI->GetPathQueryRef(path); |
| 1692 | } |
| 1693 | return rv; |
| 1694 | } |
| 1695 | |
| 1696 | NS_IMPL_ISUPPORTS(nsHttpChannelAuthProvider, nsICancelable,MozExternalRefCountType nsHttpChannelAuthProvider::AddRef(void ) { static_assert(!std::is_destructible_v<nsHttpChannelAuthProvider >, "Reference-counted class " "nsHttpChannelAuthProvider" " should not have a public destructor. " "Make this class's destructor non-public"); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 1698 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsHttpChannelAuthProvider" != nullptr)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!("nsHttpChannelAuthProvider" != nullptr))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsHttpChannelAuthProvider\" != nullptr" " (" "Must specify a name" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1698); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsHttpChannelAuthProvider" " not thread-safe" ); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ( "nsHttpChannelAuthProvider"), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType nsHttpChannelAuthProvider:: Release(void) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 1698 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsHttpChannelAuthProvider" != nullptr)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!("nsHttpChannelAuthProvider" != nullptr))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsHttpChannelAuthProvider\" != nullptr" " (" "Must specify a name" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1698); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsHttpChannelAuthProvider" " not thread-safe" ); const char* const nametmp = "nsHttpChannelAuthProvider"; nsrefcnt count = --mRefCnt; NS_LogRelease((this), (count), (nametmp)) ; if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult nsHttpChannelAuthProvider::QueryInterface( const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<nsHttpChannelAuthProvider, nsICancelable >, int32_t( reinterpret_cast<char*>(static_cast<nsICancelable *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIHttpChannelAuthProvider >, int32_t( reinterpret_cast<char*>(static_cast<nsIHttpChannelAuthProvider *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIAuthPromptCallback >, int32_t( reinterpret_cast<char*>(static_cast<nsIAuthPromptCallback *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIHttpAuthenticatorCallback >, int32_t( reinterpret_cast<char*>(static_cast<nsIHttpAuthenticatorCallback *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsISupports >, int32_t(reinterpret_cast<char*>(static_cast<nsISupports *>( static_cast<nsICancelable*>((nsHttpChannelAuthProvider *)0x1000))) - reinterpret_cast<char*>((nsHttpChannelAuthProvider *)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table ) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; } |
| 1697 | nsIHttpChannelAuthProvider, nsIAuthPromptCallback,MozExternalRefCountType nsHttpChannelAuthProvider::AddRef(void ) { static_assert(!std::is_destructible_v<nsHttpChannelAuthProvider >, "Reference-counted class " "nsHttpChannelAuthProvider" " should not have a public destructor. " "Make this class's destructor non-public"); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 1698 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsHttpChannelAuthProvider" != nullptr)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!("nsHttpChannelAuthProvider" != nullptr))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsHttpChannelAuthProvider\" != nullptr" " (" "Must specify a name" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1698); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsHttpChannelAuthProvider" " not thread-safe" ); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ( "nsHttpChannelAuthProvider"), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType nsHttpChannelAuthProvider:: Release(void) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 1698 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsHttpChannelAuthProvider" != nullptr)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!("nsHttpChannelAuthProvider" != nullptr))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsHttpChannelAuthProvider\" != nullptr" " (" "Must specify a name" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1698); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsHttpChannelAuthProvider" " not thread-safe" ); const char* const nametmp = "nsHttpChannelAuthProvider"; nsrefcnt count = --mRefCnt; NS_LogRelease((this), (count), (nametmp)) ; if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult nsHttpChannelAuthProvider::QueryInterface( const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<nsHttpChannelAuthProvider, nsICancelable >, int32_t( reinterpret_cast<char*>(static_cast<nsICancelable *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIHttpChannelAuthProvider >, int32_t( reinterpret_cast<char*>(static_cast<nsIHttpChannelAuthProvider *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIAuthPromptCallback >, int32_t( reinterpret_cast<char*>(static_cast<nsIAuthPromptCallback *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIHttpAuthenticatorCallback >, int32_t( reinterpret_cast<char*>(static_cast<nsIHttpAuthenticatorCallback *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsISupports >, int32_t(reinterpret_cast<char*>(static_cast<nsISupports *>( static_cast<nsICancelable*>((nsHttpChannelAuthProvider *)0x1000))) - reinterpret_cast<char*>((nsHttpChannelAuthProvider *)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table ) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; } |
| 1698 | nsIHttpAuthenticatorCallback)MozExternalRefCountType nsHttpChannelAuthProvider::AddRef(void ) { static_assert(!std::is_destructible_v<nsHttpChannelAuthProvider >, "Reference-counted class " "nsHttpChannelAuthProvider" " should not have a public destructor. " "Make this class's destructor non-public"); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 1698 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsHttpChannelAuthProvider" != nullptr)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!("nsHttpChannelAuthProvider" != nullptr))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsHttpChannelAuthProvider\" != nullptr" " (" "Must specify a name" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1698); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsHttpChannelAuthProvider" " not thread-safe" ); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ( "nsHttpChannelAuthProvider"), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType nsHttpChannelAuthProvider:: Release(void) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 1698 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsHttpChannelAuthProvider" != nullptr)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!("nsHttpChannelAuthProvider" != nullptr))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsHttpChannelAuthProvider\" != nullptr" " (" "Must specify a name" ")", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1698); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsHttpChannelAuthProvider" " not thread-safe" ); const char* const nametmp = "nsHttpChannelAuthProvider"; nsrefcnt count = --mRefCnt; NS_LogRelease((this), (count), (nametmp)) ; if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult nsHttpChannelAuthProvider::QueryInterface( const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp" , 1698); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<nsHttpChannelAuthProvider, nsICancelable >, int32_t( reinterpret_cast<char*>(static_cast<nsICancelable *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIHttpChannelAuthProvider >, int32_t( reinterpret_cast<char*>(static_cast<nsIHttpChannelAuthProvider *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIAuthPromptCallback >, int32_t( reinterpret_cast<char*>(static_cast<nsIAuthPromptCallback *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsIHttpAuthenticatorCallback >, int32_t( reinterpret_cast<char*>(static_cast<nsIHttpAuthenticatorCallback *>((nsHttpChannelAuthProvider*)0x1000)) - reinterpret_cast <char*>((nsHttpChannelAuthProvider*)0x1000))}, {&mozilla ::detail::kImplementedIID<nsHttpChannelAuthProvider, nsISupports >, int32_t(reinterpret_cast<char*>(static_cast<nsISupports *>( static_cast<nsICancelable*>((nsHttpChannelAuthProvider *)0x1000))) - reinterpret_cast<char*>((nsHttpChannelAuthProvider *)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table ) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; } |
| 1699 | |
| 1700 | } // namespace mozilla::net |