Esempio n. 1
0
        internal static bool TryCreate(SecurityBindingElement sbe, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, out BasicHttpSecurity security)
        {
            security = null;
            BasicHttpMessageSecurity messageSecurity = null;

            if (sbe != null)
            {
                mode &= UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential;
                bool isSecureTransportMode;
                if (!BasicHttpMessageSecurity.TryCreate(sbe, out messageSecurity, out isSecureTransportMode))
                {
                    return(false);
                }
            }
            else
            {
                mode &= ~(UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential);
            }
            BasicHttpSecurityMode basicHttpSecurityMode = BasicHttpSecurityModeHelper.ToSecurityMode(mode);

            Fx.Assert(BasicHttpSecurityModeHelper.IsDefined(basicHttpSecurityMode), string.Format("Invalid BasicHttpSecurityMode value: {0}.", basicHttpSecurityMode.ToString()));
            security = new BasicHttpSecurity(basicHttpSecurityMode, transportSecurity, messageSecurity);

            throw ExceptionHelper.PlatformNotSupported("BasicHttpSecurity MessageSecurity is not supported");
        }
Esempio n. 2
0
        internal static bool TryCreate(SecurityBindingElement sbe, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, out BasicHttpSecurity security)
        {
            security = null;
            BasicHttpMessageSecurity messageSecurity = null;

            if (sbe != null)
            {
                mode &= UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential;
                bool isSecureTransportMode;
                if (!BasicHttpMessageSecurity.TryCreate(sbe, out messageSecurity, out isSecureTransportMode))
                {
                    return(false);
                }
            }
            else
            {
                mode &= ~(UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential);
            }
            BasicHttpSecurityMode basicHttpSecurityMode = BasicHttpSecurityModeHelper.ToSecurityMode(mode);

            Fx.Assert(BasicHttpSecurityModeHelper.IsDefined(basicHttpSecurityMode), string.Format("Invalid BasicHttpSecurityMode value: {0}.", basicHttpSecurityMode.ToString()));
            security = new BasicHttpSecurity(basicHttpSecurityMode, transportSecurity, messageSecurity);

            return(System.ServiceModel.Configuration.SecurityElement.AreBindingsMatching(security.CreateMessageSecurity(), sbe));
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the System.ServiceModel.BasicHttpBinding class.
 /// </summary>
 public BasicHttpBinding()
 {
     Security = new BasicHttpSecurity()
     {
         Mode = BasicHttpSecurityMode.None
     };
 }
Esempio n. 4
0
        public override BindingElementCollection CreateBindingElements()
        {
            CheckSettings();

            // return collection of BindingElements
            BindingElementCollection bindingElements = new BindingElementCollection();

            // add security (*optional)
            SecurityBindingElement messageSecurity = BasicHttpSecurity.CreateMessageSecurity();

            if (messageSecurity != null)
            {
                bindingElements.Add(messageSecurity);
            }

            // add encoding
            switch (MessageEncoding)
            {
            case NetHttpMessageEncoding.Text:
                bindingElements.Add(TextMessageEncodingBindingElement);
                break;

            case NetHttpMessageEncoding.Mtom:
                throw ExceptionHelper.PlatformNotSupported(SR.Format(SR.UnsupportedBindingProperty, "MessageEncoding", MessageEncoding));

            default:
                bindingElements.Add(_binaryMessageEncodingBindingElement);
                break;
            }

            // add transport (http or https)
            bindingElements.Add(GetTransport());

            return(bindingElements.Clone());
        }
Esempio n. 5
0
 private static bool GetSecurityModeFromTransport(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity, out UnifiedSecurityMode mode)
 {
     mode = UnifiedSecurityMode.None;
     if (http == null)
     {
         return(false);
     }
     if (http is HttpsTransportBindingElement)
     {
         mode = UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Transport;
         BasicHttpSecurity.EnableTransportSecurity((HttpsTransportBindingElement)http, transportSecurity);
     }
     else if (HttpTransportSecurity.IsDisabledTransportAuthentication(http))
     {
         mode = UnifiedSecurityMode.Message | UnifiedSecurityMode.None;
     }
     else
     {
         if (!BasicHttpSecurity.IsEnabledTransportAuthentication(http, transportSecurity))
         {
             return(false);
         }
         mode = UnifiedSecurityMode.TransportCredentialOnly;
     }
     return(true);
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the System.ServiceModel.BasicHttpBinding class
 /// with a specified type of security used by the binding.
 /// </summary>
 /// <param name="securityMode">
 /// The value of System.ServiceModel.BasicHttpSecurityMode that specifies the
 /// type of security that is used with the SOAP message and for the client.
 /// </param>
 public BasicHttpBinding(BasicHttpSecurityMode securityMode)
 {
     Security = new BasicHttpSecurity()
     {
         Mode = securityMode
     };
 }
Esempio n. 7
0
        // In the Win8 profile, some settings for the binding security are not supported.
        internal virtual void CheckSettings()
        {
            BasicHttpSecurity security = this.BasicHttpSecurity;

            if (security == null)
            {
                return;
            }

            BasicHttpSecurityMode mode = security.Mode;

            if (mode == BasicHttpSecurityMode.None)
            {
                return;
            }
            else if (mode == BasicHttpSecurityMode.Message)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(string.Format(SRServiceModel.UnsupportedSecuritySetting, "Mode", mode)));
            }

            // Transport.ClientCredentialType = InheritedFromHost is not supported.
            Fx.Assert(
                (mode == BasicHttpSecurityMode.Transport) || (mode == BasicHttpSecurityMode.TransportCredentialOnly) || (mode == BasicHttpSecurityMode.TransportWithMessageCredential),
                "Unexpected BasicHttpSecurityMode value: " + mode);
            HttpTransportSecurity transport = security.Transport;

            if (transport?.ClientCredentialType == HttpClientCredentialType.InheritedFromHost)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(string.Format(SRServiceModel.UnsupportedSecuritySetting, "Transport.ClientCredentialType", transport.ClientCredentialType)));
            }
        }
