public BinaryFormatter(ISurrogateSelector selector, StreamingContext context)
 {
     this.m_typeFormat = FormatterTypeStyle.TypesAlways;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates = selector;
     this.m_context = context;
 }
		public SoapCore (object owner, IDictionary properties, string[] allowedProperties)
		{
			_properties = properties;

			foreach(DictionaryEntry property in properties)
			{
				string key = (string) property.Key;
				if (Array.IndexOf (allowedProperties, key) == -1)
					throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
				
				switch (key)
				{
					case "includeVersions": 
						_includeVersions = Convert.ToBoolean (property.Value);
						break;
						
					case "strictBinding":
						_strictBinding = Convert.ToBoolean (property.Value);
						break;
#if NET_1_1
					case "typeFilterLevel":
						if (property.Value is TypeFilterLevel)
							_filterLevel = (TypeFilterLevel) property.Value;
						else {
							string s = (string) property.Value;
							_filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
						}
						break;
#endif
				}
			}
			
			Init ();
		}
 public BinaryFormatter()
 {
     this.m_typeFormat = FormatterTypeStyle.TypesAlways;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates = null;
     this.m_context = new StreamingContext(StreamingContextStates.All);
 }
Example #4
0
 public BinaryFormatter()
 {
     this.m_typeFormat    = FormatterTypeStyle.TypesAlways;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates    = null;
     this.m_context       = new StreamingContext(StreamingContextStates.All);
 }
Example #5
0
 public BinaryFormatter(ISurrogateSelector selector, StreamingContext context)
 {
     this.m_typeFormat    = FormatterTypeStyle.TypesAlways;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates    = selector;
     this.m_context       = context;
 }
 public SoapFormatter()
 {
     this.m_assemblyFormat = FormatterAssemblyStyle.Full;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates = null;
     this.m_context = new StreamingContext(StreamingContextStates.All);
 }
Example #7
0
        private static T FormatterClone <T>(
            T obj,
            ISerializationSurrogate surrogate     = null,
            FormatterAssemblyStyle assemblyFormat = FormatterAssemblyStyle.Full,
            TypeFilterLevel filterLevel           = TypeFilterLevel.Full,
            FormatterTypeStyle typeFormat         = FormatterTypeStyle.TypesAlways)
        {
            BinaryFormatter f;

            if (surrogate == null)
            {
                f = new BinaryFormatter();
            }
            else
            {
                var c = new StreamingContext();
                var s = new SurrogateSelector();
                s.AddSurrogate(obj.GetType(), c, surrogate);
                f = new BinaryFormatter(s, c);
            }
            f.AssemblyFormat = assemblyFormat;
            f.FilterLevel    = filterLevel;
            f.TypeFormat     = typeFormat;

            using (var s = new MemoryStream())
            {
                f.Serialize(s, obj);
                Assert.NotEqual(0, s.Position);
                s.Position = 0;
                return((T)(f.Deserialize(s)));
            }
        }
 public SoapFormatter(ISurrogateSelector selector, StreamingContext context)
 {
     this.m_assemblyFormat = FormatterAssemblyStyle.Full;
     this.m_securityLevel = TypeFilterLevel.Full;
     this.m_surrogates = selector;
     this.m_context = context;
 }
Example #9
0
 public SoapFormatter(ISurrogateSelector selector, StreamingContext context)
 {
     this.m_assemblyFormat = FormatterAssemblyStyle.Full;
     this.m_securityLevel  = TypeFilterLevel.Full;
     this.m_surrogates     = selector;
     this.m_context        = context;
 }
        } // BinaryServerFormatterSinkProvider

        public BinaryServerFormatterSinkProvider(IDictionary properties, ICollection providerData)
        {
            // look at properties
            if (properties != null)
            {
                foreach (DictionaryEntry entry in properties)
                {
                    String keyStr = entry.Key.ToString();
                    switch (keyStr)
                    {
                    case "includeVersions": _includeVersioning = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture); break;

                    case "strictBinding": _strictBinding = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture); break;

                    case "typeFilterLevel":
                        _formatterSecurityLevel = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), (string)entry.Value);
                        break;

                    default:
                        break;
                    }
                }
            }

            // not expecting any provider data
            CoreChannel.VerifyNoProviderData(this.GetType().Name, providerData);
        } // BinaryServerFormatterSinkProvider
