| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Net; |
| | | 6 | | using System.Net.Security; |
| | | 7 | | using System.Security.Authentication.ExtendedProtection; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Channels |
| | | 10 | | { |
| | | 11 | | internal static class ChannelBindingUtility |
| | | 12 | | { |
| | 0 | 13 | | private static readonly ExtendedProtectionPolicy s_disabledPolicy = new ExtendedProtectionPolicy(PolicyEnforceme |
| | | 14 | | |
| | 0 | 15 | | public static ExtendedProtectionPolicy DefaultPolicy { get; } = s_disabledPolicy; |
| | | 16 | | |
| | | 17 | | public static ChannelBinding GetToken(SslStream stream) |
| | | 18 | | { |
| | 0 | 19 | | return GetToken(stream.TransportContext); |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | public static ChannelBinding GetToken(TransportContext context) |
| | | 23 | | { |
| | 0 | 24 | | ChannelBinding token = null; |
| | 0 | 25 | | if (context != null) |
| | | 26 | | { |
| | 0 | 27 | | token = context.GetChannelBinding(ChannelBindingKind.Endpoint); |
| | | 28 | | } |
| | 0 | 29 | | return token; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public static void TryAddToMessage(ChannelBinding channelBindingToken, Message message, bool messagePropertyOwns |
| | | 33 | | { |
| | 0 | 34 | | if (channelBindingToken != null) |
| | | 35 | | { |
| | 0 | 36 | | ChannelBindingMessageProperty property = new ChannelBindingMessageProperty(channelBindingToken, messageP |
| | 0 | 37 | | property.AddTo(message); |
| | 0 | 38 | | ((IDisposable)property).Dispose(); //message.Properties.Add() creates a copy... |
| | | 39 | | } |
| | 0 | 40 | | } |
| | | 41 | | |
| | | 42 | | public static void Dispose(ref ChannelBinding channelBinding) |
| | | 43 | | { |
| | | 44 | | // Explicitly cast to IDisposable to avoid the SecurityException. |
| | | 45 | | // I don't think this is relevant on .Net Core but I don't believe |
| | | 46 | | // it will emit any extra code from the JIT. |
| | 0 | 47 | | IDisposable disposable = (IDisposable)channelBinding; |
| | 0 | 48 | | channelBinding = null; |
| | 0 | 49 | | if (disposable != null) |
| | | 50 | | { |
| | 0 | 51 | | disposable.Dispose(); |
| | | 52 | | } |
| | 0 | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |