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(); } } } }
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()); } }
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()); } }