Ejemplo n.º 1
0
        /// <summary>
        /// Overrides the certificates given in app.config with the ones set programatically
        /// </summary>
        protected void OverrideConfig()
        {
            if (pListenerIdentity != null)
            {
                // Override certificate
                // TOOD: what is going on here? why only override the servicehost cridentials one time ?
                if (pListenerIdentity.ListenerCertificate != null && pServiceHost != null)
                {
                    pServiceHost.Credentials.ServiceCertificate.Certificate = pListenerIdentity.ListenerCertificate.Certificate;
                }
                else
                {
                    pListenerIdentity.ListenerCertificate = new OcesX509Certificate(pServiceHost.Credentials.ServiceCertificate.Certificate);
                }
            }
            else
            {
                CustomBinding           customBinding    = (CustomBinding)pServiceHost.Description.Endpoints[0].Binding;
                TransportBindingElement transportBinding = customBinding.Elements.Find <TransportBindingElement>();
                EmailTransport          emailTransport   = new EmailTransport(transportBinding);
                OcesX509Certificate     ocesCertificate  = new OcesX509Certificate(pServiceHost.Credentials.ServiceCertificate.Certificate);
                pListenerIdentity = new ListenerIdentity(emailTransport, ocesCertificate);
            }

            //Override transport binding
            pEmailBinding = GetEmailBinding();
            if (pListenerIdentity.Transport != null)
            {
                pEmailBinding.CopyElement((EmailBindingElement)pListenerIdentity.Transport.TransportBinding);
            }
            else
            {
                pListenerIdentity.Transport = new EmailTransport(pEmailBinding);
            }
        }
        protected internal override BindingElement CreateBindingElement()
        {
            TransportBindingElement binding = this.CreateDefaultBindingElement();

            this.ApplyConfiguration(binding);
            return(binding);
        }
        internal static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, PrivacyNoticeBindingElement privacy, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding)
        {
            WSFederationHttpSecurityMode mode;
            WSFederationHttpSecurity     security2;
            bool isReliableSession = rsbe != null;

            binding = null;
            HttpTransportSecurity transportSecurity = new HttpTransportSecurity();

            if (!GetSecurityModeFromTransport(transport, transportSecurity, out mode))
            {
                return(false);
            }
            HttpsTransportBindingElement element = transport as HttpsTransportBindingElement;

            if (((element != null) && (element.MessageSecurityVersion != null)) && (element.MessageSecurityVersion.SecurityPolicyVersion != WSMessageSecurityVersion.SecurityPolicyVersion))
            {
                return(false);
            }
            if (TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security2))
            {
                binding = new WSFederationHttpBinding(security2, privacy, isReliableSession);
            }
            if ((rsbe != null) && (rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessagingFebruary2005))
            {
                return(false);
            }
            if ((tfbe != null) && (tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransactionOctober2004))
            {
                return(false);
            }
            return(binding != null);
        }
        protected override IChannelFactory <IAsyncRequestChannel> GetNegotiationChannelFactory(IChannelFactory <IAsyncRequestChannel> transportChannelFactory, ChannelBuilder channelBuilder)
        {
            ISecurityCapabilities      securityCapabilities = _bootstrapSecurityBindingElement.GetProperty <ISecurityCapabilities>(IssuerBindingContext);
            SecurityCredentialsManager securityCredentials  = IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>();

            if (securityCredentials == null)
            {
                securityCredentials = ClientCredentials.CreateDefaultCredentials();
            }

            _bootstrapSecurityBindingElement.ReaderQuotas = IssuerBindingContext.GetInnerProperty <XmlDictionaryReaderQuotas>();
            if (_bootstrapSecurityBindingElement.ReaderQuotas == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.EncodingBindingElementDoesNotHandleReaderQuotas));
            }

            TransportBindingElement transportBindingElement = IssuerBindingContext.RemainingBindingElements.Find <TransportBindingElement>();

            if (transportBindingElement != null)
            {
                _bootstrapSecurityBindingElement.MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize;
            }

            SecurityProtocolFactory securityProtocolFactory = _bootstrapSecurityBindingElement.CreateSecurityProtocolFactory <IAsyncRequestChannel>(IssuerBindingContext.Clone(), securityCredentials, false, IssuerBindingContext.Clone());

            return(new SecurityChannelFactory <IAsyncRequestChannel>(
                       securityCapabilities, IssuerBindingContext, channelBuilder, securityProtocolFactory, transportChannelFactory));
        }