Esempio n. 8
0
        internal static bool GetSecurityModeFromTransport(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity, out UnifiedSecurityMode mode)
        {
            mode = UnifiedSecurityMode.None;
            if (http == null)
            {
                return(false);
            }

            Fx.Assert(http.AuthenticationScheme.IsSingleton(), "authenticationScheme used in an Http(s)ChannelFactory must be a singleton value.");

            if (http is HttpsTransportBindingElement)
            {
                mode = UnifiedSecurityMode.Transport | UnifiedSecurityMode.TransportWithMessageCredential;
                BasicHttpSecurity.EnableTransportSecurity((HttpsTransportBindingElement)http, transportSecurity);
            }
            else if (HttpTransportSecurity.IsDisabledTransportAuthentication(http))
            {
                mode = UnifiedSecurityMode.Message | UnifiedSecurityMode.None;
            }
            else if (!BasicHttpSecurity.IsEnabledTransportAuthentication(http, transportSecurity))
            {
                return(false);
            }
            else
            {
                mode = UnifiedSecurityMode.TransportCredentialOnly;
            }

            return(true);
        }
 internal void ApplyConfiguration(BasicHttpSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     security.Mode = this.Mode;
     this.Transport.ApplyConfiguration(security.Transport);
     this.Message.ApplyConfiguration(security.Message);
 }
 internal void InitializeFrom(BasicHttpSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Mode, security.Mode);
     this.Transport.InitializeFrom(security.Transport);
     this.Message.InitializeFrom(security.Message);
 }
 internal void InitializeFrom(BasicHttpSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     this.Mode = security.Mode;
     this.Transport.InitializeFrom(security.Transport);
     this.Message.InitializeFrom(security.Message);
 }
Esempio n. 12
0
        internal static BasicHttpsSecurity ToBasicHttpsSecurity(BasicHttpSecurity basicHttpSecurity)
        {
            Fx.Assert(basicHttpSecurity != null, "basicHttpSecurity cannot be null");

            BasicHttpsSecurity basicHttpsSecurity = new BasicHttpsSecurity()
            {
                Transport = basicHttpSecurity.Transport,
                Mode      = BasicHttpsSecurityModeHelper.ToBasicHttpsSecurityMode(basicHttpSecurity.Mode)
            };

            return(basicHttpsSecurity);
        }
