Reorganized the project to put the library one folder down.
This commit is contained in:
36
NSspi/SecureBuffer/SecureBuffer.cs
Normal file
36
NSspi/SecureBuffer/SecureBuffer.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
internal struct SecureBufferInternal
|
||||
{
|
||||
public int Count;
|
||||
|
||||
public BufferType Type;
|
||||
|
||||
// A pointer to a byte[]
|
||||
public IntPtr Buffer;
|
||||
}
|
||||
|
||||
internal class SecureBuffer
|
||||
{
|
||||
public SecureBuffer( byte[] buffer, BufferType type )
|
||||
{
|
||||
this.Buffer = buffer;
|
||||
this.Type = type;
|
||||
this.Length = this.Buffer.Length;
|
||||
}
|
||||
|
||||
public BufferType Type { get; set; }
|
||||
|
||||
public byte[] Buffer { get; set; }
|
||||
|
||||
public int Length { get; internal set; }
|
||||
}
|
||||
}
|
||||
108
NSspi/SecureBuffer/SecureBufferAdapter.cs
Normal file
108
NSspi/SecureBuffer/SecureBufferAdapter.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
internal class SecureBufferAdapter : IDisposable
|
||||
{
|
||||
private bool disposed;
|
||||
|
||||
private IList<SecureBuffer> buffers;
|
||||
|
||||
private GCHandle descriptorHandle;
|
||||
|
||||
private GCHandle[] bufferHandles;
|
||||
|
||||
private SecureBufferDescInternal descriptor;
|
||||
private SecureBufferInternal[] bufferCarrier;
|
||||
private GCHandle bufferCarrierHandle;
|
||||
|
||||
public SecureBufferAdapter( SecureBuffer buffer )
|
||||
: this( new[] { buffer } )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//[ReliabilityContract( Consistency.MayCorruptAppDomain, Cer.None)]
|
||||
public SecureBufferAdapter( IList<SecureBuffer> buffers )
|
||||
{
|
||||
this.buffers = buffers;
|
||||
|
||||
this.disposed = false;
|
||||
|
||||
this.bufferHandles = new GCHandle[this.buffers.Count];
|
||||
this.bufferCarrier = new SecureBufferInternal[this.buffers.Count];
|
||||
|
||||
for ( int i = 0; i < this.buffers.Count; i++ )
|
||||
{
|
||||
this.bufferHandles[i] = GCHandle.Alloc( this.buffers[i].Buffer, GCHandleType.Pinned );
|
||||
|
||||
this.bufferCarrier[i] = new SecureBufferInternal();
|
||||
this.bufferCarrier[i].Type = this.buffers[i].Type;
|
||||
this.bufferCarrier[i].Count = this.buffers[i].Buffer.Length;
|
||||
this.bufferCarrier[i].Buffer = bufferHandles[i].AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
this.bufferCarrierHandle = GCHandle.Alloc( bufferCarrier, GCHandleType.Pinned );
|
||||
|
||||
this.descriptor = new SecureBufferDescInternal();
|
||||
this.descriptor.Version = SecureBufferDescInternal.ApiVersion;
|
||||
this.descriptor.NumBuffers = this.buffers.Count;
|
||||
this.descriptor.Buffers = bufferCarrierHandle.AddrOfPinnedObject();
|
||||
|
||||
this.descriptorHandle = GCHandle.Alloc( descriptor, GCHandleType.Pinned );
|
||||
}
|
||||
|
||||
~SecureBufferAdapter()
|
||||
{
|
||||
Dispose( false );
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( this.disposed )
|
||||
{
|
||||
throw new ObjectDisposedException( "Cannot use SecureBufferListHandle after it has been disposed" );
|
||||
}
|
||||
|
||||
return this.descriptorHandle.AddrOfPinnedObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose( true );
|
||||
GC.SuppressFinalize( this );
|
||||
}
|
||||
|
||||
protected virtual void Dispose( bool disposing )
|
||||
{
|
||||
if ( this.disposed == true ) { return; }
|
||||
|
||||
if ( disposing )
|
||||
{
|
||||
for ( int i = 0; i < this.buffers.Count; i++ )
|
||||
{
|
||||
this.buffers[i].Length = this.bufferCarrier[i].Count;
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < this.bufferHandles.Length; i++ )
|
||||
{
|
||||
this.bufferHandles[i].Free();
|
||||
}
|
||||
|
||||
this.bufferCarrierHandle.Free();
|
||||
this.descriptorHandle.Free();
|
||||
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
NSspi/SecureBuffer/SecureBufferDataRep.cs
Normal file
18
NSspi/SecureBuffer/SecureBufferDataRep.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
internal enum SecureBufferDataRep : int
|
||||
{
|
||||
/*
|
||||
#define SECURITY_NATIVE_DREP 0x00000010
|
||||
#define SECURITY_NETWORK_DREP 0x00000000
|
||||
*/
|
||||
Nativee = 0x10,
|
||||
Network = 0x00
|
||||
}
|
||||
}
|
||||
22
NSspi/SecureBuffer/SecureBufferDesc.cs
Normal file
22
NSspi/SecureBuffer/SecureBufferDesc.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential)]
|
||||
internal struct SecureBufferDescInternal
|
||||
{
|
||||
public int Version;
|
||||
public int NumBuffers;
|
||||
|
||||
// A pointer to a SecureBuffer[]
|
||||
public IntPtr Buffers;
|
||||
|
||||
public const int ApiVersion = 0;
|
||||
}
|
||||
}
|
||||
26
NSspi/SecureBuffer/SecureBufferType.cs
Normal file
26
NSspi/SecureBuffer/SecureBufferType.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
internal enum BufferType : int
|
||||
{
|
||||
Empty = 0x00,
|
||||
Data = 0x01,
|
||||
Token = 0x02,
|
||||
Parameters = 0x03,
|
||||
Missing = 0x04,
|
||||
Extra = 0x05,
|
||||
Trailer = 0x06,
|
||||
Header = 0x07,
|
||||
Padding = 0x09,
|
||||
Stream = 0x0A,
|
||||
ChannelBindings = 0x0E,
|
||||
TargetHost = 0x10,
|
||||
ReadOnlyFlag = unchecked( (int)0x80000000 ),
|
||||
ReadOnlyWithChecksum = 0x10000000
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user