Ejemplo n.º 5
0
        private bool IsBindingElementsMatch(HttpRelayTransportBindingElement transport, MessageEncodingBindingElement encoding)
        {
            if (this.MessageEncoding == WSMessageEncoding.Text)
            {
                Type type = typeof(BindingElement);
                TextMessageEncodingBindingElement textMessageEncodingBindingElement = this.textEncoding;
                object[] objArray = new object[] { encoding };
                if (!(bool)InvokeHelper.InvokeInstanceMethod(type, textMessageEncodingBindingElement, "IsMatch", objArray))
                {
                    return(false);
                }
            }
            else if (this.MessageEncoding == WSMessageEncoding.Mtom)
            {
                Type type1 = typeof(BindingElement);
                MtomMessageEncodingBindingElement mtomMessageEncodingBindingElement = this.mtomEncoding;
                object[] objArray1 = new object[] { encoding };
                if (!(bool)InvokeHelper.InvokeInstanceMethod(type1, mtomMessageEncodingBindingElement, "IsMatch", objArray1))
                {
                    return(false);
                }
            }
            Type type2 = typeof(BindingElement);
            TransportBindingElement transportBindingElement = this.GetTransport();

            object[] objArray2 = new object[] { transport };
            if (!(bool)InvokeHelper.InvokeInstanceMethod(type2, transportBindingElement, "IsMatch", objArray2))
            {
                return(false);
            }
            return(true);
        }
 internal static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, PrivacyNoticeBindingElement privacy, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding)
 {
     WSFederationHttpSecurityMode mode;
     WSFederationHttpSecurity security2;
     bool isReliableSession = rsbe != null;
     binding = null;
     HttpTransportSecurity transportSecurity = new HttpTransportSecurity();
     if (!WSFederationHttpBinding.GetSecurityModeFromTransport(transport, transportSecurity, out mode))
     {
         return false;
     }
     HttpsTransportBindingElement element = transport as HttpsTransportBindingElement;
     if (((element != null) && (element.MessageSecurityVersion != null)) && (element.MessageSecurityVersion.SecurityPolicyVersion != WS2007MessageSecurityVersion.SecurityPolicyVersion))
     {
         return false;
     }
     if (TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security2))
     {
         binding = new WS2007FederationHttpBinding(security2, privacy, isReliableSession);
     }
     if ((rsbe != null) && (rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11))
     {
         return false;
     }
     if ((tfbe != null) && (tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransaction11))
     {
         return false;
     }
     return (binding != null);
 }
        public async Task OnConnectedAsync(FramingConnection connection)
        {
            if (!_transportSettingsCache.TryGetValue(connection.ServiceDispatcher, out ITransportFactorySettings settings))
            {
                BindingElementCollection be  = connection.ServiceDispatcher.Binding.CreateBindingElements();
                TransportBindingElement  tbe = be.Find <TransportBindingElement>();
                settings = new NetFramingTransportSettings
                {
                    CloseTimeout           = connection.ServiceDispatcher.Binding.CloseTimeout,
                    OpenTimeout            = connection.ServiceDispatcher.Binding.OpenTimeout,
                    ReceiveTimeout         = connection.ServiceDispatcher.Binding.ReceiveTimeout,
                    SendTimeout            = connection.ServiceDispatcher.Binding.SendTimeout,
                    ManualAddressing       = tbe.ManualAddressing,
                    BufferManager          = connection.BufferManager,
                    MaxReceivedMessageSize = tbe.MaxReceivedMessageSize,
                    MessageEncoderFactory  = connection.MessageEncoderFactory
                };
            }

            var channel = new ServerFramingDuplexSessionChannel(connection, settings, false, _servicesScopeFactory.CreateScope().ServiceProvider);

            channel.ChannelDispatcher = await connection.ServiceDispatcher.CreateServiceChannelDispatcherAsync(channel);

            await channel.StartReceivingAsync();
        }
        protected override BindingElement CreateBindingElement()
        {
            TransportBindingElement element = CreateDefaultBindingElement();

            this.ApplyConfiguration(element);
            return(element);
        }
        private static string GetTransport(System.ServiceModel.Channels.Binding binding)
        {
            TransportBindingElement transport = binding.CreateBindingElements().Find <TransportBindingElement>();

            if (transport != null)
            {
                if (typeof(HttpTransportBindingElement) == transport.GetType())
                {
                    return("http://schemas.xmlsoap.org/soap/http");
                }
                if (typeof(HttpsTransportBindingElement) == transport.GetType())
                {
                    return("http://schemas.xmlsoap.org/soap/https");
                }
                if (typeof(TcpTransportBindingElement) == transport.GetType())
                {
                    return("http://schemas.microsoft.com/soap/tcp");
                }
                if (typeof(NamedPipeTransportBindingElement) == transport.GetType())
                {
                    return("http://schemas.microsoft.com/soap/named-pipe");
                }
                if (typeof(MsmqTransportBindingElement) == transport.GetType())
                {
                    return("http://schemas.microsoft.com/soap/msmq");
                }
            }
            return("");
        }
Ejemplo n.º 10
0
 private async Task EnsureChannelAsync(FramingConnection connection)
 {
     if (_replyChannel == null)
     {
         await using (await _lock.TakeLockAsync())
         {
             if (_replyChannel == null)
             {
                 BindingElementCollection  be       = connection.ServiceDispatcher.Binding.CreateBindingElements();
                 TransportBindingElement   tbe      = be.Find <TransportBindingElement>();
                 ITransportFactorySettings settings = new NetFramingTransportSettings
                 {
                     CloseTimeout           = connection.ServiceDispatcher.Binding.CloseTimeout,
                     OpenTimeout            = connection.ServiceDispatcher.Binding.OpenTimeout,
                     ReceiveTimeout         = connection.ServiceDispatcher.Binding.ReceiveTimeout,
                     SendTimeout            = connection.ServiceDispatcher.Binding.SendTimeout,
                     ManualAddressing       = tbe.ManualAddressing,
                     BufferManager          = connection.BufferManager,
                     MaxReceivedMessageSize = tbe.MaxReceivedMessageSize,
                     MessageEncoderFactory  = connection.MessageEncoderFactory
                 };
                 _replyChannel = new ConnectionOrientedTransportReplyChannel(settings, null,
                                                                             _servicesScopeFactory.CreateScope().ServiceProvider);
                 _channelDispatcher =
                     await connection.ServiceDispatcher.CreateServiceChannelDispatcherAsync(_replyChannel);
             }
         }
     }
 }