Esempio n. 13
0
 private void Initialize()
 {
     MessageEncoding = NetHttpBindingDefaults.MessageEncoding;
     _binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement()
     {
         MessageVersion = MessageVersion.Soap12WSAddressing10
     };
     TextMessageEncodingBindingElement.MessageVersion = MessageVersion.Soap12WSAddressing10;
     WebSocketSettings.TransportUsage = NetHttpBindingDefaults.TransportUsage;
     WebSocketSettings.SubProtocol    = WebSocketTransportSettings.SoapSubProtocol;
     _basicHttpSecurity = new BasicHttpSecurity();
 }
        internal static BasicHttpsSecurity ToBasicHttpsSecurity(BasicHttpSecurity basicHttpSecurity)
        {
            Fx.Assert(basicHttpSecurity != null, "basicHttpSecurity cannot be null");

            BasicHttpsSecurity basicHttpsSecurity = new BasicHttpsSecurity()
            {
                Transport = basicHttpSecurity.Transport,
                Mode = BasicHttpsSecurityModeHelper.ToBasicHttpsSecurityMode(basicHttpSecurity.Mode)
            };

            return basicHttpsSecurity;
        }
Esempio n. 15
0
        internal static BasicHttpSecurity ToBasicHttpSecurity(BasicHttpsSecurity basicHttpsSecurity)
        {
            Fx.Assert(basicHttpsSecurity != null, "Cannot pass in a null value for basicHttpsSecurity");

            BasicHttpSecurity basicHttpSecurity = new BasicHttpSecurity()
            {
                Transport = basicHttpsSecurity.Transport,
                Mode = BasicHttpsSecurityModeHelper.ToBasicHttpSecurityMode(basicHttpsSecurity.Mode)
            };

            return basicHttpSecurity;
        }
Esempio n. 16
0
        internal static BasicHttpSecurity ToBasicHttpSecurity(BasicHttpsSecurity basicHttpsSecurity)
        {
            Fx.Assert(basicHttpsSecurity != null, "Cannot pass in a null value for basicHttpsSecurity");

            BasicHttpSecurity basicHttpSecurity = new BasicHttpSecurity()
            {
                Transport = basicHttpsSecurity.Transport,
                Mode      = BasicHttpsSecurityModeHelper.ToBasicHttpSecurityMode(basicHttpsSecurity.Mode)
            };

            return(basicHttpSecurity);
        }
Esempio n. 17
0
 private void Initialize()
 {
     _messageEncoding = NetHttpBindingDefaults.MessageEncoding;
     _binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement()
     {
         MessageVersion = MessageVersion.Soap12WSAddressing10
     };
     this.TextMessageEncodingBindingElement.MessageVersion = MessageVersion.Soap12WSAddressing10;
     _session         = new ReliableSessionBindingElement();
     _reliableSession = new OptionalReliableSession(_session);
     this.WebSocketSettings.TransportUsage = NetHttpBindingDefaults.TransportUsage;
     this.WebSocketSettings.SubProtocol    = WebSocketTransportSettings.SoapSubProtocol;
     _basicHttpSecurity = new BasicHttpSecurity();
 }
Esempio n. 18
0
 private BasicHttpsSecurity(BasicHttpsSecurityMode mode, HttpTransportSecurity transportSecurity)
 {
     if (!BasicHttpsSecurityModeHelper.IsDefined(mode))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("mode"));
     }
     HttpTransportSecurity httpTransportSecurity = transportSecurity == null ? new HttpTransportSecurity() : transportSecurity;
     BasicHttpSecurityMode basicHttpSecurityMode = BasicHttpsSecurityModeHelper.ToBasicHttpSecurityMode(mode);
     _basicHttpSecurity = new BasicHttpSecurity()
     {
         Mode = basicHttpSecurityMode,
         Transport = httpTransportSecurity
     };
 }
Esempio n. 19
0
    public static void Default_Ctor_Initializes_Properties()
    {
        BasicHttpSecurity security = new BasicHttpSecurity();

        // These properties are not in a public contract
        BasicHttpSecurityMode expectedMode = BasicHttpSecurityMode.None;
        BasicHttpSecurityMode actualMode = security.Mode;
        Assert.True(expectedMode == actualMode, String.Format("Mode expected: {0}, actual: {1}", expectedMode, actualMode));

        HttpTransportSecurity transportSecurity = security.Transport;
        Assert.True(transportSecurity != null, "Transport property should have been non-null");

        BasicHttpMessageSecurity httpSecurity = security.Message;
        Assert.True(httpSecurity != null, "Message property should have been non-null");
    }
