Example #1
0
        protected override void OnStart(string[] args)
        {
            Log.Info("Starting Signing Server");

            string configFileLocation;
            var    executable = Assembly.GetEntryAssembly();

            if (executable != null)
            {
                configFileLocation = new FileInfo(executable.Location).DirectoryName;
            }
            else
            {
                configFileLocation = Environment.CurrentDirectory;
            }


            var configFile = Path.Combine(configFileLocation, "config.json");

            if (!File.Exists(configFile))
            {
                Log.Fatal("Could not find config.json beside executable");
                Stop();
                return;
            }

            try
            {
                Log.Info("Loading configuration");
                var configuration = JsonConvert.DeserializeObject <SigningServerConfiguration>(File.ReadAllText(configFile));
                Log.Info("Starting server");

                SigningServer = new SigningServer(configuration, new DefaultSigningToolProvider());
                _serviceHost  = new ServiceHost(SigningServer);

                // Setup without transport security (new mode)
                var uri = new UriBuilder
                {
                    Scheme = "net.tcp",
                    Host   = Dns.GetHostName(),
                    Port   = configuration.Port
                };
                var binding = new NetTcpBinding
                {
                    TransferMode           = TransferMode.Streamed,
                    MaxReceivedMessageSize = int.MaxValue,
                    MaxBufferSize          = int.MaxValue,
                    OpenTimeout            = TimeSpan.FromMinutes(5),
                    CloseTimeout           = TimeSpan.FromMinutes(5),
                    SendTimeout            = TimeSpan.FromMinutes(60),
                    ReceiveTimeout         = TimeSpan.FromMinutes(60),
                    MaxConnections         = int.MaxValue,
                    PortSharingEnabled     = false,
                };
                binding.Security.Mode = SecurityMode.None;
                var endPoint = _serviceHost.AddServiceEndpoint(typeof(ISigningServer), binding, uri.Uri);
                endPoint.Behaviors.Add(new AddClientMessageInspectorBehavior());

                // Setup without transport security (new mode)
                uri.Port = configuration.LegacyPort;
                var legacyBinding = new NetTcpBinding
                {
                    TransferMode           = TransferMode.Streamed,
                    MaxReceivedMessageSize = int.MaxValue,
                    MaxBufferSize          = int.MaxValue,
                    OpenTimeout            = TimeSpan.FromMinutes(5),
                    CloseTimeout           = TimeSpan.FromMinutes(5),
                    SendTimeout            = TimeSpan.FromMinutes(60),
                    ReceiveTimeout         = TimeSpan.FromMinutes(60),
                    MaxConnections         = int.MaxValue,
                    PortSharingEnabled     = false,
                };
                var legacyEndpoint = _serviceHost.AddServiceEndpoint(typeof(ISigningServer), legacyBinding, uri.Uri);
                legacyEndpoint.Behaviors.Add(new AddClientMessageInspectorBehavior());
                _serviceHost.Open();
            }
            catch (Exception e)
            {
                Log.Fatal(e, "Starting the server failed");
                Stop();
                return;
            }
        }
        protected override void OnStart(string[] args)
        {
            Log.Info("Starting Signing Server");

            string configFileLocation;
            var    executable = Assembly.GetEntryAssembly();

            if (executable != null)
            {
                configFileLocation = new FileInfo(executable.Location).DirectoryName;
            }
            else
            {
                configFileLocation = Environment.CurrentDirectory;
            }


            var configFile = Path.Combine(configFileLocation, "config.json");

            if (!File.Exists(configFile))
            {
                Log.Fatal("Could not find config.json beside executable");
                Stop();
                return;
            }

            try
            {
                Log.Info("Loading configuration");
                var configuration = JsonConvert.DeserializeObject <SigningServerConfiguration>(File.ReadAllText(configFile));
                Log.Info("Starting server");

                SigningServer = new SigningServer(configuration, new DefaultSigningToolProvider());
                _serviceHost  = new ServiceHost(SigningServer);
                var uri = new UriBuilder
                {
                    Scheme = "net.tcp",
                    Host   = Dns.GetHostName(),
                    Port   = configuration.Port
                };
                _serviceHost.AddServiceEndpoint(typeof(ISigningServer), new NetTcpBinding
                {
                    TransferMode           = TransferMode.Streamed,
                    MaxReceivedMessageSize = int.MaxValue,
                    MaxBufferSize          = int.MaxValue,
                    OpenTimeout            = TimeSpan.MaxValue,
                    CloseTimeout           = TimeSpan.MaxValue,
                    SendTimeout            = TimeSpan.MaxValue,
                    ReceiveTimeout         = TimeSpan.MaxValue,
                    MaxConnections         = int.MaxValue,
                }, uri.Uri);

                _serviceHost.Open();
            }
            catch (Exception e)
            {
                Log.Fatal(e, "Starting the server failed");
                Stop();
                return;
            }
        }