From cfba81cfe2e5fa677aabaab7c714eb175dbbda6a Mon Sep 17 00:00:00 2001 From: antiduh Date: Thu, 19 Jun 2014 21:53:34 +0000 Subject: [PATCH] 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. --- Contexts/ClientContext.cs | 43 ++++++++++++++++++++++++++++++++ Contexts/Context.cs | 52 +++++++++++++++++++++++++++++++++++++++ Contexts/ContextAttrib.cs | 21 ++++++++++++++++ Contexts/ServerContext.cs | 12 +++++++++ NSspi.csproj | 4 +++ 5 files changed, 132 insertions(+) create mode 100644 Contexts/ClientContext.cs create mode 100644 Contexts/Context.cs create mode 100644 Contexts/ContextAttrib.cs create mode 100644 Contexts/ServerContext.cs diff --git a/Contexts/ClientContext.cs b/Contexts/ClientContext.cs new file mode 100644 index 0000000..209280a --- /dev/null +++ b/Contexts/ClientContext.cs @@ -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 + ); + + + } + } +} diff --git a/Contexts/Context.cs b/Contexts/Context.cs new file mode 100644 index 0000000..cac0346 --- /dev/null +++ b/Contexts/Context.cs @@ -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; + } + } +} diff --git a/Contexts/ContextAttrib.cs b/Contexts/ContextAttrib.cs new file mode 100644 index 0000000..de04053 --- /dev/null +++ b/Contexts/ContextAttrib.cs @@ -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 + { + } +} diff --git a/Contexts/ServerContext.cs b/Contexts/ServerContext.cs new file mode 100644 index 0000000..553b137 --- /dev/null +++ b/Contexts/ServerContext.cs @@ -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 + { + } +} diff --git a/NSspi.csproj b/NSspi.csproj index 64b7366..e9ebffb 100644 --- a/NSspi.csproj +++ b/NSspi.csproj @@ -44,6 +44,10 @@ + + + +