Esempio n. 20
0
        private BasicHttpsSecurity(BasicHttpsSecurityMode mode, HttpTransportSecurity transportSecurity)
        {
            if (!BasicHttpsSecurityModeHelper.IsDefined(mode))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(mode)));
            }
            HttpTransportSecurity httpTransportSecurity = transportSecurity == null ? new HttpTransportSecurity() : transportSecurity;
            BasicHttpSecurityMode basicHttpSecurityMode = BasicHttpsSecurityModeHelper.ToBasicHttpSecurityMode(mode);

            BasicHttpSecurity = new BasicHttpSecurity()
            {
                Mode      = basicHttpSecurityMode,
                Transport = httpTransportSecurity
            };
        }
Esempio n. 21
0
        private static void GetHttpBindingBaseDetails(HttpBindingBase binding, ref string name, ref string mode, ref string credentialType)
        {
            if (binding is BasicHttpContextBinding)
            {
                name = GetBindingName <BasicHttpContextBinding>(binding);
            }
            else if (binding is BasicHttpBinding)
            {
                name = GetBindingName <BasicHttpBinding>(binding);
            }
            else if (binding is NetHttpBinding)
            {
                name = GetBindingName <NetHttpBinding>(binding);
            }
            else if (binding is NetHttpsBinding)
            {
                name = GetBindingName <NetHttpsBinding>(binding);
            }
            else if (binding is BasicHttpsBinding)
            {
                name = GetBindingName <BasicHttpsBinding>(binding);
            }
            else
            {
                name = GetBindingName <HttpBindingBase>(binding);
            }

            BasicHttpSecurity basicHttpSecurity = binding.BasicHttpSecurity;

            mode = basicHttpSecurity?.Mode.ToString();
            switch (basicHttpSecurity?.Mode)
            {
            case BasicHttpSecurityMode.None:
                credentialType = "N/A";
                break;

            case BasicHttpSecurityMode.Transport:
            case BasicHttpSecurityMode.TransportCredentialOnly:
                credentialType = basicHttpSecurity.Transport?.ClientCredentialType.ToString();
                break;

            case BasicHttpSecurityMode.Message:
            case BasicHttpSecurityMode.TransportWithMessageCredential:
                credentialType = $"{basicHttpSecurity.Transport?.ClientCredentialType.ToString()}+{basicHttpSecurity.Message?.ClientCredentialType.ToString()}";
                break;
            }
        }
        BasicHttpsSecurity(BasicHttpsSecurityMode mode, HttpTransportSecurity transportSecurity, BasicHttpMessageSecurity messageSecurity)
        {
            if (!BasicHttpsSecurityModeHelper.IsDefined(mode))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("mode"));
            }
            HttpTransportSecurity    httpTransportSecurity = transportSecurity == null ? new HttpTransportSecurity() : transportSecurity;
            BasicHttpMessageSecurity httpMessageSecurity   = messageSecurity == null ? new BasicHttpMessageSecurity() : messageSecurity;
            BasicHttpSecurityMode    basicHttpSecurityMode = BasicHttpsSecurityModeHelper.ToBasicHttpSecurityMode(mode);

            this.basicHttpSecurity = new BasicHttpSecurity()
            {
                Mode      = basicHttpSecurityMode,
                Transport = httpTransportSecurity,
                Message   = httpMessageSecurity
            };
        }
        // In the Win8 profile, some settings for the binding security are not supported.
        internal virtual void CheckSettings()
        {
            if (!UnsafeNativeMethods.IsTailoredApplication.Value)
            {
                return;
            }

            BasicHttpSecurity security = this.BasicHttpSecurity;

            if (security == null)
            {
                return;
            }

            BasicHttpSecurityMode mode = security.Mode;

            if (mode == BasicHttpSecurityMode.None)
            {
                return;
            }
            else if (mode == BasicHttpSecurityMode.Message)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedSecuritySetting, "Mode", mode)));
            }

            // Message.ClientCredentialType = Certificate is not supported.
            if (mode == BasicHttpSecurityMode.TransportWithMessageCredential)
            {
                BasicHttpMessageSecurity message = security.Message;
                if ((message != null) && (message.ClientCredentialType == BasicHttpMessageCredentialType.Certificate))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedSecuritySetting, "Message.ClientCredentialType", message.ClientCredentialType)));
                }
            }

            // Transport.ClientCredentialType = Certificate or InheritedFromHost are not supported.
            Fx.Assert(
                (mode == BasicHttpSecurityMode.Transport) || (mode == BasicHttpSecurityMode.TransportCredentialOnly) || (mode == BasicHttpSecurityMode.TransportWithMessageCredential),
                "Unexpected BasicHttpSecurityMode value: " + mode);
            HttpTransportSecurity transport = security.Transport;

            if ((transport != null) && ((transport.ClientCredentialType == HttpClientCredentialType.Certificate) || (transport.ClientCredentialType == HttpClientCredentialType.InheritedFromHost)))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedSecuritySetting, "Transport.ClientCredentialType", transport.ClientCredentialType)));
            }
        }
