Helper methods to safely invoke the VerifySignature and MakeSignature native methods.

This commit is contained in:
antiduh
2014-06-27 01:52:42 +00:00
parent 4224193f6f
commit ffb7e36edb
2 changed files with 96 additions and 62 deletions

View File

@@ -279,37 +279,12 @@ namespace NSspi.Contexts
using ( adapter = new SecureBufferAdapter( new[] { dataBuffer, signatureBuffer } ) )
{
bool gotRef = false;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
this.ContextHandle.DangerousAddRef( ref gotRef );
}
catch ( Exception )
{
if ( gotRef )
{
this.ContextHandle.DangerousRelease();
gotRef = false;
}
throw;
}
finally
{
if ( gotRef )
{
status = ContextNativeMethods.MakeSignature(
ref this.ContextHandle.rawHandle,
0,
adapter.Handle,
0
);
this.ContextHandle.DangerousRelease();
}
}
status = ContextNativeMethods.SafeMakeSignature(
this.ContextHandle,
0,
adapter,
0
);
}
if ( status != SecurityStatus.OK )
@@ -384,37 +359,12 @@ namespace NSspi.Contexts
using ( adapter = new SecureBufferAdapter( new[] { dataBuffer, signatureBuffer } ) )
{
bool gotRef = false;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
this.ContextHandle.DangerousAddRef( ref gotRef );
}
catch ( Exception )
{
if ( gotRef )
{
this.ContextHandle.DangerousRelease();
gotRef = false;
}
throw;
}
finally
{
if ( gotRef )
{
status = ContextNativeMethods.VerifySignature(
ref this.ContextHandle.rawHandle,
adapter.Handle,
0,
0
);
this.ContextHandle.DangerousRelease();
}
}
status = ContextNativeMethods.SafeVerifySignature(
this.ContextHandle,
0,
adapter,
0
);
}
if ( status == SecurityStatus.OK )

View File

@@ -257,5 +257,89 @@ namespace NSspi.Contexts
return status;
}
internal static SecurityStatus SafeMakeSignature(
SafeContextHandle handle,
int qualityOfProtection,
SecureBufferAdapter adapter,
int sequenceNumber )
{
bool gotRef = false;
SecurityStatus status = SecurityStatus.InternalError;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
handle.DangerousAddRef( ref gotRef );
}
catch ( Exception )
{
if ( gotRef )
{
handle.DangerousRelease();
gotRef = false;
}
throw;
}
finally
{
if ( gotRef )
{
status = ContextNativeMethods.MakeSignature(
ref handle.rawHandle,
0,
adapter.Handle,
0
);
handle.DangerousRelease();
}
}
return status;
}
internal static SecurityStatus SafeVerifySignature(
SafeContextHandle handle,
int qualityOfProtection,
SecureBufferAdapter adapter,
int sequenceNumber )
{
bool gotRef = false;
SecurityStatus status = SecurityStatus.InternalError;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
handle.DangerousAddRef( ref gotRef );
}
catch ( Exception )
{
if ( gotRef )
{
handle.DangerousRelease();
gotRef = false;
}
throw;
}
finally
{
if ( gotRef )
{
status = ContextNativeMethods.VerifySignature(
ref handle.rawHandle,
adapter.Handle,
0,
0
);
handle.DangerousRelease();
}
}
return status;
}
}
}