Ejemplo n.º 11
0
        protected TransportChannelFactory(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory) : base(context.Binding)
        {
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;
            Collection <MessageEncodingBindingElement> messageEncodingBindingElements = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncodingBindingElements.Count > 1)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(Microsoft.ServiceBus.SR.GetString(Resources.MultipleMebesInParameters, new object[0])));
            }
            if (messageEncodingBindingElements.Count != 1)
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }
            else
            {
                this.messageEncoderFactory = messageEncodingBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            if (this.messageEncoderFactory == null)
            {
                this.messageVersion = System.ServiceModel.Channels.MessageVersion.None;
                return;
            }
            this.messageVersion = this.messageEncoderFactory.MessageVersion;
        }
Ejemplo n.º 12
0
        private static string GetDefaultEndpoint(System.ServiceModel.Channels.Binding binding, string serviceName)
        {
            TransportBindingElement transport = binding.CreateBindingElements().Find <TransportBindingElement>();

            if (transport != null)
            {
                if (typeof(HttpTransportBindingElement) == transport.GetType())
                {
                    UriBuilder ub = new UriBuilder(transport.Scheme, "localhost");
                    ub.Path = serviceName;
                    return(ub.Uri.ToString());
                }
                if (typeof(HttpsTransportBindingElement) == transport.GetType())
                {
                    UriBuilder ub = new UriBuilder(transport.Scheme, "localhost");
                    ub.Path = serviceName;
                    return(ub.Uri.ToString());
                }
                if (typeof(TcpTransportBindingElement) == transport.GetType())
                {
                    UriBuilder ub = new UriBuilder(transport.Scheme, "localhost");
                    ub.Path = serviceName;
                    return(ub.Uri.ToString());
                }
                if (typeof(NamedPipeTransportBindingElement) == transport.GetType())
                {
                    return("tbd");
                }
                if (typeof(MsmqTransportBindingElement) == transport.GetType())
                {
                    return("tbd");
                }
            }
            return("");
        }
Ejemplo n.º 13
0
 private void initialize()
 {
     _ReliableSessionBindingElement = new ReliableSessionBindingElement();
     _CompositeDuplexBindingElement = new CompositeDuplexBindingElement();
     _EncodingBindingElement        = new TextMessageEncodingBindingElement();
     _OneWayEncodingBindingElement  = new OneWayEncoderBindingElement();
     _TransportBindingElement       = new ExUdpBindingElement();
 }
        protected internal override void InitializeFrom(BindingElement bindingElement)
        {
            base.InitializeFrom(bindingElement);
            TransportBindingElement element = (TransportBindingElement)bindingElement;

            this.ManualAddressing       = element.ManualAddressing;
            this.MaxBufferPoolSize      = element.MaxBufferPoolSize;
            this.MaxReceivedMessageSize = element.MaxReceivedMessageSize;
        }
        private void InitializeValue()
        {
            _compressionTypeOptions = CompressionTypeOptions.None;
            _operationBehaviours    = new Dictionary <string, OperationBehaviourElement>();

            this._encoding      = new BinaryMessageEncodingBindingElement();
            this._transport     = GetTransport();
            this._mainTransport = new ProtoBufMetaDataBindingElement(this._transport);
        }
Ejemplo n.º 16
0
        protected internal override void InitializeFrom(BindingElement bindingElement)
        {
            base.InitializeFrom(bindingElement);
            TransportBindingElement binding = (TransportBindingElement)bindingElement;

            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ManualAddressing, binding.ManualAddressing);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBufferPoolSize, binding.MaxBufferPoolSize);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxReceivedMessageSize, binding.MaxReceivedMessageSize);
        }
Ejemplo n.º 17
0
        public override void ApplyConfiguration(BindingElement bindingElement)
        {
            base.ApplyConfiguration(bindingElement);
            TransportBindingElement binding = (TransportBindingElement)bindingElement;

            binding.ManualAddressing       = this.ManualAddressing;
            binding.MaxBufferPoolSize      = this.MaxBufferPoolSize;
            binding.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
        }
Ejemplo n.º 18
0
        private void InitializeValue()
        {
            _compressionTypeOptions = CompressionTypeOptions.None;
            _operationBehaviours = new Dictionary<string, OperationBehaviourElement>();

            this._encoding = new BinaryMessageEncodingBindingElement();
            this._transport = GetTransport();
            this._mainTransport = new ProtoBufMetaDataBindingElement(this._transport);
        }
Ejemplo n.º 19
0
        //private readonly BufferManager _bufferManager;
        ////private readonly MessageEncoderFactory _encoderFactory;
        //private readonly Uri _uri;

        public MetaReplyChannelListener(TransportBindingElement transportElement, BindingContext context, IChannelListener <IReplyChannel> innerListener)
            : base(context.Binding)
        {
            _innerListener = innerListener;
            //this.MaxReceivedMessageSize = transportElement.MaxReceivedMessageSize;
            //var messageElement = context.BindingParameters.Remove<MessageEncodingBindingElement>();
            //this._bufferManager = BufferManager.CreateBufferManager(transportElement.MaxBufferPoolSize, (int)this.MaxReceivedMessageSize);
            ////this._encoderFactory = messageElement.CreateMessageEncoderFactory();
            //this._uri = new Uri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);
        }