Esempio n. 24
0
        public override BindingElementCollection CreateBindingElements()
        {
            CheckSettings();

            // return collection of BindingElements
            BindingElementCollection bindingElements = new BindingElementCollection();

            // order of BindingElements is important
            // add session
            if (_reliableSession.Enabled)
            {
                bindingElements.Add(_session);
            }

            // add security (*optional)
            SecurityBindingElement messageSecurity = BasicHttpSecurity.CreateMessageSecurity();

            if (messageSecurity != null)
            {
                bindingElements.Add(messageSecurity);
            }

            // add encoding
            switch (MessageEncoding)
            {
            case NetHttpMessageEncoding.Text:
                bindingElements.Add(TextMessageEncodingBindingElement);
                break;

            case NetHttpMessageEncoding.Mtom:
                bindingElements.Add(MtomMessageEncodingBindingElement);
                break;

            default:
                bindingElements.Add(_binaryMessageEncodingBindingElement);
                break;
            }

            // add transport (http or https)
            bindingElements.Add(GetTransport());

            return(bindingElements.Clone());
        }
Esempio n. 25
0
        internal TransportBindingElement GetTransport()
        {
            Fx.Assert(this.BasicHttpSecurity != null, "this.BasicHttpSecurity should not return null from a derived class.");

            BasicHttpSecurity basicHttpSecurity = this.BasicHttpSecurity;

            if (basicHttpSecurity.Mode == BasicHttpSecurityMode.Transport || basicHttpSecurity.Mode == BasicHttpSecurityMode.TransportWithMessageCredential)
            {
                basicHttpSecurity.EnableTransportSecurity(_httpsTransport);
                return(_httpsTransport);
            }
            else if (basicHttpSecurity.Mode == BasicHttpSecurityMode.TransportCredentialOnly)
            {
                basicHttpSecurity.EnableTransportAuthentication(_httpTransport);
                return(_httpTransport);
            }
            else
            {
                // ensure that there is no transport security
                basicHttpSecurity.DisableTransportAuthentication(_httpTransport);
                return(_httpTransport);
            }
        }
        internal static bool TryCreate(SecurityBindingElement sbe, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, out BasicHttpSecurity security)
        {
            security = null;
            BasicHttpMessageSecurity security2 = null;

            if (sbe != null)
            {
                bool flag;
                mode &= UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Message;
                if (!BasicHttpMessageSecurity.TryCreate(sbe, out security2, out flag))
                {
                    return(false);
                }
            }
            else
            {
                mode &= ~(UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Message);
            }
            BasicHttpSecurityMode mode2 = BasicHttpSecurityModeHelper.ToSecurityMode(mode);

            security = new BasicHttpSecurity(mode2, transportSecurity, security2);
            return(SecurityElementBase.AreBindingsMatching(security.CreateMessageSecurity(), sbe));
        }
Esempio n. 27
0
		public BasicHttpBinding (
			BasicHttpSecurityMode securityMode)
		{
			security = new BasicHttpSecurity (securityMode);
		}
 NetHttpBinding(BasicHttpSecurity security)
     : base()
 {
     this.Initialize();
     this.basicHttpSecurity = security;
 }
Esempio n. 29
0
 public BasicHttpBinding(
     BasicHttpSecurityMode securityMode)
 {
     security = new BasicHttpSecurity(securityMode);
 }
			public BasicHttpSecurityConfiguration (BasicHttpSecurity security)
			{
				Security = security;
			}
 private void Initialize()
 {
     _basicHttpSecurity = new BasicHttpSecurity();
 }
Esempio n. 32
0
 internal static bool TryCreateSecurity(SecurityBindingElement securityElement, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, out BasicHttpSecurity security)
 {
     return(BasicHttpSecurity.TryCreate(securityElement, mode, transportSecurity, out security));
 }
