示例#1
0
        public ConnectionPage(MainFrm ui, TabPage tab)
            : base(ui, tab)
        {
            _setStatus            = SetStatus;
            _connectTaskCompleted = ConnectTaskCompleted;
            _modifiedClientsDir   = Directory.CreateDirectory("Modified Clients");

            HandshakeMngr = new HandshakeManager(ui);

            UI.CoTVariablesVw.AddItem("productdata.load.url", "");
            UI.CoTVariablesVw.AddItem("external.texts.txt", "");
            UI.CoTVariablesVw.AddItem("external.variables.txt", "");
            UI.CoTVariablesVw.AddItem("external.override.texts.txt", "");
            UI.CoTVariablesVw.AddItem("external.figurepartlist.txt", "");
            UI.CoTVariablesVw.AddItem("external.override.variables.txt", "");

            ResourceReplacements = new Dictionary <string, string>(
                UI.CoTVariablesVw.Items.Count);

            UI.CoTProxyPortTxt.DataBindings.Add("Value", this,
                                                nameof(ProxyPort), false, DataSourceUpdateMode.OnPropertyChanged);

            UI.CoTConnectBtn.Click += CoTConnectBtn_Click;

            UI.CoTDestroyCertificatesBtn.Click   += CoTDestroyCertificatesBtn_Click;
            UI.CoTExportRootCertificateBtn.Click += CoTExportRootCertificateBtn_Click;

            UI.CoTClearVariableBtn.Click  += CoTClearVariableBtn_Click;
            UI.CoTUpdateVariableBtn.Click += CoTUpdateVariableBtn_Click;

            UI.CoTVariablesVw.ItemChecked  += CoTVariablesVw_ItemChecked;
            UI.CoTVariablesVw.ItemSelected += CoTVariablesVw_ItemSelected;
        }
示例#2
0
        private void UpdateDMDisplay()
        {
            List <string> allDMs = HandshakeManager.GetAllDMs();

            if (allDMs != null)
            {//if this is null, we have a problem
                foreach (string s in allDMs)
                {
                    string avail = HandshakeManager.GetDMAvailability(s);
                    string role  = HandshakeManager.GetDMRole(s);
                    if (DMInfo.GetDMAvail(s) != avail)
                    {
                        switch (avail)
                        {
                        case "Available":
                        case "Taken":
                        case "Ready":
                            DMInfo.UpdateDMStatus(s, role, avail);
                            break;

                        default:
                            throw new Exception("Incorrect return value for DM availability");
                        }
                    }
                }
            }
        }
示例#3
0
文件: MainFrm.cs 项目: Prixm/Tanji
        public MainFrm()
        {
            InitializeComponent();
            Connection = new HConnection();

            UpdateUI  = new UpdateFrm(this);
            ConnectUI = new ConnectFrm(this);
            if (!IsDebugging)
            {
                Load  += MainFrm_Load;
                Shown += MainFrm_Shown;

                Connection.Connected    += Connected;
                Connection.Disconnected += Disconnected;
            }

            // Data Priority - #1 | Notify Extensions
            ExtensionMngr = new ExtensionManager(this);
            // Data Priority - #2 | Process Handshake
            HandshakeMngr = new HandshakeManager(this);
            // Data Priority - #3 | Display Data
            PacketLoggerUI = new PacketLoggerFrm(this);

            EncoderMngr   = new EncoderManager(this);
            InjectionMngr = new InjectionManager(this);
        }