Ejemplo n.º 20
0
 public SimpleDatagramBinding()
 {
     BindingElement[] bindingElements = new BindingElement[]
     {
         new TextMessageEncodingBindingElement(),
         new HttpTransportBindingElement()
     };
     bindingElementCollection = new BindingElementCollection(bindingElements);
     transportBindingElement = (TransportBindingElement)bindingElements[1];
 }
Ejemplo n.º 21
0
 public SimpleDatagramBinding()
 {
     BindingElement[] bindingElements = new BindingElement[]
     {
         new SimpleDatagramBindingElement(),
         new TextMessageEncodingBindingElement(),
         new HttpTransportBindingElement()
     };
     bindingElementCollection = new BindingElementCollection(bindingElements);
     transportBindingElement  = (TransportBindingElement)bindingElements[2];
 }
Ejemplo n.º 22
0
 public SimpleSessionBinding()
 {
     BindingElement[] bindingElements = new BindingElement[]
     {
         new SimpleSessionBindingElement(),
         new BinaryMessageEncodingBindingElement(),
         new TcpTransportBindingElement()
     };
     bindingElementCollection = new BindingElementCollection(bindingElements);
     transportBindingElement  = (TransportBindingElement)bindingElements[2];
 }
Ejemplo n.º 23
0
 public SimpleSessionBinding()
 {
     BindingElement[] bindingElements = new BindingElement[]
     {
     new SimpleSessionBindingElement(),
     new BinaryMessageEncodingBindingElement(),
     new TcpTransportBindingElement()
     };
     bindingElementCollection = new BindingElementCollection(bindingElements);
     transportBindingElement = (TransportBindingElement)bindingElements[2];
 }
Ejemplo n.º 24
0
        public UdpChannelFactory(TransportBindingElement bindingElement, BindingContext context)
            : base(context.Binding)
        {
            _BufferManager = BufferManager.CreateBufferManager(bindingElement.MaxBufferPoolSize, ExDefaultValue.MaxBufferSize);
            var me = context.BindingParameters.Find <MessageEncodingBindingElement>();

            if (me != null)
            {
                _MessageEncoderFactory = me.CreateMessageEncoderFactory();
            }
        }
Ejemplo n.º 25
0
        internal static bool TryGetAllowCookiesFromTransport(TransportBindingElement transport, out bool allowCookies)
        {
            HttpRelayTransportBindingElement httpRelayTransportBindingElement = transport as HttpRelayTransportBindingElement;

            if (httpRelayTransportBindingElement == null)
            {
                allowCookies = false;
                return(false);
            }
            allowCookies = httpRelayTransportBindingElement.AllowCookies;
            return(true);
        }
Ejemplo n.º 26
0
        internal static bool IsManualAddressing(Binding binding)
        {
            TransportBindingElement transport = binding.CreateBindingElements().Find <TransportBindingElement>();

            if (transport == null)
            {
                string    text  = SR.Format(SR.SFxBindingMustContainTransport2, binding.Name, binding.Namespace);
                Exception error = new InvalidOperationException(text);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
            }
            return(transport.ManualAddressing);
        }
