Beispiel #1
0
        public RtmpServer(RtmpEndpoint endpoint)
		{
			_connections = new Hashtable();
			_socketListeners = new ArrayList();
            _endpoint = endpoint;
            _rtmpHandler = new RtmpHandler(endpoint);

            try
            {
                if (endpoint.ChannelDefinition.Properties.KeystoreFile != null)
                {

                    FileSystemResource fsr = new FileSystemResource(endpoint.ChannelDefinition.Properties.KeystoreFile);
                    if (fsr.Exists)
                    {
                        if (endpoint.ChannelDefinition.Properties.KeystorePassword != null)
                            _serverCertificate = new X509Certificate2(fsr.File.FullName, endpoint.ChannelDefinition.Properties.KeystorePassword);
                        else
                            _serverCertificate = X509Certificate.CreateFromCertFile(fsr.File.FullName);
                        log.Info(string.Format("Certificate issued to {0} and is valid from {1} until {2}.", _serverCertificate.Subject, _serverCertificate.GetEffectiveDateString(), _serverCertificate.GetExpirationDateString()));
                    }
                    else
                        log.Error("Certificate file not found");
                }
                else
                {
                    if (endpoint.ChannelDefinition.Properties.ServerCertificate != null)
                    {
                        StoreName storeName = (StoreName)Enum.Parse(typeof(StoreName), endpoint.ChannelDefinition.Properties.ServerCertificate.StoreName, false);
                        StoreLocation storeLocation = (StoreLocation)Enum.Parse(typeof(StoreLocation), endpoint.ChannelDefinition.Properties.ServerCertificate.StoreLocation, false);
                        X509FindType x509FindType = (X509FindType)Enum.Parse(typeof(X509FindType), endpoint.ChannelDefinition.Properties.ServerCertificate.X509FindType, false);
                        X509Store store = new X509Store(storeName, storeLocation);
                        store.Open(OpenFlags.ReadOnly);
                        X509Certificate2Collection certificateCollection = store.Certificates.Find(x509FindType, endpoint.ChannelDefinition.Properties.ServerCertificate.FindValue, false);
                        X509Certificate2Enumerator enumerator = certificateCollection.GetEnumerator();
                        if (enumerator.MoveNext())
                        {
                            _serverCertificate = enumerator.Current;
                            log.Info(string.Format("Certificate issued to {0} and is valid from {1} until {2}.", _serverCertificate.Subject, _serverCertificate.GetEffectiveDateString(), _serverCertificate.GetExpirationDateString()));
                        }
                        else
                            log.Error("Certificate not found");
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Error loading certificate.", ex);
            }
		}
Beispiel #2
0
        /// <summary>
        /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="configFolderPaths">Possible configuration file locations.</param>
        /// <param name="serviceBrowserAvailable">Indicates whether the service browser is avaliable.</param>
        public void Init(string[] configFolderPaths, bool serviceBrowserAvailable)
		{
			_messageBroker = new MessageBroker(this);

            string servicesConfigFile = null;
            for (int i = 0; i < configFolderPaths.Length; i++)
            {
                servicesConfigFile = Path.Combine(configFolderPaths[i], "services-config.xml");
                if (log.IsDebugEnabled)
                    log.Debug(__Res.GetString(__Res.MessageServer_TryingServiceConfig, servicesConfigFile));
                if (File.Exists(servicesConfigFile))
                    break;
            }
            if (servicesConfigFile != null && File.Exists(servicesConfigFile))
            {
                if (log.IsDebugEnabled)
                    log.Debug(__Res.GetString(__Res.MessageServer_LoadingServiceConfig, servicesConfigFile));
                _servicesConfiguration = ServicesConfiguration.Load(servicesConfigFile);
            }
            else
            {
                if (log.IsDebugEnabled)
                    log.Debug(__Res.GetString(__Res.MessageServer_LoadingConfigDefault));
                _servicesConfiguration = ServicesConfiguration.CreateDefault();
            }

            foreach (ChannelDefinition channelDefinition in _servicesConfiguration.Channels)
            {
                Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(channelDefinition.Endpoint.Class));
                if (type != null)
                {
                    IEndpoint endpoint = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, channelDefinition }) as IEndpoint;
                    if (endpoint != null)
                        _messageBroker.AddEndpoint(endpoint);
                }
                else
                    log.Error(__Res.GetString(__Res.Type_InitError, channelDefinition.Class));
            }
            ChannelDefinition rtmptChannelDefinition = new ChannelDefinition();
            rtmptChannelDefinition.Id = RtmptEndpoint.FluorineRtmptEndpointId;
            IEndpoint rtmptEndpoint = new RtmptEndpoint(_messageBroker, rtmptChannelDefinition);
            _messageBroker.AddEndpoint(rtmptEndpoint);

            if (_servicesConfiguration.Factories != null)
            {
                foreach (Factory factory in _servicesConfiguration.Factories)
                {
                    Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(factory.Class));
                    if (type != null)
                    {
                        IFlexFactory flexFactory = ObjectFactory.CreateInstance(type, new object[0]) as IFlexFactory;
                        if (flexFactory != null)
                            _messageBroker.AddFactory(factory.Id, flexFactory);
                    }
                    else
                        log.Error(__Res.GetString(__Res.Type_InitError, factory.Class));
                }
            }
            //Add the dotnet Factory
            _messageBroker.AddFactory(DotNetFactory.Id, new DotNetFactory());
            
            if (serviceBrowserAvailable)
            {
                ServiceDefinition serviceConfiguration = _servicesConfiguration.GetServiceByClass("flex.messaging.services.RemotingService");
                if (serviceConfiguration != null)
                {
                    AdapterDefinition adapter = serviceConfiguration.GetAdapterByClass(typeof(Remoting.RemotingAdapter).FullName);
                    if (adapter != null)
                        InstallServiceBrowserDestinations(serviceConfiguration, adapter);
                    else
                    {
                        adapter = serviceConfiguration.GetDefaultAdapter();
                        if (adapter != null)
                            InstallServiceBrowserDestinations(serviceConfiguration, adapter);
                    }
                }
            }
            if (_servicesConfiguration.Services.ServiceDefinitions != null)
            {
                foreach (ServiceDefinition serviceDefinition in _servicesConfiguration.Services.ServiceDefinitions)
                {
                    Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(serviceDefinition.Class));//current assembly only
                    if (type != null)
                    {
                        IService service = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, serviceDefinition }) as IService;
                        if (service != null)
                            _messageBroker.AddService(service);
                    }
                    else
                        log.Error(__Res.GetString(__Res.Type_InitError, serviceDefinition.Class));
                }
            }
            if (_servicesConfiguration.Services.Includes != null)
            {
                foreach (ServiceInclude include in _servicesConfiguration.Services.Includes)
                {
                    ServiceDefinition serviceDefinition = include.ServiceDefinition;
                    Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(serviceDefinition.Class));//current assembly only
                    if (type != null)
                    {
                        IService service = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, serviceDefinition }) as IService;
                        if (service != null)
                            _messageBroker.AddService(service);
                    }
                    else
                        log.Error(__Res.GetString(__Res.Type_InitError, serviceDefinition.Class));
                }
            }
            if (_servicesConfiguration.Security != null)
            {
                if (_servicesConfiguration.Security.LoginCommands != null && _servicesConfiguration.Security.LoginCommands.Length > 0)
                {
                    LoginCommand loginCommand = _servicesConfiguration.Security.GetLoginCommand(LoginCommand.FluorineLoginCommand);
                    if (loginCommand != null)
                    {
                        Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(loginCommand.Class));
                        if (type != null)
                        {
                            ILoginCommand loginCommandObj = ObjectFactory.CreateInstance(type, new object[] { }) as ILoginCommand;
                            _messageBroker.LoginManager.LoginCommand = loginCommandObj;
                            _messageBroker.LoginManager.IsPerClientAuthentication = loginCommand.IsPerClientAuthentication;
                        }
                        else
                            log.Error(__Res.GetString(__Res.Type_InitError, loginCommand.Class));
                    }
                    else
                        log.Error(__Res.GetString(__Res.Type_InitError, "<<LoginCommand class>>"));
                }
            }
            InitAuthenticationService();

            try
            {
                if (FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings != null &&
                    FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.Enable)
                {
                    IResource resource;
                    if (FluorineContext.Current != null)
                        resource = FluorineContext.Current.GetResource(FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
                    else
                        resource = new FileSystemResource(FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
                    if (resource.Exists)
                    {
                        log.Info(__Res.GetString(__Res.Silverlight_StartPS, resource.File.FullName));
                        _policyServer = new PolicyServer(resource.File.FullName);
                    }
                    else
                        throw new FileNotFoundException("Policy file not found", FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
                }
            }
            catch (Exception ex)
            {
                log.Error(__Res.GetString(__Res.Silverlight_PSError), ex);
            }
		}