示例#4
0
        private void LoadScenario(string logType, DateTime time, string groupName, string replayFile)
        {
            ServerOptions.WriteFile();
            serverState = ServerState.RUNNING;

            string scenarioTitle = ServerOptions.DefaultScenarioPath.Remove(ServerOptions.DefaultScenarioPath.LastIndexOf('.'));

            scenarioTitle = scenarioTitle.Remove(0, scenarioTitle.LastIndexOf('\\') + 1);
            debugFile     = String.Format("{0}\\Debug\\DDDDebugLog-{1}.{2}.{3:yyyyMMddHHmmss}.txt", ServerOptions.EventLogDirectory, scenarioTitle, groupName, time);
            log           = String.Format("{0}\\DDDLog-{1}.{2}.{3:yyyyMMddHHmmss}.ddd", ServerOptions.EventLogDirectory, scenarioTitle, groupName, time);
            //TODO: Add back in later WriteClientAppConfig();
            SendServerStateEvent("LOADING_SCENARIO", scenarioTitle);
            if (System.IO.File.Exists(ServerOptions.SimulationModelPath))
            {
                switch (logType)
                {
                case "Limited":
                    //Begin Logging

                    simEngine.StartReplayLogger(Log, logType, productVersion, compileDate);
                    break;

                case "Detailed":
                    //Begin logging

                    simEngine.StartReplayLogger(Log, logType, productVersion, compileDate);
                    break;

                default:     //Don't log
                    break;
                }
                simEngine.StartTextChatServer();
                simEngine.StartWhiteboardServer();

                //  Start the voice server if it exists and is needed
                //    The conditions will be added later
                if (ServerOptions.EnableVoiceServer)
                {
                    HandshakeManager.SetVoiceEnabled(true);
                    HandshakeManager.SetVoiceServerName(ServerOptions.VoiceServerHostname);
                    HandshakeManager.SetVoiceServerPassword(ServerOptions.VoiceServerUserPassword);
                    HandshakeManager.SetVoiceServerPort(ServerOptions.VoiceServerPort);
                    simEngine.StartVoiceServer(ServerOptions.VoiceServerPort, ServerOptions.VoiceServerUserPassword,
                                               ServerOptions.VoiceServerAdminUsername, ServerOptions.VoiceServerAdminPassword, ServerOptions.EnableVoiceServerRecordings, time, false, 0.0);
                }
                else
                {
                    HandshakeManager.SetVoiceEnabled(false);
                    HandshakeManager.SetVoiceServerName(ServerOptions.VoiceServerHostname);
                    HandshakeManager.SetVoiceServerPassword(ServerOptions.VoiceServerUserPassword);
                    HandshakeManager.SetVoiceServerPort(ServerOptions.VoiceServerPort);
                }
                StartSimulationPaused(ServerOptions.ScenarioSchemaPath, ServerOptions.DefaultScenarioPath, replayFile);
            }
            else
            {
                throw new Exception("Error setting simulation model.");
            }
        }
示例#5
0
        protected static SecureSocket GetHandshakedSocket(Uri uri)
        {
            string selectedProtocol = null;

            var extensions = new[] { ExtensionType.Renegotiation, ExtensionType.ALPN };

            var options = _useSecurePort
                              ? new SecurityOptions(SecureProtocol.Tls1, extensions, new[] { Protocols.Http2, Protocols.Http1 },
                                                    ConnectionEnd.Client)
                              : new SecurityOptions(SecureProtocol.None, extensions, new[] { Protocols.Http2, Protocols.Http1 },
                                                    ConnectionEnd.Client);

            options.VerificationType  = CredentialVerification.None;
            options.Certificate       = Org.Mentalis.Security.Certificates.Certificate.CreateFromCerFile(@"certificate.pfx");
            options.Flags             = SecurityFlags.Default;
            options.AllowedAlgorithms = SslAlgorithms.RSA_AES_256_SHA | SslAlgorithms.NULL_COMPRESSION;

            var sessionSocket = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream,
                                                 ProtocolType.Tcp, options);

            using (var monitor = new ALPNExtensionMonitor())
            {
                monitor.OnProtocolSelected += (sender, args) => { selectedProtocol = args.SelectedProtocol; };

                sessionSocket.Connect(new DnsEndPoint(uri.Host, uri.Port), monitor);

                if (_useHandshake)
                {
                    var handshakeEnv = new Dictionary <string, object>
                    {
                        { ":method", "get" },
                        { ":version", Protocols.Http1 },
                        { ":path", uri.PathAndQuery },
                        { ":scheme", uri.Scheme },
                        { ":host", uri.Host },
                        { "securityOptions", options },
                        { "secureSocket", sessionSocket },
                        { "end", ConnectionEnd.Client }
                    };

                    _handshakeResult = HandshakeManager.GetHandshakeAction(handshakeEnv).Invoke();
                }
            }

            SendSessionHeader(sessionSocket);

            return(sessionSocket);
        }