Ejemplo n.º 27
0
        // This is effectively just a copy of WSHttpBinding.TryCreate(), only it news up the 2007 version
        internal new static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding)
        {
            bool isReliableSession = (rsbe != null);

            binding = null;

            // reverse GetTransport
            HttpTransportSecurity transportSecurity = WSHttpSecurity.GetDefaultHttpTransportSecurity();
            UnifiedSecurityMode   mode;

            if (!WSHttpBinding.GetSecurityModeFromTransport(transport, transportSecurity, out mode))
            {
                return(false);
            }

            HttpsTransportBindingElement httpsBinding = transport as HttpsTransportBindingElement;

            if (httpsBinding != null && httpsBinding.MessageSecurityVersion != null)
            {
                if (httpsBinding.MessageSecurityVersion.SecurityPolicyVersion != s_WS2007MessageSecurityVersion.SecurityPolicyVersion)
                {
                    return(false);
                }
            }

            WSHttpSecurity security;

            if (WS2007HttpBinding.TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security))
            {
                WS2007HttpBinding ws2007HttpBinding = new WS2007HttpBinding(security, isReliableSession);

                bool allowCookies;
                if (!WSHttpBinding.TryGetAllowCookiesFromTransport(transport, out allowCookies))
                {
                    return(false);
                }

                ws2007HttpBinding.AllowCookies = allowCookies;
                binding = ws2007HttpBinding;
            }

            if (rsbe != null && rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11)
            {
                return(false);
            }

            if (tfbe != null && tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransaction11)
            {
                return(false);
            }

            return(binding != null);
        }
        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
            CustomBinding binding = new CustomBinding(endpoint.Binding);
            TransportBindingElement tbe = binding.Elements.Find<TransportBindingElement>();
            tbe.ManualAddressing = false;
            endpoint.Binding = binding;

            foreach (OperationDescription opDesc in endpoint.Contract.Operations)
            {
                ReplaceFormatterBehavior(opDesc, endpoint);
            }
        }
        internal IChannelListener <TChannel> BuildNegotiationChannelListener <TChannel>(BindingContext context)
            where TChannel : class, IChannel
        {
            SecurityCredentialsManager securityCredentials = this.IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>();

            if (securityCredentials == null)
            {
                securityCredentials = ServiceCredentials.CreateDefaultCredentials();
            }

            this.bootstrapSecurityBindingElement.ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>();
            if (this.bootstrapSecurityBindingElement.ReaderQuotas == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.EncodingBindingElementDoesNotHandleReaderQuotas)));
            }

            TransportBindingElement transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>();

            if (transportBindingElement != null)
            {
                this.bootstrapSecurityBindingElement.MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize;
            }

            SecurityProtocolFactory        securityProtocolFactory = this.bootstrapSecurityBindingElement.CreateSecurityProtocolFactory <TChannel>(this.IssuerBindingContext.Clone(), securityCredentials, true, this.IssuerBindingContext.Clone());
            MessageSecurityProtocolFactory soapBindingFactory      = securityProtocolFactory as MessageSecurityProtocolFactory;

            if (soapBindingFactory != null)
            {
                soapBindingFactory.ApplyConfidentiality             = soapBindingFactory.ApplyIntegrity
                                                                    = soapBindingFactory.RequireConfidentiality = soapBindingFactory.RequireIntegrity = true;
                MessagePartSpecification bodyPart = new MessagePartSpecification(true);
                soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.AddParts(bodyPart, RequestSecurityTokenResponseAction);
                soapBindingFactory.ProtectionRequirements.OutgoingEncryptionParts.AddParts(bodyPart, RequestSecurityTokenResponseAction);
                soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.AddParts(bodyPart, RequestSecurityTokenAction);
                soapBindingFactory.ProtectionRequirements.IncomingEncryptionParts.AddParts(bodyPart, RequestSecurityTokenAction);
            }

            SecurityChannelListener <TChannel> securityChannelListener =
                new SecurityChannelListener <TChannel>(this.bootstrapSecurityBindingElement, context);

            securityChannelListener.SecurityProtocolFactory = securityProtocolFactory;
            // do not send back unsecured faults over composite duplex
            securityChannelListener.SendUnsecuredFaults = !SecurityUtils.IsCompositeDuplexBinding(context);

            ChannelBuilder channelBuilder = new ChannelBuilder(context, true);

            securityChannelListener.InitializeListener(channelBuilder);
            this.shouldMatchRstWithEndpointFilter = SecurityUtils.ShouldMatchRstWithEndpointFilter(this.bootstrapSecurityBindingElement);
            return(securityChannelListener);
        }
        // This is effectively just a copy of WSHttpBinding.TryCreate(), only it news up the 2007 version
        internal new static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding)
        {
            bool isReliableSession = (rsbe != null);
            binding = null;

            // reverse GetTransport
            HttpTransportSecurity transportSecurity = WSHttpSecurity.GetDefaultHttpTransportSecurity();
            UnifiedSecurityMode mode;
            if (!WSHttpBinding.GetSecurityModeFromTransport(transport, transportSecurity, out mode))
            {
                return false;
            }

            HttpsTransportBindingElement httpsBinding = transport as HttpsTransportBindingElement;
            if (httpsBinding != null && httpsBinding.MessageSecurityVersion != null)
            {
                if (httpsBinding.MessageSecurityVersion.SecurityPolicyVersion != WS2007MessageSecurityVersion.SecurityPolicyVersion)
                {
                    return false;
                }
            }

            WSHttpSecurity security;
            if (WS2007HttpBinding.TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security))
            {
                WS2007HttpBinding ws2007HttpBinding = new WS2007HttpBinding(security, isReliableSession);

                bool allowCookies;
                if (!WSHttpBinding.TryGetAllowCookiesFromTransport(transport, out allowCookies))
                {
                    return false;
                }

                ws2007HttpBinding.AllowCookies = allowCookies;
                binding = ws2007HttpBinding;
            }

            if (rsbe != null && rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11)
            {
                return false;
            }

            if (tfbe != null && tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransaction11)
            {
                return false;
            }

            return binding != null;
        }
Ejemplo n.º 31
0
        public UdpChannelListener(TransportBindingElement bindingElement, BindingContext context)
        {
            _BufferManager = BufferManager.CreateBufferManager(bindingElement.MaxBufferPoolSize, ExDefaultValue.MaxBufferSize);
            var me = context.BindingParameters.Find <MessageEncodingBindingElement>();

            if (me != null)
            {
                _MessageEncoderFactory = me.CreateMessageEncoderFactory();
            }

            _ChannelQueue             = new ExQueue <IInputChannel>();
            _CurrentChannelLockObject = new object();
            _Sockets = new List <Socket>(2);
            initializeUri(context);
        }