Example #11
0
 public SoapFormatter()
 {
     this.m_assemblyFormat = FormatterAssemblyStyle.Full;
     this.m_securityLevel  = TypeFilterLevel.Full;
     this.m_surrogates     = null;
     this.m_context        = new StreamingContext(StreamingContextStates.All);
 }
Example #12
0
 // Constructor.
 public BinaryFormatter()
 {
     this.context        = new StreamingContext(StreamingContextStates.All);
     this.assemblyFormat = FormatterAssemblyStyle.Full;
     this.typeFormat     = FormatterTypeStyle.TypesAlways;
     this.filterLevel    = TypeFilterLevel.Full;
     this.converter      = new FormatterConverter();
 }
Example #13
0
 public ObjectReader(BinaryFormatter formatter)
 {
     this._surrogateSelector = formatter.SurrogateSelector;
     this._context           = formatter.Context;
     this._binder            = formatter.Binder;
     this._manager           = new ObjectManager(this._surrogateSelector, this._context);
     this._filterLevel       = formatter.FilterLevel;
 }
	// Constructor.
	public BinaryFormatter()
			{
				this.context = new StreamingContext(StreamingContextStates.All);
				this.assemblyFormat = FormatterAssemblyStyle.Full;
				this.typeFormat = FormatterTypeStyle.TypesAlways;
				this.filterLevel = TypeFilterLevel.Full;
				this.converter = new FormatterConverter();
			}
	public BinaryFormatter(ISurrogateSelector selector,
						   StreamingContext context)
			{
				this.surrogateSelector = selector;
				this.context = context;
				this.assemblyFormat = FormatterAssemblyStyle.Full;
				this.typeFormat = FormatterTypeStyle.TypesAlways;
				this.filterLevel = TypeFilterLevel.Full;
				this.converter = new FormatterConverter();
			}
Example #16
0
        public ObjectReader(BinaryFormatter formatter)
        {
//			_formatter = formatter;
            _surrogateSelector = formatter.SurrogateSelector;
            _context           = formatter.Context;
            _binder            = formatter.Binder;
            _manager           = new ObjectManager(_surrogateSelector, _context);

            _filterLevel = formatter.FilterLevel;
        }
Example #17
0
		public ObjectReader (BinaryFormatter formatter)
		{
//			_formatter = formatter;
			_surrogateSelector = formatter.SurrogateSelector;
			_context = formatter.Context;
			_binder = formatter.Binder;
			_manager = new ObjectManager (_surrogateSelector, _context);
			
			_filterLevel = formatter.FilterLevel;
		}
