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

reduce use of TRACE_VERBOSE in SslStream #37917

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
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 @@ -225,9 +225,7 @@ public static unsafe int AcquireDefaultCredential(
ref outCredential._handle,
out timeStamp);

#if TRACE_VERBOSE
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"{nameof(Interop.SspiCli.AcquireCredentialsHandleW)} returns 0x{errorCode:x}, handle = {outCredential}");
#endif
if (NetEventSource.IsEnabled) NetEventSource.Verbose(null, $"{nameof(Interop.SspiCli.AcquireCredentialsHandleW)} returns 0x{errorCode:x}, handle = {outCredential}");
wfurt marked this conversation as resolved.
Show resolved Hide resolved

if (errorCode != 0)
{
Expand Down Expand Up @@ -307,9 +305,7 @@ public static unsafe int AcquireCredentialsHandle(
authdata.paCred = copiedPtr;
}

#if TRACE_VERBOSE
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"{nameof(Interop.SspiCli.AcquireCredentialsHandleW)} returns 0x{errorCode:x}, handle = {outCredential}");
#endif
if (NetEventSource.IsEnabled) NetEventSource.Verbose(null, $"{nameof(Interop.SspiCli.AcquireCredentialsHandleW)} returns 0x{errorCode:x}, handle = {outCredential}");

if (errorCode != 0)
{
Expand Down Expand Up @@ -401,13 +397,7 @@ internal static unsafe int InitializeSecurityContext(
ref SecurityBuffer outSecBuffer,
ref Interop.SspiCli.ContextFlags outFlags)
{
#if TRACE_VERBOSE
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(null, $"credential:{inCredentials}, crefContext:{refContext}, targetName:{targetName}, inFlags:{inFlags}, endianness:{endianness}");
NetEventSource.Info(null, $"inSecBuffers.Length = {inSecBuffers.Length}");
}
#endif
if (NetEventSource.IsEnabled) NetEventSource.Enter(null, $"credential:{inCredentials}, crefContext:{refContext}, targetName:{targetName}, inFlags:{inFlags}, endianness:{endianness}");

if (inCredentials == null)
{
Expand Down Expand Up @@ -639,13 +629,7 @@ internal static unsafe int AcceptSecurityContext(
ref SecurityBuffer outSecBuffer,
ref Interop.SspiCli.ContextFlags outFlags)
{
#if TRACE_VERBOSE
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(null, $"credential={inCredentials}, refContext={refContext}, inFlags={inFlags}");
NetEventSource.Info(null, $"inSecBuffers.Length = {inSecBuffers.Length}");
}
#endif
if (NetEventSource.IsEnabled) NetEventSource.Enter(null, $"credential={inCredentials}, refContext={refContext}, inFlags={inFlags}");

if (inCredentials == null)
{
Expand Down Expand Up @@ -900,9 +884,6 @@ internal static unsafe int CompleteAuthToken(
inSecBuffer.unmanagedToken != null ? inSecBuffer.unmanagedToken.DangerousGetHandle() :
inSecBuffer.token == null || inSecBuffer.token.Length == 0 ? IntPtr.Zero :
(IntPtr)(pinnedToken + inSecBuffer.offset);
#if TRACE_VERBOSE
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"SecBuffer: cbBuffer:{inSecBuffer.size} BufferType: {inSecBuffer.type}");
#endif

Interop.SspiCli.CredHandle contextHandle = refContext != null ? refContext._handle : default;
if (refContext == null || refContext.IsInvalid)
Expand Down Expand Up @@ -964,9 +945,6 @@ internal static unsafe int ApplyControlToken(
inSecBuffer.unmanagedToken != null ? inSecBuffer.unmanagedToken.DangerousGetHandle() :
inSecBuffer.token == null || inSecBuffer.token.Length == 0 ? IntPtr.Zero :
(IntPtr)(pinnedInSecBufferToken + inSecBuffer.offset);
#if TRACE_VERBOSE
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"SecBuffer: cbBuffer:{inSecBuffer.size} BufferType:{inSecBuffer.type}");
#endif

Interop.SspiCli.CredHandle contextHandle = refContext != null ? refContext._handle : default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,36 @@ private void CriticalFailure(string thisOrContextObject, string? memberName, str
WriteEvent(CriticalFailureEventId, thisOrContextObject, memberName ?? MissingMember, message);
#endregion

#region Verbose
/// <summary>Logs an info message at verbose mode.</summary>
/// <param name="thisOrContextObject">`this`, or another object that serves to provide context for the operation.</param>
/// <param name="formattableString">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Verbose(object? thisOrContextObject, FormattableString formattableString, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
}

/// <summary>Logs an info at verbose mode.</summary>
/// <param name="thisOrContextObject">`this`, or another object that serves to provide context for the operation.</param>
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Verbose(object? thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(message);
if (IsEnabled) Log.VerboseMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString());
}

[Event(ErrorEventId, Level = EventLevel.Verbose, Keywords = Keywords.Default)]
private void VerboseMessage(string thisOrContextObject, string? memberName, string? message) =>
WriteEvent(ErrorEventId, thisOrContextObject, memberName ?? MissingMember, message);
#endregion

#region DumpBuffer
/// <summary>Logs the contents of a buffer.</summary>
/// <param name="thisOrContextObject">`this`, or another object that serves to provide context for the operation.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,13 +1089,6 @@ private Framing DetectFraming(ReadOnlySpan<byte> bytes)
return Framing.Invalid;
}

#if TRACE_VERBOSE
if (bytes[1] != 3 && NetEventSource.IsEnabled)
{
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"WARNING: SslState::DetectFraming() SSL protocol is > 3, trying SSL3 framing in retail = {bytes[1]:x}");
}
#endif

version = (bytes[1] << 8) | bytes[2];
if (version < 0x300 || version >= 0x500)
{
Expand All @@ -1108,14 +1101,6 @@ private Framing DetectFraming(ReadOnlySpan<byte> bytes)
return Framing.SinceSSL3;
}

#if TRACE_VERBOSE
if ((bytes[0] & 0x80) == 0 && NetEventSource.IsEnabled)
{
// We have a three-byte header format
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"WARNING: SslState::DetectFraming() SSL v <=2 HELLO has no high bit set for 3 bytes header, we are broken, received byte = {bytes[0]:x}");
}
#endif

if (bytes.Length < 3)
{
return Framing.Invalid;
Expand Down