Modified the initialization process a little to better control when a context is marked as initialized.
This commit is contained in:
@@ -114,15 +114,11 @@ namespace NSspi.Contexts
|
||||
|
||||
if ( status == SecurityStatus.OK )
|
||||
{
|
||||
this.Initialized = true;
|
||||
base.Initialize( rawExpiry.ToDateTime() );
|
||||
outToken = null;
|
||||
|
||||
this.Expiry = rawExpiry.ToDateTime();
|
||||
}
|
||||
else if ( status == SecurityStatus.ContinueNeeded )
|
||||
{
|
||||
this.Initialized = false;
|
||||
|
||||
outToken = new byte[outTokenBuffer.Length];
|
||||
Array.Copy( outTokenBuffer.Buffer, outToken, outToken.Length );
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace NSspi.Contexts
|
||||
/// <summary>
|
||||
/// Whether or not the context is fully formed.
|
||||
/// </summary>
|
||||
public bool Initialized { get; protected set; }
|
||||
public bool Initialized { get; private set; }
|
||||
|
||||
protected Credential Credential { get; private set; }
|
||||
|
||||
public SafeContextHandle ContextHandle { get; protected set; }
|
||||
public SafeContextHandle ContextHandle { get; private set; }
|
||||
|
||||
public string AuthorityName
|
||||
{
|
||||
@@ -48,10 +48,20 @@ namespace NSspi.Contexts
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime Expiry { get; protected set; }
|
||||
public DateTime Expiry { get; private set; }
|
||||
|
||||
public bool Disposed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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 )
|
||||
{
|
||||
this.Expiry = expiry;
|
||||
this.Initialized = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose( true );
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace NSspi.Contexts
|
||||
|
||||
public SecurityStatus AcceptToken( byte[] clientToken, out byte[] nextToken )
|
||||
{
|
||||
SecureBuffer clientBuffer = new SecureBuffer( clientToken, BufferType.Token );
|
||||
SecureBuffer outBuffer = new SecureBuffer( new byte[12288], BufferType.Token );
|
||||
SecureBuffer clientBuffer;
|
||||
SecureBuffer outBuffer;
|
||||
|
||||
SecurityStatus status;
|
||||
TimeStamp rawExpiry = new TimeStamp();
|
||||
@@ -49,6 +49,15 @@ namespace NSspi.Contexts
|
||||
{
|
||||
throw new ObjectDisposedException( "ServerContext" );
|
||||
}
|
||||
else if( this.Initialized )
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Attempted to continue initialization of a ServerContext after initialization had completed."
|
||||
);
|
||||
}
|
||||
|
||||
clientBuffer = new SecureBuffer( clientToken, BufferType.Token );
|
||||
outBuffer = new SecureBuffer( new byte[12288], BufferType.Token );
|
||||
|
||||
using ( clientAdapter = new SecureBufferAdapter( clientBuffer ) )
|
||||
{
|
||||
@@ -90,7 +99,8 @@ namespace NSspi.Contexts
|
||||
if ( status == SecurityStatus.OK )
|
||||
{
|
||||
nextToken = null;
|
||||
this.Initialized = true;
|
||||
|
||||
base.Initialize( rawExpiry.ToDateTime() );
|
||||
|
||||
if ( outBuffer.Length != 0 )
|
||||
{
|
||||
@@ -101,13 +111,9 @@ namespace NSspi.Contexts
|
||||
{
|
||||
nextToken = null;
|
||||
}
|
||||
|
||||
this.Expiry = rawExpiry.ToDateTime();
|
||||
}
|
||||
else if ( status == SecurityStatus.ContinueNeeded )
|
||||
{
|
||||
this.Initialized = false;
|
||||
|
||||
nextToken = new byte[outBuffer.Length];
|
||||
Array.Copy( outBuffer.Buffer, nextToken, nextToken.Length );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user