public static SafeFreeContextBufferChannelBinding QueryContextChannelBinding(SSPIInterface secModule, SafeDeleteContext securityContext, Interop.Secur32.ContextAttribute contextAttribute) { GlobalLog.Enter("QueryContextChannelBinding", contextAttribute.ToString()); SafeFreeContextBufferChannelBinding result; int errorCode = secModule.QueryContextChannelBinding(securityContext, contextAttribute, out result); if (errorCode != 0) { GlobalLog.Leave("QueryContextChannelBinding", "ERROR = " + ErrorDescription(errorCode)); return(null); } GlobalLog.Leave("QueryContextChannelBinding", Logging.HashString(result)); return(result); }
private object QueryContextAttributes(SafeDeleteContext securityContext, Interop.Secur32.ContextAttribute contextAttribute, out int errorCode) { GlobalLog.Enter("QueryContextAttributes", contextAttribute.ToString()); int nativeBlockSize = IntPtr.Size; Type handleType = null; switch (contextAttribute) { case Interop.Secur32.ContextAttribute.Sizes: nativeBlockSize = SecSizes.SizeOf; break; case Interop.Secur32.ContextAttribute.StreamSizes: nativeBlockSize = StreamSizes.SizeOf; break; case Interop.Secur32.ContextAttribute.Names: handleType = typeof(SafeFreeContextBuffer); break; case Interop.Secur32.ContextAttribute.PackageInfo: handleType = typeof(SafeFreeContextBuffer); break; case Interop.Secur32.ContextAttribute.NegotiationInfo: handleType = typeof(SafeFreeContextBuffer); nativeBlockSize = Marshal.SizeOf <NegotiationInfo>(); break; case Interop.Secur32.ContextAttribute.ClientSpecifiedSpn: handleType = typeof(SafeFreeContextBuffer); break; case Interop.Secur32.ContextAttribute.RemoteCertificate: handleType = typeof(SafeFreeCertContext); break; case Interop.Secur32.ContextAttribute.LocalCertificate: handleType = typeof(SafeFreeCertContext); break; case Interop.Secur32.ContextAttribute.IssuerListInfoEx: nativeBlockSize = Marshal.SizeOf <Interop.Secur32.IssuerListInfoEx>(); handleType = typeof(SafeFreeContextBuffer); break; case Interop.Secur32.ContextAttribute.ConnectionInfo: nativeBlockSize = Marshal.SizeOf <SslConnectionInfo>(); break; default: throw new ArgumentException(SR.Format(SR.net_invalid_enum, "ContextAttribute"), "contextAttribute"); } SafeHandle SspiHandle = null; object attribute = null; try { byte[] nativeBuffer = new byte[nativeBlockSize]; errorCode = QueryContextAttributes(securityContext, contextAttribute, nativeBuffer, handleType, out SspiHandle); if (errorCode != 0) { GlobalLog.Leave("Win32:QueryContextAttributes", "ERROR = " + ErrorDescription(errorCode)); return(null); } switch (contextAttribute) { case Interop.Secur32.ContextAttribute.Sizes: attribute = new SecSizes(nativeBuffer); break; case Interop.Secur32.ContextAttribute.StreamSizes: attribute = new StreamSizes(nativeBuffer); break; case Interop.Secur32.ContextAttribute.Names: attribute = Marshal.PtrToStringUni(SspiHandle.DangerousGetHandle()); break; case Interop.Secur32.ContextAttribute.PackageInfo: attribute = new SecurityPackageInfoClass(SspiHandle, 0); break; case Interop.Secur32.ContextAttribute.NegotiationInfo: unsafe { fixed(void *ptr = nativeBuffer) { attribute = new NegotiationInfoClass(SspiHandle, Marshal.ReadInt32(new IntPtr(ptr), NegotiationInfo.NegotiationStateOffest)); } } break; case Interop.Secur32.ContextAttribute.ClientSpecifiedSpn: attribute = Marshal.PtrToStringUni(SspiHandle.DangerousGetHandle()); break; case Interop.Secur32.ContextAttribute.LocalCertificate: goto case Interop.Secur32.ContextAttribute.RemoteCertificate; case Interop.Secur32.ContextAttribute.RemoteCertificate: attribute = SspiHandle; SspiHandle = null; break; case Interop.Secur32.ContextAttribute.IssuerListInfoEx: attribute = new Interop.Secur32.IssuerListInfoEx(SspiHandle, nativeBuffer); SspiHandle = null; break; case Interop.Secur32.ContextAttribute.ConnectionInfo: attribute = new SslConnectionInfo(nativeBuffer); break; default: // Will return null. break; } } finally { if (SspiHandle != null) { SspiHandle.Dispose(); } } GlobalLog.Leave("QueryContextAttributes", Logging.ObjectToString(attribute)); return(attribute); }