Ejemplo n.º 32
0
 private void AddDemuxerBindingElement(BindingElementCollection elements)
 {
     if (elements.Find <ChannelDemuxerBindingElement>() == null)
     {
         // add the channel demuxer binding element right above the transport
         TransportBindingElement transport = elements.Find <TransportBindingElement>();
         if (transport == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.TransportBindingElementNotFound));
         }
         // cache the context state in the demuxer so that the same context state can be provided to the transport
         // when building auxilliary channels and listeners (for ex, for security negotiation)
         elements.Insert(elements.IndexOf(transport), new ChannelDemuxerBindingElement(true));
     }
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Configure any endpoint for the maximum size of message.
        /// </summary>
        /// <param name="baseAddress">base address for the service</param>
        /// <returns><code>true</code> if an endpoint is configured, <code>false</code> if no
        ///		endpoint is configured</returns>
        private bool ConfigureEndpoint(Uri baseAddress)
        {
            // Find endpoints for the specified base address.
            foreach (ServiceEndpoint se in Description.Endpoints)
            {
                if (se.Address.Uri == baseAddress)
                {
                    // Is the binding a default HTTP binding?
                    if (se.Binding is WebHttpBinding)
                    {
                        // HTTP. Set the size of messages, and buffers, to the max for this instance,
                        // but only if it is greater than the default.
                        WebHttpBinding binding = (WebHttpBinding)se.Binding;
                        if (binding.MaxReceivedMessageSize < maxReceivedMessageSize)
                        {
                            binding.MaxReceivedMessageSize = maxReceivedMessageSize;
                            binding.MaxBufferSize          = maxReceivedMessageSize;
                            binding.MaxBufferPoolSize      = maxReceivedMessageSize;
                        }
                    }
                    // Is the binding a custom binding?
                    else if (se.Binding is CustomBinding)
                    {
                        // Find the transport binding element.
                        foreach (BindingElement bindingElement in ((CustomBinding)se.Binding).Elements)
                        {
                            if (bindingElement is TransportBindingElement)
                            {
                                // Set the size of messages, and buffers, to the max for this instance,
                                // but only if it is greater than the defaul.
                                TransportBindingElement transportBindingElement = (TransportBindingElement)bindingElement;
                                if (transportBindingElement.MaxReceivedMessageSize < maxReceivedMessageSize)
                                {
                                    transportBindingElement.MaxReceivedMessageSize = maxReceivedMessageSize;
                                    transportBindingElement.MaxBufferPoolSize      = maxReceivedMessageSize;
                                }
                            }
                        }
                    }

                    // Indicate an endpoint was configures.
                    return(true);
                }
            }

            // Indicate no endpoint was configured.
            return(false);
        }
        static void ImportAddress(WsdlEndpointConversionContext context, TransportBindingElement transportBindingElement)
        {
            EndpointAddress address = context.Endpoint.Address = WsdlImporter.WSAddressingHelper.ImportAddress(context.WsdlPort);
            if (address != null)
            {
                context.Endpoint.Address = address;

                // Replace the http BE with https BE only if the uri scheme is https and the transport binding element is a HttpTransportBindingElement but not HttpsTransportBindingElement
                if (address.Uri.Scheme == Uri.UriSchemeHttps && transportBindingElement is HttpTransportBindingElement && !(transportBindingElement is HttpsTransportBindingElement))
                {
                    BindingElementCollection elements = ConvertToCustomBinding(context).Elements;
                    elements.Remove(transportBindingElement);
                    elements.Add(CreateHttpsFromHttp(transportBindingElement as HttpTransportBindingElement));
                }
            }
        }
