public SafeFreeContextBufferChannelBinding(SafeChannelBindingHandle binding)
 {
     Debug.Assert(null != binding && !binding.IsInvalid, "input channelBinding is invalid");
     bool gotRef = false;
     binding.DangerousAddRef(ref gotRef);
     handle = binding.DangerousGetHandle();
     _channelBinding = binding;
 }
示例#2
0
 protected override bool ReleaseHandle()
 {
     if (_bindingHandle != null)
     {
         SetHandle(IntPtr.Zero);
         _bindingHandle.Dispose();
         _bindingHandle = null;
     }
     return true;
 }
示例#3
0
 internal void SetToken(X509Certificate2 cert)
 {
     // Parity with WinHTTP: only support retrieval of CBT for ChannelBindingKind.Endpoint.
     _bindingHandle = new SafeChannelBindingHandle(ChannelBindingKind.Endpoint);
     using (HashAlgorithm hashAlgo = Interop.OpenSsl.GetHashForChannelBinding(cert))
     {
         _bindingHash = hashAlgo.ComputeHash(cert.RawData);
         _bindingHandle.SetCertHash(_bindingHash);
         SetHandle(_bindingHandle.DangerousGetHandle());
     }
 }
示例#4
0
 internal void SetToken(X509Certificate2 cert)
 {
     // Parity with WinHTTP : CurHandler only supports retrieval of ChannelBindingKind.Endpoint for CBT.
     _bindingHandle = new SafeChannelBindingHandle(ChannelBindingKind.Endpoint);
     using (HashAlgorithm hashAlgo = Interop.OpenSsl.GetHashForChannelBinding(cert))
     {
         byte[] bindingHash = hashAlgo.ComputeHash(cert.RawData);
         _bindingHandle.SetCertHash(bindingHash);
         _description = BitConverter.ToString(bindingHash).Replace('-', ' ');
         SetHandle(_bindingHandle.DangerousGetHandle());
     }
 }
示例#5
0
        internal static SafeChannelBindingHandle QueryChannelBinding(SafeSslHandle context, ChannelBindingKind bindingType)
        {
            SafeChannelBindingHandle bindingHandle;
            switch (bindingType)
            {
                case ChannelBindingKind.Endpoint:
                    bindingHandle = new SafeChannelBindingHandle(bindingType);
                    QueryEndPointChannelBinding(context, bindingHandle);
                    break;

                case ChannelBindingKind.Unique:
                    bindingHandle = new SafeChannelBindingHandle(bindingType);
                    QueryUniqueChannelBinding(context, bindingHandle);
                    break;

                default:
                    // Keeping parity with windows, we should return null in this case.
                    bindingHandle = null;
                    break;
            }

            return bindingHandle;
        }
示例#6
0
        private static void QueryUniqueChannelBinding(SafeSslHandle context, SafeChannelBindingHandle bindingHandle)
        {
            bool sessionReused = Ssl.SslSessionReused(context);
            int certHashLength = context.IsServer ^ sessionReused ?
                                 Ssl.SslGetPeerFinished(context, bindingHandle.CertHashPtr, bindingHandle.Length) :
                                 Ssl.SslGetFinished(context, bindingHandle.CertHashPtr, bindingHandle.Length);

            if (0 == certHashLength)
            {
                throw CreateSslException(SR.net_ssl_get_channel_binding_token_failed);
            }

            bindingHandle.SetCertHashLength(certHashLength);
        }
示例#7
0
        private static void QueryEndPointChannelBinding(SafeSslHandle context, SafeChannelBindingHandle bindingHandle)
        {
            using (SafeX509Handle certSafeHandle = GetPeerCertificate(context))
            {
                if (certSafeHandle == null || certSafeHandle.IsInvalid)
                {
                    throw CreateSslException(SR.net_ssl_invalid_certificate);
                }

                bool gotReference = false;

                try
                {
                    certSafeHandle.DangerousAddRef(ref gotReference);
                    using (X509Certificate2 cert = new X509Certificate2(certSafeHandle.DangerousGetHandle()))
                    using (HashAlgorithm hashAlgo = GetHashForChannelBinding(cert))
                    {
                        byte[] bindingHash = hashAlgo.ComputeHash(cert.RawData);
                        bindingHandle.SetCertHash(bindingHash);
                    }
                }
                finally
                {
                    if (gotReference)
                    {
                        certSafeHandle.DangerousRelease();
                    }
                }
            }
        }