Code cleanup
Fixed code style using CodeMaid.
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
@@ -37,8 +32,7 @@ namespace NSspi
|
||||
buffer[position + 0] = (byte)( value >> 24 );
|
||||
buffer[position + 1] = (byte)( value >> 16 );
|
||||
buffer[position + 2] = (byte)( value >> 8 );
|
||||
buffer[position + 3] = (byte)( value);
|
||||
|
||||
buffer[position + 3] = (byte)( value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Buffers;
|
||||
using NSspi.Credentials;
|
||||
|
||||
@@ -90,12 +85,12 @@ namespace NSspi.Contexts
|
||||
// The security package tells us how big its biggest token will be. We'll allocate a buffer
|
||||
// that size, and it'll tell us how much it used.
|
||||
outTokenBuffer = new SecureBuffer(
|
||||
new byte[ this.Credential.PackageInfo.MaxTokenLength ],
|
||||
new byte[this.Credential.PackageInfo.MaxTokenLength],
|
||||
BufferType.Token
|
||||
);
|
||||
|
||||
serverBuffer = null;
|
||||
if ( serverToken != null )
|
||||
if( serverToken != null )
|
||||
{
|
||||
serverBuffer = new SecureBuffer( serverToken, BufferType.Token );
|
||||
}
|
||||
@@ -115,9 +110,9 @@ namespace NSspi.Contexts
|
||||
// Windows, 128 bits on 64-bit Windows.
|
||||
// - So in the end, on a 64-bit machine, we're passing a 64-bit value (the pointer to the struct) that
|
||||
// points to 128 bits of memory (the struct itself) for where to write the handle numbers.
|
||||
using ( outAdapter = new SecureBufferAdapter( outTokenBuffer ) )
|
||||
using( outAdapter = new SecureBufferAdapter( outTokenBuffer ) )
|
||||
{
|
||||
if ( this.ContextHandle.IsInvalid )
|
||||
if( this.ContextHandle.IsInvalid )
|
||||
{
|
||||
status = ContextNativeMethods.InitializeSecurityContext_1(
|
||||
ref this.Credential.Handle.rawHandle,
|
||||
@@ -136,7 +131,7 @@ namespace NSspi.Contexts
|
||||
}
|
||||
else
|
||||
{
|
||||
using ( serverAdapter = new SecureBufferAdapter( serverBuffer ) )
|
||||
using( serverAdapter = new SecureBufferAdapter( serverBuffer ) )
|
||||
{
|
||||
status = ContextNativeMethods.InitializeSecurityContext_2(
|
||||
ref this.Credential.Handle.rawHandle,
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Buffers;
|
||||
using NSspi.Contexts;
|
||||
using NSspi.Credentials;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
@@ -28,7 +23,7 @@ namespace NSspi.Contexts
|
||||
/// and the Initialize method has been called.
|
||||
/// </summary>
|
||||
/// <param name="cred"></param>
|
||||
protected Context(Credential cred)
|
||||
protected Context( Credential cred )
|
||||
{
|
||||
this.Credential = cred;
|
||||
|
||||
@@ -61,7 +56,7 @@ namespace NSspi.Contexts
|
||||
get
|
||||
{
|
||||
CheckLifecycle();
|
||||
return QueryContextString(ContextQueryAttrib.Authority);
|
||||
return QueryContextString( ContextQueryAttrib.Authority );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +68,7 @@ namespace NSspi.Contexts
|
||||
get
|
||||
{
|
||||
CheckLifecycle();
|
||||
return QueryContextString(ContextQueryAttrib.Names);
|
||||
return QueryContextString( ContextQueryAttrib.Names );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +86,7 @@ namespace NSspi.Contexts
|
||||
/// Marks the context as having completed the initialization process, ie, exchanging of authentication tokens.
|
||||
/// </summary>
|
||||
/// <param name="expiry">The date and time that the context will expire.</param>
|
||||
protected void Initialize(DateTime expiry)
|
||||
protected void Initialize( DateTime expiry )
|
||||
{
|
||||
this.Expiry = expiry;
|
||||
this.Initialized = true;
|
||||
@@ -102,19 +97,19 @@ namespace NSspi.Contexts
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
Dispose( true );
|
||||
GC.SuppressFinalize( this );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases resources associated with the context.
|
||||
/// </summary>
|
||||
/// <param name="disposing">If true, release managed resources, else release only unmanaged resources.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
protected virtual void Dispose( bool disposing )
|
||||
{
|
||||
if (this.Disposed) { return; }
|
||||
if( this.Disposed ) { return; }
|
||||
|
||||
if (disposing)
|
||||
if( disposing )
|
||||
{
|
||||
this.ContextHandle.Dispose();
|
||||
}
|
||||
@@ -136,7 +131,7 @@ namespace NSspi.Contexts
|
||||
/// </remarks>
|
||||
/// <param name="input">The raw message to encrypt.</param>
|
||||
/// <returns>The packed and encrypted message.</returns>
|
||||
public byte[] Encrypt(byte[] input)
|
||||
public byte[] Encrypt( byte[] input )
|
||||
{
|
||||
// The message is encrypted in place in the buffer we provide to Win32 EncryptMessage
|
||||
SecPkgContext_Sizes sizes;
|
||||
@@ -153,13 +148,13 @@ namespace NSspi.Contexts
|
||||
|
||||
sizes = QueryBufferSizes();
|
||||
|
||||
trailerBuffer = new SecureBuffer(new byte[sizes.SecurityTrailer], BufferType.Token);
|
||||
dataBuffer = new SecureBuffer(new byte[input.Length], BufferType.Data);
|
||||
paddingBuffer = new SecureBuffer(new byte[sizes.BlockSize], BufferType.Padding);
|
||||
trailerBuffer = new SecureBuffer( new byte[sizes.SecurityTrailer], BufferType.Token );
|
||||
dataBuffer = new SecureBuffer( new byte[input.Length], BufferType.Data );
|
||||
paddingBuffer = new SecureBuffer( new byte[sizes.BlockSize], BufferType.Padding );
|
||||
|
||||
Array.Copy(input, dataBuffer.Buffer, input.Length);
|
||||
Array.Copy( input, dataBuffer.Buffer, input.Length );
|
||||
|
||||
using (adapter = new SecureBufferAdapter(new[] { trailerBuffer, dataBuffer, paddingBuffer }))
|
||||
using( adapter = new SecureBufferAdapter( new[] { trailerBuffer, dataBuffer, paddingBuffer } ) )
|
||||
{
|
||||
status = ContextNativeMethods.SafeEncryptMessage(
|
||||
this.ContextHandle,
|
||||
@@ -169,9 +164,9 @@ namespace NSspi.Contexts
|
||||
);
|
||||
}
|
||||
|
||||
if (status != SecurityStatus.OK)
|
||||
if( status != SecurityStatus.OK )
|
||||
{
|
||||
throw new SSPIException("Failed to encrypt message", status);
|
||||
throw new SSPIException( "Failed to encrypt message", status );
|
||||
}
|
||||
|
||||
int position = 0;
|
||||
@@ -183,22 +178,22 @@ namespace NSspi.Contexts
|
||||
// -- The encrypted message
|
||||
result = new byte[2 + 4 + 2 + trailerBuffer.Length + dataBuffer.Length + paddingBuffer.Length];
|
||||
|
||||
ByteWriter.WriteInt16_BE((short)trailerBuffer.Length, result, position);
|
||||
ByteWriter.WriteInt16_BE( (short)trailerBuffer.Length, result, position );
|
||||
position += 2;
|
||||
|
||||
ByteWriter.WriteInt32_BE(dataBuffer.Length, result, position);
|
||||
ByteWriter.WriteInt32_BE( dataBuffer.Length, result, position );
|
||||
position += 4;
|
||||
|
||||
ByteWriter.WriteInt16_BE((short)paddingBuffer.Length, result, position);
|
||||
ByteWriter.WriteInt16_BE( (short)paddingBuffer.Length, result, position );
|
||||
position += 2;
|
||||
|
||||
Array.Copy(trailerBuffer.Buffer, 0, result, position, trailerBuffer.Length);
|
||||
Array.Copy( trailerBuffer.Buffer, 0, result, position, trailerBuffer.Length );
|
||||
position += trailerBuffer.Length;
|
||||
|
||||
Array.Copy(dataBuffer.Buffer, 0, result, position, dataBuffer.Length);
|
||||
Array.Copy( dataBuffer.Buffer, 0, result, position, dataBuffer.Length );
|
||||
position += dataBuffer.Length;
|
||||
|
||||
Array.Copy(paddingBuffer.Buffer, 0, result, position, paddingBuffer.Length);
|
||||
Array.Copy( paddingBuffer.Buffer, 0, result, position, paddingBuffer.Length );
|
||||
position += paddingBuffer.Length;
|
||||
|
||||
return result;
|
||||
@@ -218,7 +213,7 @@ namespace NSspi.Contexts
|
||||
/// </remarks>
|
||||
/// <param name="input">The packed and encrypted data.</param>
|
||||
/// <returns>The original plaintext message.</returns>
|
||||
public byte[] Decrypt(byte[] input)
|
||||
public byte[] Decrypt( byte[] input )
|
||||
{
|
||||
SecPkgContext_Sizes sizes;
|
||||
|
||||
@@ -241,63 +236,62 @@ namespace NSspi.Contexts
|
||||
sizes = QueryBufferSizes();
|
||||
|
||||
// This check is required, but not sufficient. We could be stricter.
|
||||
if (input.Length < 2 + 4 + 2 + sizes.SecurityTrailer)
|
||||
if( input.Length < 2 + 4 + 2 + sizes.SecurityTrailer )
|
||||
{
|
||||
throw new ArgumentException("Buffer is too small to possibly contain an encrypted message");
|
||||
throw new ArgumentException( "Buffer is too small to possibly contain an encrypted message" );
|
||||
}
|
||||
|
||||
position = 0;
|
||||
|
||||
trailerLength = ByteWriter.ReadInt16_BE(input, position);
|
||||
trailerLength = ByteWriter.ReadInt16_BE( input, position );
|
||||
position += 2;
|
||||
|
||||
dataLength = ByteWriter.ReadInt32_BE(input, position);
|
||||
dataLength = ByteWriter.ReadInt32_BE( input, position );
|
||||
position += 4;
|
||||
|
||||
paddingLength = ByteWriter.ReadInt16_BE(input, position);
|
||||
paddingLength = ByteWriter.ReadInt16_BE( input, position );
|
||||
position += 2;
|
||||
|
||||
if (trailerLength + dataLength + paddingLength + 2 + 4 + 2 > input.Length)
|
||||
if( trailerLength + dataLength + paddingLength + 2 + 4 + 2 > input.Length )
|
||||
{
|
||||
throw new ArgumentException("The buffer contains invalid data - the embedded length data does not add up.");
|
||||
throw new ArgumentException( "The buffer contains invalid data - the embedded length data does not add up." );
|
||||
}
|
||||
|
||||
trailerBuffer = new SecureBuffer(new byte[trailerLength], BufferType.Token);
|
||||
dataBuffer = new SecureBuffer(new byte[dataLength], BufferType.Data);
|
||||
paddingBuffer = new SecureBuffer(new byte[paddingLength], BufferType.Padding);
|
||||
trailerBuffer = new SecureBuffer( new byte[trailerLength], BufferType.Token );
|
||||
dataBuffer = new SecureBuffer( new byte[dataLength], BufferType.Data );
|
||||
paddingBuffer = new SecureBuffer( new byte[paddingLength], BufferType.Padding );
|
||||
|
||||
remaining = input.Length - position;
|
||||
|
||||
if (trailerBuffer.Length <= remaining)
|
||||
if( trailerBuffer.Length <= remaining )
|
||||
{
|
||||
Array.Copy(input, position, trailerBuffer.Buffer, 0, trailerBuffer.Length);
|
||||
Array.Copy( input, position, trailerBuffer.Buffer, 0, trailerBuffer.Length );
|
||||
position += trailerBuffer.Length;
|
||||
remaining -= trailerBuffer.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Input is missing data - it is not long enough to contain a fully encrypted message");
|
||||
throw new ArgumentException( "Input is missing data - it is not long enough to contain a fully encrypted message" );
|
||||
}
|
||||
|
||||
if (dataBuffer.Length <= remaining)
|
||||
if( dataBuffer.Length <= remaining )
|
||||
{
|
||||
Array.Copy(input, position, dataBuffer.Buffer, 0, dataBuffer.Length);
|
||||
Array.Copy( input, position, dataBuffer.Buffer, 0, dataBuffer.Length );
|
||||
position += dataBuffer.Length;
|
||||
remaining -= dataBuffer.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Input is missing data - it is not long enough to contain a fully encrypted message");
|
||||
throw new ArgumentException( "Input is missing data - it is not long enough to contain a fully encrypted message" );
|
||||
}
|
||||
|
||||
if (paddingBuffer.Length <= remaining)
|
||||
if( paddingBuffer.Length <= remaining )
|
||||
{
|
||||
Array.Copy(input, position, paddingBuffer.Buffer, 0, paddingBuffer.Length);
|
||||
Array.Copy( input, position, paddingBuffer.Buffer, 0, paddingBuffer.Length );
|
||||
}
|
||||
// else there was no padding.
|
||||
|
||||
|
||||
using (adapter = new SecureBufferAdapter(new[] { trailerBuffer, dataBuffer, paddingBuffer }))
|
||||
using( adapter = new SecureBufferAdapter( new[] { trailerBuffer, dataBuffer, paddingBuffer } ) )
|
||||
{
|
||||
status = ContextNativeMethods.SafeDecryptMessage(
|
||||
this.ContextHandle,
|
||||
@@ -307,13 +301,13 @@ namespace NSspi.Contexts
|
||||
);
|
||||
}
|
||||
|
||||
if (status != SecurityStatus.OK)
|
||||
if( status != SecurityStatus.OK )
|
||||
{
|
||||
throw new SSPIException("Failed to encrypt message", status);
|
||||
throw new SSPIException( "Failed to encrypt message", status );
|
||||
}
|
||||
|
||||
result = new byte[dataBuffer.Length];
|
||||
Array.Copy(dataBuffer.Buffer, 0, result, 0, dataBuffer.Length);
|
||||
Array.Copy( dataBuffer.Buffer, 0, result, 0, dataBuffer.Length );
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -330,7 +324,7 @@ namespace NSspi.Contexts
|
||||
/// </remarks>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public byte[] MakeSignature(byte[] message)
|
||||
public byte[] MakeSignature( byte[] message )
|
||||
{
|
||||
SecurityStatus status = SecurityStatus.InternalError;
|
||||
|
||||
@@ -343,12 +337,12 @@ namespace NSspi.Contexts
|
||||
|
||||
sizes = QueryBufferSizes();
|
||||
|
||||
dataBuffer = new SecureBuffer(new byte[message.Length], BufferType.Data);
|
||||
signatureBuffer = new SecureBuffer(new byte[sizes.MaxSignature], BufferType.Token);
|
||||
dataBuffer = new SecureBuffer( new byte[message.Length], BufferType.Data );
|
||||
signatureBuffer = new SecureBuffer( new byte[sizes.MaxSignature], BufferType.Token );
|
||||
|
||||
Array.Copy(message, dataBuffer.Buffer, message.Length);
|
||||
Array.Copy( message, dataBuffer.Buffer, message.Length );
|
||||
|
||||
using (adapter = new SecureBufferAdapter(new[] { dataBuffer, signatureBuffer }))
|
||||
using( adapter = new SecureBufferAdapter( new[] { dataBuffer, signatureBuffer } ) )
|
||||
{
|
||||
status = ContextNativeMethods.SafeMakeSignature(
|
||||
this.ContextHandle,
|
||||
@@ -358,9 +352,9 @@ namespace NSspi.Contexts
|
||||
);
|
||||
}
|
||||
|
||||
if (status != SecurityStatus.OK)
|
||||
if( status != SecurityStatus.OK )
|
||||
{
|
||||
throw new SSPIException("Failed to create message signature.", status);
|
||||
throw new SSPIException( "Failed to create message signature.", status );
|
||||
}
|
||||
|
||||
byte[] outMessage;
|
||||
@@ -374,22 +368,21 @@ namespace NSspi.Contexts
|
||||
|
||||
outMessage = new byte[4 + 2 + dataBuffer.Length + signatureBuffer.Length];
|
||||
|
||||
ByteWriter.WriteInt32_BE(dataBuffer.Length, outMessage, position);
|
||||
ByteWriter.WriteInt32_BE( dataBuffer.Length, outMessage, position );
|
||||
position += 4;
|
||||
|
||||
ByteWriter.WriteInt16_BE((Int16)signatureBuffer.Length, outMessage, position);
|
||||
ByteWriter.WriteInt16_BE( (Int16)signatureBuffer.Length, outMessage, position );
|
||||
position += 2;
|
||||
|
||||
Array.Copy(dataBuffer.Buffer, 0, outMessage, position, dataBuffer.Length);
|
||||
Array.Copy( dataBuffer.Buffer, 0, outMessage, position, dataBuffer.Length );
|
||||
position += dataBuffer.Length;
|
||||
|
||||
Array.Copy(signatureBuffer.Buffer, 0, outMessage, position, signatureBuffer.Length);
|
||||
Array.Copy( signatureBuffer.Buffer, 0, outMessage, position, signatureBuffer.Length );
|
||||
position += signatureBuffer.Length;
|
||||
|
||||
return outMessage;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Session Key from a context or null on failure.
|
||||
/// </summary>
|
||||
@@ -410,15 +403,14 @@ namespace NSspi.Contexts
|
||||
ref SessionKey
|
||||
);
|
||||
|
||||
if (status != SecurityStatus.OK)
|
||||
if( status != SecurityStatus.OK )
|
||||
{
|
||||
throw new SSPIException("Failed to query session key.", status);
|
||||
throw new SSPIException( "Failed to query session key.", status );
|
||||
}
|
||||
|
||||
return SessionKey;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the signature of a signed message
|
||||
/// </summary>
|
||||
@@ -432,7 +424,7 @@ namespace NSspi.Contexts
|
||||
/// <param name="signedMessage">The packed signed message.</param>
|
||||
/// <param name="origMessage">The extracted original message.</param>
|
||||
/// <returns>True if the message has a valid signature, false otherwise.</returns>
|
||||
public bool VerifySignature(byte[] signedMessage, out byte[] origMessage)
|
||||
public bool VerifySignature( byte[] signedMessage, out byte[] origMessage )
|
||||
{
|
||||
SecurityStatus status = SecurityStatus.InternalError;
|
||||
|
||||
@@ -445,35 +437,35 @@ namespace NSspi.Contexts
|
||||
|
||||
sizes = QueryBufferSizes();
|
||||
|
||||
if (signedMessage.Length < 2 + 4 + sizes.MaxSignature)
|
||||
if( signedMessage.Length < 2 + 4 + sizes.MaxSignature )
|
||||
{
|
||||
throw new ArgumentException("Input message is too small to possibly fit a valid message");
|
||||
throw new ArgumentException( "Input message is too small to possibly fit a valid message" );
|
||||
}
|
||||
|
||||
int position = 0;
|
||||
int messageLen;
|
||||
int sigLen;
|
||||
|
||||
messageLen = ByteWriter.ReadInt32_BE(signedMessage, 0);
|
||||
messageLen = ByteWriter.ReadInt32_BE( signedMessage, 0 );
|
||||
position += 4;
|
||||
|
||||
sigLen = ByteWriter.ReadInt16_BE(signedMessage, position);
|
||||
sigLen = ByteWriter.ReadInt16_BE( signedMessage, position );
|
||||
position += 2;
|
||||
|
||||
if (messageLen + sigLen + 2 + 4 > signedMessage.Length)
|
||||
if( messageLen + sigLen + 2 + 4 > signedMessage.Length )
|
||||
{
|
||||
throw new ArgumentException("The buffer contains invalid data - the embedded length data does not add up.");
|
||||
throw new ArgumentException( "The buffer contains invalid data - the embedded length data does not add up." );
|
||||
}
|
||||
|
||||
dataBuffer = new SecureBuffer(new byte[messageLen], BufferType.Data);
|
||||
Array.Copy(signedMessage, position, dataBuffer.Buffer, 0, messageLen);
|
||||
dataBuffer = new SecureBuffer( new byte[messageLen], BufferType.Data );
|
||||
Array.Copy( signedMessage, position, dataBuffer.Buffer, 0, messageLen );
|
||||
position += messageLen;
|
||||
|
||||
signatureBuffer = new SecureBuffer(new byte[sigLen], BufferType.Token);
|
||||
Array.Copy(signedMessage, position, signatureBuffer.Buffer, 0, sigLen);
|
||||
signatureBuffer = new SecureBuffer( new byte[sigLen], BufferType.Token );
|
||||
Array.Copy( signedMessage, position, signatureBuffer.Buffer, 0, sigLen );
|
||||
position += sigLen;
|
||||
|
||||
using (adapter = new SecureBufferAdapter(new[] { dataBuffer, signatureBuffer }))
|
||||
using( adapter = new SecureBufferAdapter( new[] { dataBuffer, signatureBuffer } ) )
|
||||
{
|
||||
status = ContextNativeMethods.SafeVerifySignature(
|
||||
this.ContextHandle,
|
||||
@@ -483,20 +475,20 @@ namespace NSspi.Contexts
|
||||
);
|
||||
}
|
||||
|
||||
if (status == SecurityStatus.OK)
|
||||
if( status == SecurityStatus.OK )
|
||||
{
|
||||
origMessage = dataBuffer.Buffer;
|
||||
return true;
|
||||
}
|
||||
else if (status == SecurityStatus.MessageAltered ||
|
||||
status == SecurityStatus.OutOfSequence)
|
||||
else if( status == SecurityStatus.MessageAltered ||
|
||||
status == SecurityStatus.OutOfSequence )
|
||||
{
|
||||
origMessage = null;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SSPIException("Failed to determine the veracity of a signed message.", status);
|
||||
throw new SSPIException( "Failed to determine the veracity of a signed message.", status );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,11 +505,11 @@ namespace NSspi.Contexts
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try
|
||||
{
|
||||
this.ContextHandle.DangerousAddRef(ref gotRef);
|
||||
this.ContextHandle.DangerousAddRef( ref gotRef );
|
||||
}
|
||||
catch (Exception)
|
||||
catch( Exception )
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
this.ContextHandle.DangerousRelease();
|
||||
gotRef = false;
|
||||
@@ -527,7 +519,7 @@ namespace NSspi.Contexts
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
status = ContextNativeMethods.QueryContextAttributes_Sizes(
|
||||
ref this.ContextHandle.rawHandle,
|
||||
@@ -538,9 +530,9 @@ namespace NSspi.Contexts
|
||||
}
|
||||
}
|
||||
|
||||
if (status != SecurityStatus.OK)
|
||||
if( status != SecurityStatus.OK )
|
||||
{
|
||||
throw new SSPIException("Failed to query context buffer size attributes", status);
|
||||
throw new SSPIException( "Failed to query context buffer size attributes", status );
|
||||
}
|
||||
|
||||
return sizes;
|
||||
@@ -551,16 +543,16 @@ namespace NSspi.Contexts
|
||||
/// </summary>
|
||||
/// <param name="attrib">The string-valued attribute to query.</param>
|
||||
/// <returns></returns>
|
||||
private string QueryContextString(ContextQueryAttrib attrib)
|
||||
private string QueryContextString( ContextQueryAttrib attrib )
|
||||
{
|
||||
SecPkgContext_String stringAttrib;
|
||||
SecurityStatus status = SecurityStatus.InternalError;
|
||||
string result = null;
|
||||
bool gotRef = false;
|
||||
|
||||
if (attrib != ContextQueryAttrib.Names && attrib != ContextQueryAttrib.Authority)
|
||||
if( attrib != ContextQueryAttrib.Names && attrib != ContextQueryAttrib.Authority )
|
||||
{
|
||||
throw new InvalidOperationException("QueryContextString can only be used to query context Name and Authority attributes");
|
||||
throw new InvalidOperationException( "QueryContextString can only be used to query context Name and Authority attributes" );
|
||||
}
|
||||
|
||||
stringAttrib = new SecPkgContext_String();
|
||||
@@ -568,11 +560,11 @@ namespace NSspi.Contexts
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try
|
||||
{
|
||||
this.ContextHandle.DangerousAddRef(ref gotRef);
|
||||
this.ContextHandle.DangerousAddRef( ref gotRef );
|
||||
}
|
||||
catch (Exception)
|
||||
catch( Exception )
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
this.ContextHandle.DangerousRelease();
|
||||
gotRef = false;
|
||||
@@ -581,7 +573,7 @@ namespace NSspi.Contexts
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
status = ContextNativeMethods.QueryContextAttributes_String(
|
||||
ref this.ContextHandle.rawHandle,
|
||||
@@ -591,21 +583,21 @@ namespace NSspi.Contexts
|
||||
|
||||
this.ContextHandle.DangerousRelease();
|
||||
|
||||
if (status == SecurityStatus.OK)
|
||||
if( status == SecurityStatus.OK )
|
||||
{
|
||||
result = Marshal.PtrToStringUni(stringAttrib.StringResult);
|
||||
ContextNativeMethods.FreeContextBuffer(stringAttrib.StringResult);
|
||||
result = Marshal.PtrToStringUni( stringAttrib.StringResult );
|
||||
ContextNativeMethods.FreeContextBuffer( stringAttrib.StringResult );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (status == SecurityStatus.Unsupported)
|
||||
if( status == SecurityStatus.Unsupported )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (status != SecurityStatus.OK)
|
||||
else if( status != SecurityStatus.OK )
|
||||
{
|
||||
throw new SSPIException("Failed to query the context's associated user name", status);
|
||||
throw new SSPIException( "Failed to query the context's associated user name", status );
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -617,13 +609,13 @@ namespace NSspi.Contexts
|
||||
/// </summary>
|
||||
private void CheckLifecycle()
|
||||
{
|
||||
if (this.Initialized == false)
|
||||
if( this.Initialized == false )
|
||||
{
|
||||
throw new InvalidOperationException("The context is not yet fully formed.");
|
||||
throw new InvalidOperationException( "The context is not yet fully formed." );
|
||||
}
|
||||
else if (this.Disposed)
|
||||
else if( this.Disposed )
|
||||
{
|
||||
throw new ObjectDisposedException("Context");
|
||||
throw new ObjectDisposedException( "Context" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
@@ -36,7 +32,6 @@ namespace NSspi.Contexts
|
||||
/// </summary>
|
||||
MutualAuth = 0x00000002,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Detect replayed messages that have been encoded by using the EncryptMessage or MakeSignature
|
||||
/// message support functionality.
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Buffers;
|
||||
using NSspi.Contexts;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
@@ -45,7 +40,7 @@ namespace NSspi.Contexts
|
||||
);
|
||||
*/
|
||||
|
||||
[DllImport("Secur32.dll", EntryPoint = "AcceptSecurityContext", CharSet = CharSet.Unicode)]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "AcceptSecurityContext", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus AcceptSecurityContext_1(
|
||||
ref RawSspiHandle credHandle,
|
||||
IntPtr oldContextHandle,
|
||||
@@ -58,8 +53,7 @@ namespace NSspi.Contexts
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
|
||||
[DllImport("Secur32.dll", EntryPoint = "AcceptSecurityContext", CharSet = CharSet.Unicode)]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "AcceptSecurityContext", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus AcceptSecurityContext_2(
|
||||
ref RawSspiHandle credHandle,
|
||||
ref RawSspiHandle oldContextHandle,
|
||||
@@ -72,8 +66,7 @@ namespace NSspi.Contexts
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
|
||||
[DllImport("Secur32.dll", EntryPoint = "InitializeSecurityContext", CharSet = CharSet.Unicode)]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "InitializeSecurityContext", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus InitializeSecurityContext_1(
|
||||
ref RawSspiHandle credentialHandle,
|
||||
IntPtr zero,
|
||||
@@ -89,8 +82,7 @@ namespace NSspi.Contexts
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
|
||||
[DllImport("Secur32.dll", EntryPoint = "InitializeSecurityContext", CharSet = CharSet.Unicode)]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "InitializeSecurityContext", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus InitializeSecurityContext_2(
|
||||
ref RawSspiHandle credentialHandle,
|
||||
ref RawSspiHandle previousHandle,
|
||||
@@ -106,13 +98,12 @@ namespace NSspi.Contexts
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "DeleteSecurityContext", CharSet = CharSet.Unicode)]
|
||||
internal static extern SecurityStatus DeleteSecurityContext(ref RawSspiHandle contextHandle);
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "DeleteSecurityContext", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus DeleteSecurityContext( ref RawSspiHandle contextHandle );
|
||||
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "EncryptMessage", CharSet = CharSet.Unicode)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "EncryptMessage", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus EncryptMessage(
|
||||
ref RawSspiHandle contextHandle,
|
||||
int qualityOfProtection,
|
||||
@@ -120,8 +111,8 @@ namespace NSspi.Contexts
|
||||
int sequenceNumber
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "DecryptMessage", CharSet = CharSet.Unicode)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "DecryptMessage", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus DecryptMessage(
|
||||
ref RawSspiHandle contextHandle,
|
||||
IntPtr bufferDescriptor,
|
||||
@@ -129,8 +120,8 @@ namespace NSspi.Contexts
|
||||
int qualityOfProtection
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "MakeSignature", CharSet = CharSet.Unicode)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "MakeSignature", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus MakeSignature(
|
||||
ref RawSspiHandle contextHandle,
|
||||
int qualityOfProtection,
|
||||
@@ -138,8 +129,8 @@ namespace NSspi.Contexts
|
||||
int sequenceNumber
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "VerifySignature", CharSet = CharSet.Unicode)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "VerifySignature", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus VerifySignature(
|
||||
ref RawSspiHandle contextHandle,
|
||||
IntPtr bufferDescriptor,
|
||||
@@ -147,45 +138,44 @@ namespace NSspi.Contexts
|
||||
int qualityOfProtection
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus QueryContextAttributes_Sizes(
|
||||
ref RawSspiHandle contextHandle,
|
||||
ContextQueryAttrib attrib,
|
||||
ref SecPkgContext_Sizes sizes
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus QueryContextAttributes_String(
|
||||
ref RawSspiHandle contextHandle,
|
||||
ContextQueryAttrib attrib,
|
||||
ref SecPkgContext_String names
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "QueryContextAttributes", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus QueryContextAttributes(
|
||||
ref RawSspiHandle contextHandle,
|
||||
ContextQueryAttrib attrib,
|
||||
IntPtr attribute
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "FreeContextBuffer", CharSet = CharSet.Unicode)]
|
||||
internal static extern SecurityStatus FreeContextBuffer(IntPtr handle);
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "FreeContextBuffer", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus FreeContextBuffer( IntPtr handle );
|
||||
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "ImpersonateSecurityContext", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus ImpersonateSecurityContext( ref RawSspiHandle contextHandle );
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "ImpersonateSecurityContext", CharSet = CharSet.Unicode)]
|
||||
internal static extern SecurityStatus ImpersonateSecurityContext(ref RawSspiHandle contextHandle);
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "RevertSecurityContext", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus RevertSecurityContext( ref RawSspiHandle contextHandle );
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport("Secur32.dll", EntryPoint = "RevertSecurityContext", CharSet = CharSet.Unicode)]
|
||||
internal static extern SecurityStatus RevertSecurityContext(ref RawSspiHandle contextHandle);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
class KeyStruct
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
private class KeyStruct
|
||||
{
|
||||
public int size;
|
||||
public IntPtr data;
|
||||
@@ -202,18 +192,17 @@ namespace NSspi.Contexts
|
||||
SecurityStatus status = SecurityStatus.InternalError;
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
|
||||
|
||||
int pointerSize = System.Environment.Is64BitOperatingSystem ? 8 : 4; //NOTE: update this when 128 bit processors exist
|
||||
IntPtr alloc_buffer = Marshal.AllocHGlobal(sizeof(uint) + pointerSize); //NOTE: this is at most 4 + sizeof(void*) bytes
|
||||
//see struct SecPkgContext_SessionKey
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa380096(v=vs.85).aspx
|
||||
IntPtr alloc_buffer = Marshal.AllocHGlobal( sizeof( uint ) + pointerSize ); //NOTE: this is at most 4 + sizeof(void*) bytes
|
||||
//see struct SecPkgContext_SessionKey
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa380096(v=vs.85).aspx
|
||||
try
|
||||
{
|
||||
handle.DangerousAddRef(ref gotRef);
|
||||
handle.DangerousAddRef( ref gotRef );
|
||||
}
|
||||
catch (Exception)
|
||||
catch( Exception )
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
handle.DangerousRelease();
|
||||
gotRef = false;
|
||||
@@ -224,35 +213,33 @@ namespace NSspi.Contexts
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
status = ContextNativeMethods.QueryContextAttributes(
|
||||
ref handle.rawHandle,
|
||||
attribute,
|
||||
alloc_buffer
|
||||
);
|
||||
if (status == SecurityStatus.OK)
|
||||
if( status == SecurityStatus.OK )
|
||||
{
|
||||
KeyStruct key = new KeyStruct();
|
||||
|
||||
Marshal.PtrToStructure(alloc_buffer, key); // fit to the proper size, read a byte[]
|
||||
Marshal.PtrToStructure( alloc_buffer, key ); // fit to the proper size, read a byte[]
|
||||
|
||||
byte[] sizedBuffer = new byte[key.size];
|
||||
|
||||
for (int i = 0; i < key.size; i++)
|
||||
sizedBuffer[i] = Marshal.ReadByte(key.data, i);
|
||||
for( int i = 0; i < key.size; i++ )
|
||||
sizedBuffer[i] = Marshal.ReadByte( key.data, i );
|
||||
|
||||
buffer = sizedBuffer;
|
||||
}
|
||||
handle.DangerousRelease();
|
||||
}
|
||||
}
|
||||
Marshal.FreeHGlobal(alloc_buffer);
|
||||
Marshal.FreeHGlobal( alloc_buffer );
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Safely invokes the native EncryptMessage function, making sure that handle ref counting is
|
||||
/// performed in a proper CER.
|
||||
@@ -266,7 +253,7 @@ namespace NSspi.Contexts
|
||||
SafeContextHandle handle,
|
||||
int qualityOfProtection,
|
||||
SecureBufferAdapter bufferAdapter,
|
||||
int sequenceNumber)
|
||||
int sequenceNumber )
|
||||
{
|
||||
SecurityStatus status = SecurityStatus.InternalError;
|
||||
bool gotRef = false;
|
||||
@@ -274,11 +261,11 @@ namespace NSspi.Contexts
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try
|
||||
{
|
||||
handle.DangerousAddRef(ref gotRef);
|
||||
handle.DangerousAddRef( ref gotRef );
|
||||
}
|
||||
catch (Exception)
|
||||
catch( Exception )
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
handle.DangerousRelease();
|
||||
gotRef = false;
|
||||
@@ -288,7 +275,7 @@ namespace NSspi.Contexts
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
status = ContextNativeMethods.EncryptMessage(
|
||||
ref handle.rawHandle,
|
||||
@@ -317,7 +304,7 @@ namespace NSspi.Contexts
|
||||
SafeContextHandle handle,
|
||||
int qualityOfProtection,
|
||||
SecureBufferAdapter bufferAdapter,
|
||||
int sequenceNumber)
|
||||
int sequenceNumber )
|
||||
{
|
||||
SecurityStatus status = SecurityStatus.InvalidHandle;
|
||||
bool gotRef = false;
|
||||
@@ -325,11 +312,11 @@ namespace NSspi.Contexts
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try
|
||||
{
|
||||
handle.DangerousAddRef(ref gotRef);
|
||||
handle.DangerousAddRef( ref gotRef );
|
||||
}
|
||||
catch (Exception)
|
||||
catch( Exception )
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
handle.DangerousRelease();
|
||||
gotRef = false;
|
||||
@@ -339,7 +326,7 @@ namespace NSspi.Contexts
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
status = ContextNativeMethods.DecryptMessage(
|
||||
ref handle.rawHandle,
|
||||
@@ -368,7 +355,7 @@ namespace NSspi.Contexts
|
||||
SafeContextHandle handle,
|
||||
int qualityOfProtection,
|
||||
SecureBufferAdapter adapter,
|
||||
int sequenceNumber)
|
||||
int sequenceNumber )
|
||||
{
|
||||
bool gotRef = false;
|
||||
SecurityStatus status = SecurityStatus.InternalError;
|
||||
@@ -376,11 +363,11 @@ namespace NSspi.Contexts
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try
|
||||
{
|
||||
handle.DangerousAddRef(ref gotRef);
|
||||
handle.DangerousAddRef( ref gotRef );
|
||||
}
|
||||
catch (Exception)
|
||||
catch( Exception )
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
handle.DangerousRelease();
|
||||
gotRef = false;
|
||||
@@ -390,7 +377,7 @@ namespace NSspi.Contexts
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
status = ContextNativeMethods.MakeSignature(
|
||||
ref handle.rawHandle,
|
||||
@@ -419,7 +406,7 @@ namespace NSspi.Contexts
|
||||
SafeContextHandle handle,
|
||||
int qualityOfProtection,
|
||||
SecureBufferAdapter adapter,
|
||||
int sequenceNumber)
|
||||
int sequenceNumber )
|
||||
{
|
||||
bool gotRef = false;
|
||||
SecurityStatus status = SecurityStatus.InternalError;
|
||||
@@ -427,11 +414,11 @@ namespace NSspi.Contexts
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try
|
||||
{
|
||||
handle.DangerousAddRef(ref gotRef);
|
||||
handle.DangerousAddRef( ref gotRef );
|
||||
}
|
||||
catch (Exception)
|
||||
catch( Exception )
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
handle.DangerousRelease();
|
||||
gotRef = false;
|
||||
@@ -441,7 +428,7 @@ namespace NSspi.Contexts
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gotRef)
|
||||
if( gotRef )
|
||||
{
|
||||
status = ContextNativeMethods.VerifySignature(
|
||||
ref handle.rawHandle,
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
@@ -37,7 +33,6 @@ namespace NSspi.Contexts
|
||||
/// </remarks>
|
||||
Authority = 6,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Queries the context for it's neogtiated SessionKey
|
||||
/// </summary>
|
||||
@@ -46,8 +41,6 @@ namespace NSspi.Contexts
|
||||
/// </remarks>
|
||||
SessionKey = 9,
|
||||
|
||||
|
||||
AccessToken = 13, //not implemented yet but this would be cool
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
@@ -27,7 +23,7 @@ namespace NSspi.Contexts
|
||||
/// Initializes a new instance of the ImpersonationHandle. Does not perform impersonation.
|
||||
/// </summary>
|
||||
/// <param name="server">The server context that is performing impersonation.</param>
|
||||
internal ImpersonationHandle(ServerContext server)
|
||||
internal ImpersonationHandle( ServerContext server )
|
||||
{
|
||||
this.server = server;
|
||||
this.disposed = false;
|
||||
@@ -54,6 +50,5 @@ namespace NSspi.Contexts
|
||||
this.server.RevertImpersonate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Buffers;
|
||||
using NSspi.Credentials;
|
||||
|
||||
@@ -25,7 +21,7 @@ namespace NSspi.Contexts
|
||||
/// </summary>
|
||||
/// <param name="cred"></param>
|
||||
/// <param name="requestedAttribs"></param>
|
||||
public ServerContext(ServerCredential cred, ContextAttrib requestedAttribs) : base ( cred )
|
||||
public ServerContext( ServerCredential cred, ContextAttrib requestedAttribs ) : base( cred )
|
||||
{
|
||||
this.requestedAttribs = requestedAttribs;
|
||||
this.finalAttribs = ContextAttrib.Zero;
|
||||
@@ -90,13 +86,13 @@ namespace NSspi.Contexts
|
||||
clientBuffer = new SecureBuffer( clientToken, BufferType.Token );
|
||||
|
||||
outBuffer = new SecureBuffer(
|
||||
new byte[ this.Credential.PackageInfo.MaxTokenLength ],
|
||||
new byte[this.Credential.PackageInfo.MaxTokenLength],
|
||||
BufferType.Token
|
||||
);
|
||||
|
||||
using ( clientAdapter = new SecureBufferAdapter( clientBuffer ) )
|
||||
using( clientAdapter = new SecureBufferAdapter( clientBuffer ) )
|
||||
{
|
||||
using ( outAdapter = new SecureBufferAdapter( outBuffer ) )
|
||||
using( outAdapter = new SecureBufferAdapter( outBuffer ) )
|
||||
{
|
||||
if( this.ContextHandle.IsInvalid )
|
||||
{
|
||||
@@ -125,19 +121,17 @@ namespace NSspi.Contexts
|
||||
ref this.finalAttribs,
|
||||
ref rawExpiry
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( status == SecurityStatus.OK )
|
||||
if( status == SecurityStatus.OK )
|
||||
{
|
||||
nextToken = null;
|
||||
|
||||
base.Initialize( rawExpiry.ToDateTime() );
|
||||
|
||||
if ( outBuffer.Length != 0 )
|
||||
if( outBuffer.Length != 0 )
|
||||
{
|
||||
nextToken = new byte[outBuffer.Length];
|
||||
Array.Copy( outBuffer.Buffer, nextToken, nextToken.Length );
|
||||
@@ -147,7 +141,7 @@ namespace NSspi.Contexts
|
||||
nextToken = null;
|
||||
}
|
||||
}
|
||||
else if ( status == SecurityStatus.ContinueNeeded )
|
||||
else if( status == SecurityStatus.ContinueNeeded )
|
||||
{
|
||||
nextToken = new byte[outBuffer.Length];
|
||||
Array.Copy( outBuffer.Buffer, nextToken, nextToken.Length );
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Credentials;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
@@ -187,9 +180,9 @@ namespace NSspi.Credentials
|
||||
|
||||
protected virtual void Dispose( bool disposing )
|
||||
{
|
||||
if ( this.disposed == false )
|
||||
if( this.disposed == false )
|
||||
{
|
||||
if ( disposing )
|
||||
if( disposing )
|
||||
{
|
||||
this.safeCredHandle.Dispose();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Credentials;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
internal static class CredentialNativeMethods
|
||||
{
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "AcquireCredentialsHandle", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus AcquireCredentialsHandle(
|
||||
string principleName,
|
||||
@@ -31,7 +26,6 @@ namespace NSspi.Credentials
|
||||
ref RawSspiHandle credentialHandle
|
||||
);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The overload of the QueryCredentialsAttribute method that is used for querying the name attribute.
|
||||
/// In this call, it takes a void* to a structure that contains a wide char pointer. The wide character
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
@@ -57,13 +53,12 @@ namespace NSspi.Credentials
|
||||
);
|
||||
}
|
||||
|
||||
if ( status != SecurityStatus.OK )
|
||||
if( status != SecurityStatus.OK )
|
||||
{
|
||||
throw new SSPIException( "Failed to call AcquireCredentialHandle", status );
|
||||
}
|
||||
|
||||
this.Expiry = rawExpiry.ToDateTime();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
@@ -28,5 +24,4 @@ namespace NSspi.Credentials
|
||||
return status == SecurityStatus.OK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Contexts;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "FreeContextBuffer", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus FreeContextBuffer( IntPtr buffer );
|
||||
|
||||
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "QuerySecurityPackageInfo", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus QuerySecurityPackageInfo( string packageName, ref IntPtr pkgInfo );
|
||||
@@ -23,6 +17,5 @@ namespace NSspi
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "EnumerateSecurityPackages", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus EnumerateSecurityPackages( ref int numPackages, ref IntPtr pkgInfoArry );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
@@ -35,11 +31,11 @@ namespace NSspi
|
||||
{
|
||||
status = NativeMethods.QuerySecurityPackageInfo( packageName, ref rawInfoPtr );
|
||||
|
||||
if ( rawInfoPtr != IntPtr.Zero )
|
||||
if( rawInfoPtr != IntPtr.Zero )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( status == SecurityStatus.OK )
|
||||
if( status == SecurityStatus.OK )
|
||||
{
|
||||
// This performs allocations as it makes room for the strings contained in the SecPkgInfo class.
|
||||
Marshal.PtrToStructure( rawInfoPtr, info );
|
||||
@@ -71,7 +67,7 @@ namespace NSspi
|
||||
IntPtr pkgArrayPtr;
|
||||
IntPtr pkgPtr;
|
||||
int numPackages = 0;
|
||||
int pkgSize = Marshal.SizeOf( typeof(SecPkgInfo) );
|
||||
int pkgSize = Marshal.SizeOf( typeof( SecPkgInfo ) );
|
||||
|
||||
pkgArrayPtr = new IntPtr();
|
||||
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("NSspi")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Kevin Thompson")]
|
||||
[assembly: AssemblyProduct("NSspi")]
|
||||
[assembly: AssemblyCopyright("Copyright © Kevin Thompson 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyTitle( "NSspi" )]
|
||||
[assembly: AssemblyDescription( "" )]
|
||||
[assembly: AssemblyConfiguration( "" )]
|
||||
[assembly: AssemblyCompany( "Kevin Thompson" )]
|
||||
[assembly: AssemblyProduct( "NSspi" )]
|
||||
[assembly: AssemblyCopyright( "Copyright © Kevin Thompson 2014" )]
|
||||
[assembly: AssemblyTrademark( "" )]
|
||||
[assembly: AssemblyCulture( "" )]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: ComVisible( false )]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("9abf710c-c646-42aa-8183-76bfa141a07b")]
|
||||
[assembly: Guid( "9abf710c-c646-42aa-8183-76bfa141a07b" )]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
@@ -32,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.1.3.0")]
|
||||
[assembly: AssemblyFileVersion("0.1.2.0")]
|
||||
[assembly: AssemblyVersion( "0.1.3.0" )]
|
||||
[assembly: AssemblyFileVersion( "0.1.2.0" )]
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
@@ -35,7 +31,7 @@ namespace NSspi
|
||||
protected SSPIException( SerializationInfo info, StreamingContext context )
|
||||
: base( info, context )
|
||||
{
|
||||
this.message = info.GetString("message");
|
||||
this.message = info.GetString( "message" );
|
||||
this.errorCode = (SecurityStatus)info.GetUInt32( "errorCode" );
|
||||
}
|
||||
|
||||
@@ -74,7 +70,7 @@ namespace NSspi
|
||||
"{0}. Error Code = '0x{1:X}' - \"{2}\".",
|
||||
this.message,
|
||||
this.errorCode,
|
||||
EnumMgr.ToText(this.errorCode)
|
||||
EnumMgr.ToText( this.errorCode )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
@@ -55,47 +51,47 @@ namespace NSspi
|
||||
/// <summary>
|
||||
/// Whether the package supports generating messages with integrity information. Required for MakeSignature and VerifySignature.
|
||||
/// </summary>
|
||||
Integrity = 0x1,
|
||||
Integrity = 0x1,
|
||||
|
||||
/// <summary>
|
||||
/// Whether the package supports generating encrypted messages. Required for EncryptMessage and DecryptMessage.
|
||||
/// </summary>
|
||||
Privacy = 0x2,
|
||||
Privacy = 0x2,
|
||||
|
||||
/// <summary>
|
||||
/// Whether the package uses any other buffer information than token buffers.
|
||||
/// </summary>
|
||||
TokenOnly = 0x4,
|
||||
TokenOnly = 0x4,
|
||||
|
||||
/// <summary>
|
||||
/// Whether the package supports datagram-style authentication.
|
||||
/// </summary>
|
||||
Datagram = 0x8,
|
||||
Datagram = 0x8,
|
||||
|
||||
/// <summary>
|
||||
/// Whether the package supports creating contexts with connection semantics
|
||||
/// </summary>
|
||||
Connection = 0x10,
|
||||
Connection = 0x10,
|
||||
|
||||
/// <summary>
|
||||
/// Multiple legs are neccessary for authentication.
|
||||
/// </summary>
|
||||
MultiLeg = 0x20,
|
||||
MultiLeg = 0x20,
|
||||
|
||||
/// <summary>
|
||||
/// Server authentication is not supported.
|
||||
/// </summary>
|
||||
ClientOnly = 0x40,
|
||||
ClientOnly = 0x40,
|
||||
|
||||
/// <summary>
|
||||
/// Supports extended error handling facilities.
|
||||
/// </summary>
|
||||
ExtendedError = 0x80,
|
||||
ExtendedError = 0x80,
|
||||
|
||||
/// <summary>
|
||||
/// Supports client impersonation on the server.
|
||||
/// </summary>
|
||||
Impersonation = 0x100,
|
||||
Impersonation = 0x100,
|
||||
|
||||
/// <summary>
|
||||
/// Understands Windows princple and target names.
|
||||
@@ -105,42 +101,42 @@ namespace NSspi
|
||||
/// <summary>
|
||||
/// Supports stream semantics
|
||||
/// </summary>
|
||||
Stream = 0x400,
|
||||
Stream = 0x400,
|
||||
|
||||
/// <summary>
|
||||
/// Package may be used by the Negiotiate meta-package.
|
||||
/// </summary>
|
||||
Negotiable = 0x800,
|
||||
Negotiable = 0x800,
|
||||
|
||||
/// <summary>
|
||||
/// Compatible with GSS.
|
||||
/// </summary>
|
||||
GssCompatible = 0x1000,
|
||||
GssCompatible = 0x1000,
|
||||
|
||||
/// <summary>
|
||||
/// Supports LsaLogonUser
|
||||
/// </summary>
|
||||
Logon = 0x2000,
|
||||
Logon = 0x2000,
|
||||
|
||||
/// <summary>
|
||||
/// Token buffers are in Ascii format.
|
||||
/// </summary>
|
||||
AsciiBuffers = 0x4000,
|
||||
AsciiBuffers = 0x4000,
|
||||
|
||||
/// <summary>
|
||||
/// Supports separating large tokens into multiple buffers.
|
||||
/// </summary>
|
||||
Fragment = 0x8000,
|
||||
Fragment = 0x8000,
|
||||
|
||||
/// <summary>
|
||||
/// Supports mutual authentication between a client and server.
|
||||
/// </summary>
|
||||
MutualAuth = 0x10000,
|
||||
MutualAuth = 0x10000,
|
||||
|
||||
/// <summary>
|
||||
/// Supports credential delegation from the server to a third context.
|
||||
/// </summary>
|
||||
Delegation = 0x20000,
|
||||
Delegation = 0x20000,
|
||||
|
||||
/// <summary>
|
||||
/// Supports calling EncryptMessage with the read-only-checksum flag, which protects data only
|
||||
@@ -157,11 +153,11 @@ namespace NSspi
|
||||
/// <summary>
|
||||
/// Extends the negotiate package; only one such package may be registered at any time.
|
||||
/// </summary>
|
||||
ExtendsNego = 0x00100000,
|
||||
ExtendsNego = 0x00100000,
|
||||
|
||||
/// <summary>
|
||||
/// This package is negotiated by the package of type ExtendsNego.
|
||||
/// </summary>
|
||||
Negotiable2 = 0x00200000,
|
||||
Negotiable2 = 0x00200000,
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
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
|
||||
{
|
||||
@@ -120,7 +117,7 @@ namespace NSspi.Buffers
|
||||
this.bufferHandles = new GCHandle[this.buffers.Count];
|
||||
this.bufferCarrier = new SecureBufferInternal[this.buffers.Count];
|
||||
|
||||
for ( int i = 0; i < this.buffers.Count; i++ )
|
||||
for( int i = 0; i < this.buffers.Count; i++ )
|
||||
{
|
||||
this.bufferHandles[i] = GCHandle.Alloc( this.buffers[i].Buffer, GCHandleType.Pinned );
|
||||
|
||||
@@ -156,7 +153,7 @@ namespace NSspi.Buffers
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( this.disposed )
|
||||
if( this.disposed )
|
||||
{
|
||||
throw new ObjectDisposedException( "Cannot use SecureBufferListHandle after it has been disposed" );
|
||||
}
|
||||
@@ -184,9 +181,9 @@ namespace NSspi.Buffers
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
private void Dispose( bool disposing )
|
||||
{
|
||||
if ( this.disposed == true ) { return; }
|
||||
if( this.disposed == true ) { return; }
|
||||
|
||||
if ( disposing )
|
||||
if( disposing )
|
||||
{
|
||||
// When this class is actually being used for its original purpose - to convey buffers
|
||||
// back and forth to SSPI calls - we need to copy the potentially modified structure members
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
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
|
||||
{
|
||||
@@ -12,7 +7,7 @@ namespace NSspi.Buffers
|
||||
/// Represents the native layout of the secure buffer descriptor that is provided directly
|
||||
/// to native API calls.
|
||||
/// </summary>
|
||||
[StructLayout( LayoutKind.Sequential)]
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
internal struct SecureBufferDescInternal
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Buffers
|
||||
{
|
||||
@@ -57,7 +53,7 @@ namespace NSspi.Buffers
|
||||
Stream = 0x0A,
|
||||
ChannelBindings = 0x0E,
|
||||
TargetHost = 0x10,
|
||||
ReadOnlyFlag = unchecked( (int)0x80000000 ),
|
||||
ReadOnlyFlag = unchecked((int)0x80000000),
|
||||
ReadOnlyWithChecksum = 0x10000000
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
@@ -31,7 +27,7 @@ namespace NSspi
|
||||
/// The request completed successfully
|
||||
/// </summary>
|
||||
[EnumString( "No error" )]
|
||||
OK = 0x00000000,
|
||||
OK = 0x00000000,
|
||||
|
||||
/// <summary>
|
||||
/// The token returned by the context needs to be provided to the cooperating party
|
||||
@@ -45,7 +41,7 @@ namespace NSspi
|
||||
/// must call CompleteAuthToken.
|
||||
/// </summary>
|
||||
[EnumString( "Authentication cycle needs to perform a 'complete'." )]
|
||||
CompleteNeeded = 0x00090313,
|
||||
CompleteNeeded = 0x00090313,
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after a client calls InitializeSecurityContext to indicate that the client
|
||||
@@ -64,66 +60,65 @@ namespace NSspi
|
||||
CredentialsNeeded = 0x00090320,
|
||||
|
||||
[EnumString( "The context data must be re-negotiated with the peer" )]
|
||||
Renegotiate = 0x00090321,
|
||||
Renegotiate = 0x00090321,
|
||||
|
||||
// Errors
|
||||
[EnumString( "Not enough memory.")]
|
||||
OutOfMemory = 0x80090300,
|
||||
[EnumString( "Not enough memory." )]
|
||||
OutOfMemory = 0x80090300,
|
||||
|
||||
[EnumString( "The handle provided to the API was invalid.")]
|
||||
InvalidHandle = 0x80090301,
|
||||
[EnumString( "The handle provided to the API was invalid." )]
|
||||
InvalidHandle = 0x80090301,
|
||||
|
||||
[EnumString( "The attempted operation is not supported")]
|
||||
Unsupported = 0x80090302,
|
||||
[EnumString( "The attempted operation is not supported" )]
|
||||
Unsupported = 0x80090302,
|
||||
|
||||
[EnumString( "The specified principle is not known in the authentication system.")]
|
||||
TargetUnknown = 0x80090303,
|
||||
[EnumString( "The specified principle is not known in the authentication system." )]
|
||||
TargetUnknown = 0x80090303,
|
||||
|
||||
[EnumString( "An internal error occurred" )]
|
||||
InternalError = 0x80090304,
|
||||
InternalError = 0x80090304,
|
||||
|
||||
/// <summary>
|
||||
/// No security provider package was found with the given name.
|
||||
/// </summary>
|
||||
[EnumString( "The requested security package was not found.")]
|
||||
PackageNotFound = 0x80090305,
|
||||
[EnumString( "The requested security package was not found." )]
|
||||
PackageNotFound = 0x80090305,
|
||||
|
||||
NotOwner = 0x80090306,
|
||||
CannotInstall = 0x80090307,
|
||||
NotOwner = 0x80090306,
|
||||
CannotInstall = 0x80090307,
|
||||
|
||||
/// <summary>
|
||||
/// A token was provided that contained incorrect or corrupted data.
|
||||
/// </summary>
|
||||
[EnumString("The provided authentication token is invalid or corrupted.")]
|
||||
InvalidToken = 0x80090308,
|
||||
[EnumString( "The provided authentication token is invalid or corrupted." )]
|
||||
InvalidToken = 0x80090308,
|
||||
|
||||
CannotPack = 0x80090309,
|
||||
QopNotSupported = 0x8009030A,
|
||||
CannotPack = 0x80090309,
|
||||
QopNotSupported = 0x8009030A,
|
||||
|
||||
/// <summary>
|
||||
/// Impersonation is not supported.
|
||||
/// </summary>
|
||||
[EnumString("Impersonation is not supported with the current security package.")]
|
||||
NoImpersonation = 0x8009030B,
|
||||
[EnumString( "Impersonation is not supported with the current security package." )]
|
||||
NoImpersonation = 0x8009030B,
|
||||
|
||||
[EnumString("The logon was denied, perhaps because the provided credentials were incorrect.")]
|
||||
LogonDenied = 0x8009030C,
|
||||
[EnumString( "The logon was denied, perhaps because the provided credentials were incorrect." )]
|
||||
LogonDenied = 0x8009030C,
|
||||
|
||||
[EnumString( "The credentials provided are not recognized by the selected security package." )]
|
||||
UnknownCredentials = 0x8009030D,
|
||||
|
||||
[EnumString( "The credentials provided are not recognized by the selected security package.")]
|
||||
UnknownCredentials = 0x8009030D,
|
||||
|
||||
[EnumString( "No credentials are available in the selected security package.")]
|
||||
NoCredentials = 0x8009030E,
|
||||
[EnumString( "No credentials are available in the selected security package." )]
|
||||
NoCredentials = 0x8009030E,
|
||||
|
||||
[EnumString( "A message that was provided to the Decrypt or VerifySignature functions was altered " +
|
||||
"after it was created.")]
|
||||
MessageAltered = 0x8009030F,
|
||||
"after it was created." )]
|
||||
MessageAltered = 0x8009030F,
|
||||
|
||||
[EnumString( "A message was received out of the expected order.")]
|
||||
OutOfSequence = 0x80090310,
|
||||
[EnumString( "A message was received out of the expected order." )]
|
||||
OutOfSequence = 0x80090310,
|
||||
|
||||
[EnumString( "The current security package cannot contact an authenticating authority.")]
|
||||
[EnumString( "The current security package cannot contact an authenticating authority." )]
|
||||
NoAuthenticatingAuthority = 0x80090311,
|
||||
|
||||
/// <summary>
|
||||
@@ -137,20 +132,21 @@ namespace NSspi
|
||||
/// will indicate success, but will save off the extra, unrelated data in a buffer of
|
||||
/// type 'extra'.
|
||||
/// </remarks>
|
||||
IncompleteMessage = 0x80090318,
|
||||
IncompleteMessage = 0x80090318,
|
||||
|
||||
IncompleteCredentials = 0x80090320,
|
||||
BufferNotEnough = 0x80090321,
|
||||
WrongPrincipal = 0x80090322,
|
||||
TimeSkew = 0x80090324,
|
||||
UntrustedRoot = 0x80090325,
|
||||
IllegalMessage = 0x80090326,
|
||||
CertUnknown = 0x80090327,
|
||||
CertExpired = 0x80090328,
|
||||
AlgorithmMismatch = 0x80090331,
|
||||
SecurityQosFailed = 0x80090332,
|
||||
BufferNotEnough = 0x80090321,
|
||||
WrongPrincipal = 0x80090322,
|
||||
TimeSkew = 0x80090324,
|
||||
UntrustedRoot = 0x80090325,
|
||||
IllegalMessage = 0x80090326,
|
||||
CertUnknown = 0x80090327,
|
||||
CertExpired = 0x80090328,
|
||||
AlgorithmMismatch = 0x80090331,
|
||||
SecurityQosFailed = 0x80090332,
|
||||
SmartcardLogonRequired = 0x8009033E,
|
||||
UnsupportedPreauth = 0x80090343,
|
||||
BadBinding = 0x80090346
|
||||
UnsupportedPreauth = 0x80090343,
|
||||
BadBinding = 0x80090346
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,5 +164,4 @@ namespace NSspi
|
||||
return (uint)status > 0x80000000u;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NSspi.Contexts;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
@@ -25,7 +19,7 @@ namespace NSspi
|
||||
/// to this handle for performing work (InitializeSecurityContext, eg) should be performed a CER
|
||||
/// that employs handle reference counting across the native API invocation.
|
||||
/// </remarks>
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 ) ]
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
internal struct RawSspiHandle
|
||||
{
|
||||
private IntPtr lowPart;
|
||||
@@ -46,7 +40,7 @@ namespace NSspi
|
||||
/// <remarks>
|
||||
/// This method is executed in a CER during handle release.
|
||||
/// </remarks>
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
public void SetInvalid()
|
||||
{
|
||||
this.lowPart = IntPtr.Zero;
|
||||
@@ -69,7 +63,7 @@ namespace NSspi
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get { return IsClosed || this.rawHandle.IsZero(); }
|
||||
get { return IsClosed || this.rawHandle.IsZero(); }
|
||||
}
|
||||
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
@@ -29,13 +25,13 @@ namespace NSspi
|
||||
/// <returns></returns>
|
||||
public DateTime ToDateTime()
|
||||
{
|
||||
ulong test = (ulong)this.time + (ulong)(Epoch.Ticks);
|
||||
ulong test = (ulong)this.time + (ulong)( Epoch.Ticks );
|
||||
|
||||
// Sometimes the value returned is massive, eg, 0x7fffff154e84ffff, which is a value
|
||||
// somewhere in the year 30848. This would overflow DateTime, since it peaks at 31-Dec-9999.
|
||||
// It turns out that this value corresponds to a TimeStamp's maximum value, reduced by my local timezone
|
||||
// http://stackoverflow.com/questions/24478056/
|
||||
if ( test > (ulong)DateTime.MaxValue.Ticks )
|
||||
if( test > (ulong)DateTime.MaxValue.Ticks )
|
||||
{
|
||||
return DateTime.MaxValue;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
||||
</startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -47,7 +47,6 @@ namespace NSspi
|
||||
ContextAttrib.Delegate
|
||||
);
|
||||
|
||||
|
||||
server = new ServerContext(
|
||||
serverCred,
|
||||
ContextAttrib.MutualAuth |
|
||||
@@ -64,18 +63,17 @@ namespace NSspi
|
||||
|
||||
clientStatus = client.Init( serverToken, out clientToken );
|
||||
|
||||
while ( true )
|
||||
while( true )
|
||||
{
|
||||
serverStatus = server.AcceptToken( clientToken, out serverToken );
|
||||
|
||||
if ( serverStatus != SecurityStatus.ContinueNeeded && clientStatus != SecurityStatus.ContinueNeeded ) { break; }
|
||||
if( serverStatus != SecurityStatus.ContinueNeeded && clientStatus != SecurityStatus.ContinueNeeded ) { break; }
|
||||
|
||||
clientStatus = client.Init( serverToken, out clientToken );
|
||||
|
||||
if ( serverStatus != SecurityStatus.ContinueNeeded && clientStatus != SecurityStatus.ContinueNeeded ) { break; }
|
||||
if( serverStatus != SecurityStatus.ContinueNeeded && clientStatus != SecurityStatus.ContinueNeeded ) { break; }
|
||||
}
|
||||
|
||||
|
||||
Console.Out.WriteLine( "Server authority: " + server.AuthorityName );
|
||||
Console.Out.WriteLine( "Server context user: " + server.ContextUserName );
|
||||
|
||||
@@ -102,7 +100,7 @@ namespace NSspi
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
for( int i= 0; i < plainText.Length; i++ )
|
||||
for( int i = 0; i < plainText.Length; i++ )
|
||||
{
|
||||
if( plainText[i] != roundTripPlaintext[i] )
|
||||
{
|
||||
@@ -117,25 +115,23 @@ namespace NSspi
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
|
||||
using( server.ImpersonateClient() )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cipherText = client.MakeSignature( plainText );
|
||||
|
||||
bool goodSig = server.VerifySignature( cipherText, out roundTripPlaintext );
|
||||
|
||||
if ( goodSig == false ||
|
||||
if( goodSig == false ||
|
||||
roundTripPlaintext.Length != plainText.Length )
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
for ( int i = 0; i < plainText.Length; i++ )
|
||||
for( int i = 0; i < plainText.Length; i++ )
|
||||
{
|
||||
if ( plainText[i] != roundTripPlaintext[i] )
|
||||
if( plainText[i] != roundTripPlaintext[i] )
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
@@ -145,12 +141,12 @@ namespace NSspi
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( server != null )
|
||||
if( server != null )
|
||||
{
|
||||
server.Dispose();
|
||||
}
|
||||
|
||||
if ( client != null )
|
||||
if( client != null )
|
||||
{
|
||||
client.Dispose();
|
||||
}
|
||||
@@ -160,7 +156,7 @@ namespace NSspi
|
||||
clientCred.Dispose();
|
||||
}
|
||||
|
||||
if ( serverCred != null )
|
||||
if( serverCred != null )
|
||||
{
|
||||
serverCred.Dispose();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
||||
</startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -1,12 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using NSspi;
|
||||
using NSspi.Contexts;
|
||||
@@ -107,7 +101,6 @@ namespace TestClient
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +109,6 @@ namespace TestClient
|
||||
this.connection.Stop();
|
||||
}
|
||||
|
||||
|
||||
private void encryptButton_Click( object sender, EventArgs e )
|
||||
{
|
||||
byte[] plaintext;
|
||||
@@ -149,7 +141,7 @@ namespace TestClient
|
||||
|
||||
private void connection_Received( Message message )
|
||||
{
|
||||
this.Invoke( (Action)delegate()
|
||||
this.Invoke( (Action)delegate ()
|
||||
{
|
||||
if( message.Operation == ProtocolOp.ServerToken )
|
||||
{
|
||||
@@ -180,7 +172,7 @@ namespace TestClient
|
||||
this.initializing = false;
|
||||
this.lastServerToken = null;
|
||||
|
||||
this.BeginInvoke( (Action)delegate()
|
||||
this.BeginInvoke( (Action)delegate ()
|
||||
{
|
||||
this.context.Dispose();
|
||||
this.context = new ClientContext(
|
||||
@@ -195,7 +187,7 @@ namespace TestClient
|
||||
);
|
||||
|
||||
UpdateButtons();
|
||||
});
|
||||
} );
|
||||
}
|
||||
|
||||
private void DoInit()
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TestClient
|
||||
{
|
||||
static class Program
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
private static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault( false );
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
||||
</startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using NSspi;
|
||||
|
||||
@@ -33,7 +29,7 @@ namespace TestProtocol
|
||||
{
|
||||
if( this.running )
|
||||
{
|
||||
throw new InvalidOperationException("Already running");
|
||||
throw new InvalidOperationException( "Already running" );
|
||||
}
|
||||
|
||||
this.socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
|
||||
@@ -65,7 +61,7 @@ namespace TestProtocol
|
||||
throw new InvalidOperationException( "Not connected" );
|
||||
}
|
||||
|
||||
byte[] outBuffer = new byte[ message.Data.Length + 8 ];
|
||||
byte[] outBuffer = new byte[message.Data.Length + 8];
|
||||
int position = 0;
|
||||
|
||||
ByteWriter.WriteInt32_BE( (int)message.Operation, outBuffer, position );
|
||||
@@ -124,7 +120,6 @@ namespace TestProtocol
|
||||
// |--4 bytes--|--4 bytes--|---N--|
|
||||
// Every command is a TLV - | Operation | Length | Data |
|
||||
|
||||
|
||||
// Read the operation.
|
||||
this.socket.Receive( readBuffer, 4, SocketFlags.None );
|
||||
|
||||
@@ -153,7 +148,6 @@ namespace TestProtocol
|
||||
remaining -= chunkLength;
|
||||
position += chunkLength;
|
||||
}
|
||||
|
||||
}
|
||||
catch( SocketException e )
|
||||
{
|
||||
@@ -187,7 +181,6 @@ namespace TestProtocol
|
||||
catch( Exception e )
|
||||
{ }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,6 @@ namespace TestProtocol
|
||||
catch( Exception )
|
||||
{ }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try
|
||||
@@ -225,5 +224,4 @@ namespace TestProtocol
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestProtocol
|
||||
{
|
||||
public class Message
|
||||
{
|
||||
public Message(ProtocolOp op, byte[] data)
|
||||
public Message( ProtocolOp op, byte[] data )
|
||||
{
|
||||
this.Operation = op;
|
||||
this.Data = data;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestProtocol
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
||||
</startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -1,18 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TestServer
|
||||
{
|
||||
static class Program
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
private static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault( false );
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TestProtocol;
|
||||
|
||||
@@ -129,7 +123,7 @@ namespace TestServer
|
||||
{
|
||||
MessageBox.Show( "Starting impersonation: " + Environment.UserName );
|
||||
|
||||
FileStream stream = File.Create( Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory) + @"\test.txt" );
|
||||
FileStream stream = File.Create( Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory ) + @"\test.txt" );
|
||||
StreamWriter writer = new StreamWriter( stream, Encoding.UTF8 );
|
||||
|
||||
writer.WriteLine( "Hello world." );
|
||||
@@ -150,7 +144,6 @@ namespace TestServer
|
||||
this.signButton.Enabled = this.connected;
|
||||
}
|
||||
|
||||
|
||||
private void server_Received( Message message )
|
||||
{
|
||||
if( message.Operation == ProtocolOp.ClientToken )
|
||||
@@ -177,7 +170,6 @@ namespace TestServer
|
||||
this.initializing = true;
|
||||
this.connected = false;
|
||||
|
||||
|
||||
this.serverContext.Dispose();
|
||||
this.serverContext = new ServerContext(
|
||||
serverCred,
|
||||
@@ -189,14 +181,13 @@ namespace TestServer
|
||||
ContextAttrib.Confidentiality
|
||||
);
|
||||
|
||||
this.BeginInvoke( (Action)delegate()
|
||||
this.BeginInvoke( (Action)delegate ()
|
||||
{
|
||||
UpdateButtons();
|
||||
this.clientUsernameTextBox.Text = "";
|
||||
});
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
private void HandleInit( Message message )
|
||||
{
|
||||
byte[] nextToken;
|
||||
@@ -218,7 +209,7 @@ namespace TestServer
|
||||
this.initializing = false;
|
||||
this.connected = true;
|
||||
|
||||
this.Invoke( (Action)delegate()
|
||||
this.Invoke( (Action)delegate ()
|
||||
{
|
||||
UpdateButtons();
|
||||
this.clientUsernameTextBox.Text = serverContext.ContextUserName;
|
||||
@@ -227,18 +218,17 @@ namespace TestServer
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Invoke( (Action)delegate()
|
||||
this.Invoke( (Action)delegate ()
|
||||
{
|
||||
MessageBox.Show( "Failed to accept token from client. Sspi error code: " + status );
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEncrypted( Message message )
|
||||
{
|
||||
this.Invoke( (Action)delegate()
|
||||
this.Invoke( (Action)delegate ()
|
||||
{
|
||||
byte[] plainText = this.serverContext.Decrypt( message.Data );
|
||||
string text = Encoding.UTF8.GetString( plainText );
|
||||
@@ -249,7 +239,7 @@ namespace TestServer
|
||||
|
||||
private void HandleSigned( Message message )
|
||||
{
|
||||
this.Invoke( (Action)delegate()
|
||||
this.Invoke( (Action)delegate ()
|
||||
{
|
||||
byte[] plainText;
|
||||
|
||||
@@ -268,11 +258,10 @@ namespace TestServer
|
||||
|
||||
private void HandleUnknown( Message message )
|
||||
{
|
||||
this.Invoke( (Action)delegate()
|
||||
this.Invoke( (Action)delegate ()
|
||||
{
|
||||
MessageBox.Show( "Received unexpected message from server. Message type: " + message.Operation );
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user