Example #18
0
 public BinaryFormatter(ISurrogateSelector selector,
                        StreamingContext context)
 {
     this.surrogateSelector = selector;
     this.context           = context;
     this.assemblyFormat    = FormatterAssemblyStyle.Full;
     this.typeFormat        = FormatterTypeStyle.TypesAlways;
     this.filterLevel       = TypeFilterLevel.Full;
     this.converter         = new FormatterConverter();
 }
 /// <summary>Determines whether the specified <see cref="T:System.Type" /> can be deserialized with the <see cref="T:System.Runtime.Serialization.Formatters.TypeFilterLevel" /> property set to Low.</summary>
 /// <param name="t">The <see cref="T:System.Type" /> to check for the ability to deserialize. </param>
 /// <param name="securityLevel">The <see cref="T:System.Runtime.Serialization.Formatters.TypeFilterLevel" /> property value. </param>
 /// <exception cref="T:System.Security.SecurityException">The <paramref name="t" /> parameter is an advanced type and cannot be deserialized when the <see cref="T:System.Runtime.Serialization.Formatters.TypeFilterLevel" /> property is set to Low. </exception>
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     if (securityLevel == TypeFilterLevel.Full)
     {
         return;
     }
     FormatterServices.CheckNotAssignable(typeof(DelegateSerializationHolder), t);
     FormatterServices.CheckNotAssignable(typeof(ISponsor), t);
     FormatterServices.CheckNotAssignable(typeof(IEnvoyInfo), t);
     FormatterServices.CheckNotAssignable(typeof(ObjRef), t);
 }
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     if (securityLevel == TypeFilterLevel.Full)
     {
         return;
     }
     CheckNotAssignable(typeof(System.DelegateSerializationHolder), t);
     CheckNotAssignable(typeof(System.Runtime.Remoting.Lifetime.ISponsor), t);
     CheckNotAssignable(typeof(System.Runtime.Remoting.IEnvoyInfo), t);
     CheckNotAssignable(typeof(System.Runtime.Remoting.ObjRef), t);
 }
Example #21
0
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     if (securityLevel == TypeFilterLevel.Low)
     {
         for (int i = 0; i < advancedTypes.Length; i++)
         {
             if (advancedTypes[i].IsAssignableFrom(t))
             {
                 throw new SecurityException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_TypeSecurity"), new object[] { advancedTypes[i].FullName, t.FullName }));
             }
         }
     }
 }
Example #22
0
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     if (securityLevel == TypeFilterLevel.Low)
     {
         for (int i = 0; i < advancedTypes.Length; i++)
         {
             if (advancedTypes[i].IsAssignableFrom(t))
             {
                 throw new SecurityException(Environment.GetResourceString("Serialization_TypeSecurity", advancedTypes[i].FullName, t.FullName));
             }
         }
     }
 }
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     if (securityLevel == TypeFilterLevel.Low)
     {
         for (int i = 0; i < advancedTypes.Length; i++)
         {
             if (advancedTypes[i].IsAssignableFrom(t))
             {
                 throw new SecurityException(Environment.GetResourceString("Serialization_TypeSecurity", new object[] { advancedTypes[i].FullName, t.FullName }));
             }
         }
     }
 }
Example #24
0
        } // classUriHeaderHandler


        internal static IMessage DeserializeSoapRequestMessage(
            Stream inputStream, Header[] h, bool bStrictBinding, TypeFilterLevel securityLevel)
        {
            SoapFormatter fmt = CreateSoapFormatter(false, bStrictBinding);

            fmt.FilterLevel = securityLevel;
            MethodCall mc = new MethodCall(h);

            fmt.Deserialize(inputStream, new HeaderHandler(mc.HeaderHandler));

            IMessage resMessage = (IMessage)mc;

            return(resMessage);
        } // DeserializeSoapRequestMessage
	// Check whether a type can be deserialized.
	public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
			{
			#if CONFIG_REMOTING
				if(securityLevel == TypeFilterLevel.Low)
				{
					if(typeof(IEnvoyInfo).IsAssignableFrom(t) ||
					   typeof(ISponsor).IsAssignableFrom(t) ||
					   typeof(ObjRef).IsAssignableFrom(t))
					{
						throw new SecurityException
							(String.Format(_("Security_RemotingCheckType"), t));
					}
				}
			#endif
			}
Example #26
0
 // Check whether a type can be deserialized.
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
                 #if CONFIG_REMOTING
     if (securityLevel == TypeFilterLevel.Low)
     {
         if (typeof(IEnvoyInfo).IsAssignableFrom(t) ||
             typeof(ISponsor).IsAssignableFrom(t) ||
             typeof(ObjRef).IsAssignableFrom(t))
         {
             throw new SecurityException
                       (String.Format(_("Security_RemotingCheckType"), t));
         }
     }
                 #endif
 }