Esempio n. 33
0
 private BasicHttpBinding(BasicHttpSecurity security)
 {
     this.security = new BasicHttpSecurity();
     this.Initialize();
     this.security = security;
 }
 public BasicHttpBinding(BasicHttpSecurityMode securityMode)
 {
     this.security = new BasicHttpSecurity();
     this.Initialize();
     this.security.Mode = securityMode;
 }
Esempio n. 35
0
 internal static bool TryCreateSecurity(SecurityBindingElement securityElement, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, out BasicHttpSecurity security)
 {
     return BasicHttpSecurity.TryCreate(securityElement, mode, transportSecurity, out security);
 }
 private BasicHttpBinding(BasicHttpSecurity security)
 {
     this.security = new BasicHttpSecurity();
     this.Initialize();
     this.security = security;
 }
Esempio n. 37
0
 private BasicHttpBinding(BasicHttpSecurity security)
     : base()
 {
     this.Initialize();
     _basicHttpSecurity = security;
 }
Esempio n. 38
0
 void Initialize()
 {
     this.basicHttpSecurity = new BasicHttpSecurity();
 }
 internal static bool TryCreate(SecurityBindingElement sbe, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, out BasicHttpSecurity security)
 {
     security = null;
     BasicHttpMessageSecurity security2 = null;
     if (sbe != null)
     {
         bool flag;
         mode &= UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Message;
         if (!BasicHttpMessageSecurity.TryCreate(sbe, out security2, out flag))
         {
             return false;
         }
     }
     else
     {
         mode &= ~(UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Message);
     }
     BasicHttpSecurityMode mode2 = BasicHttpSecurityModeHelper.ToSecurityMode(mode);
     security = new BasicHttpSecurity(mode2, transportSecurity, security2);
     return SecurityElementBase.AreBindingsMatching(security.CreateMessageSecurity(), sbe);
 }
Esempio n. 40
0
 private static BasicHttpBinding CreateDefaultBinding()
 {
     BasicHttpBinding binding = new BasicHttpBinding();
     binding.CloseTimeout = new TimeSpan(0, 1, 0);
     binding.OpenTimeout = new TimeSpan(0, 1, 0);
     binding.SendTimeout = new TimeSpan(0, 10, 0);
     binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
     binding.AllowCookies = false;
     binding.BypassProxyOnLocal = false;
     binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
     binding.MaxBufferSize = 65536;
     binding.MaxReceivedMessageSize = 65536L;
     binding.MaxBufferPoolSize = 524288L;
     binding.MessageEncoding = WSMessageEncoding.Text;
     binding.TextEncoding = Encoding.UTF8;
     binding.TransferMode = TransferMode.Buffered;
     binding.UseDefaultWebProxy = true;
     XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
     readerQuotas.MaxDepth = 32;
     readerQuotas.MaxStringContentLength = 8192;
     readerQuotas.MaxArrayLength = 16384;
     readerQuotas.MaxBytesPerRead = 4096;
     readerQuotas.MaxNameTableCharCount = 16384;
     binding.ReaderQuotas = readerQuotas;
     BasicHttpSecurity security = new BasicHttpSecurity();
     security.Mode = BasicHttpSecurityMode.Transport;
     HttpTransportSecurity transport = new HttpTransportSecurity();
     transport.ClientCredentialType = HttpClientCredentialType.None;
     transport.ProxyCredentialType = HttpProxyCredentialType.None;
     transport.Realm = string.Empty;
     security.Transport = transport;
     BasicHttpMessageSecurity message = new BasicHttpMessageSecurity();
     message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
     message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
     security.Message = message;
     binding.Security = security;
     return binding;
 }
        internal static bool TryCreate(SecurityBindingElement sbe, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, out BasicHttpSecurity security)
        {
            security = null;
            BasicHttpMessageSecurity messageSecurity = null;
            if (sbe != null)
            {
                mode &= UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential;
                bool isSecureTransportMode;
                if (!BasicHttpMessageSecurity.TryCreate(sbe, out messageSecurity, out isSecureTransportMode))
                {
                    return false;
                }
            }
            else
            {
                mode &= ~(UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential);
            }
            BasicHttpSecurityMode basicHttpSecurityMode = BasicHttpSecurityModeHelper.ToSecurityMode(mode);
            Fx.Assert(BasicHttpSecurityModeHelper.IsDefined(basicHttpSecurityMode), string.Format("Invalid BasicHttpSecurityMode value: {0}.", basicHttpSecurityMode.ToString()));
            security = new BasicHttpSecurity(basicHttpSecurityMode, transportSecurity, messageSecurity);

            return SecurityElement.AreBindingsMatching(security.CreateMessageSecurity(), sbe);
        }
