Switch the rest of the API to the new TimeStamp structure. Fix the TimeStamp structure to handle dates that are past the upper limit of DateTime.MaxValue.
This commit is contained in:
@@ -24,7 +24,7 @@ namespace NSspi.Contexts
|
||||
|
||||
public SecurityStatus Init( byte[] serverToken, out byte[] outToken )
|
||||
{
|
||||
long rawExpiry = 0;
|
||||
TimeStamp rawExpiry = new TimeStamp();
|
||||
|
||||
SecurityStatus status;
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace NSspi.Contexts
|
||||
this.Initialized = true;
|
||||
outToken = null;
|
||||
|
||||
this.Expiry = TimeStamp.Calc( rawExpiry );
|
||||
this.Expiry = rawExpiry.ToDateTime();
|
||||
}
|
||||
else if ( status == SecurityStatus.ContinueNeeded )
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace NSspi.Contexts
|
||||
ref RawSspiHandle newContextHandle,
|
||||
IntPtr outputBuffer,
|
||||
ref ContextAttrib outputAttribs,
|
||||
ref long expiry
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace NSspi.Contexts
|
||||
ref RawSspiHandle newContextHandle,
|
||||
IntPtr outputBuffer,
|
||||
ref ContextAttrib outputAttribs,
|
||||
ref long expiry
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace NSspi.Contexts
|
||||
ref RawSspiHandle newContextHandle,
|
||||
IntPtr outputBuffer,
|
||||
ref ContextAttrib contextAttribs,
|
||||
ref long expiry
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace NSspi.Contexts
|
||||
ref RawSspiHandle newContextHandle,
|
||||
IntPtr outputBuffer,
|
||||
ref ContextAttrib contextAttribs,
|
||||
ref long expiry
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success )]
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace NSspi.Contexts
|
||||
SecureBuffer outBuffer = new SecureBuffer( new byte[12288], BufferType.Token );
|
||||
|
||||
SecurityStatus status;
|
||||
long rawExpiry = 0;
|
||||
TimeStamp rawExpiry = new TimeStamp();
|
||||
|
||||
SecureBufferAdapter clientAdapter;
|
||||
SecureBufferAdapter outAdapter;
|
||||
@@ -87,7 +87,7 @@ namespace NSspi.Contexts
|
||||
nextToken = null;
|
||||
}
|
||||
|
||||
this.Expiry = TimeStamp.Calc( rawExpiry );
|
||||
this.Expiry = rawExpiry.ToDateTime();
|
||||
|
||||
InitProviderCapabilities();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace NSspi.Credentials
|
||||
{
|
||||
string packageName;
|
||||
CredentialUse use;
|
||||
long rawExpiry = 0;
|
||||
TimeStamp rawExpiry = new TimeStamp();
|
||||
|
||||
// -- Package --
|
||||
if ( package == SecurityPackage.Kerberos )
|
||||
@@ -101,7 +101,7 @@ namespace NSspi.Credentials
|
||||
throw new SSPIException( "Failed to call AcquireCredentialHandle", status );
|
||||
}
|
||||
|
||||
this.expiry = TimeStamp.Calc( rawExpiry );
|
||||
this.expiry = rawExpiry.ToDateTime();
|
||||
}
|
||||
|
||||
~Credential()
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace NSspi.Credentials
|
||||
IntPtr getKeyFunc,
|
||||
IntPtr getKeyData,
|
||||
ref RawSspiHandle credentialHandle,
|
||||
ref long expiry
|
||||
ref TimeStamp expiry
|
||||
);
|
||||
|
||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||
|
||||
@@ -1,18 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
public static class TimeStamp
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
public struct TimeStamp
|
||||
{
|
||||
public static readonly DateTime Epoch = new DateTime( 1601, 1, 1, 0, 0, 0, DateTimeKind.Utc );
|
||||
|
||||
public static DateTime Calc( long rawExpiry )
|
||||
private long time;
|
||||
|
||||
public DateTime ToDateTime()
|
||||
{
|
||||
return TimeStamp.Epoch.AddTicks( rawExpiry );
|
||||
ulong test = (ulong)this.time + (ulong)(Epoch.Ticks);
|
||||
|
||||
// Sometimes the value returned is massive, eg, 0x7fffff154e84ffff, which is a value
|
||||
// somewhere in the year 30848. This would overflow DateTime, since it peaks at 31-Dec-9999.
|
||||
// http://stackoverflow.com/questions/24478056/
|
||||
if ( test > (ulong)DateTime.MaxValue.Ticks )
|
||||
{
|
||||
return DateTime.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTime.FromFileTimeUtc( this.time );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user