Reworked the Expiry support to expose it in the first place, and to store and present it as a DateTime object.

This commit is contained in:
antiduh
2014-06-29 14:24:58 +00:00
parent bc97ef64ae
commit 5272979f19
6 changed files with 46 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ namespace NSspi.Contexts
public SecurityStatus Init( byte[] serverToken, out byte[] outToken ) public SecurityStatus Init( byte[] serverToken, out byte[] outToken )
{ {
long expiry = 0; long rawExpiry = 0;
SecurityStatus status; SecurityStatus status;
@@ -82,7 +82,7 @@ namespace NSspi.Contexts
ref this.ContextHandle.rawHandle, ref this.ContextHandle.rawHandle,
outAdapter.Handle, outAdapter.Handle,
ref this.finalAttribs, ref this.finalAttribs,
ref expiry ref rawExpiry
); );
} }
else else
@@ -101,7 +101,7 @@ namespace NSspi.Contexts
ref this.ContextHandle.rawHandle, ref this.ContextHandle.rawHandle,
outAdapter.Handle, outAdapter.Handle,
ref this.finalAttribs, ref this.finalAttribs,
ref expiry ref rawExpiry
); );
} }
} }
@@ -111,6 +111,8 @@ namespace NSspi.Contexts
{ {
this.Initialized = true; this.Initialized = true;
outToken = null; outToken = null;
this.Expiry = TimeStamp.Calc( rawExpiry );
} }
else if ( status == SecurityStatus.ContinueNeeded ) else if ( status == SecurityStatus.ContinueNeeded )
{ {

View File

@@ -53,6 +53,8 @@ namespace NSspi.Contexts
} }
} }
public DateTime Expiry { get; protected set; }
public bool Disposed { get; private set; } public bool Disposed { get; private set; }
public void Dispose() public void Dispose()

View File

@@ -30,7 +30,7 @@ namespace NSspi.Contexts
SecureBuffer outBuffer = new SecureBuffer( new byte[12288], BufferType.Token ); SecureBuffer outBuffer = new SecureBuffer( new byte[12288], BufferType.Token );
SecurityStatus status; SecurityStatus status;
long expiry = 0; long rawExpiry = 0;
SecureBufferAdapter clientAdapter; SecureBufferAdapter clientAdapter;
SecureBufferAdapter outAdapter; SecureBufferAdapter outAdapter;
@@ -50,7 +50,7 @@ namespace NSspi.Contexts
ref this.ContextHandle.rawHandle, ref this.ContextHandle.rawHandle,
outAdapter.Handle, outAdapter.Handle,
ref this.finalAttribs, ref this.finalAttribs,
ref expiry ref rawExpiry
); );
} }
else else
@@ -64,7 +64,7 @@ namespace NSspi.Contexts
ref this.ContextHandle.rawHandle, ref this.ContextHandle.rawHandle,
outAdapter.Handle, outAdapter.Handle,
ref this.finalAttribs, ref this.finalAttribs,
ref expiry ref rawExpiry
); );
@@ -87,6 +87,8 @@ namespace NSspi.Contexts
nextToken = null; nextToken = null;
} }
this.Expiry = TimeStamp.Calc( rawExpiry );
InitProviderCapabilities(); InitProviderCapabilities();
} }
else if ( status == SecurityStatus.ContinueNeeded ) else if ( status == SecurityStatus.ContinueNeeded )

View File

@@ -19,14 +19,15 @@ namespace NSspi.Credentials
private SecurityPackage securityPackage; private SecurityPackage securityPackage;
private SafeCredentialHandle safeCredHandle; private SafeCredentialHandle safeCredHandle;
private long expiry;
private DateTime expiry;
public Credential(SecurityPackage package, CredentialType credentialType) public Credential(SecurityPackage package, CredentialType credentialType)
{ {
this.disposed = false; this.disposed = false;
this.securityPackage = package; this.securityPackage = package;
this.expiry = 0; this.expiry = DateTime.MinValue;
Init( package, credentialType ); Init( package, credentialType );
} }
@@ -35,6 +36,7 @@ namespace NSspi.Credentials
{ {
string packageName; string packageName;
CredentialUse use; CredentialUse use;
long rawExpiry = 0;
// -- Package -- // -- Package --
if ( package == SecurityPackage.Kerberos ) if ( package == SecurityPackage.Kerberos )
@@ -90,7 +92,7 @@ namespace NSspi.Credentials
IntPtr.Zero, IntPtr.Zero,
IntPtr.Zero, IntPtr.Zero,
ref this.safeCredHandle.rawHandle, ref this.safeCredHandle.rawHandle,
ref this.expiry ref rawExpiry
); );
} }
@@ -98,6 +100,8 @@ namespace NSspi.Credentials
{ {
throw new SSPIException( "Failed to call AcquireCredentialHandle", status ); throw new SSPIException( "Failed to call AcquireCredentialHandle", status );
} }
this.expiry = TimeStamp.Calc( rawExpiry );
} }
~Credential() ~Credential()
@@ -177,6 +181,14 @@ namespace NSspi.Credentials
} }
} }
public DateTime Expiry
{
get
{
return this.expiry;
}
}
public SafeCredentialHandle Handle public SafeCredentialHandle Handle
{ {
get get
@@ -203,6 +215,5 @@ namespace NSspi.Credentials
this.disposed = true; this.disposed = true;
} }
} }
} }
} }

View File

@@ -80,6 +80,7 @@
<Compile Include="SecurityStatus.cs" /> <Compile Include="SecurityStatus.cs" />
<Compile Include="SSPIException.cs" /> <Compile Include="SSPIException.cs" />
<Compile Include="SspiHandle.cs" /> <Compile Include="SspiHandle.cs" />
<Compile Include="TimeStamp.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

18
NSspi/TimeStamp.cs Normal file
View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NSspi
{
public static class TimeStamp
{
public static readonly DateTime Epoch = new DateTime( 1601, 1, 1, 0, 0, 0, DateTimeKind.Utc );
public static DateTime Calc( long rawExpiry )
{
return TimeStamp.Epoch.AddTicks( rawExpiry );
}
}
}