Example #27
0
        } // DeserializeSoapResponseMessage

        internal static IMessage DeserializeBinaryRequestMessage(
            String objectUri,
            Stream inputStream,
            bool bStrictBinding,
            TypeFilterLevel securityLevel)
        {
            BinaryFormatter fmt = CreateBinaryFormatter(false, bStrictBinding);

            fmt.FilterLevel = securityLevel;
            UriHeaderHandler uriHH = new UriHeaderHandler(objectUri);

            IMessage reqMsg =
                (IMessage)fmt.UnsafeDeserialize(inputStream, new HeaderHandler(uriHH.HeaderHandler));

            return(reqMsg);
        } // DeserializeBinaryRequestMessage
Example #28
0
        public BinaryCore(object owner, IDictionary properties, string[] allowedProperties)
        {
            _properties = properties;

            if (_properties == null)
            {
                _properties = new Hashtable(10);
            }

            foreach (DictionaryEntry property in properties)
            {
                string key = (string)property.Key;
                if (Array.IndexOf(allowedProperties, key) == -1)
                {
                    throw new RemotingException(owner.GetType().Name + " does not recognize '" + key + "' configuration property");
                }

                switch (key)
                {
                case "includeVersions":
                    _includeVersions = Convert.ToBoolean(property.Value);
                    break;

                case "strictBinding":
                    _strictBinding = Convert.ToBoolean(property.Value);
                    break;

#if NET_1_1
                case "typeFilterLevel":
                    if (property.Value is TypeFilterLevel)
                    {
                        _filterLevel = (TypeFilterLevel)property.Value;
                    }
                    else
                    {
                        string s = (string)property.Value;
                        _filterLevel = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), s);
                    }
                    break;
#endif
                }
            }

            Init();
        }
Example #29
0
        private void Initialise(TypeFilterLevel typeFilterLevel, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider, int port, bool listen, bool keepAlive, ulong keepAliveTime, ulong KeepAliveInterval, short maxRetries, int retryDelay, IPAddress bindToAddress)
        {
            _tcpKeepAliveEnabled  = keepAlive;
            _tcpKeepAliveTime     = keepAliveTime;
            _tcpKeepAliveInterval = KeepAliveInterval;
            _maxRetries           = maxRetries;
            _retryDelay           = retryDelay;
            _bindToAddress        = bindToAddress;

            if (clientSinkProvider == null)
            {
                clientSinkProvider = new BinaryClientFormatterSinkProvider();
            }
            if (serverSinkProvider == null)
            {
                Trace.WriteLine("Setting serialization filter: {0}", typeFilterLevel);
                BinaryServerFormatterSinkProvider tempProvider = new BinaryServerFormatterSinkProvider();
                tempProvider.TypeFilterLevel = typeFilterLevel;
                serverSinkProvider           = tempProvider;
            }

            // Initialise clientSinkProvider
            this.clientSinkProvider = clientSinkProvider;
            while (clientSinkProvider.Next != null)
            {
                clientSinkProvider = clientSinkProvider.Next;
            }
            clientSinkProvider.Next = new ClientTransportSinkProvider();

            messageSink = new ServerTransportSink(ChannelServices.CreateServerChannelSinkChain(serverSinkProvider, this));
            serverSinkProvider.GetChannelData(channelData);

            if (listen)
            {
                StartListening(port);
            }

            channelData = new TcpExChannelData(this);

            Manager.BeginReadMessage(_channelID, null, new AsyncCallback(messageSink.ReceiveMessage), _channelID);
        }
Example #30
0
		public BinaryCore (TypeFilterLevel filterLevel)
		{
			_filterLevel = filterLevel;
			_properties = new Hashtable ();
			Init ();
		}
Example #31
0
 public SafeBinaryCore(TypeFilterLevel defaultFilterLevel)
 {
     _filterLevel = defaultFilterLevel;
     _properties  = new Hashtable();
     Init();
 }