示例#6
0
        public void UpgradeHandshakeSuccessful()
        {
            const string requestStr = @"http://*****:*****@"certificate.pfx"),
                Flags             = SecurityFlags.Default,
                AllowedAlgorithms = SslAlgorithms.RSA_AES_256_SHA | SslAlgorithms.NULL_COMPRESSION
            };

            var sessionSocket = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream,
                                                 ProtocolType.Tcp, options);

            sessionSocket.Connect(new DnsEndPoint(uri.Host, uri.Port));

            var handshakeEnv = new Dictionary <string, object>
            {
                { ":method", "get" },
                { ":version", Protocols.Http1 },
                { ":path", uri.PathAndQuery },
                { ":scheme", uri.Scheme },
                { ":host", uri.Host },
                { "securityOptions", options },
                { "secureSocket", sessionSocket },
                { "end", ConnectionEnd.Client }
            };

            bool gotFailedException = false;

            try
            {
                HandshakeManager.GetHandshakeAction(handshakeEnv).Invoke();
            }
            catch (Http2HandshakeFailed)
            {
                gotFailedException = true;
            }

            sessionSocket.Close();
            Assert.Equal(gotFailedException, false);
        }
示例#7
0
        public void AlpnSelectionHttp2Successful()
        {
            const string requestStr       = @"https://*****:*****@"certificate.pfx"),
                Flags             = SecurityFlags.Default,
                AllowedAlgorithms = SslAlgorithms.RSA_AES_256_SHA | SslAlgorithms.NULL_COMPRESSION
            };

            var sessionSocket = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream,
                                                 ProtocolType.Tcp, options);

            using (var monitor = new ALPNExtensionMonitor())
            {
                monitor.OnProtocolSelected += (sender, args) => { selectedProtocol = args.SelectedProtocol; };

                sessionSocket.Connect(new DnsEndPoint(uri.Host, uri.Port), monitor);

                var handshakeEnv = new Dictionary <string, object>
                {
                    { ":method", "get" },
                    { ":version", Protocols.Http1 },
                    { ":path", uri.PathAndQuery },
                    { ":scheme", uri.Scheme },
                    { ":host", uri.Host },
                    { "securityOptions", options },
                    { "secureSocket", sessionSocket },
                    { "end", ConnectionEnd.Client }
                };

                HandshakeManager.GetHandshakeAction(handshakeEnv).Invoke();
            }

            sessionSocket.Close();
            Assert.Equal(Protocols.Http2, selectedProtocol);
        }
