本文整理汇总了C#中SafeDeleteContext.DangerousGetHandle方法的典型用法代码示例。如果您正苦于以下问题:C# SafeDeleteContext.DangerousGetHandle方法的具体用法?C# SafeDeleteContext.DangerousGetHandle怎么用?C# SafeDeleteContext.DangerousGetHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SafeDeleteContext
的用法示例。
在下文中一共展示了SafeDeleteContext.DangerousGetHandle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryContextConnectionInfo
public int QueryContextConnectionInfo(SafeDeleteContext securityContext, out SslConnectionInfo connectionInfo)
{
bool gotReference = false;
connectionInfo = null;
try
{
securityContext.DangerousAddRef(ref gotReference);
Interop.libssl.SSL_CIPHER cipher = Interop.OpenSsl.GetConnectionInfo(securityContext.DangerousGetHandle());
connectionInfo = new SslConnectionInfo(cipher);
return 0;
}
catch
{
return -1;
}
finally
{
if (gotReference)
{
securityContext.DangerousRelease();
}
}
}
示例2: EncryptDecryptHelper
private SecurityStatus EncryptDecryptHelper(SafeDeleteContext securityContext, byte[] buffer, int offset, int size, int headerSize, int trailerSize, bool encrypt, out int resultSize)
{
bool gotReference = false;
GCHandle inputHandle = new GCHandle();
resultSize = 0;
try
{
securityContext.DangerousAddRef(ref gotReference);
inputHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
IntPtr inputPtr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
if (encrypt)
{
resultSize = Interop.OpenSsl.Encrypt(securityContext.DangerousGetHandle(), inputPtr, offset, size, buffer.Length);
}
else
{
resultSize = Interop.OpenSsl.Decrypt(securityContext.DangerousGetHandle(), inputPtr, size);
}
return ((size == 0) || (resultSize > 0)) ? SecurityStatus.OK : SecurityStatus.ContextExpired;
}
catch
{
return SecurityStatus.InternalError;
}
finally
{
if (inputHandle.IsAllocated)
{
inputHandle.Free();
}
if (gotReference)
{
securityContext.DangerousRelease();
}
}
}
示例3: QueryContextRemoteCertificate
public int QueryContextRemoteCertificate(SafeDeleteContext securityContext, out SafeFreeCertContext remoteCertContext)
{
bool gotReference = false;
remoteCertContext = null;
try
{
securityContext.DangerousAddRef(ref gotReference);
IntPtr certPtr = Interop.OpenSsl.GetPeerCertificate(securityContext.DangerousGetHandle());
remoteCertContext = new SafeFreeCertContext(certPtr);
return 0;
}
catch
{
return -1;
}
finally
{
if (gotReference)
{
securityContext.DangerousRelease();
}
}
}
示例4: EncryptDecryptHelper
private SecurityStatus EncryptDecryptHelper(SafeDeleteContext securityContext, byte[] buffer, int offset, int size, int headerSize, int trailerSize, bool encrypt, out int resultSize)
{
bool gotReference = false;
resultSize = 0;
try
{
securityContext.DangerousAddRef(ref gotReference);
Interop.libssl.SslErrorCode errorCode = Interop.libssl.SslErrorCode.SSL_ERROR_NONE;
unsafe
{
fixed (byte* bufferPtr = buffer)
{
IntPtr inputPtr = new IntPtr(bufferPtr);
IntPtr scHandle = securityContext.DangerousGetHandle();
resultSize = encrypt ?
Interop.OpenSsl.Encrypt(scHandle, inputPtr, offset, size, buffer.Length, out errorCode) :
Interop.OpenSsl.Decrypt(scHandle, inputPtr, size, out errorCode);
}
}
switch (errorCode)
{
case Interop.libssl.SslErrorCode.SSL_ERROR_RENEGOTIATE:
return SecurityStatus.Renegotiate;
case Interop.libssl.SslErrorCode.SSL_ERROR_ZERO_RETURN:
return SecurityStatus.ContextExpired;
case Interop.libssl.SslErrorCode.SSL_ERROR_NONE:
case Interop.libssl.SslErrorCode.SSL_ERROR_WANT_READ:
return SecurityStatus.OK;
default:
return SecurityStatus.InternalError;
}
}
catch (Exception ex)
{
Debug.Fail("Exception Caught. - " + ex);
return SecurityStatus.InternalError;
}
finally
{
if (gotReference)
{
securityContext.DangerousRelease();
}
}
}
示例5: GetRemoteCertificate
//
// Extracts a remote certificate upon request.
//
internal override X509Certificate2 GetRemoteCertificate(SafeDeleteContext securityContext, out X509Certificate2Collection remoteCertificateStore)
{
remoteCertificateStore = null;
bool gotReference = false;
if (securityContext == null)
{
return null;
}
GlobalLog.Enter("SecureChannel#" + Logging.HashString(this) + "::RemoteCertificate{get;}");
X509Certificate2 result = null;
SafeFreeCertContext remoteContext = null;
try
{
int errorCode = SSPIWrapper.QueryContextRemoteCertificate(GlobalSSPI.SSPISecureChannel, securityContext, out remoteContext);
if (remoteContext != null && !remoteContext.IsInvalid)
{
remoteContext.DangerousAddRef(ref gotReference);
result = new X509Certificate2(remoteContext.DangerousGetHandle());
}
remoteCertificateStore = new X509Certificate2Collection();
SafeSharedX509StackHandle chainStack =
Interop.OpenSsl.GetPeerCertificateChain(securityContext.DangerousGetHandle());
GC.KeepAlive(securityContext);
using (chainStack)
{
if (!chainStack.IsInvalid)
{
int count = Interop.Crypto.GetX509StackFieldCount(chainStack);
for (int i = 0; i < count; i++)
{
IntPtr certPtr = Interop.Crypto.GetX509StackField(chainStack, i);
if (certPtr != IntPtr.Zero)
{
// X509Certificate2(IntPtr) calls X509_dup, so the reference is appropriately tracked.
X509Certificate2 chainCert = new X509Certificate2(certPtr);
remoteCertificateStore.Add(chainCert);
}
}
}
}
}
finally
{
if (gotReference)
{
remoteContext.DangerousRelease();
}
if (remoteContext != null)
{
remoteContext.Dispose();
}
}
if (Logging.On)
{
Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_remote_certificate, (result == null ? "null" : result.ToString(true))));
}
GlobalLog.Leave("SecureChannel#" + Logging.HashString(this) + "::RemoteCertificate{get;}", (result == null ? "null" : result.Subject));
return result;
}
示例6: EncryptDecryptHelper
private SecurityStatus EncryptDecryptHelper(SafeDeleteContext securityContext, byte[] buffer, int offset, int size, int headerSize, int trailerSize, bool encrypt, out int resultSize)
{
bool gotReference = false;
resultSize = 0;
try
{
securityContext.DangerousAddRef(ref gotReference);
unsafe
{
fixed (byte* bufferPtr = buffer)
{
IntPtr inputPtr = new IntPtr(bufferPtr);
IntPtr scHandle = securityContext.DangerousGetHandle();
resultSize = encrypt ?
Interop.OpenSsl.Encrypt(scHandle, inputPtr, offset, size, buffer.Length) :
Interop.OpenSsl.Decrypt(scHandle, inputPtr, size);
}
}
return ((size == 0) || (resultSize > 0)) ? SecurityStatus.OK : SecurityStatus.ContextExpired;
}
catch (Exception ex)
{
Debug.Fail("Exception Caught. - " + ex);
return SecurityStatus.InternalError;
}
finally
{
if (gotReference)
{
securityContext.DangerousRelease();
}
}
}