Example #32
0
        public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat)
        {
            object clone = FormatterClone(obj, null, assemblyFormat, filterLevel, typeFormat);

            if (!ReferenceEquals(obj, string.Empty)) // "" is interned and will roundtrip as the same object
            {
                Assert.NotSame(obj, clone);
            }

            CheckForAnyEquals(obj, clone);
        }
 public static void CheckTypeSecurity(Type t,  TypeFilterLevel securityLevel) {            
     if (securityLevel == TypeFilterLevel.Low){
         for(int i=0;i<advancedTypes.Length;i++){
             if (advancedTypes[i].IsAssignableFrom(t))
                 throw new SecurityException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_TypeSecurity"), advancedTypes[i].FullName, t.FullName));
         }                  
     }
 }    
Example #34
0
        private void Initialise(TypeFilterLevel typeFilterLevel, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider, int port, bool listen, bool keepAlive, ulong keepAliveTime, ulong KeepAliveInterval, short maxRetries, int retryDelay, IPAddress bindToAddress)
        {
            _tcpKeepAliveEnabled = keepAlive;
            _tcpKeepAliveTime = keepAliveTime;
            _tcpKeepAliveInterval = KeepAliveInterval;
            _maxRetries = maxRetries;
            _retryDelay = retryDelay;
            _bindToAddress = bindToAddress;

            if (clientSinkProvider == null)
                clientSinkProvider = new BinaryClientFormatterSinkProvider();
            if (serverSinkProvider == null)
            {
                Trace.WriteLine("Setting serialization filter: {0}", typeFilterLevel);
                BinaryServerFormatterSinkProvider tempProvider = new BinaryServerFormatterSinkProvider();
                tempProvider.TypeFilterLevel = typeFilterLevel;
                serverSinkProvider = tempProvider;
            }

            // Initialise clientSinkProvider
            this.clientSinkProvider = clientSinkProvider;
            while (clientSinkProvider.Next != null)
                clientSinkProvider = clientSinkProvider.Next;
            clientSinkProvider.Next = new ClientTransportSinkProvider();

            messageSink = new ServerTransportSink(ChannelServices.CreateServerChannelSinkChain(serverSinkProvider, this));
            serverSinkProvider.GetChannelData(channelData);

            if (listen)
            {
                StartListening(port);
            }

            channelData = new TcpExChannelData(this);

            Manager.BeginReadMessage(_channelID, null, new AsyncCallback(messageSink.ReceiveMessage), _channelID);
        }
Example #35
0
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     // nop
 }
        public void ValidateNonSerializableTypes(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat)
        {
            var f = new BinaryFormatter()
            {
                AssemblyFormat = assemblyFormat,
                FilterLevel    = filterLevel,
                TypeFormat     = typeFormat
            };

            using (var s = new MemoryStream())
            {
                Assert.Throws <SerializationException>(() => f.Serialize(s, obj));
            }
        }
Example #37
0
        public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat, bool unsafeDeserialize)
        {
            object result = FormatterClone(obj, null, assemblyFormat, filterLevel, typeFormat, unsafeDeserialize);

            if (!ReferenceEquals(obj, string.Empty)) // "" is interned and will roundtrip as the same object
            {
                Assert.NotSame(obj, result);
            }
            Assert.Equal(obj, result);
        }
