| File: | root/firefox-clang/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp |
| Warning: | line 956, 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 | mCurrentChallenge = cc[i].challenge; |
| 686 | // imperfect; does not save server-side preference ordering. |
| 687 | // instead, continues with remaining string as provided by client |
| 688 | mRemainingChallenges.Truncate(); |
| 689 | while (i + 1 < cc.Length()) { |
| 690 | i++; |
| 691 | mRemainingChallenges.Append(cc[i].challenge); |
| 692 | mRemainingChallenges.Append("\n"_ns); |
| 693 | } |
| 694 | return rv; |
| 695 | } |
| 696 | |
| 697 | // reset the auth type and continuation state |
| 698 | NS_IF_RELEASE(*currentContinuationState)do { if (*currentContinuationState) { (*currentContinuationState )->Release(); (*currentContinuationState) = 0; } } while ( 0); |
| 699 | currentAuthType->Truncate(); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | if (!gotCreds && !currentAuthType->IsEmpty()) { |
| 704 | // looks like we never found the auth type we were looking for. |
| 705 | // reset the auth type and continuation state, and try again. |
| 706 | currentAuthType->Truncate(); |
| 707 | NS_IF_RELEASE(*currentContinuationState)do { if (*currentContinuationState) { (*currentContinuationState )->Release(); (*currentContinuationState) = 0; } } while ( 0); |
| 708 | |
| 709 | rv = GetCredentials(challenges, proxyAuth, creds); |
| 710 | } |
| 711 | |
| 712 | return rv; |
| 713 | } |
| 714 | |
| 715 | nsresult nsHttpChannelAuthProvider::GetAuthorizationMembers( |
| 716 | bool proxyAuth, nsACString& scheme, nsCString& host, int32_t& port, |
| 717 | nsACString& path, nsHttpAuthIdentity*& ident, |
| 718 | nsISupports**& continuationState) { |
| 719 | if (proxyAuth) { |
| 720 | 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" , 721); AnnotateMozCrashReason("MOZ_ASSERT" "(" "UsingHttpProxy()" ") (" "proxyAuth is true, but no HTTP proxy is configured!" ")" ); do { MOZ_CrashSequence(__null, 721); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 721 | "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" , 721); AnnotateMozCrashReason("MOZ_ASSERT" "(" "UsingHttpProxy()" ") (" "proxyAuth is true, but no HTTP proxy is configured!" ")" ); do { MOZ_CrashSequence(__null, 721); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 722 | |
| 723 | host = ProxyHost(); |
| 724 | port = ProxyPort(); |
| 725 | ident = &mProxyIdent; |
| 726 | scheme.AssignLiteral("http"); |
| 727 | |
| 728 | continuationState = &mProxyAuthContinuationState; |
| 729 | } else { |
| 730 | host = Host(); |
| 731 | port = Port(); |
| 732 | ident = &mIdent; |
| 733 | |
| 734 | nsresult rv; |
| 735 | rv = GetCurrentPath(path); |
| 736 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 737 | |
| 738 | rv = mURI->GetScheme(scheme); |
| 739 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 740 | |
| 741 | continuationState = &mAuthContinuationState; |
| 742 | } |
| 743 | |
| 744 | return NS_OK; |
| 745 | } |
| 746 | |
| 747 | nsresult nsHttpChannelAuthProvider::GetCredentialsForChallenge( |
| 748 | const nsACString& aChallenge, const nsACString& aAuthType, bool proxyAuth, |
| 749 | nsIHttpAuthenticator* auth, nsCString& creds) { |
| 750 | 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) |
| 751 | ("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) |
| 752 | "[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) |
| 753 | 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); |
| 754 | |
| 755 | // this getter never fails |
| 756 | nsHttpAuthCache* authCache = gHttpHandler->AuthCache(mIsPrivate); |
| 757 | |
| 758 | uint32_t authFlags; |
| 759 | nsresult rv = auth->GetAuthFlags(&authFlags); |
| 760 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 761 | |
| 762 | nsAutoCString realm; |
| 763 | ParseRealm(aChallenge, realm); |
| 764 | |
| 765 | // if no realm, then use the auth type as the realm. ToUpperCase so the |
| 766 | // ficticious realm stands out a bit more. |
| 767 | // XXX this will cause some single signon misses! |
| 768 | // XXX this was meant to be used with NTLM, which supplies no realm. |
| 769 | /* |
| 770 | if (realm.IsEmpty()) { |
| 771 | realm = authType; |
| 772 | ToUpperCase(realm); |
| 773 | } |
| 774 | */ |
| 775 | |
| 776 | // set informations that depend on whether |
| 777 | // we're authenticating against a proxy |
| 778 | // or a webserver |
| 779 | nsAutoCString host; |
| 780 | int32_t port; |
| 781 | nsHttpAuthIdentity* ident; |
| 782 | nsAutoCString path, scheme; |
| 783 | bool identFromURI = false; |
| 784 | nsISupports** continuationState; |
| 785 | |
| 786 | rv = GetAuthorizationMembers(proxyAuth, scheme, host, port, path, ident, |
| 787 | continuationState); |
| 788 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 789 | |
| 790 | uint32_t loadFlags; |
| 791 | rv = mAuthChannel->GetLoadFlags(&loadFlags); |
| 792 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 793 | |
| 794 | // Fill only for non-proxy auth, proxy credentials are not OA-isolated. |
| 795 | nsAutoCString suffix; |
| 796 | |
| 797 | if (!proxyAuth) { |
| 798 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 799 | GetOriginAttributesSuffix(chan, suffix); |
| 800 | |
| 801 | // if this is the first challenge, then try using the identity |
| 802 | // specified in the URL. |
| 803 | if (mIdent.IsEmpty()) { |
| 804 | GetIdentityFromURI(authFlags, mIdent); |
| 805 | identFromURI = !mIdent.IsEmpty(); |
| 806 | } |
| 807 | |
| 808 | if ((loadFlags & nsIRequest::LOAD_ANONYMOUS) && !identFromURI) { |
| 809 | 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); |
| 810 | return NS_ERROR_NOT_AVAILABLE; |
| 811 | } |
| 812 | |
| 813 | // Let explicit URL credentials pass |
| 814 | // regardless of the LOAD_ANONYMOUS flag |
| 815 | } else if ((loadFlags & nsIRequest::LOAD_ANONYMOUS) && !UsingHttpProxy()) { |
| 816 | 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); |
| 817 | return NS_ERROR_NOT_AVAILABLE; |
| 818 | } |
| 819 | |
| 820 | // |
| 821 | // if we already tried some credentials for this transaction, then |
| 822 | // we need to possibly clear them from the cache, unless the credentials |
| 823 | // in the cache have changed, in which case we'd want to give them a |
| 824 | // try instead. |
| 825 | // |
| 826 | RefPtr<nsHttpAuthEntry> entry; |
| 827 | (void)authCache->GetAuthEntryForDomain(scheme, host, port, realm, suffix, |
| 828 | entry); |
| 829 | |
| 830 | // hold reference to the auth session state (in case we clear our |
| 831 | // reference to the entry). |
| 832 | nsCOMPtr<nsISupports> sessionStateGrip; |
| 833 | if (entry) sessionStateGrip = entry->mMetaData; |
| 834 | |
| 835 | // remember if we already had the continuation state. it means we are in |
| 836 | // the middle of the authentication exchange and the connection must be |
| 837 | // kept sticky then (and only then). |
| 838 | bool authAtProgress = !!*continuationState; |
| 839 | |
| 840 | // for digest auth, maybe our cached nonce value simply timed out... |
| 841 | bool identityInvalid; |
| 842 | nsISupports* sessionState = sessionStateGrip; |
| 843 | rv = auth->ChallengeReceived(mAuthChannel, aChallenge, proxyAuth, |
| 844 | &sessionState, &*continuationState, |
| 845 | &identityInvalid); |
| 846 | sessionStateGrip.swap(sessionState); |
| 847 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 848 | |
| 849 | 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); |
| 850 | |
| 851 | if (mConnectionBased && identityInvalid) { |
| 852 | // If the flag is set and identity is invalid, it means we received the |
| 853 | // first challange for a new negotiation round after negotiating a |
| 854 | // connection based auth failed (invalid password). The mConnectionBased |
| 855 | // flag is set later for the newly received challenge, so here it reflects |
| 856 | // the previous 401/7 response schema. |
| 857 | rv = mAuthChannel->CloseStickyConnection(); |
| 858 | 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" , 858); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 858); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 859 | if (!proxyAuth) { |
| 860 | // We must clear proxy ident in the following scenario + explanation: |
| 861 | // - we are authenticating to an NTLM proxy and an NTLM server |
| 862 | // - we successfully authenticated to the proxy, mProxyIdent keeps |
| 863 | // the user name/domain and password, the identity has also been cached |
| 864 | // - we just threw away the connection because we are now asking for |
| 865 | // creds for the server (WWW auth) |
| 866 | // - hence, we will have to auth to the proxy again as well |
| 867 | // - if we didn't clear the proxy identity, it would be considered |
| 868 | // as non-valid and we would ask the user again ; clearing it forces |
| 869 | // use of the cached identity and not asking the user again |
| 870 | ClearProxyIdent(); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | mConnectionBased = !!(authFlags & nsIHttpAuthenticator::CONNECTION_BASED); |
| 875 | |
| 876 | // It's legal if the peer closes the connection after the first 401/7. |
| 877 | // Making the connection sticky will prevent its restart giving the user |
| 878 | // a 'network reset' error every time. Hence, we mark the connection |
| 879 | // as restartable. |
| 880 | mAuthChannel->ConnectionRestartable(!authAtProgress); |
| 881 | |
| 882 | if (identFromURI && |
| 883 | (authFlags & nsIHttpAuthenticator::IDENTITY_INCLUDES_DOMAIN)) { |
| 884 | 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); |
| 885 | ident->Clear(); |
| 886 | identFromURI = false; |
| 887 | } |
| 888 | |
| 889 | if (identityInvalid) { |
| 890 | if (entry) { |
| 891 | if (ident->Equals(entry->Identity())) { |
| 892 | if (!identFromURI) { |
| 893 | 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); |
| 894 | // ok, we've already tried this user identity, so clear the |
| 895 | // corresponding entry from the auth cache. |
| 896 | authCache->ClearAuthEntry(scheme, host, port, realm, suffix); |
| 897 | entry = nullptr; |
| 898 | ident->Clear(); |
| 899 | } |
| 900 | } else if (!identFromURI || |
| 901 | (ident->User() == entry->Identity().User() && |
| 902 | !(loadFlags & (nsIChannel::LOAD_ANONYMOUS | |
| 903 | nsIChannel::LOAD_EXPLICIT_CREDENTIALS)))) { |
| 904 | 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); |
| 905 | // the password from the auth cache is more likely to be |
| 906 | // correct than the one in the URL. at least, we know that it |
| 907 | // works with the given username. it is possible for a server |
| 908 | // to distinguish logons based on the supplied password alone, |
| 909 | // but that would be quite unusual... and i don't think we need |
| 910 | // to worry about such unorthodox cases. |
| 911 | *ident = entry->Identity(); |
| 912 | identFromURI = false; |
| 913 | if (entry->Creds()[0] != '\0') { |
| 914 | 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); |
| 915 | creds.Assign(entry->Creds()); |
| 916 | return entry->AddPath(path); |
| 917 | } |
| 918 | } |
| 919 | } else if (!identFromURI) { |
| 920 | // hmm... identity invalid, but no auth entry! the realm probably |
| 921 | // changed (see bug 201986). |
| 922 | ident->Clear(); |
| 923 | } |
| 924 | |
| 925 | if (!entry && ident->IsEmpty()) { |
| 926 | uint32_t level = nsIAuthPrompt2::LEVEL_NONE; |
| 927 | if ((!proxyAuth && mUsingSSL) || (proxyAuth && mProxyUsingSSL)) { |
| 928 | level = nsIAuthPrompt2::LEVEL_SECURE; |
| 929 | } else if (authFlags & nsIHttpAuthenticator::IDENTITY_ENCRYPTED) { |
| 930 | level = nsIAuthPrompt2::LEVEL_PW_ENCRYPTED; |
| 931 | } |
| 932 | |
| 933 | // Depending on the pref setting, the authentication dialog may be |
| 934 | // blocked for all sub-resources, blocked for cross-origin |
| 935 | // sub-resources, or always allowed for sub-resources. |
| 936 | // For more details look at the bug 647010. |
| 937 | // BlockPrompt will set mCrossOrigin parameter as well. |
| 938 | if (BlockPrompt(proxyAuth)) { |
| 939 | 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) |
| 940 | "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) |
| 941 | "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) |
| 942 | "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) |
| 943 | 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) |
| 944 | 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) |
| 945 | 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) |
| 946 | 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) |
| 947 | 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); |
| 948 | return NS_ERROR_ABORT; |
| 949 | } |
| 950 | |
| 951 | // at this point we are forced to interact with the user to get |
| 952 | // their username and password for this domain. |
| 953 | rv = PromptForIdentity(level, proxyAuth, realm, aAuthType, authFlags, |
| 954 | *ident); |
| 955 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 956 | identFromURI = false; |
Value stored to 'identFromURI' is never read | |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | // get credentials for the given user:pass |
| 961 | // |
| 962 | // always store the credentials we're trying now so that they will be used |
| 963 | // on subsequent links. This will potentially remove good credentials from |
| 964 | // the cache. This is ok as we don't want to use cached credentials if the |
| 965 | // user specified something on the URI or in another manner. This is so |
| 966 | // that we don't transparently authenticate as someone they're not |
| 967 | // expecting to authenticate as. |
| 968 | // |
| 969 | nsCString result; |
| 970 | rv = GenCredsAndSetEntry(auth, proxyAuth, scheme, host, port, path, realm, |
| 971 | aChallenge, *ident, sessionStateGrip, creds); |
| 972 | return rv; |
| 973 | } |
| 974 | |
| 975 | bool nsHttpChannelAuthProvider::BlockPrompt(bool proxyAuth) { |
| 976 | // Verify that it's ok to prompt for credentials here, per spec |
| 977 | // http://xhr.spec.whatwg.org/#the-send%28%29-method |
| 978 | |
| 979 | nsCOMPtr<nsIHttpChannelInternal> chanInternal = |
| 980 | do_QueryInterface(mAuthChannel); |
| 981 | 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" , 981); AnnotateMozCrashReason("MOZ_ASSERT" "(" "chanInternal" ")"); do { MOZ_CrashSequence(__null, 981); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 982 | |
| 983 | if (chanInternal->GetBlockAuthPrompt()) { |
| 984 | 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) |
| 985 | ("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) |
| 986 | "[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) |
| 987 | 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); |
| 988 | return true; |
| 989 | } |
| 990 | |
| 991 | if (proxyAuth) { |
| 992 | // Do not block auth-dialog if this is a proxy authentication. |
| 993 | return false; |
| 994 | } |
| 995 | |
| 996 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 997 | nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo(); |
| 998 | |
| 999 | // We will treat loads w/o loadInfo as a top level document. |
| 1000 | bool topDoc = true; |
| 1001 | bool xhr = false; |
| 1002 | bool nonWebContent = false; |
| 1003 | |
| 1004 | if (loadInfo->GetExternalContentPolicyType() != |
| 1005 | ExtContentPolicy::TYPE_DOCUMENT) { |
| 1006 | topDoc = false; |
| 1007 | } |
| 1008 | |
| 1009 | if (!topDoc) { |
| 1010 | nsCOMPtr<nsIPrincipal> triggeringPrinc = loadInfo->TriggeringPrincipal(); |
| 1011 | if (triggeringPrinc->IsSystemPrincipal()) { |
| 1012 | nonWebContent = true; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | if (loadInfo->GetExternalContentPolicyType() == |
| 1017 | ExtContentPolicy::TYPE_XMLHTTPREQUEST) { |
| 1018 | xhr = true; |
| 1019 | } |
| 1020 | |
| 1021 | if (!topDoc && !xhr) { |
| 1022 | nsCOMPtr<nsIURI> topURI; |
| 1023 | (void)chanInternal->GetTopWindowURI(getter_AddRefs(topURI)); |
| 1024 | if (topURI) { |
| 1025 | mCrossOrigin = !NS_SecurityCompareURIs(topURI, mURI, true); |
| 1026 | } else { |
| 1027 | nsIPrincipal* loadingPrinc = loadInfo->GetLoadingPrincipal(); |
| 1028 | 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" , 1028); AnnotateMozCrashReason("MOZ_ASSERT" "(" "loadingPrinc" ")"); do { MOZ_CrashSequence(__null, 1028); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1029 | mCrossOrigin = !loadingPrinc->IsSameOrigin(mURI); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | if (!topDoc && |
| 1034 | !StaticPrefs:: |
| 1035 | network_auth_non_web_content_triggered_resources_http_auth_allow() && |
| 1036 | nonWebContent) { |
| 1037 | return true; |
| 1038 | } |
| 1039 | |
| 1040 | switch (StaticPrefs::network_auth_subresource_http_auth_allow()) { |
| 1041 | case SUBRESOURCE_AUTH_DIALOG_DISALLOW_ALL0: |
| 1042 | // Do not open the http-authentication credentials dialog for |
| 1043 | // the sub-resources. |
| 1044 | return !topDoc && !xhr; |
| 1045 | case SUBRESOURCE_AUTH_DIALOG_DISALLOW_CROSS_ORIGIN1: |
| 1046 | // Open the http-authentication credentials dialog for |
| 1047 | // the sub-resources only if they are not cross-origin. |
| 1048 | return !topDoc && !xhr && mCrossOrigin; |
| 1049 | case SUBRESOURCE_AUTH_DIALOG_ALLOW_ALL2: |
| 1050 | // Allow the http-authentication dialog for subresources. |
| 1051 | // If pref network.auth.subresource-img-cross-origin-http-auth-allow |
| 1052 | // is set, http-authentication dialog for image subresources is |
| 1053 | // blocked. |
| 1054 | if (mCrossOrigin && |
| 1055 | !StaticPrefs:: |
| 1056 | network_auth_subresource_img_cross_origin_http_auth_allow() && |
| 1057 | loadInfo && |
| 1058 | ((loadInfo->GetExternalContentPolicyType() == |
| 1059 | ExtContentPolicy::TYPE_IMAGE) || |
| 1060 | (loadInfo->GetExternalContentPolicyType() == |
| 1061 | ExtContentPolicy::TYPE_IMAGESET))) { |
| 1062 | return true; |
| 1063 | } |
| 1064 | return false; |
| 1065 | default: |
| 1066 | // This is an invalid value. |
| 1067 | 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" , 1067); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "A non valid value!" ")"); do { MOZ_CrashSequence(__null, 1067 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 1068 | } |
| 1069 | return false; |
| 1070 | } |
| 1071 | |
| 1072 | inline void GetAuthType(const nsACString& aChallenge, nsCString& authType) { |
| 1073 | auto spaceIndex = aChallenge.FindChar(' '); |
| 1074 | authType = Substring(aChallenge, 0, spaceIndex); |
| 1075 | // normalize to lowercase |
| 1076 | ToLowerCase(authType); |
| 1077 | } |
| 1078 | |
| 1079 | nsresult nsHttpChannelAuthProvider::GetAuthenticator( |
| 1080 | const nsACString& aChallenge, nsCString& authType, |
| 1081 | nsIHttpAuthenticator** auth) { |
| 1082 | 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) |
| 1083 | 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); |
| 1084 | |
| 1085 | GetAuthType(aChallenge, authType); |
| 1086 | |
| 1087 | nsCOMPtr<nsIHttpAuthenticator> authenticator; |
| 1088 | #ifdef MOZ_AUTH_EXTENSION1 |
| 1089 | if (authType.EqualsLiteral("negotiate")) { |
| 1090 | authenticator = nsHttpNegotiateAuth::GetOrCreate(); |
| 1091 | } else |
| 1092 | #endif |
| 1093 | if (authType.EqualsLiteral("basic")) { |
| 1094 | authenticator = nsHttpBasicAuth::GetOrCreate(); |
| 1095 | } else if (authType.EqualsLiteral("digest")) { |
| 1096 | authenticator = nsHttpDigestAuth::GetOrCreate(); |
| 1097 | } else if (authType.EqualsLiteral("ntlm")) { |
| 1098 | authenticator = nsHttpNTLMAuth::GetOrCreate(); |
| 1099 | } else if (authType.EqualsLiteral("mock_auth") && |
| 1100 | PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR")) { |
| 1101 | authenticator = MockHttpAuth::Create(); |
| 1102 | } else { |
| 1103 | return NS_ERROR_FACTORY_NOT_REGISTERED; |
| 1104 | } |
| 1105 | |
| 1106 | if (!authenticator) { |
| 1107 | // If called during shutdown it's possible that the singleton authenticator |
| 1108 | // was already cleared so we have a null one here. |
| 1109 | return NS_ERROR_NOT_AVAILABLE; |
| 1110 | } |
| 1111 | |
| 1112 | 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" , 1112); AnnotateMozCrashReason("MOZ_ASSERT" "(" "authenticator" ")"); do { MOZ_CrashSequence(__null, 1112); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1113 | authenticator.forget(auth); |
| 1114 | |
| 1115 | return NS_OK; |
| 1116 | } |
| 1117 | |
| 1118 | // buf contains "domain\user" |
| 1119 | static void ParseUserDomain(const nsAString& buf, nsDependentSubstring& user, |
| 1120 | nsDependentSubstring& domain) { |
| 1121 | auto backslashPos = buf.FindChar(u'\\'); |
| 1122 | if (backslashPos != kNotFound) { |
| 1123 | domain.Rebind(buf, 0, backslashPos); |
| 1124 | user.Rebind(buf, backslashPos + 1); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | void nsHttpChannelAuthProvider::GetIdentityFromURI(uint32_t authFlags, |
| 1129 | nsHttpAuthIdentity& ident) { |
| 1130 | 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) |
| 1131 | 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); |
| 1132 | |
| 1133 | bool hasUserPass; |
| 1134 | if (NS_FAILED(mURI->GetHasUserPass(&hasUserPass))((bool)(__builtin_expect(!!(NS_FAILED_impl(mURI->GetHasUserPass (&hasUserPass))), 0))) || !hasUserPass) { |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | nsAutoString userBuf; |
| 1139 | nsAutoString passBuf; |
| 1140 | |
| 1141 | // XXX i18n |
| 1142 | nsAutoCString buf; |
| 1143 | nsresult rv = mURI->GetUsername(buf); |
| 1144 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1145 | return; |
| 1146 | } |
| 1147 | NS_UnescapeURL(buf); |
| 1148 | CopyUTF8toUTF16(buf, userBuf); |
| 1149 | |
| 1150 | rv = mURI->GetPassword(buf); |
| 1151 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1152 | return; |
| 1153 | } |
| 1154 | NS_UnescapeURL(buf); |
| 1155 | CopyUTF8toUTF16(buf, passBuf); |
| 1156 | |
| 1157 | nsDependentSubstring user(userBuf, 0); |
| 1158 | nsDependentSubstring domain(EmptyString(), 0); |
| 1159 | |
| 1160 | if (authFlags & nsIHttpAuthenticator::IDENTITY_INCLUDES_DOMAIN) { |
| 1161 | ParseUserDomain(userBuf, user, domain); |
| 1162 | } |
| 1163 | |
| 1164 | ident = nsHttpAuthIdentity(domain, user, passBuf); |
| 1165 | } |
| 1166 | |
| 1167 | void nsHttpChannelAuthProvider::ParseRealm(const nsACString& aChallenge, |
| 1168 | nsACString& realm) { |
| 1169 | // |
| 1170 | // From RFC2617 section 1.2, the realm value is defined as such: |
| 1171 | // |
| 1172 | // realm = "realm" "=" realm-value |
| 1173 | // realm-value = quoted-string |
| 1174 | // |
| 1175 | // but, we'll accept anything after the the "=" up to the first space, or |
| 1176 | // end-of-line, if the string is not quoted. |
| 1177 | // |
| 1178 | |
| 1179 | Tokenizer t(aChallenge); |
| 1180 | |
| 1181 | // The challenge begins with the authType. |
| 1182 | // If we can't find that something has probably gone wrong. |
| 1183 | t.SkipWhites(); |
| 1184 | nsDependentCSubstring authType; |
| 1185 | if (!t.ReadWord(authType)) { |
| 1186 | return; |
| 1187 | } |
| 1188 | |
| 1189 | // Will return true if the tokenizer advanced the cursor - false otherwise. |
| 1190 | auto readParam = [&](nsDependentCSubstring& key, nsAutoCString& value) { |
| 1191 | key.Rebind(EmptyCString(), 0); |
| 1192 | value.Truncate(); |
| 1193 | |
| 1194 | t.SkipWhites(); |
| 1195 | if (!t.ReadWord(key)) { |
| 1196 | return false; |
| 1197 | } |
| 1198 | t.SkipWhites(); |
| 1199 | if (!t.CheckChar('=')) { |
| 1200 | return true; |
| 1201 | } |
| 1202 | t.SkipWhites(); |
| 1203 | |
| 1204 | Tokenizer::Token token1; |
| 1205 | |
| 1206 | t.Record(); |
| 1207 | if (!t.Next(token1)) { |
| 1208 | return true; |
| 1209 | } |
| 1210 | nsDependentCSubstring sub; |
| 1211 | bool hasQuote = false; |
| 1212 | if (token1.Equals(Tokenizer::Token::Char('"'))) { |
| 1213 | hasQuote = true; |
| 1214 | } else { |
| 1215 | t.Claim(sub, Tokenizer::ClaimInclusion::INCLUDE_LAST); |
| 1216 | value.Append(sub); |
| 1217 | } |
| 1218 | t.Record(); |
| 1219 | Tokenizer::Token token2; |
| 1220 | while (t.Next(token2)) { |
| 1221 | if (hasQuote && token2.Equals(Tokenizer::Token::Char('"')) && |
| 1222 | !token1.Equals(Tokenizer::Token::Char('\\'))) { |
| 1223 | break; |
| 1224 | } |
| 1225 | if (!hasQuote && (token2.Type() == Tokenizer::TokenType::TOKEN_WS || |
| 1226 | token2.Type() == Tokenizer::TokenType::TOKEN_EOL)) { |
| 1227 | break; |
| 1228 | } |
| 1229 | |
| 1230 | t.Claim(sub, Tokenizer::ClaimInclusion::INCLUDE_LAST); |
| 1231 | if (!sub.Equals(R"(\)")) { |
| 1232 | value.Append(sub); |
| 1233 | } |
| 1234 | t.Record(); |
| 1235 | token1 = token2; |
| 1236 | } |
| 1237 | return true; |
| 1238 | }; |
| 1239 | |
| 1240 | while (!t.CheckEOF()) { |
| 1241 | nsDependentCSubstring key; |
| 1242 | nsAutoCString value; |
| 1243 | // If we couldn't read anything, and the input isn't followed by a , |
| 1244 | // then we exit. |
| 1245 | if (!readParam(key, value) && !t.Check(Tokenizer::Token::Char(','))) { |
| 1246 | break; |
| 1247 | } |
| 1248 | // When we find the first instance of realm we exit. |
| 1249 | // Theoretically there should be only one instance and we should fail |
| 1250 | // if there are more, but we're trying to preserve existing behaviour. |
| 1251 | if (key.Equals("realm"_ns, nsCaseInsensitiveCStringComparator)) { |
| 1252 | realm = value; |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | class nsHTTPAuthInformation : public nsAuthInformationHolder { |
| 1259 | public: |
| 1260 | nsHTTPAuthInformation(uint32_t aFlags, const nsString& aRealm, |
| 1261 | const nsACString& aAuthType) |
| 1262 | : nsAuthInformationHolder(aFlags, aRealm, aAuthType) {} |
| 1263 | |
| 1264 | void SetToHttpAuthIdentity(uint32_t authFlags, nsHttpAuthIdentity& identity); |
| 1265 | }; |
| 1266 | |
| 1267 | void nsHTTPAuthInformation::SetToHttpAuthIdentity( |
| 1268 | uint32_t authFlags, nsHttpAuthIdentity& identity) { |
| 1269 | identity = nsHttpAuthIdentity(Domain(), User(), Password()); |
| 1270 | } |
| 1271 | |
| 1272 | nsresult nsHttpChannelAuthProvider::PromptForIdentity( |
| 1273 | uint32_t level, bool proxyAuth, const nsACString& realm, |
| 1274 | const nsACString& authType, uint32_t authFlags, nsHttpAuthIdentity& ident) { |
| 1275 | 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) |
| 1276 | 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); |
| 1277 | |
| 1278 | nsresult rv; |
| 1279 | |
| 1280 | nsCOMPtr<nsIInterfaceRequestor> callbacks; |
| 1281 | rv = mAuthChannel->GetNotificationCallbacks(getter_AddRefs(callbacks)); |
| 1282 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1283 | |
| 1284 | nsCOMPtr<nsILoadGroup> loadGroup; |
| 1285 | rv = mAuthChannel->GetLoadGroup(getter_AddRefs(loadGroup)); |
| 1286 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1287 | |
| 1288 | nsCOMPtr<nsIAuthPrompt2> authPrompt; |
| 1289 | GetAuthPrompt(callbacks, proxyAuth, getter_AddRefs(authPrompt)); |
| 1290 | if (!authPrompt && loadGroup) { |
| 1291 | nsCOMPtr<nsIInterfaceRequestor> cbs; |
| 1292 | loadGroup->GetNotificationCallbacks(getter_AddRefs(cbs)); |
| 1293 | GetAuthPrompt(cbs, proxyAuth, getter_AddRefs(authPrompt)); |
| 1294 | } |
| 1295 | if (!authPrompt) return NS_ERROR_NO_INTERFACE; |
| 1296 | |
| 1297 | // XXX i18n: need to support non-ASCII realm strings (see bug 41489) |
| 1298 | NS_ConvertASCIItoUTF16 realmU(realm); |
| 1299 | |
| 1300 | // prompt the user... |
| 1301 | uint32_t promptFlags = 0; |
| 1302 | if (proxyAuth) { |
| 1303 | promptFlags |= nsIAuthInformation::AUTH_PROXY; |
| 1304 | if (mTriedProxyAuth) promptFlags |= nsIAuthInformation::PREVIOUS_FAILED; |
| 1305 | mTriedProxyAuth = true; |
| 1306 | } else { |
| 1307 | promptFlags |= nsIAuthInformation::AUTH_HOST; |
| 1308 | if (mTriedHostAuth) promptFlags |= nsIAuthInformation::PREVIOUS_FAILED; |
| 1309 | mTriedHostAuth = true; |
| 1310 | } |
| 1311 | |
| 1312 | if (authFlags & nsIHttpAuthenticator::IDENTITY_INCLUDES_DOMAIN) { |
| 1313 | promptFlags |= nsIAuthInformation::NEED_DOMAIN; |
| 1314 | } |
| 1315 | |
| 1316 | if (mCrossOrigin) { |
| 1317 | promptFlags |= nsIAuthInformation::CROSS_ORIGIN_SUB_RESOURCE; |
| 1318 | } |
| 1319 | |
| 1320 | RefPtr<nsHTTPAuthInformation> holder = |
| 1321 | new nsHTTPAuthInformation(promptFlags, realmU, authType); |
| 1322 | if (!holder) return NS_ERROR_OUT_OF_MEMORY; |
| 1323 | |
| 1324 | nsCOMPtr<nsIChannel> channel(do_QueryInterface(mAuthChannel, &rv)); |
| 1325 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1326 | |
| 1327 | rv = authPrompt->AsyncPromptAuth(channel, this, nullptr, level, holder, |
| 1328 | getter_AddRefs(mAsyncPromptAuthCancelable)); |
| 1329 | |
| 1330 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1331 | // indicate using this error code that authentication prompt |
| 1332 | // result is expected asynchronously |
| 1333 | rv = NS_ERROR_IN_PROGRESS; |
| 1334 | } else { |
| 1335 | // Fall back to synchronous prompt |
| 1336 | bool retval = false; |
| 1337 | rv = authPrompt->PromptAuth(channel, level, holder, &retval); |
| 1338 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1339 | |
| 1340 | if (!retval) { |
| 1341 | rv = NS_ERROR_ABORT; |
| 1342 | } else { |
| 1343 | holder->SetToHttpAuthIdentity(authFlags, ident); |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | if (mConnectionBased) { |
| 1348 | // Connection can be reset by the server in the meantime user is entering |
| 1349 | // the credentials. Result would be just a "Connection was reset" error. |
| 1350 | // Hence, we drop the current regardless if the user would make it on time |
| 1351 | // to provide credentials. |
| 1352 | // It's OK to send the NTLM type 1 message (response to the plain "NTLM" |
| 1353 | // challenge) on a new connection. |
| 1354 | { |
| 1355 | DebugOnly<nsresult> rv = mAuthChannel->CloseStickyConnection(); |
| 1356 | 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" , 1356); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1356); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | return rv; |
| 1361 | } |
| 1362 | |
| 1363 | NS_IMETHODIMPnsresult nsHttpChannelAuthProvider::OnAuthAvailable( |
| 1364 | nsISupports* aContext, nsIAuthInformation* aAuthInfo) { |
| 1365 | 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) |
| 1366 | 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); |
| 1367 | |
| 1368 | mAsyncPromptAuthCancelable = nullptr; |
| 1369 | if (!mAuthChannel) return NS_OK; |
| 1370 | |
| 1371 | nsresult rv; |
| 1372 | |
| 1373 | nsAutoCString host; |
| 1374 | int32_t port; |
| 1375 | nsHttpAuthIdentity* ident; |
| 1376 | nsAutoCString path, scheme; |
| 1377 | nsISupports** continuationState; |
| 1378 | rv = GetAuthorizationMembers(mProxyAuth, scheme, host, port, path, ident, |
| 1379 | continuationState); |
| 1380 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) OnAuthCancelled(aContext, false); |
| 1381 | |
| 1382 | nsAutoCString realm; |
| 1383 | ParseRealm(mCurrentChallenge, realm); |
| 1384 | |
| 1385 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 1386 | nsAutoCString suffix; |
| 1387 | if (!mProxyAuth) { |
| 1388 | // Fill only for non-proxy auth, proxy credentials are not OA-isolated. |
| 1389 | GetOriginAttributesSuffix(chan, suffix); |
| 1390 | } |
| 1391 | |
| 1392 | nsHttpAuthCache* authCache = gHttpHandler->AuthCache(mIsPrivate); |
| 1393 | RefPtr<nsHttpAuthEntry> entry; |
| 1394 | (void)authCache->GetAuthEntryForDomain(scheme, host, port, realm, suffix, |
| 1395 | entry); |
| 1396 | |
| 1397 | nsCOMPtr<nsISupports> sessionStateGrip; |
| 1398 | if (entry) sessionStateGrip = entry->mMetaData; |
| 1399 | |
| 1400 | nsString domain, user, password; |
| 1401 | aAuthInfo->GetDomain(domain); |
| 1402 | aAuthInfo->GetUsername(user); |
| 1403 | aAuthInfo->GetPassword(password); |
| 1404 | *ident = nsHttpAuthIdentity(domain, user, password); |
| 1405 | |
| 1406 | nsAutoCString unused; |
| 1407 | nsCOMPtr<nsIHttpAuthenticator> auth; |
| 1408 | rv = GetAuthenticator(mCurrentChallenge, unused, getter_AddRefs(auth)); |
| 1409 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1410 | 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" , 1410); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "GetAuthenticator failed" ")"); do { MOZ_CrashSequence(__null , 1410); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 1411 | OnAuthCancelled(aContext, true); |
| 1412 | return NS_OK; |
| 1413 | } |
| 1414 | |
| 1415 | nsCString creds; |
| 1416 | rv = GenCredsAndSetEntry(auth, mProxyAuth, scheme, host, port, path, realm, |
| 1417 | mCurrentChallenge, *ident, sessionStateGrip, creds); |
| 1418 | |
| 1419 | mCurrentChallenge.Truncate(); |
| 1420 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1421 | OnAuthCancelled(aContext, true); |
| 1422 | return NS_OK; |
| 1423 | } |
| 1424 | |
| 1425 | return ContinueOnAuthAvailable(creds); |
| 1426 | } |
| 1427 | |
| 1428 | NS_IMETHODIMPnsresult nsHttpChannelAuthProvider::OnAuthCancelled(nsISupports* aContext, |
| 1429 | bool userCancel) { |
| 1430 | 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) |
| 1431 | 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); |
| 1432 | |
| 1433 | mAsyncPromptAuthCancelable = nullptr; |
| 1434 | if (!mAuthChannel) return NS_OK; |
| 1435 | |
| 1436 | // When user cancels or auth fails we want to close the connection for |
| 1437 | // connection based schemes like NTLM. Some servers don't like re-negotiation |
| 1438 | // on the same connection. |
| 1439 | nsresult rv; |
| 1440 | if (mConnectionBased) { |
| 1441 | rv = mAuthChannel->CloseStickyConnection(); |
| 1442 | 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" , 1442); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1442); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1443 | mConnectionBased = false; |
| 1444 | } |
| 1445 | |
| 1446 | nsCOMPtr<nsIChannel> channel = do_QueryInterface(mAuthChannel); |
| 1447 | if (channel) { |
| 1448 | nsresult status; |
| 1449 | (void)channel->GetStatus(&status); |
| 1450 | if (NS_FAILED(status)((bool)(__builtin_expect(!!(NS_FAILED_impl(status)), 0)))) { |
| 1451 | // If the channel is already cancelled, there is no need to deal with the |
| 1452 | // rest challenges. |
| 1453 | 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); |
| 1454 | mRemainingChallenges.Truncate(); |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | if (userCancel) { |
| 1459 | if (!mRemainingChallenges.IsEmpty()) { |
| 1460 | // there are still some challenges to process, do so |
| 1461 | |
| 1462 | // Get rid of current continuationState to avoid reusing it in |
| 1463 | // next challenges since it is no longer relevant. |
| 1464 | if (mProxyAuth) { |
| 1465 | NS_IF_RELEASE(mProxyAuthContinuationState)do { if (mProxyAuthContinuationState) { (mProxyAuthContinuationState )->Release(); (mProxyAuthContinuationState) = 0; } } while (0); |
| 1466 | } else { |
| 1467 | NS_IF_RELEASE(mAuthContinuationState)do { if (mAuthContinuationState) { (mAuthContinuationState)-> Release(); (mAuthContinuationState) = 0; } } while (0); |
| 1468 | } |
| 1469 | nsAutoCString creds; |
| 1470 | rv = GetCredentials(mRemainingChallenges, mProxyAuth, creds); |
| 1471 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1472 | // GetCredentials loaded the credentials from the cache or |
| 1473 | // some other way in a synchronous manner, process those |
| 1474 | // credentials now |
| 1475 | mRemainingChallenges.Truncate(); |
| 1476 | return ContinueOnAuthAvailable(creds); |
| 1477 | } |
| 1478 | if (rv == NS_ERROR_IN_PROGRESS) { |
| 1479 | // GetCredentials successfully queued another authprompt for |
| 1480 | // a challenge from the list, we are now waiting for the user |
| 1481 | // to provide the credentials |
| 1482 | return NS_OK; |
| 1483 | } |
| 1484 | |
| 1485 | // otherwise, we failed... |
| 1486 | } |
| 1487 | |
| 1488 | mRemainingChallenges.Truncate(); |
| 1489 | } |
| 1490 | |
| 1491 | rv = mAuthChannel->OnAuthCancelled(userCancel); |
| 1492 | 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" , 1492); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1492); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1493 | |
| 1494 | return NS_OK; |
| 1495 | } |
| 1496 | |
| 1497 | NS_IMETHODIMPnsresult nsHttpChannelAuthProvider::OnCredsGenerated( |
| 1498 | const nsACString& aGeneratedCreds, uint32_t aFlags, nsresult aResult, |
| 1499 | nsISupports* aSessionState, nsISupports* aContinuationState) { |
| 1500 | nsresult rv; |
| 1501 | |
| 1502 | 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" , 1502); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence(__null, 1502); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1503 | |
| 1504 | // When channel is closed, do not proceed |
| 1505 | if (!mAuthChannel) { |
| 1506 | return NS_OK; |
| 1507 | } |
| 1508 | |
| 1509 | mGenerateCredentialsCancelable = nullptr; |
| 1510 | |
| 1511 | if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) { |
| 1512 | return OnAuthCancelled(nullptr, true); |
| 1513 | } |
| 1514 | |
| 1515 | // We want to update m(Proxy)AuthContinuationState in case it was changed by |
| 1516 | // nsHttpNegotiateAuth::GenerateCredentials |
| 1517 | nsCOMPtr<nsISupports> contState(aContinuationState); |
| 1518 | if (mProxyAuth) { |
| 1519 | contState.swap(mProxyAuthContinuationState); |
| 1520 | } else { |
| 1521 | contState.swap(mAuthContinuationState); |
| 1522 | } |
| 1523 | |
| 1524 | nsCOMPtr<nsIHttpAuthenticator> auth; |
| 1525 | nsAutoCString unused; |
| 1526 | rv = GetAuthenticator(mCurrentChallenge, unused, getter_AddRefs(auth)); |
| 1527 | 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" , 1527); return rv; } } while (false); |
| 1528 | |
| 1529 | nsAutoCString host; |
| 1530 | int32_t port; |
| 1531 | nsHttpAuthIdentity* ident; |
| 1532 | nsAutoCString directory, scheme; |
| 1533 | nsISupports** unusedContinuationState; |
| 1534 | |
| 1535 | // Get realm from challenge |
| 1536 | nsAutoCString realm; |
| 1537 | ParseRealm(mCurrentChallenge, realm); |
| 1538 | |
| 1539 | rv = GetAuthorizationMembers(mProxyAuth, scheme, host, port, directory, ident, |
| 1540 | unusedContinuationState); |
| 1541 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1542 | |
| 1543 | rv = |
| 1544 | UpdateCache(auth, scheme, host, port, directory, realm, mCurrentChallenge, |
| 1545 | *ident, aGeneratedCreds, aFlags, aSessionState, mProxyAuth); |
| 1546 | 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" , 1546); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1546); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1547 | mCurrentChallenge.Truncate(); |
| 1548 | |
| 1549 | rv = ContinueOnAuthAvailable(aGeneratedCreds); |
| 1550 | 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" , 1550); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1550); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1551 | return NS_OK; |
| 1552 | } |
| 1553 | |
| 1554 | nsresult nsHttpChannelAuthProvider::ContinueOnAuthAvailable( |
| 1555 | const nsACString& creds) { |
| 1556 | nsresult rv; |
| 1557 | if (mProxyAuth) { |
| 1558 | rv = mAuthChannel->SetProxyCredentials(creds); |
| 1559 | } else { |
| 1560 | rv = mAuthChannel->SetWWWCredentials(creds); |
| 1561 | } |
| 1562 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv; |
| 1563 | |
| 1564 | // drop our remaining list of challenges. We don't need them, because we |
| 1565 | // have now authenticated against a challenge and will be sending that |
| 1566 | // information to the server (or proxy). If it doesn't accept our |
| 1567 | // authentication it'll respond with failure and resend the challenge list |
| 1568 | mRemainingChallenges.Truncate(); |
| 1569 | |
| 1570 | (void)mAuthChannel->OnAuthAvailable(); |
| 1571 | |
| 1572 | return NS_OK; |
| 1573 | } |
| 1574 | |
| 1575 | void nsHttpChannelAuthProvider::SetAuthorizationHeader( |
| 1576 | nsHttpAuthCache* authCache, const nsHttpAtom& header, |
| 1577 | const nsACString& scheme, const nsACString& host, int32_t port, |
| 1578 | const nsACString& path, nsHttpAuthIdentity& ident) { |
| 1579 | RefPtr<nsHttpAuthEntry> entry; |
| 1580 | nsresult rv; |
| 1581 | |
| 1582 | // set informations that depend on whether |
| 1583 | // we're authenticating against a proxy |
| 1584 | // or a webserver |
| 1585 | nsISupports** continuationState; |
| 1586 | |
| 1587 | nsAutoCString suffix; |
| 1588 | if (header == nsHttp::Proxy_Authorization) { |
| 1589 | continuationState = &mProxyAuthContinuationState; |
| 1590 | |
| 1591 | if (mProxyInfo) { |
| 1592 | nsAutoCString type; |
| 1593 | mProxyInfo->GetType(type); |
| 1594 | if (type.EqualsLiteral("https") || type.EqualsLiteral("masque")) { |
| 1595 | // Let this be overriden by anything from the cache. |
| 1596 | auto const& pa = mProxyInfo->ProxyAuthorizationHeader(); |
| 1597 | if (!pa.IsEmpty()) { |
| 1598 | rv = mAuthChannel->SetProxyCredentials(pa); |
| 1599 | 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" , 1599); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1599); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1600 | } |
| 1601 | } |
| 1602 | } |
| 1603 | } else { |
| 1604 | continuationState = &mAuthContinuationState; |
| 1605 | |
| 1606 | nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel); |
| 1607 | GetOriginAttributesSuffix(chan, suffix); |
| 1608 | } |
| 1609 | |
| 1610 | rv = authCache->GetAuthEntryForPath(scheme, host, port, path, suffix, entry); |
| 1611 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1612 | // if we are trying to add a header for origin server auth and if the |
| 1613 | // URL contains an explicit username, then try the given username first. |
| 1614 | // we only want to do this, however, if we know the URL requires auth |
| 1615 | // based on the presence of an auth cache entry for this URL (which is |
| 1616 | // true since we are here). but, if the username from the URL matches |
| 1617 | // the username from the cache, then we should prefer the password |
| 1618 | // stored in the cache since that is most likely to be valid. |
| 1619 | if (header == nsHttp::Authorization && entry->Domain()[0] == '\0') { |
| 1620 | GetIdentityFromURI(0, ident); |
| 1621 | // if the usernames match, then clear the ident so we will pick |
| 1622 | // up the one from the auth cache instead. |
| 1623 | // when this is undesired, specify LOAD_EXPLICIT_CREDENTIALS load |
| 1624 | // flag. |
| 1625 | if (ident.User() == entry->User()) { |
| 1626 | uint32_t loadFlags; |
| 1627 | if (NS_SUCCEEDED(mAuthChannel->GetLoadFlags(&loadFlags))((bool)(__builtin_expect(!!(!NS_FAILED_impl(mAuthChannel-> GetLoadFlags(&loadFlags))), 1))) && |
| 1628 | !(loadFlags & nsIChannel::LOAD_EXPLICIT_CREDENTIALS)) { |
| 1629 | ident.Clear(); |
| 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | bool identFromURI; |
| 1634 | if (ident.IsEmpty()) { |
| 1635 | ident = entry->Identity(); |
| 1636 | identFromURI = false; |
| 1637 | } else { |
| 1638 | identFromURI = true; |
| 1639 | } |
| 1640 | |
| 1641 | nsCString temp; // this must have the same lifetime as creds |
| 1642 | nsAutoCString creds(entry->Creds()); |
| 1643 | // we can only send a preemptive Authorization header if we have either |
| 1644 | // stored credentials or a stored challenge from which to derive |
| 1645 | // credentials. if the identity is from the URI, then we cannot use |
| 1646 | // the stored credentials. |
| 1647 | if ((creds.IsEmpty() || identFromURI) && !entry->Challenge().IsEmpty()) { |
| 1648 | nsCOMPtr<nsIHttpAuthenticator> auth; |
| 1649 | nsAutoCString unused; |
| 1650 | rv = GetAuthenticator(entry->Challenge(), unused, getter_AddRefs(auth)); |
| 1651 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 1652 | bool proxyAuth = (header == nsHttp::Proxy_Authorization); |
| 1653 | rv = GenCredsAndSetEntry(auth, proxyAuth, scheme, host, port, path, |
| 1654 | entry->Realm(), entry->Challenge(), ident, |
| 1655 | entry->mMetaData, temp); |
| 1656 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) creds = temp; |
| 1657 | |
| 1658 | // make sure the continuation state is null since we do not |
| 1659 | // support mixing preemptive and 'multirequest' authentication. |
| 1660 | NS_IF_RELEASE(*continuationState)do { if (*continuationState) { (*continuationState)->Release (); (*continuationState) = 0; } } while (0); |
| 1661 | } |
| 1662 | } |
| 1663 | if (!creds.IsEmpty()) { |
| 1664 | 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); |
| 1665 | if (header == nsHttp::Proxy_Authorization) { |
| 1666 | rv = mAuthChannel->SetProxyCredentials(creds); |
| 1667 | 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" , 1667); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1667); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1668 | } else { |
| 1669 | rv = mAuthChannel->SetWWWCredentials(creds); |
| 1670 | 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" , 1670); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 1670); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1671 | } |
| 1672 | } else { |
| 1673 | ident.Clear(); // don't remember the identity |
| 1674 | } |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | nsresult nsHttpChannelAuthProvider::GetCurrentPath(nsACString& path) { |
| 1679 | nsresult rv; |
| 1680 | nsCOMPtr<nsIURL> url = do_QueryInterface(mURI); |
| 1681 | if (url) { |
| 1682 | rv = url->GetDirectory(path); |
| 1683 | } else { |
| 1684 | rv = mURI->GetPathQueryRef(path); |
| 1685 | } |
| 1686 | return rv; |
| 1687 | } |
| 1688 | |
| 1689 | 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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 1691 ); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1691); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 1691 ); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1691); __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" , 1691); 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; } |
| 1690 | 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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 1691 ); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1691); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 1691 ); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1691); __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" , 1691); 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; } |
| 1691 | 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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 1691 ); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1691); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 1691 ); __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" , 1691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsHttpChannelAuthProvider\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 1691); __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" , 1691); 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; } |
| 1692 | |
| 1693 | } // namespace mozilla::net |