Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling CompleteAuthToken when needed #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions NSspi/Contexts/ClientContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,33 @@ ref rawExpiry
);
}
}
}

if( status.IsError() == false )
{
if( status == SecurityStatus.OK )
if (status.IsError() == false)
{
base.Initialize( rawExpiry.ToDateTime() );
}
if (status == SecurityStatus.OK)
{
base.Initialize(rawExpiry.ToDateTime());
}

outToken = null;

outToken = null;
if (outTokenBuffer.Length != 0)
{
outToken = new byte[outTokenBuffer.Length];
Array.Copy(outTokenBuffer.Buffer, outToken, outToken.Length);
}

if( outTokenBuffer.Length != 0 )
if (status == SecurityStatus.CompleteNeeded || status == SecurityStatus.CompAndContinue)
{
ContextNativeMethods.CompleteAuthToken(ref this.ContextHandle.rawHandle, outAdapter.Handle);
status = (status == SecurityStatus.CompleteNeeded) ? SecurityStatus.OK : SecurityStatus.ContinueNeeded;
}
}
else
{
outToken = new byte[outTokenBuffer.Length];
Array.Copy( outTokenBuffer.Buffer, outToken, outToken.Length );
throw new SSPIException("Failed to invoke InitializeSecurityContext for a client", status);
}
}
else
{
throw new SSPIException( "Failed to invoke InitializeSecurityContext for a client", status );
}

return status;
}
Expand Down
4 changes: 4 additions & 0 deletions NSspi/Contexts/ContextNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ ref TimeStamp expiry
[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 = "CompleteAuthToken", CharSet = CharSet.Unicode)]
internal static extern SecurityStatus CompleteAuthToken(ref RawSspiHandle contextHandle, IntPtr buffer);

[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )]
[DllImport( "Secur32.dll", EntryPoint = "EncryptMessage", CharSet = CharSet.Unicode )]
internal static extern SecurityStatus EncryptMessage(
Expand Down