I can now successfully call InitializeSecurityContext and get a status of ContinueNeeded.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -8,7 +9,7 @@ namespace NSspi.Contexts
|
||||
{
|
||||
public class ClientContext : Context
|
||||
{
|
||||
public ClientContext( ClientCredential cred, string serverPrinc, ContextReqAttrib attribs )
|
||||
public ClientContext( ClientCredential cred, string serverPrinc, ContextAttrib attribs )
|
||||
: base( cred )
|
||||
{
|
||||
long credHandle = base.Credential.CredentialHandle;
|
||||
@@ -17,26 +18,58 @@ namespace NSspi.Contexts
|
||||
long newContextHandle = 0;
|
||||
|
||||
long expiry = 0;
|
||||
int newContextAttribs = 0;
|
||||
ContextAttrib newContextAttribs = 0;
|
||||
|
||||
SecurityStatus status;
|
||||
SecureBufferDesc descriptor;
|
||||
SecureBuffer secureBuffer;
|
||||
byte[] tokenBuffer = new byte[100000];
|
||||
GCHandle tokenBufferHandle;
|
||||
GCHandle bufferArrayHandle;
|
||||
GCHandle descriptorHandle;
|
||||
SecureBuffer[] bufferArray;
|
||||
|
||||
tokenBufferHandle = GCHandle.Alloc( tokenBuffer, GCHandleType.Pinned );
|
||||
|
||||
secureBuffer = new SecureBuffer();
|
||||
secureBuffer.Type = BufferType.Token;
|
||||
secureBuffer.Count = tokenBuffer.Length;
|
||||
secureBuffer.Buffer = tokenBufferHandle.AddrOfPinnedObject();
|
||||
|
||||
bufferArray = new SecureBuffer[1];
|
||||
bufferArray[0] = secureBuffer;
|
||||
bufferArrayHandle = GCHandle.Alloc( bufferArray, GCHandleType.Pinned );
|
||||
|
||||
|
||||
status = NativeMethods.InitializeSecurityContext_Client(
|
||||
descriptor = new SecureBufferDesc();
|
||||
descriptor.Version = SecureBufferDesc.ApiVersion;
|
||||
descriptor.NumBuffers = bufferArray.Length;
|
||||
descriptor.Buffers = bufferArrayHandle.AddrOfPinnedObject();
|
||||
|
||||
descriptorHandle = GCHandle.Alloc( descriptor, GCHandleType.Pinned );
|
||||
|
||||
status = NativeMethods.InitializeSecurityContext_Client1(
|
||||
ref credHandle,
|
||||
ref prevContextHandle,
|
||||
IntPtr.Zero,
|
||||
serverPrinc,
|
||||
attribs,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
SecureBufferDataRep.Network,
|
||||
IntPtr.Zero,
|
||||
0,
|
||||
ref newContextHandle,
|
||||
IntPtr.Zero,
|
||||
descriptorHandle.AddrOfPinnedObject(),
|
||||
ref newContextAttribs,
|
||||
ref expiry
|
||||
);
|
||||
|
||||
descriptorHandle.Free();
|
||||
bufferArrayHandle.Free();
|
||||
tokenBufferHandle.Free();
|
||||
|
||||
secureBuffer = bufferArray[0];
|
||||
|
||||
Console.Out.WriteLine( status );
|
||||
base.ContextHandle = newContextHandle;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user