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 )
{
long expiry = 0;
long rawExpiry = 0;
SecurityStatus status;
@@ -82,7 +82,7 @@ namespace NSspi.Contexts
ref this.ContextHandle.rawHandle,
outAdapter.Handle,
ref this.finalAttribs,
ref expiry
ref rawExpiry
);
}
else
@@ -101,7 +101,7 @@ namespace NSspi.Contexts
ref this.ContextHandle.rawHandle,
outAdapter.Handle,
ref this.finalAttribs,
ref expiry
ref rawExpiry
);
}
}
@@ -111,6 +111,8 @@ namespace NSspi.Contexts
{
this.Initialized = true;
outToken = null;
this.Expiry = TimeStamp.Calc( rawExpiry );
}
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 void Dispose()

View File

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

View File

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

View File

@@ -80,6 +80,7 @@
<Compile Include="SecurityStatus.cs" />
<Compile Include="SSPIException.cs" />
<Compile Include="SspiHandle.cs" />
<Compile Include="TimeStamp.cs" />
</ItemGroup>
<ItemGroup />
<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 );
}
}
}