Working on some of the fundamentals of the Context side of things. The Win 32 API is very wonky here though. Going to take some time.
This commit is contained in:
43
Contexts/ClientContext.cs
Normal file
43
Contexts/ClientContext.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
public class ClientContext : Context
|
||||
{
|
||||
public ClientContext( ClientCredential cred, string serverPrinc, ContextReqAttrib attribs )
|
||||
: base( cred )
|
||||
{
|
||||
long credHandle = base.Credential.CredentialHandle;
|
||||
|
||||
long prevContextHandle = 0;
|
||||
long newContextHandle = 0;
|
||||
|
||||
long expiry = 0;
|
||||
int newContextAttribs = 0;
|
||||
|
||||
SecurityStatus status;
|
||||
|
||||
|
||||
status = NativeMethods.InitializeSecurityContext_Client(
|
||||
ref credHandle,
|
||||
ref prevContextHandle,
|
||||
serverPrinc,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
IntPtr.Zero,
|
||||
0,
|
||||
ref newContextHandle,
|
||||
IntPtr.Zero,
|
||||
ref newContextAttribs,
|
||||
ref expiry
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Contexts/Context.cs
Normal file
52
Contexts/Context.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
public class Context : IDisposable
|
||||
{
|
||||
private bool disposed;
|
||||
|
||||
public Context( Credential cred )
|
||||
{
|
||||
this.Credential = cred;
|
||||
|
||||
this.disposed = false;
|
||||
}
|
||||
|
||||
~Context()
|
||||
{
|
||||
Dispose( false );
|
||||
}
|
||||
|
||||
protected Credential Credential { get; private set; }
|
||||
|
||||
public long ContextHandle { get; protected set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose( true );
|
||||
GC.SuppressFinalize( this );
|
||||
}
|
||||
|
||||
protected virtual void Dispose( bool disposing )
|
||||
{
|
||||
if( this.disposed ) { return; }
|
||||
|
||||
if( disposing )
|
||||
{
|
||||
this.Credential.Dispose();
|
||||
}
|
||||
|
||||
long contextHandleCopy = this.ContextHandle;
|
||||
NativeMethods.DeleteSecurityContext( ref contextHandleCopy );
|
||||
|
||||
this.ContextHandle = 0;
|
||||
|
||||
this.disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Contexts/ContextAttrib.cs
Normal file
21
Contexts/ContextAttrib.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
[Flags]
|
||||
public enum ContextReqAttrib : int
|
||||
{
|
||||
None = 0,
|
||||
Delegate = 1,
|
||||
Identify = 2,
|
||||
MutualAuth = 4,
|
||||
}
|
||||
|
||||
public enum ContextResultAttrib : int
|
||||
{
|
||||
}
|
||||
}
|
||||
12
Contexts/ServerContext.cs
Normal file
12
Contexts/ServerContext.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Contexts
|
||||
{
|
||||
class ServerContext
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,10 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Contexts\ClientContext.cs" />
|
||||
<Compile Include="Contexts\Context.cs" />
|
||||
<Compile Include="Contexts\ContextAttrib.cs" />
|
||||
<Compile Include="Contexts\ServerContext.cs" />
|
||||
<Compile Include="Credentials\ClientCredential.cs" />
|
||||
<Compile Include="Credentials\Credential.cs" />
|
||||
<Compile Include="Credentials\CredentialPackage.cs" />
|
||||
|
||||
Reference in New Issue
Block a user