Пример #1
0
        private static WCFClientServer ConnectToServerViaCert()
        {
            try
            {
                NetTcpBinding bindingServer = new NetTcpBinding();
                bindingServer.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;

                Console.WriteLine("Expected Server(user) name: ");
                string expectedServer = Console.ReadLine();

                //gets server certificate from trustedPeople folder
                X509Certificate2 servCert        = CertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, expectedServer);
                EndpointAddress  addressServer   = new EndpointAddress(new Uri(ConfigurationSettings.AppSettings.Get("ServerProxy")), new X509CertificateEndpointIdentity(servCert));
                var             callbackInstance = new DisconnectCallback();
                WCFClientServer proxy            = new WCFClientServer(callbackInstance, bindingServer, addressServer);

                proxy.TestCommunication();
                Console.WriteLine("TestCommunication() with server successful.");

                return(proxy);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #2
0
        public static void Prompt()
        {
            int option = 0;

            do
            {
                Console.WriteLine("1. Generate Certificate (with private key)");
                Console.WriteLine("2. Generate Certificate (without private key)");
                Console.WriteLine("3. Add rights");
                Console.WriteLine("4. Connect to server via certificate AUTH");
                Console.WriteLine("5. Revoke certificate");
                Console.WriteLine("6. Ping server");
                Console.WriteLine("7. EXIT");
                int.TryParse(Console.ReadLine(), out option);

                switch (option)
                {
                case 1:
                    Console.WriteLine("Choose root: ");
                    string root = Console.ReadLine();
                    cmsClient.GenerateCertificate(root);
                    break;

                case 2:
                    Console.WriteLine("Choose root: ");
                    string root2 = Console.ReadLine();
                    cmsClient.GenerateCertificateWithoutPVK(root2);
                    break;

                case 3:
                    Helper.ProvideCertRight(WindowsIdentity.GetCurrent().Name);
                    break;

                case 4:
                    myChannel = ConnectToServerViaCert();
                    //ConnectToServerViaCert();
                    break;

                case 5:
                    RevokeCertificate();
                    break;

                case 6:
                    PingServer(myChannel);     //u novom threadu mozda bolje
                    break;

                case 7:     //exit program
                    break;

                default:
                    Console.WriteLine("Invalid input");
                    break;
                }
            } while (option != 7);
        }
Пример #3
0
        private static void PingServer(WCFClientServer proxy)
        {
            Console.WriteLine("Starting to ping server...");
            Random r = new Random();

            try
            {
                while (true)
                {
                    Thread.Sleep(r.Next(1, 10) * 1000); //sleep 1-10s

                    proxy.PingServer(DateTime.Now);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }