CERs around the handle usage in MakeSignature and VerifySignature

This commit is contained in:
antiduh
2014-06-27 01:47:43 +00:00
parent fc9daf3611
commit 4224193f6f

View File

@@ -279,13 +279,37 @@ namespace NSspi.Contexts
using ( adapter = new SecureBufferAdapter( new[] { dataBuffer, signatureBuffer } ) ) using ( adapter = new SecureBufferAdapter( new[] { dataBuffer, signatureBuffer } ) )
{ {
// TODO CER 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( status = ContextNativeMethods.MakeSignature(
ref this.ContextHandle.rawHandle, ref this.ContextHandle.rawHandle,
0, 0,
adapter.Handle, adapter.Handle,
0 0
); );
this.ContextHandle.DangerousRelease();
}
}
} }
if ( status != SecurityStatus.OK ) if ( status != SecurityStatus.OK )
@@ -359,6 +383,27 @@ namespace NSspi.Contexts
position += sigLen; position += sigLen;
using ( adapter = new SecureBufferAdapter( new[] { dataBuffer, signatureBuffer } ) ) 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( status = ContextNativeMethods.VerifySignature(
ref this.ContextHandle.rawHandle, ref this.ContextHandle.rawHandle,
@@ -366,6 +411,10 @@ namespace NSspi.Contexts
0, 0,
0 0
); );
this.ContextHandle.DangerousRelease();
}
}
} }
if ( status == SecurityStatus.OK ) if ( status == SecurityStatus.OK )