Esempio n. 42
0
 public BasicHttpBinding(BasicHttpSecurityMode securityMode)
 {
     this.security = new BasicHttpSecurity();
     this.Initialize();
     this.security.Mode = securityMode;
 }
 public BasicHttpSecurityConfiguration(BasicHttpSecurity security)
 {
     Security = security;
 }
Esempio n. 44
0
        public static List<BasicHttpBinding> GetBasicHttpBindings(string exeConfigPath)
        {
            var svcSection = Read.Config.ExeConfig.GetServiceModelSection(exeConfigPath);

            var configs = new List<BasicHttpBinding>();
            foreach (
                var section in
                    svcSection.Bindings.BasicHttpBinding.ConfiguredBindings
                        .Cast<BasicHttpBindingElement>())
            {
                var df = new BasicHttpBinding();
                var binding = new BasicHttpBinding
                {
                    Name = section.Name,

                    MaxBufferPoolSize = section.MaxBufferPoolSize > 0 ? section.MaxBufferPoolSize : df.MaxBufferPoolSize,
                    MaxReceivedMessageSize =
                        section.MaxReceivedMessageSize > 0 ? section.MaxReceivedMessageSize : df.MaxReceivedMessageSize,
                    CloseTimeout = section.CloseTimeout != TimeSpan.Zero ? section.CloseTimeout : df.CloseTimeout,
                    OpenTimeout = section.OpenTimeout != TimeSpan.Zero ? section.OpenTimeout : df.OpenTimeout,
                    SendTimeout = section.SendTimeout != TimeSpan.Zero ? section.SendTimeout : df.SendTimeout,
                    ReceiveTimeout =
                        section.ReceiveTimeout != TimeSpan.Zero ? section.ReceiveTimeout : df.ReceiveTimeout,

                    TextEncoding = section.TextEncoding ?? df.TextEncoding,

                    MessageEncoding = section.MessageEncoding,
                    AllowCookies = section.AllowCookies,
                    BypassProxyOnLocal = section.BypassProxyOnLocal,
                    HostNameComparisonMode = section.HostNameComparisonMode,
                    UseDefaultWebProxy = section.UseDefaultWebProxy,
                };

                var readerQuotasSection = section.ReaderQuotas;
                var readerQuotas = new System.Xml.XmlDictionaryReaderQuotas();
                if (readerQuotasSection != null && readerQuotasSection.MaxDepth > 0)
                {
                    readerQuotas.MaxDepth = readerQuotasSection.MaxDepth;
                    readerQuotas.MaxStringContentLength = readerQuotasSection.MaxStringContentLength;
                    readerQuotas.MaxArrayLength = readerQuotasSection.MaxArrayLength;
                    readerQuotas.MaxBytesPerRead = readerQuotasSection.MaxBytesPerRead;
                    readerQuotas.MaxNameTableCharCount = readerQuotasSection.MaxNameTableCharCount;
                }
                else
                {
                    readerQuotas = null;
                }

                var messageSection = section.Security.Message;
                var message = new BasicHttpMessageSecurity
                {
                    ClientCredentialType = messageSection.ClientCredentialType,
                    AlgorithmSuite = messageSection.AlgorithmSuite,
                };
                var transportSection = section.Security.Transport;
                var transport = new HttpTransportSecurity
                {
                    ClientCredentialType = transportSection.ClientCredentialType,
                    ProxyCredentialType = transportSection.ProxyCredentialType
                };
                var basicHttpSecurity = new BasicHttpSecurity()
                {
                    Message = message,
                    Mode = section.Security.Mode,
                    Transport = transport
                };

                binding.Security = basicHttpSecurity;
                if (readerQuotas != null)
                {
                    binding.ReaderQuotas = readerQuotas;
                }

                configs.Add(binding);
            }
            return configs;
        }
Esempio n. 45
0
 private NetHttpBinding(BasicHttpSecurity security)
     : base()
 {
     Initialize();
     _basicHttpSecurity = security;
 }