Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NullReferenceException when using BasicHttpBinding and NTLM web proxy authentication #4555

Merged
merged 4 commits into from
Mar 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ internal async Task<HttpClient> GetHttpClientAsync(EndpointAddress to, Uri via,
httpClient.DefaultRequestHeaders.ExpectContinue = true;
}

// We provide our own CancellationToken for each request. Setting HttpClient.Timeout to -1
// We provide our own CancellationToken for each request. Setting HttpClient.Timeout to -1
// prevents a call to CancellationToken.CancelAfter that HttpClient does internally which
// causes TimerQueue contention at high load.
httpClient.Timeout = Timeout.InfiniteTimeSpan;
Expand Down Expand Up @@ -556,7 +556,18 @@ private void InitializeSecurityTokenManager()

protected virtual bool IsSecurityTokenManagerRequired()
{
return AuthenticationScheme != AuthenticationSchemes.Anonymous;
if (AuthenticationScheme != AuthenticationSchemes.Anonymous)
{
return true;
}
if (_proxyFactory != null && _proxyFactory.AuthenticationScheme != AuthenticationSchemes.Anonymous)
{
return true;
}
else
{
return false;
}
}

protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
Expand Down Expand Up @@ -998,7 +1009,7 @@ public async Task SendRequestAsync(Message message, TimeoutHelper timeoutHelper)
{
if (_channel.State != CommunicationState.Opened)
{
// if we were aborted while getting our request or doing correlation,
// if we were aborted while getting our request or doing correlation,
// we need to abort the request and bail
Cleanup();
_channel.ThrowIfDisposedOrNotOpen();
Expand Down Expand Up @@ -1280,7 +1291,7 @@ private bool PrepareMessageHeaders(Message message)
}
}

// since we don't get the output stream in send when retVal == true,
// since we don't get the output stream in send when retVal == true,
// we need to disable chunking for some verbs (DELETE/PUT)
if (suppressEntityBody)
{
Expand Down Expand Up @@ -1316,7 +1327,7 @@ private async Task SendPreauthenticationHeadRequestIfNeeded()
}

var requestUri = _httpRequestMessage.RequestUri;
// sends a HEAD request to the specificed requestUri for authentication purposes
// sends a HEAD request to the specificed requestUri for authentication purposes
Contract.Assert(requestUri != null);

HttpRequestMessage headHttpRequestMessage = new HttpRequestMessage()
Expand Down Expand Up @@ -1371,7 +1382,7 @@ public async Task<IWebProxy> CreateWebProxyAsync(AuthenticationLevel requestAuth
SR.ProxyImpersonationLevelMismatch, impersonationLevelWrapper.Value, requestImpersonationLevel)));
}

// The authentication level for target auth is also used for proxy auth (by System.Net).
// The authentication level for target auth is also used for proxy auth (by System.Net).
// Therefore, fail if proxy auth requires mutual authentication but target auth does not.
if ((authenticationLevelWrapper.Value == AuthenticationLevel.MutualAuthRequired) &&
(requestAuthenticationLevel != AuthenticationLevel.MutualAuthRequired))
Expand Down