Ejemplo n.º 1
0
        private NetTcpRelaySecurity(EndToEndSecurityMode mode, Microsoft.ServiceBus.RelayClientAuthenticationType relayClientAuthenticationType, TcpRelayTransportSecurity transportSecurity, MessageSecurityOverRelayConnection messageSecurity)
        {
            bool        flag             = EndToEndSecurityModeHelper.IsDefined(mode);
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[] str = new object[] { mode.ToString() };
            Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DebugAssert(flag, string.Format(invariantCulture, "Invalid RelaySecurityMode value: {0}.", str));
            this.mode = mode;
            this.relayClientAuthenticationType = relayClientAuthenticationType;
            this.transportSecurity             = (transportSecurity == null ? new TcpRelayTransportSecurity() : transportSecurity);
            this.messageSecurity = (messageSecurity == null ? new MessageSecurityOverRelayConnection() : messageSecurity);
        }
        internal static bool TryCreateSecurity(SecurityBindingElement sbe, RelayClientAuthenticationType relayClientAuthenticationType, Microsoft.ServiceBus.UnifiedSecurityMode mode, bool isReliableSession, TcpRelayTransportSecurity tcpTransportSecurity, out NetTcpRelaySecurity security)
        {
            if (sbe == null)
            {
                mode = mode & (Microsoft.ServiceBus.UnifiedSecurityMode.None | Microsoft.ServiceBus.UnifiedSecurityMode.Transport | Microsoft.ServiceBus.UnifiedSecurityMode.Both);
            }
            else
            {
                mode = mode & (Microsoft.ServiceBus.UnifiedSecurityMode.Message | Microsoft.ServiceBus.UnifiedSecurityMode.TransportWithMessageCredential);
            }
            EndToEndSecurityMode relaySecurityMode = EndToEndSecurityModeHelper.ToRelaySecurityMode(mode);
            bool        flag             = EndToEndSecurityModeHelper.IsDefined(relaySecurityMode);
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[] str = new object[] { relaySecurityMode.ToString() };
            Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DebugAssert(flag, string.Format(invariantCulture, "Invalid RelaySecurityMode value: {0}.", str));
            if (NetTcpRelaySecurity.TryCreate(sbe, relaySecurityMode, relayClientAuthenticationType, isReliableSession, tcpTransportSecurity, out security))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            Microsoft.ServiceBus.UnifiedSecurityMode unifiedSecurityMode;
            NetTcpRelaySecurity netTcpRelaySecurity;

            binding = null;
            if (elements.Count > 5)
            {
                return(false);
            }
            TcpRelayTransportBindingElement     tcpRelayTransportBindingElement     = null;
            BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = null;
            ReliableSessionBindingElement       reliableSessionBindingElement       = null;
            SecurityBindingElement securityBindingElement = null;

            foreach (BindingElement element in elements)
            {
                if (element is SecurityBindingElement)
                {
                    securityBindingElement = element as SecurityBindingElement;
                }
                else if (element is TransportBindingElement)
                {
                    tcpRelayTransportBindingElement = element as TcpRelayTransportBindingElement;
                }
                else if (!(element is MessageEncodingBindingElement))
                {
                    if (!(element is ReliableSessionBindingElement))
                    {
                        continue;
                    }
                    reliableSessionBindingElement = element as ReliableSessionBindingElement;
                }
                else
                {
                    binaryMessageEncodingBindingElement = element as BinaryMessageEncodingBindingElement;
                }
            }
            if (tcpRelayTransportBindingElement == null)
            {
                return(false);
            }
            if (binaryMessageEncodingBindingElement == null)
            {
                return(false);
            }
            TcpRelayTransportSecurity tcpRelayTransportSecurity = new TcpRelayTransportSecurity();

            unifiedSecurityMode = (!tcpRelayTransportBindingElement.TransportProtectionEnabled ? Microsoft.ServiceBus.UnifiedSecurityMode.None | Microsoft.ServiceBus.UnifiedSecurityMode.Message : Microsoft.ServiceBus.UnifiedSecurityMode.Transport | Microsoft.ServiceBus.UnifiedSecurityMode.TransportWithMessageCredential);
            if (!NetTcpRelayBindingBase.TryCreateSecurity(securityBindingElement, tcpRelayTransportBindingElement.RelayClientAuthenticationType, unifiedSecurityMode, reliableSessionBindingElement != null, tcpRelayTransportSecurity, out netTcpRelaySecurity))
            {
                return(false);
            }
            NetTcpRelayBinding netTcpRelayBinding = new NetTcpRelayBinding(tcpRelayTransportBindingElement, binaryMessageEncodingBindingElement, reliableSessionBindingElement, netTcpRelaySecurity);

            if (!netTcpRelayBinding.IsBindingElementsMatch(tcpRelayTransportBindingElement, binaryMessageEncodingBindingElement, reliableSessionBindingElement))
            {
                return(false);
            }
            binding = netTcpRelayBinding;
            return(true);
        }
Ejemplo n.º 4
0
        internal static bool TryCreate(SecurityBindingElement wsSecurity, EndToEndSecurityMode mode, Microsoft.ServiceBus.RelayClientAuthenticationType relayClientAuthenticationType, bool isReliableSessionEnabled, TcpRelayTransportSecurity tcpTransportSecurity, out NetTcpRelaySecurity security)
        {
            security = null;
            MessageSecurityOverRelayConnection messageSecurityOverRelayConnection = null;

            if ((mode == EndToEndSecurityMode.Message || mode == EndToEndSecurityMode.TransportWithMessageCredential) && !MessageSecurityOverRelayConnection.TryCreate(wsSecurity, isReliableSessionEnabled, out messageSecurityOverRelayConnection))
            {
                return(false);
            }
            security = new NetTcpRelaySecurity(mode, relayClientAuthenticationType, tcpTransportSecurity, messageSecurityOverRelayConnection);
            if (wsSecurity == null)
            {
                return(true);
            }
            Type type = typeof(SecurityElementBase);

            object[] objArray = new object[] { security.CreateMessageSecurity(isReliableSessionEnabled, wsSecurity.MessageSecurityVersion), wsSecurity, false };
            return((bool)InvokeHelper.InvokeStaticMethod(type, "AreBindingsMatching", objArray));
        }