Esempio n. 1
0
        /// <summary>
        /// Creates a new Kerberos Server and listen for clients.
        /// </summary>
        /// <param name="LocalAddress">IPAddress.Any</param>
        /// <param name="Port">The local port of the server.</param>
        /// <param name="PColl">The PortalCollection.</param>
        /// <param name="Kerberos">Kerberos connection settings.</param>
        public VaserServer(IPAddress LocalAddress, int Port, PortalCollection PColl, VaserKerberosServer Kerberos)
        {
            if (Kerberos == null)
            {
                throw new Exception("Missing Kerberos options in VaserServer(...)");
            }
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                _vKerberos      = Kerberos;
                ServerOption    = VaserOptions.ModeKerberos;
                PColl.Active    = true;
                PCollection     = PColl;
                _socketListener = new StreamSocketListener();
                _socketListener.ConnectionReceived += SocketListener_ConnectionReceived;
                _Port = Port.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new connection for processing data
        /// </summary>
        public Connection(Socket client, bool _IsServer, VaserOptions Mode, PortalCollection PColl, VaserKerberosServer KerberosS, VaserSSLServer SSLS, VaserKerberosClient KerberosC, VaserSSLClient SSLC, VaserServer srv = null)
        {
            IsServer          = _IsServer;
            StreamIsConnected = true;

            _rms2 = new MemoryStream();
            _rbr2 = new BinaryReader(_rms2);


            _Mode        = Mode;
            _PCollection = PColl;

            _vSSLS      = SSLS;
            _vKerberosS = KerberosS;
            _vSSLC      = SSLC;
            _vKerberosC = KerberosC;

            _SocketTCPClient             = client;
            _SocketTCPClient.LingerState = new LingerOption(true, 0);

            server = srv;

            IPv4Address = ((IPEndPoint)client.RemoteEndPoint).Address;

            link = new Link(PColl)
            {
                Connect = this
            };
            if (Mode == VaserOptions.ModeNotEncrypted)
            {
                mySendNotEncryptedCallback    = new AsyncCallback(SendNotEncryptedCallback);
                myReceiveNotEncryptedCallback = new AsyncCallback(ReceiveNotEncryptedCallback);
            }
            if (Mode == VaserOptions.ModeKerberos)
            {
                mySendKerberosCallback    = new AsyncCallback(SendKerberosCallback);
                myReceiveKerberosCallback = new AsyncCallback(ReceiveKerberosCallback);
            }

            if (Mode == VaserOptions.ModeSSL)
            {
                mySendSSLCallback    = new AsyncCallback(SendSSLCallback);
                myReceiveSSLCallback = new AsyncCallback(ReceiveSSLCallback);
            }
            if (_IsServer)
            {
                ThreadPool.QueueUserWorkItem(HandleClientComm);
            }
            else
            {
                HandleClientComm(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new connection for processing data
        /// </summary>
        public Connection(StreamSocket client, bool _IsServer, VaserOptions Mode, PortalCollection PColl, VaserKerberosServer KerberosS, VaserSSLServer SSLS, VaserKerberosClient KerberosC, VaserSSLClient SSLC, VaserServer srv = null)
        {
            IsServer          = _IsServer;
            StreamIsConnected = true;

            _rms2 = new MemoryStream();
            _rbr2 = new BinaryReader(_rms2);


            _Mode        = Mode;
            _PCollection = PColl;

            _vSSLS      = SSLS;
            _vKerberosS = KerberosS;
            _vSSLC      = SSLC;
            _vKerberosC = KerberosC;

            _SocketTCPClient = client;

            server = srv;
            //Debug.WriteLine("Init Options Done");
            IPv4Address = client.Information.RemoteAddress;

            link = new Link(PColl)
            {
                Connect = this
            };
            //Debug.WriteLine("Create Link Done");

            //Debug.WriteLine("Init Connection class DONE");
            if (_IsServer)
            {
                //Debug.WriteLine("Send to HandleClientComm");
                IAsyncAction asyncAction = ThreadPool.RunAsync(HandleClientComm);
            }
            else
            {
                HandleClientComm(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new connection for processing data
        /// </summary>
        public Connection(Socket client, bool _IsServer, VaserOptions Mode, PortalCollection PColl, VaserKerberosServer KerberosS, VaserSSLServer SSLS, VaserKerberosClient KerberosC, VaserSSLClient SSLC, VaserServer srv = null)
        {
            IsServer          = _IsServer;
            StreamIsConnected = true;


            _rms2 = new MemoryStream();
            _rbr2 = new BinaryReader(_rms2);



            _Mode        = Mode;
            _PCollection = PColl;

            _vSSLS      = SSLS;
            _vKerberosS = KerberosS;
            _vSSLC      = SSLC;
            _vKerberosC = KerberosC;

            client.SendBufferSize = 65007;
            _SocketTCPClient      = client;

            server = srv;

            IPv4Address = ((IPEndPoint)client.RemoteEndPoint).Address;

            link         = new Link(PColl);
            link.Connect = this;

            if (_IsServer)
            {
                ThreadPool.QueueUserWorkItem(HandleClientComm);
            }
            else
            {
                HandleClientComm(null);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new Kerberos Server and listen for clients.
        /// </summary>
        /// <param name="LocalAddress">IPAddress.Any</param>
        /// <param name="Port">The local port of the server.</param>
        /// <param name="PColl">The PortalCollection.</param>
        /// <param name="Kerberos">Kerberos connection settings.</param>
        public VaserServer(IPAddress LocalAddress, int Port, PortalCollection PColl, VaserKerberosServer Kerberos)
        {
            if (Kerberos == null)
            {
                throw new Exception("Missing Kerberos options in VaserServer(...)");
            }
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                _vKerberos   = Kerberos;
                ServerOption = VaserOptions.ModeKerberos;
                PColl.Active = true;
                PCollection  = PColl;
                _TCPListener = new TcpListener(LocalAddress, Port);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 6
0
        public static void Run()
        {
            Console.WriteLine("Welcome to the Vaser testengine");
            Console.WriteLine("Prepareing server");
            Console.WriteLine("");

            Console.WriteLine("Creating container: TestContainer");


            //create connection managing lists



            //initialize the server
            Console.WriteLine("Creating portal: system");
            system = new Portal(100);
            PortalCollection PC = new PortalCollection();

            PC.RegisterPortal(system);

            system.IncomingPacket += OnSystemPacket;



            // ###########################################################
            // Create a TestCert in CMD: makecert -sr LocalMachine -ss root -r -n "CN=localhost" -sky exchange -sk 123456
            // Do not use in Production | do not use localhost -> use your machinename!
            // ###########################################################



            /*Console.WriteLine("Import Test Cert");
             * //Import Test Cert
             * X509Certificate2 cert = new X509Certificate2();
             *
             * X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
             * store.Open(OpenFlags.ReadOnly);
             * var certificates = store.Certificates.Find(X509FindType.FindBySubjectDistinguishedName, "CN=localhost", false);
             * store.Close();
             *
             * if (certificates.Count == 0)
             * {
             *  Console.WriteLine("Server certificate not found");
             *  Console.ReadKey();
             *  return;
             * }
             * else
             * {
             *  Console.WriteLine("Test Cert was found");
             * }
             *
             * // Get the value.
             * string resultsTrue = cert.ToString(true);
             * // Display the value to the console.
             * Console.WriteLine(resultsTrue);
             * // Get the value.
             * string resultsFalse = cert.ToString(false);
             * // Display the value to the console.
             * Console.WriteLine(resultsFalse);
             */
            //start the server
            Console.WriteLine("Creating server: IPAddress any, Port 3100, VaserMode ModeSSL");
            //VaserSSLServer ssl = new VaserSSLServer(certificates[0]);
            VaserKerberosServer kerberos = new VaserKerberosServer();
            VaserServer         Server1  = new VaserServer(System.Net.IPAddress.Any, 3100, PC);

            Server1.NewLink           += OnNewLink;
            Server1.DisconnectingLink += OnDisconnectingLink;
            Server1.Start();

            Console.WriteLine("");


            bool online = true;

            //working
            while (online)
            {
                switch (testmode)
                {
                case 0:
                    Console.WriteLine("Test 1: Connection and Transfer statistics:");
                    Console.WriteLine("Waiting for Connection...");
                    testmode = 1;
                    break;

                case 4:
                    test1.Dispose();
                    Console.WriteLine("Closed");
                    testmode = -1;
                    break;
                }


                if (testmode == -1)
                {
                    break;
                }
                //Time tick
                Thread.Sleep(1);
            }

            //close Server
            Console.WriteLine("Close Server");
            Server1.Stop();



            Console.WriteLine("Test ended. Press any key...");
            Console.ReadKey();
        }