示例#8
0
        public bool Connect(Uri connectUri)
        {
            _path     = connectUri.PathAndQuery;
            _version  = Protocols.Http2;
            _scheme   = connectUri.Scheme;
            _host     = connectUri.Host;
            _port     = connectUri.Port;
            ServerUri = connectUri.Authority;

            if (_clientSession != null)
            {
                return(false);
            }

            try
            {
                int port = connectUri.Port;

                int securePort;

                if (!int.TryParse(ConfigurationManager.AppSettings["securePort"], out securePort))
                {
                    Http2Logger.LogError("Incorrect port in the config file!");
                    return(false);
                }


                //Connect alpn extension, set known protocols
                var extensions = new[] { ExtensionType.Renegotiation, ExtensionType.ALPN };

                _options = port == securePort
                               ? new SecurityOptions(SecureProtocol.Tls1, extensions, new[] { Protocols.Http1, Protocols.Http2 },
                                                     ConnectionEnd.Client)
                               : new SecurityOptions(SecureProtocol.None, extensions, new[] { Protocols.Http1, Protocols.Http2 },
                                                     ConnectionEnd.Client);

                _options.VerificationType  = CredentialVerification.None;
                _options.Certificate       = Org.Mentalis.Security.Certificates.Certificate.CreateFromCerFile(CertificatePath);
                _options.Flags             = SecurityFlags.Default;
                _options.AllowedAlgorithms = SslAlgorithms.RSA_AES_256_SHA | SslAlgorithms.NULL_COMPRESSION;

                _socket = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, _options);
                IDictionary <string, object> handshakeResult = null;
                using (var monitor = new ALPNExtensionMonitor())
                {
                    monitor.OnProtocolSelected += (o, args) => { _selectedProtocol = args.SelectedProtocol; };
                    _socket.Connect(new DnsEndPoint(connectUri.Host, connectUri.Port), monitor);

                    if (_useHandshake)
                    {
                        var handshakeEnvironment = MakeHandshakeEnvironment(_socket);
                        //Handshake manager determines what handshake must be used: upgrade or secure
                        handshakeResult = HandshakeManager.GetHandshakeAction(handshakeEnvironment).Invoke();

                        Http2Logger.LogDebug("Handshake finished");

                        if (_selectedProtocol == Protocols.Http1)
                        {
                            _useHttp20 = false;
                            return(true);
                        }
                    }
                }

                SendSessionHeader();
                _useHttp20     = true;
                _clientSession = new Http2Session(_socket, ConnectionEnd.Client, _usePriorities, _useFlowControl, handshakeResult);

                //For saving incoming data
                _clientSession.OnFrameReceived   += FrameReceivedHandler;
                _clientSession.OnRequestSent     += RequestSentHandler;
                _clientSession.OnSessionDisposed += (sender, args) => Dispose(false);
            }
            catch (Http2HandshakeFailed ex)
            {
                if (ex.Reason == HandshakeFailureReason.InternalError)
                {
                    _useHttp20 = false;
                }
                else
                {
                    Http2Logger.LogError("Specified server did not respond");
                    Dispose(true);
                    return(false);
                }
            }
            catch (SocketException)
            {
                Http2Logger.LogError("Check if any server listens port " + connectUri.Port);
                Dispose(true);
                return(false);
            }
            catch (Exception ex)
            {
                Http2Logger.LogError("Unknown connection exception was caught: " + ex.Message);
                Dispose(true);
                return(false);
            }

            return(true);
        }
