diff --git a/NSspi/Credentials/ClientCredential.cs b/NSspi/Credentials/ClientCredential.cs
index 0d3ab29..7bdb855 100644
--- a/NSspi/Credentials/ClientCredential.cs
+++ b/NSspi/Credentials/ClientCredential.cs
@@ -7,60 +7,11 @@ using System.Threading.Tasks;
namespace NSspi.Credentials
{
- public class ClientCredential : Credential
+ public class ClientCredential : CurrentCredential
{
public ClientCredential( string package )
- : base( package )
+ : base( package, CredentialUse.Outbound )
{
- Init();
}
-
- private void Init( )
- {
- string packageName;
- CredentialUse use;
- TimeStamp rawExpiry = new TimeStamp();
-
- // -- Package --
- // Copy off for the call, since this.SecurityPackage is a property.
- packageName = this.SecurityPackage;
-
- // -- Credential --
- // Client uses outbound credentials.
- use = CredentialUse.Outbound;
-
- // -- Invoke --
- SecurityStatus status = SecurityStatus.InternalError;
-
- this.Handle = new SafeCredentialHandle();
-
- // The finally clause is the actual constrained region. The VM pre-allocates any stack space,
- // performs any allocations it needs to prepare methods for execution, and postpones any
- // instances of the 'uncatchable' exceptions (ThreadAbort, StackOverflow, OutOfMemory).
- RuntimeHelpers.PrepareConstrainedRegions();
- try { }
- finally
- {
- status = CredentialNativeMethods.AcquireCredentialsHandle(
- null,
- packageName,
- use,
- IntPtr.Zero,
- IntPtr.Zero,
- IntPtr.Zero,
- IntPtr.Zero,
- ref this.Handle.rawHandle,
- ref rawExpiry
- );
- }
-
- if( status != SecurityStatus.OK )
- {
- throw new SSPIException( "Failed to call AcquireCredentialHandle", status );
- }
-
- this.Expiry = rawExpiry.ToDateTime();
- }
-
}
}
diff --git a/NSspi/Credentials/CurrentCredential.cs b/NSspi/Credentials/CurrentCredential.cs
new file mode 100644
index 0000000..e951039
--- /dev/null
+++ b/NSspi/Credentials/CurrentCredential.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NSspi.Credentials
+{
+ public class CurrentCredential : Credential
+ {
+ public CurrentCredential( string securityPackage, CredentialUse use ) :
+ base( securityPackage )
+ {
+ Init( use );
+ }
+
+ private void Init( CredentialUse use )
+ {
+ string packageName;
+ TimeStamp rawExpiry = new TimeStamp();
+ SecurityStatus status = SecurityStatus.InternalError;
+
+ // -- Package --
+ // Copy off for the call, since this.SecurityPackage is a property.
+ packageName = this.SecurityPackage;
+
+ this.Handle = new SafeCredentialHandle();
+
+ // The finally clause is the actual constrained region. The VM pre-allocates any stack space,
+ // performs any allocations it needs to prepare methods for execution, and postpones any
+ // instances of the 'uncatchable' exceptions (ThreadAbort, StackOverflow, OutOfMemory).
+ RuntimeHelpers.PrepareConstrainedRegions();
+ try { }
+ finally
+ {
+ status = CredentialNativeMethods.AcquireCredentialsHandle(
+ null,
+ packageName,
+ use,
+ IntPtr.Zero,
+ IntPtr.Zero,
+ IntPtr.Zero,
+ IntPtr.Zero,
+ ref this.Handle.rawHandle,
+ ref rawExpiry
+ );
+ }
+
+ if ( status != SecurityStatus.OK )
+ {
+ throw new SSPIException( "Failed to call AcquireCredentialHandle", status );
+ }
+
+ this.Expiry = rawExpiry.ToDateTime();
+ }
+
+ }
+}
diff --git a/NSspi/Credentials/ServerCredential.cs b/NSspi/Credentials/ServerCredential.cs
index 78aa895..7721ca6 100644
--- a/NSspi/Credentials/ServerCredential.cs
+++ b/NSspi/Credentials/ServerCredential.cs
@@ -7,61 +7,11 @@ using System.Threading.Tasks;
namespace NSspi.Credentials
{
- public class ServerCredential : Credential
+ public class ServerCredential : CurrentCredential
{
public ServerCredential( string package )
- : base( package )
+ : base( package, CredentialUse.Inbound )
{
- Init();
}
-
- private void Init()
- {
- string packageName;
- CredentialUse use;
- TimeStamp rawExpiry = new TimeStamp();
-
- // -- Package --
- // Copy off for the call, since this.SecurityPackage is a property.
- packageName = this.SecurityPackage;
-
- // -- Credential --
- // Server uses Inbound credentials.
- use = CredentialUse.Inbound;
-
- // -- Invoke --
-
- SecurityStatus status = SecurityStatus.InternalError;
-
- this.Handle = new SafeCredentialHandle();
-
- // The finally clause is the actual constrained region. The VM pre-allocates any stack space,
- // performs any allocations it needs to prepare methods for execution, and postpones any
- // instances of the 'uncatchable' exceptions (ThreadAbort, StackOverflow, OutOfMemory).
- RuntimeHelpers.PrepareConstrainedRegions();
- try { }
- finally
- {
- status = CredentialNativeMethods.AcquireCredentialsHandle(
- null,
- packageName,
- use,
- IntPtr.Zero,
- IntPtr.Zero,
- IntPtr.Zero,
- IntPtr.Zero,
- ref this.Handle.rawHandle,
- ref rawExpiry
- );
- }
-
- if( status != SecurityStatus.OK )
- {
- throw new SSPIException( "Failed to call AcquireCredentialHandle", status );
- }
-
- this.Expiry = rawExpiry.ToDateTime();
- }
-
}
}
diff --git a/NSspi/NSspi.csproj b/NSspi/NSspi.csproj
index 2132996..b1e34bc 100644
--- a/NSspi/NSspi.csproj
+++ b/NSspi/NSspi.csproj
@@ -55,6 +55,7 @@
+