Ejemplo n.º 35
0
 internal static bool GetSecurityModeFromTransport(TransportBindingElement transport, HttpTransportSecurity transportSecurity, out WSFederationHttpSecurityMode mode)
 {
     mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message | WSFederationHttpSecurityMode.TransportWithMessageCredential;
     if (transport is HttpsTransportBindingElement)
     {
         mode = WSFederationHttpSecurityMode.TransportWithMessageCredential;
     }
     else if (transport is HttpTransportBindingElement)
     {
         mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message;
     }
     else
     {
         return(false);
     }
     return(true);
 }
 internal static bool GetSecurityModeFromTransport(TransportBindingElement transport, HttpTransportSecurity transportSecurity, out UnifiedSecurityMode mode)
 {
     mode = UnifiedSecurityMode.None;
     if (transport is HttpsTransportBindingElement)
     {
         mode = UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Transport;
         WSHttpSecurity.ApplyTransportSecurity((HttpsTransportBindingElement) transport, transportSecurity);
     }
     else if (transport is HttpTransportBindingElement)
     {
         mode = UnifiedSecurityMode.Message | UnifiedSecurityMode.None;
     }
     else
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 37
0
 internal static bool GetSecurityModeFromTransport(TransportBindingElement transport, HttpRelayTransportSecurity transportSecurity, out Microsoft.ServiceBus.UnifiedSecurityMode mode)
 {
     mode = Microsoft.ServiceBus.UnifiedSecurityMode.None;
     if (!(transport is HttpsRelayTransportBindingElement))
     {
         if (!(transport is HttpRelayTransportBindingElement))
         {
             return(false);
         }
         mode = Microsoft.ServiceBus.UnifiedSecurityMode.None | Microsoft.ServiceBus.UnifiedSecurityMode.Message;
     }
     else
     {
         mode = Microsoft.ServiceBus.UnifiedSecurityMode.Transport | Microsoft.ServiceBus.UnifiedSecurityMode.TransportWithMessageCredential;
         WSHttpRelaySecurity.ApplyTransportSecurity((HttpsRelayTransportBindingElement)transport, transportSecurity);
     }
     return(true);
 }
        internal new static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, PrivacyNoticeBindingElement privacy, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding)
        {
            bool isReliableSession = (rsbe != null);
            binding = null;

            // reverse GetTransport
            HttpTransportSecurity transportSecurity = new HttpTransportSecurity();
            WSFederationHttpSecurityMode mode;
            if (!WSFederationHttpBinding.GetSecurityModeFromTransport(transport, transportSecurity, out mode))
            {
                return false;
            }

            HttpsTransportBindingElement httpsBinding = transport as HttpsTransportBindingElement;
            if (httpsBinding != null && httpsBinding.MessageSecurityVersion != null)
            {
                if (httpsBinding.MessageSecurityVersion.SecurityPolicyVersion != WS2007MessageSecurityVersion.SecurityPolicyVersion)
                {
                    return false;
                }
            }

            WSFederationHttpSecurity security;
            if (WS2007FederationHttpBinding.TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security))
            {
                binding = new WS2007FederationHttpBinding(security, privacy, isReliableSession);
            }

            if (rsbe != null && rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11)
            {
                return false;
            }

            if (tfbe != null && tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransaction11)
            {
                return false;
            }

            return binding != null;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="transport"></param>
        /// <returns></returns>
        private static System.ServiceModel.Channels.Binding CreateBinding(TransportBindingElement transport)
        {
            TextMessageEncodingBindingElement encodingBindingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressing10, Encoding.UTF8);

            var messageSecurity = new AsymmetricSecurityBindingElement();
            messageSecurity.LocalClientSettings.IdentityVerifier = new DisabledDnsIdentityCheck();

            messageSecurity.AllowSerializedSigningTokenOnReply = true;
            messageSecurity.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
            messageSecurity.RecipientTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Any, SecurityTokenInclusionMode.AlwaysToInitiator);
            messageSecurity.RecipientTokenParameters.RequireDerivedKeys = false;
            var initiator = new IssuedSecurityTokenParameters("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0");
            messageSecurity.ProtectTokens = true;
            initiator.UseStrTransform = true;
            initiator.KeyType = SecurityKeyType.AsymmetricKey;
            initiator.RequireDerivedKeys = false;
            messageSecurity.InitiatorTokenParameters = initiator;

            var customBinding = new CustomBinding(encodingBindingElement, messageSecurity, transport);

            return customBinding;
        }
 internal static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding)
 {
     UnifiedSecurityMode mode;
     WSHttpSecurity security2;
     bool isReliableSession = rsbe != null;
     binding = null;
     HttpTransportSecurity defaultHttpTransportSecurity = WSHttpSecurity.GetDefaultHttpTransportSecurity();
     if (!WSHttpBinding.GetSecurityModeFromTransport(transport, defaultHttpTransportSecurity, out mode))
     {
         return false;
     }
     HttpsTransportBindingElement element = transport as HttpsTransportBindingElement;
     if (((element != null) && (element.MessageSecurityVersion != null)) && (element.MessageSecurityVersion.SecurityPolicyVersion != WS2007MessageSecurityVersion.SecurityPolicyVersion))
     {
         return false;
     }
     if (TryCreateSecurity(sbe, mode, defaultHttpTransportSecurity, isReliableSession, out security2))
     {
         bool flag2;
         WS2007HttpBinding binding2 = new WS2007HttpBinding(security2, isReliableSession);
         if (!WSHttpBinding.TryGetAllowCookiesFromTransport(transport, out flag2))
         {
             return false;
         }
         binding2.AllowCookies = flag2;
         binding = binding2;
     }
     if ((rsbe != null) && (rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11))
     {
         return false;
     }
     if ((tfbe != null) && (tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransaction11))
     {
         return false;
     }
     return (binding != null);
 }
 internal static bool GetSecurityModeFromTransport(TransportBindingElement transport, HttpTransportSecurity transportSecurity, out WSFederationHttpSecurityMode mode)
 {
     mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message | WSFederationHttpSecurityMode.TransportWithMessageCredential;
     if (transport is HttpsTransportBindingElement)
     {
         mode = WSFederationHttpSecurityMode.TransportWithMessageCredential;
     }
     else if (transport is HttpTransportBindingElement)
     {
         mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message;
     }
     else
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Implements the constructor: TransportBindingElement()
 /// Direct superclasses: global::MetaDslx.Soal.BindingElement
 /// All superclasses: global::MetaDslx.Soal.BindingElement, global::MetaDslx.Soal.NamedElement
 /// </summary>
 public virtual void TransportBindingElement(TransportBindingElement @this)
 {
     this.BindingElement(@this);
 }
 internal static bool TryGetAllowCookiesFromTransport(TransportBindingElement transport, out bool allowCookies)
 {
     HttpTransportBindingElement element = transport as HttpTransportBindingElement;
     if (element == null)
     {
         allowCookies = false;
         return false;
     }
     allowCookies = element.AllowCookies;
     return true;
 }
Ejemplo n.º 44
0
 public PlainDsspBinding()
 {
     security = CreateSecurity();
     messageEncoding = CreateMessageEncoding();
     transport = CreateTransport();
 }
 private static void ImportAddress(WsdlEndpointConversionContext context, TransportBindingElement transportBindingElement)
 {
     EndpointAddress address = context.Endpoint.Address = WsdlImporter.WSAddressingHelper.ImportAddress(context.WsdlPort);
     if (address != null)
     {
         context.Endpoint.Address = address;
         if ((address.Uri.Scheme == Uri.UriSchemeHttps) && !(transportBindingElement is HttpsTransportBindingElement))
         {
             BindingElementCollection elements = ConvertToCustomBinding(context).Elements;
             elements.Remove(transportBindingElement);
             elements.Add(CreateHttpsFromHttp(transportBindingElement as HttpTransportBindingElement));
         }
     }
 }
 public ClientMultipleTokenBinding()
     : base("ClientMultipleTokenBinding", "http://schemas.microsoft.com/2006/11/ResourceManagement")
 {
     this.tranportBindingElement = new HttpTransportBindingElement();
 }
Ejemplo n.º 47
0
		bool ImportTransport (MetadataImporter importer, TransportBindingElement bindingElement,
		                      XmlElement transportPolicy)
		{
			XmlElement algorithmSuite, layout;
			if (!PolicyImportHelper.FindPolicyElement (
				importer, transportPolicy,
				new QName ("AlgorithmSuite", PolicyImportHelper.SecurityPolicyNS),
				false, true, out algorithmSuite) ||
			    !PolicyImportHelper.FindPolicyElement (
				importer, transportPolicy,
				new QName ("Layout", PolicyImportHelper.SecurityPolicyNS),
				false, true, out layout))
				return false;

			bool foundUnknown = false;
			foreach (var node in transportPolicy.ChildNodes) {
				var e = node as XmlElement;
				if (e == null)
					continue;
				importer.AddWarning ("Unknown policy assertion: {0}", e.OuterXml);
				foundUnknown = true;
			}

			return !foundUnknown;
		}
        /// <summary>
        /// Verifies that the quota values in a given transport binding element are maxed out.
        /// </summary>        
        private void VerifyTransportQuotas(TransportBindingElement transport, string bindingName)
        {
            if (transport != null)
            {
                if (typeof (HttpTransportBindingElement) == transport.GetType()) // http
                {
                    HttpTransportBindingElement httpTransport = transport as HttpTransportBindingElement;

                    if (httpTransport.TransferMode == TransferMode.Streamed ||
                        httpTransport.TransferMode == TransferMode.StreamedRequest)
                    {
                        Assert.IsTrue(httpTransport.MaxReceivedMessageSize == long.MaxValue,
                                      "Max receive message size is not maxed out in binding: {0}", bindingName);
                    }
                    else
                    {
                        Assert.IsTrue(httpTransport.MaxReceivedMessageSize == int.MaxValue,
                                      "Max receive message size is not maxed out in binding: {0}", bindingName);
                    }
                    Assert.IsTrue(httpTransport.MaxBufferSize == int.MaxValue,
                                  "Max buffer size is not maxed out in binding: {0}", bindingName);
                }
                else if (typeof (TcpTransportBindingElement) == transport.GetType()) // tcp                            
                {
                    TcpTransportBindingElement tcpTransport = transport as TcpTransportBindingElement;

                    if (tcpTransport.TransferMode == TransferMode.Streamed ||
                        tcpTransport.TransferMode == TransferMode.StreamedRequest)
                    {
                        Assert.IsTrue(tcpTransport.MaxReceivedMessageSize == long.MaxValue,
                                      "Max receive message size is not maxed out in binding: {0}", bindingName);
                    }
                    else
                    {
                        Assert.IsTrue(tcpTransport.MaxReceivedMessageSize == int.MaxValue,
                                      "Max receive message size is not maxed out in binding: {0}", bindingName);
                    }
                    Assert.IsTrue(tcpTransport.MaxBufferSize == int.MaxValue,
                                  "Max buffer size is not maxed out in binding: {0}", bindingName);
                }
                else if (typeof (NamedPipeTransportBindingElement) == transport.GetType()) // pipe
                {
                    NamedPipeTransportBindingElement pipeTransport = transport as NamedPipeTransportBindingElement;

                    if (pipeTransport.TransferMode == TransferMode.Streamed ||
                        pipeTransport.TransferMode == TransferMode.StreamedRequest)
                    {
                        Assert.IsTrue(pipeTransport.MaxReceivedMessageSize == long.MaxValue,
                                      "Max receive message size is not maxed out in binding: {0}", bindingName);
                    }
                    else
                    {
                        Assert.IsTrue(pipeTransport.MaxReceivedMessageSize == int.MaxValue,
                                      "Max receive message size is not maxed out in binding: {0}", bindingName);
                    }
                    Assert.IsTrue(pipeTransport.MaxBufferSize == int.MaxValue,
                                  "Max buffer size is not maxed out in binding: {0}", bindingName);
                }
                else if (typeof (MsmqTransportBindingElement) == transport.GetType()) // msmq
                {
                    MsmqTransportBindingElement msmqTransport = transport as MsmqTransportBindingElement;
                    Assert.IsTrue(msmqTransport.MaxReceivedMessageSize == long.MaxValue,
                                  "Max receive message size is not maxed out in binding: {0}", bindingName);
                }
                else
                {
                    // We don't know the transport type (probably a custom transport). So let's max it out to the int.MaxValue.
                    Assert.IsTrue(transport.MaxReceivedMessageSize == int.MaxValue,
                                  "Max receive message size is not maxed out in binding: {0}", bindingName);
                }
            }
        }