示例#9
0
        public void SimControlLoadReplay(String replayLogPath, Double replaySpeed)
        {
            Authenticator.LoadUserFile();


            if (replayLogPath == this.Log)
            {
                SendServerStateEvent("REPLAY_LOAD_FAILURE", "Your current replay log is set to the same file as the file you'll be replaying from.  To prevent error, change one of these two files before starting the server.");
                return;
            }
            if (Authenticator.GetNumUsers() == 0)
            {
                SendServerStateEvent("REPLAY_LOAD_FAILURE", "You must create at least one user account before loading a replay.\nUse the Users-->User Administration menu item.");
                return;
            }


            try
            {
                StreamReader re = File.OpenText(replayLogPath);

                string input = re.ReadLine();

                re.Close();
                creatorRegex = new Regex(@"^<Creator><Version>" + SimCoreServer.GetProductVersion() + "</Version><CompiledOn>" + SimCoreServer.GetCompileDate() + "</CompiledOn></Creator>$", RegexOptions.Singleline);
                if (!creatorRegex.IsMatch(input))
                {
                    SendServerStateEvent("REPLAY_LOAD_FAILURE", "This file must be replayed in a different version of the DDD.");
                    return;
                }
            }
            catch (System.IO.IOException exc)
            {
                SendServerStateEvent("REPLAY_LOAD_FAILURE", String.Format("The selected file could not be opened for replay.\n{0}", exc.Message));
                return;
            }

            simEngine.StartTextChatServer();
            simEngine.StartWhiteboardServer();

            //  Start the voice server if it exists and is needed
            //    The conditions will be added later
            if (ServerOptions.EnableVoiceServer)
            {
                // Get the simulation start time from the replay filename
                DateTime time = DateTime.Now;

                try
                {
                    string timeString = replayLogPath.Remove(replayLogPath.LastIndexOf('.'));

                    timeString = timeString.Substring(timeString.LastIndexOf('.') + 1);

                    time = DateTime.ParseExact(timeString, "yyyyMMddHHmmss", null);
                }
                catch (Exception exc)
                {
                }

                HandshakeManager.SetVoiceEnabled(true);
                HandshakeManager.SetVoiceServerName(ServerOptions.VoiceServerHostname);
                HandshakeManager.SetVoiceServerPassword(ServerOptions.VoiceServerUserPassword);
                HandshakeManager.SetVoiceServerPort(ServerOptions.VoiceServerPort);
                simEngine.StartVoiceServer(ServerOptions.VoiceServerPort, ServerOptions.VoiceServerUserPassword,
                                           ServerOptions.VoiceServerAdminUsername, ServerOptions.VoiceServerAdminPassword, ServerOptions.EnableVoiceServerRecordings, time, true, replaySpeed);
            }
            else
            {
                HandshakeManager.SetVoiceEnabled(false);
                HandshakeManager.SetVoiceServerName(ServerOptions.VoiceServerHostname);
                HandshakeManager.SetVoiceServerPassword(ServerOptions.VoiceServerUserPassword);
                HandshakeManager.SetVoiceServerPort(ServerOptions.VoiceServerPort);
            }

            this.StartReplay(replayLogPath, false);
            this.SimControlPauseScenario();
            SimCoreServer.replayState = Aptima.Asim.DDD.SimCoreServer.SimCoreServer.ScenarioState.LOADING;
            this.SetReplaySpeed(replaySpeed);
        }
示例#10
0
        private void HandleAcceptedClient(SecureSocket incomingClient)
        {
            bool   backToHttp11         = false;
            string alpnSelectedProtocol = Protocols.Http2;
            var    handshakeEnvironment = MakeHandshakeEnvironment(incomingClient);
            IDictionary <string, object> handshakeResult = null;

            //Think out smarter way to get handshake result.
            //DO NOT change Middleware function. If you will do so, server will not even launch. (It's owin's problem)
            Func <Task> handshakeAction = () =>
            {
                var handshakeTask = new Task(() =>
                {
                    handshakeResult = HandshakeManager.GetHandshakeAction(handshakeEnvironment).Invoke();
                });
                return(handshakeTask);
            };

            if (_useHandshake)
            {
                var environment = new Dictionary <string, object>
                {
                    //Sets the handshake action depends on port.
                    { "HandshakeAction", handshakeAction },
                };

                try
                {
                    var handshakeTask = _next(environment);

                    handshakeTask.Start();
                    if (!handshakeTask.Wait(6000))
                    {
                        incomingClient.Close();
                        Http2Logger.LogError("Handshake timeout. Connection dropped.");
                        return;
                    }

                    alpnSelectedProtocol = incomingClient.SelectedProtocol;
                }
                catch (Http2HandshakeFailed ex)
                {
                    if (ex.Reason == HandshakeFailureReason.InternalError)
                    {
                        backToHttp11 = true;
                    }
                    else
                    {
                        incomingClient.Close();
                        Http2Logger.LogError("Handshake timeout. Client was disconnected.");
                        return;
                    }
                }
                catch (Exception e)
                {
                    Http2Logger.LogError("Exception occured. Closing client's socket. " + e.Message);
                    incomingClient.Close();
                    return;
                }
            }
            try
            {
                HandleRequest(incomingClient, alpnSelectedProtocol, backToHttp11, handshakeResult);
            }
            catch (Exception e)
            {
                Http2Logger.LogError("Exception occured. Closing client's socket. " + e.Message);
                incomingClient.Close();
            }
        }