Example #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TcpExChannel"/> class.
 /// </summary>
 /// <param name="filterLevel">The type filter level.</param>
 /// <param name="listen">if set to <c>true</c>, the channel will listen for incoming connections.</param>
 public TcpExChannel(TypeFilterLevel filterLevel, bool listen)
 {
     Initialise(filterLevel, null, null, 0, listen, true, 30000, 1000, 10, 1000, IPAddress.Any);
 }
        static void Main(string[] args)
        {
            try
            {
                RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
                bool            secure     = false;
                int             port       = 12345;
                string          ipc        = String.Empty;
                bool            showhelp   = false;
                TypeFilterLevel typefilter = TypeFilterLevel.Low;

                OptionSet p = new OptionSet()
                {
                    { "s|secure", "Enable secure mode", v => secure = v != null },
                    { "p|port=", "Specify the local TCP port to listen on", v => port = int.Parse(v) },
                    { "t|typefilter=", "Specify the type filter level (low,full), default low",
                      v => typefilter = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), v, true) },
                    { "i|ipc=", "Specify listening pipe name for IPC channel", v => ipc = v },
                    { "h|?|help", v => showhelp = v != null },
                };

                p.Parse(args);

                if (showhelp)
                {
                    Console.WriteLine("Example .NET Remoting Server");
                    Console.WriteLine("Copyright (c) James Forshaw 2014");
                    p.WriteOptionDescriptions(Console.Out);
                }
                else
                {
                    Trace.Listeners.Add(new ConsoleTraceListener(true));

                    IChannel    chan;
                    IDictionary properties = new Hashtable();

                    BinaryServerFormatterSinkProvider serverSinkProvider = new BinaryServerFormatterSinkProvider();
                    serverSinkProvider.TypeFilterLevel = typefilter;

                    if (!String.IsNullOrEmpty(ipc))
                    {
                        properties["portName"]        = ipc;
                        properties["authorizedGroup"] = "Everyone";

                        chan = new IpcChannel(properties, new BinaryClientFormatterSinkProvider(), serverSinkProvider);
                    }
                    else
                    {
                        properties["port"] = port;
                        chan = new TcpChannel(properties, new BinaryClientFormatterSinkProvider(), serverSinkProvider);
                    }

                    ChannelServices.RegisterChannel(chan, secure);    //register channel

                    RemotingConfiguration.RegisterWellKnownServiceType(
                        typeof(RemoteType),
                        "RemotingServer",
                        WellKnownObjectMode.Singleton);

                    bool isipc = chan is IpcChannel;

                    Console.WriteLine("Server Activated at {0}://{1}/RemotingServer", isipc ? "ipc" : "tcp", isipc ? ipc : "HOST:" + port.ToString());

                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Example #40
0
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     // nop
 }
Example #41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TcpExChannel"/> class.
 /// </summary>
 /// <param name="filterLevel">The type filter level.</param>
 /// <param name="port">Tcp port.</param>
 public TcpExChannel(TypeFilterLevel filterLevel, int port)
 {
     Initialise(filterLevel, null, null, port, true, true, 30000, 1000, 10, 1000, IPAddress.Any);
 }
