Skip to content

Commit

Permalink
Merge pull request #113 from Drawaes/FixHandleLeak
Browse files Browse the repository at this point in the history
Fix handle leak in LASS
  • Loading branch information
Drawaes authored Oct 8, 2018
2 parents 7ee03a0 + 162b2fd commit f4eb42f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions CondenserDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Release Notes", "Release No
releasenotes\4.0.2.props = releasenotes\4.0.2.props
releasenotes\4.0.3.props = releasenotes\4.0.3.props
releasenotes\4.1.0.props = releasenotes\4.1.0.props
releasenotes\4.1.1.props = releasenotes\4.1.1.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CondenserDotNet.Middleware", "src\CondenserDotNet.Middleware\CondenserDotNet.Middleware.csproj", "{5DC8FA9E-4CB9-4F80-8AA9-7F4ABF8375B3}"
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/4.1.1.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<PackageReleaseNotes>
* Fixed Security Handle Leak in LASS
</PackageReleaseNotes>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ public class ProtocolSwitchConnectionFilter : IConnectionAdapter
{
private bool _isHttp;

public ProtocolSwitchConnectionFilter()
{
}

public bool IsHttps => _isHttp;

public async Task<IAdaptedConnection> OnConnectionAsync(ConnectionAdapterContext context)
Expand All @@ -27,8 +23,11 @@ public async Task<IAdaptedConnection> OnConnectionAsync(ConnectionAdapterContext
back2Back.FirstByte = firstByte[0];
if (firstByte[0] == 0x16)
{
context.Features.Set<ITlsConnectionFeature>(new TlsConnectionFeature());
_isHttp = true;
}


throw new NotImplementedException();
//await _previous.OnConnectionAsync(context);
//var previousRequest = context.PrepareRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Core;

namespace CondenserDotNet.Middleware.ProtocolSwitcher
{
public static class ProtocolSwitcherExtensions
{
/*public static KestrelServerOptions Switcheroo(this KestrelServerOptions options)
public static ListenOptions Switcheroo(this ListenOptions options)
{
var prevFilter = options.ConnectionFilter ?? new NoOpConnectionFilter();
options.ConnectionFilter = new ProtocolSwitchConnectionFilter(prevFilter);
options.ConnectionAdapters.Add(new ProtocolSwitchConnectionFilter());
return options;
}*/
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Secur32
{
[DllImport(Libraries.Secur32, CharSet = CharSet.Unicode, SetLastError = false)]
internal static extern SEC_RESULT DeleteSecurityContext(SecurityHandle phCredential);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Security.Principal;
using static Interop.Secur32;

Expand All @@ -12,7 +12,7 @@ public class WindowsAuthFeature : IDisposable, IWindowsAuthFeature
static WindowsAuthFeature()
{
var result = AcquireCredentialsHandle(null, "Negotiate", CredentialsUse.SECPKG_CRED_INBOUND,
IntPtr.Zero, IntPtr.Zero, 0, IntPtr.Zero, out _credentialsHandle, out SecurityInteger timeSpan);
IntPtr.Zero, IntPtr.Zero, 0, IntPtr.Zero, out _credentialsHandle, out var timeSpan);
if (result != SEC_RESULT.SEC_E_OK)
{
throw new InvalidOperationException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using static Interop.Secur32;
using static Interop.Kernel32;

namespace CondenserDotNet.Middleware.WindowsAuthentication
{
Expand Down Expand Up @@ -77,7 +78,7 @@ public unsafe string AcceptSecurityToken(string returnTokenType, byte[] token)
Marshal.Copy((IntPtr)outBufferPtr, byteSpan, 0, byteSpan.Length);
returnToken = "Negotiate " + Convert.ToBase64String(byteSpan);
}
QuerySecurityContextToken(ref _context, out IntPtr handle);
QuerySecurityContextToken(ref _context, out var handle);
_identity = new WindowsIdentity(handle);
Interop.Kernel32.CloseHandle(handle);
return returnToken;
Expand All @@ -91,6 +92,7 @@ public void Dispose()
if (_context.HighPart != IntPtr.Zero || _context.LowPart != IntPtr.Zero)
{
FreeCredentialsHandle(_context);
DeleteSecurityContext(_context);
_context = default(SecurityHandle);
}
GC.SuppressFinalize(this);
Expand Down
2 changes: 1 addition & 1 deletion version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>4.1.0</VersionPrefix>
<VersionPrefix>4.1.1</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
</PropertyGroup>
</Project>

0 comments on commit f4eb42f

Please sign in to comment.