Skip to content

Commit 057a598

Browse files
author
Michael Cuomo
authored
BED-6657 - Adding Additional Logging around NTLM Authentication (#254)
* log: Add Logging Describing Outcome of GetNtlmEndpoint in CAEnrollmentProcessor * log: CodeRabbit Nits * chore: Adding more Logging around NTLM Authentication * chore: Coderabbit Suggestions
1 parent 79590a2 commit 057a598

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/CommonLib/Ntlm/HttpNtlmAuthenticationService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public async Task EnsureRequiresAuth(Uri url, bool? useBadChannelBindings) {
3737

3838
var supportedAuthSchemes = await GetSupportedNtlmAuthSchemesAsync(url);
3939

40-
_logger.LogDebug($"Supported NTLM auth schemes for {url}: " + string.Join(",", supportedAuthSchemes));
40+
_logger.LogDebug("Supported NTLM auth schemes for {Url}: {AuthSchemes}. UseBadChannelBindings: {UseBadChannelBinding}. UseBadChannelBindings is null: {UseBadChannelBindingsIsNull}",
41+
url, string.Join(",", supportedAuthSchemes), useBadChannelBindings ?? false, !useBadChannelBindings.HasValue);
4142

4243
foreach (var authScheme in supportedAuthSchemes) {
4344
if (useBadChannelBindings == null) {

src/CommonLib/Ntlm/NtlmAuthenticationHandler.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,35 @@ public virtual async Task<object> PerformNtlmAuthenticationAsync(INtlmTransport
3838
Options.Signing,
3939
Options.Signing
4040
);
41+
_logger.LogTrace("Starting {MethodName}", nameof(PerformNtlmAuthenticationAsync));
4142

43+
_logger.LogTrace("Check if cancellation token is requested.");
4244
cancellationToken.ThrowIfCancellationRequested();
45+
_logger.LogTrace("After if cancellation token is requested.");
4346

4447
// NEGOTIATE
48+
_logger.LogDebug("Initial NTLM Negotiate Step.");
4549
var negotiateMsgBytes = context.Step();
50+
_logger.LogTrace("Negotiate Step Complete.");
4651

4752
// CHALLENGE
53+
_logger.LogDebug("Challenge Negotiate bytes.");
4854
var challengeMessageBytes = await transport.NegotiateAsync(negotiateMsgBytes);
55+
_logger.LogTrace("Challenge Negotiate bytes complete.");
4956

57+
_logger.LogTrace("Check if cancellation token is requested.");
5058
cancellationToken.ThrowIfCancellationRequested();
59+
_logger.LogTrace("After if cancellation token is requested.");
5160

5261
// AUTHENTICATE
62+
_logger.LogDebug("Perform NTLM Authentication Step.");
5363
var authenticateMsgBytes = context.Step(challengeMessageBytes);
64+
_logger.LogTrace("NTLM Authentication Step Complete.");
5465

5566
// Perform final authentication
67+
_logger.LogDebug("Perform final NTLM Authentication.");
5668
var response = await transport.AuthenticateAsync(authenticateMsgBytes);
69+
_logger.LogTrace("After authentication complete.");
5770

5871
return response;
5972
}

src/CommonLib/Processors/CAEnrollmentProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private async Task<APIResult<CAEnrollmentEndpoint>> GetNtlmEndpoint(Uri url, boo
167167
url.AbsoluteUri, useBadChannelBinding, type);
168168
break;
169169
default:
170-
_logger.LogError("Unexpected status code while checking {Url}. StatusCode {StatusCode}. UseBadChannelBindings: {UseBadChannelBindings}, EnpointType: {EndpointType}",
170+
_logger.LogError("Unexpected status code while checking {Url}. StatusCode {StatusCode}. UseBadChannelBindings: {UseBadChannelBindings}, EndpointType: {EndpointType}",
171171
url.AbsoluteUri, statusCode, useBadChannelBinding, type);
172172
return APIResult<CAEnrollmentEndpoint>
173173
.Failure(
@@ -187,7 +187,7 @@ private async Task<APIResult<CAEnrollmentEndpoint>> GetNtlmEndpoint(Uri url, boo
187187
_logger.LogError("HttpRequestException occurred checking NTLM accessibility for URL: {Url}. Exception: {Message}", url.AbsoluteUri, ex.Message);
188188
return APIResult<CAEnrollmentEndpoint>
189189
.Failure(
190-
$"HttpRequestException occured checking NTLM accessibility for URL: {url}. Exception: {ex.Message}");
190+
$"HttpRequestException occurred checking NTLM accessibility for URL: {url}. Exception: {ex.Message}");
191191
} catch (HttpUnauthorizedException ex) {
192192
if (useBadChannelBinding == true) {
193193
output.Status = CAEnrollmentEndpointScanResult.NotVulnerable_NtlmChannelBindingRequired;

0 commit comments

Comments
 (0)