Example #42
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TcpExChannel"/> class.
        /// </summary>
        /// <param name="properties">Channel initialization properties. <see cref="TcpExChannel"/></param>
        /// <param name="clientSinkProvider">The client sink provider.</param>
        /// <param name="serverSinkProvider">The server sink provider.</param>
        public TcpExChannel(IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
        {
            int             port = 0;
            bool            tcpKeepAliveEnabled  = true;
            ulong           tcpKeepAliveTime     = 30000;
            ulong           tcpKeepAliveInterval = 1000;
            short           maxRetries           = 10;
            int             retryDelay           = 1000;
            bool            listen          = false;
            TypeFilterLevel typeFilterLevel = TypeFilterLevel.Low;
            IPAddress       bindToAddress   = IPAddress.Any;

            if (properties.Contains("port"))
            {
                port   = Convert.ToInt32(properties["port"]);
                listen = true;
            }
            if (properties.Contains("priority"))
            {
                priority = Convert.ToInt32(properties["priority"]);
            }
            if (properties.Contains("name"))
            {
                name = (string)properties["name"];
            }
            if (properties.Contains("listen"))
            {
                listen = Convert.ToBoolean(properties["listen"]);
            }
            if (properties.Contains("bufferSize"))
            {
                Connection.BufferSize = Convert.ToInt32(properties["bufferSize"]);
            }
            if (properties.Contains("keepAlive"))
            {
                tcpKeepAliveEnabled = Convert.ToBoolean(properties["keepAlive"]);
            }
            if (properties.Contains("keepAliveEnabled"))
            {
                tcpKeepAliveEnabled = Convert.ToBoolean(properties["keepAliveEnabled"]);
            }
            if (properties.Contains("keepAliveTime"))
            {
                tcpKeepAliveTime = Convert.ToUInt64(properties["keepAliveTime"]);
            }
            if (properties.Contains("keepAliveInterval"))
            {
                tcpKeepAliveInterval = Convert.ToUInt64(properties["keepAliveInterval"]);
            }
            if (properties.Contains("maxRetries"))
            {
                maxRetries = Convert.ToInt16(properties["maxRetries"]);
            }
            if (properties.Contains("retryDelay"))
            {
                retryDelay = Convert.ToInt32(properties["retryDelay"]);
            }
            if (properties.Contains("bindTo"))
            {
                bindToAddress = IPAddress.Parse((string)properties["bindTo"]);
            }
            if (properties.Contains("connectDuringCreation"))
            {
                ConnectDuringCreation = Convert.ToBoolean(properties["connectDuringCreation"]);
            }
            if (properties.Contains("typeFilterLevel"))
            {
                if (properties["typeFilterLevel"] is string)
                {
                    typeFilterLevel = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), (string)properties["typeFilterLevel"]);
                }
                else
                {
                    typeFilterLevel = (TypeFilterLevel)properties["typeFilterLevel"];
                }
            }
            Initialise(typeFilterLevel, clientSinkProvider, serverSinkProvider, port, listen, tcpKeepAliveEnabled, tcpKeepAliveTime, tcpKeepAliveInterval, maxRetries, retryDelay, bindToAddress);
        }
Example #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TcpExChannel"/> class.
 /// </summary>
 /// <param name="filterLevel">The type filter level.</param>
 /// <param name="listen">if set to <c>true</c>, the channel will listen for incoming connections.</param>
 public TcpExChannel(TypeFilterLevel filterLevel, bool listen)
 {
     Initialise(filterLevel, null, null, 0, listen, true, 30000, 1000, 10, 1000, IPAddress.Any);
 }
 internal static IMessage DeserializeSoapRequestMessage(Stream inputStream, Header[] h, bool bStrictBinding, TypeFilterLevel securityLevel)
 {
     SoapFormatter formatter = CreateSoapFormatter(false, bStrictBinding);
     formatter.FilterLevel = securityLevel;
     MethodCall call = new MethodCall(h);
     formatter.Deserialize(inputStream, new HeaderHandler(call.HeaderHandler));
     return call;
 }
        } // DeserializeSoapResponseMessage


        internal static IMessage DeserializeBinaryRequestMessage(
            String objectUri, 
            Stream inputStream,
            bool bStrictBinding,
            TypeFilterLevel securityLevel)
        {
            BinaryFormatter fmt = CreateBinaryFormatter(false, bStrictBinding);
            fmt.FilterLevel = securityLevel; 

            UriHeaderHandler uriHH = new UriHeaderHandler(objectUri);

            IMessage reqMsg = 
                (IMessage)fmt.UnsafeDeserialize(inputStream, new HeaderHandler(uriHH.HeaderHandler));

            return reqMsg;
        } // DeserializeBinaryRequestMessage
 internal static IMessage DeserializeBinaryRequestMessage(string objectUri, Stream inputStream, bool bStrictBinding, TypeFilterLevel securityLevel)
 {
     BinaryFormatter formatter = CreateBinaryFormatter(false, bStrictBinding);
     formatter.FilterLevel = securityLevel;
     UriHeaderHandler handler = new UriHeaderHandler(objectUri);
     return (IMessage) formatter.UnsafeDeserialize(inputStream, new HeaderHandler(handler.HeaderHandler));
 }
        } // classUriHeaderHandler


        internal static IMessage DeserializeSoapRequestMessage(
            Stream inputStream, Header[] h, bool bStrictBinding, TypeFilterLevel securityLevel)
        {
            SoapFormatter fmt = CreateSoapFormatter(false, bStrictBinding);
            fmt.FilterLevel = securityLevel;

            MethodCall mc = new MethodCall(h);
            fmt.Deserialize(inputStream, new HeaderHandler(mc.HeaderHandler));

            IMessage resMessage = (IMessage)mc;

            return resMessage;
        } // DeserializeSoapRequestMessage
 public IBinaryConfiguration WithFilterLevel(TypeFilterLevel level)
 {
     _binaryFormatter.FilterLevel = level;
     return this;
 }
Example #49
0
 /// <summary>Determines whether the specified <see cref="T:System.Type" /> can be deserialized with the <see cref="T:System.Runtime.Serialization.Formatters.TypeFilterLevel" /> property set to Low.</summary><param name="t">The <see cref="T:System.Type" /> to check for the ability to deserialize. </param><param name="securityLevel">The <see cref="T:System.Runtime.Serialization.Formatters.TypeFilterLevel" /> property value. </param><exception cref="T:System.Security.SecurityException">The <paramref name="t" /> parameter is an advanced type and cannot be deserialized when the <see cref="T:System.Runtime.Serialization.Formatters.TypeFilterLevel" /> property is set to Low. </exception>
 public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
 {
     throw new NotImplementedException();
 }
        public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat)
        {
            object clone = BinaryFormatterHelpers.Clone(obj, null, assemblyFormat, filterLevel, typeFormat);

            // string.Empty and DBNull are both singletons
            if (!ReferenceEquals(obj, string.Empty) && !(obj is DBNull))
            {
                Assert.NotSame(obj, clone);
            }

            EqualityExtensions.CheckEquals(obj, clone, isSamePlatform: true);
        }
		public static void CheckTypeSecurity (Type t, TypeFilterLevel securityLevel)
		{
			if (securityLevel == TypeFilterLevel.Full) return;
			CheckNotAssignable (typeof(System.DelegateSerializationHolder), t);
			CheckNotAssignable (typeof(System.Runtime.Remoting.Lifetime.ISponsor), t);
			CheckNotAssignable (typeof(System.Runtime.Remoting.IEnvoyInfo), t);
			CheckNotAssignable (typeof(System.Runtime.Remoting.ObjRef), t);
		}
        } // BinaryServerFormatterSinkProvider


        public BinaryServerFormatterSinkProvider(IDictionary properties, ICollection providerData)
        {       
            // look at properties
            if (properties != null)
            {
                foreach (DictionaryEntry entry in properties)
                {
                    String keyStr = entry.Key.ToString();
                    switch (keyStr)
                    {
                    case "includeVersions": _includeVersioning = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture); break;
                    case "strictBinding": _strictBinding = Convert.ToBoolean(entry.Value, CultureInfo.InvariantCulture); break;
                    case "typeFilterLevel": 
                        _formatterSecurityLevel = (TypeFilterLevel) Enum.Parse(typeof(TypeFilterLevel), (string)entry.Value); 
                        break;

                    default:
                        break;
                    }
                }
            }
        
            // not expecting any provider data
            CoreChannel.VerifyNoProviderData(this.GetType().Name, providerData);        
        } // BinaryServerFormatterSinkProvider
Example #53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TcpExChannel"/> class.
 /// </summary>
 /// <param name="filterLevel">The type filter level.</param>
 /// <param name="port">Tcp port.</param>
 public TcpExChannel(TypeFilterLevel filterLevel, int port)
 {
     Initialise(filterLevel, null, null, port, true, true, 30000, 1000,10,1000, IPAddress.Any);
 }