public async static Task<bool> CreateNewUser(CertificateInfo certificateInformation, string outputPath)
        {
            string response;

            using (SslClient stream = new SslClient(_configuration.IP, _configuration.Port))
            {
                await stream.SendStringAsync("new-user");
                response = await stream.ReceiveStringAsync();
                if (response != "provide-user-name")
                {
                    UnknownCommandError("provide-user-name", response);
                }
                await stream.SendStringAsync("user-name");
                await stream.SendStringAsync(certificateInformation.CommonName);
                response = await stream.ReceiveStringAsync();
                if (response != "provide-user-mail")
                {
                    UnknownCommandError("provide-user-mail", response);
                }
                await stream.SendStringAsync("user-mail");
                await stream.SendStringAsync(certificateInformation.Email);
                response = await stream.ReceiveStringAsync();
                if (response == "user-exists")
                {
                    ServerResponseError(response);
                }
                else if (response != "provide-user-data")
                {
                    UnknownCommandError("provide-user-data", response);
                }
                await stream.SendStringAsync("user-data");
                await stream.SendStringAsync(certificateInformation.ToString());
                response = await stream.ReceiveStringAsync();
                if (response == "problem-while-adding-user")
                {
                    ServerResponseError(response);
                }
                else if (response != "user-added")
                {
                    UnknownCommandError("user-added", response);
                }
                response = await stream.ReceiveStringAsync();
                if (response != "certificate-file")
                {
                    UnknownCommandError("certificate-file", response);
                }
                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                await stream.ReceiveFileAsync(outputPath);
                await stream.SendStringAsync("everything-ok");
            }

            return true;
        }
Exemple #2
0
 public async static Task <bool> Connect(UserCertificate certificate)
 {
     try
     {
         using (SslClient stream = new SslClient(_configuration.IP, _configuration.Port, certificate))
         {
             await stream.SendStringAsync("connect");
             await Authenticate(stream, new User(certificate));
         }
     }
     catch (AuthenticationError error)
     {
         return(false);
     }
     return(true);
 }
Exemple #3
0
        public async static Task <bool> CreateNewGroup(Group group, UserCertificate certificate)
        {
            string response;

            using (SslClient stream = new SslClient(_configuration.IP, _configuration.Port, certificate))
            {
                await stream.SendStringAsync("login");
                await Authenticate(stream, new User(certificate));

                await stream.SendStringAsync("new-group");

                response = await stream.ReceiveStringAsync();

                if (response != "provide-group-name")
                {
                    UnknownCommandError("provide-group-name", response);
                }
                await stream.SendStringAsync("group-name");

                await stream.SendStringAsync(group.Name);

                response = await stream.ReceiveStringAsync();

                if (response != "provide-group-password")
                {
                    UnknownCommandError("provide-group-password", response);
                }
                await stream.SendStringAsync("group-password");

                await stream.SendStringAsync(group.Password);

                response = await stream.ReceiveStringAsync();

                if (response == "group-exists")
                {
                    ServerResponseError(response);
                }
                else if (response != "group-added")
                {
                    UnknownCommandError("group-added", response);
                }
            }

            return(true);
        }
 private async static Task<bool> Authenticate(SslClient stream, User user)
 {
     string response;
     response = await stream.ReceiveStringAsync();
     if (response == "user-doesnt-exist")
     {
         AuthenticationError(response);
     }
     else if (response == "premission-denied")
     {
         AuthenticationError(response);
     }
     else if (response != "permission-granted")
     {
         UnknownCommandError("permission-granted", response);
     }
     return true;
 }
Exemple #5
0
        private async static Task <bool> Authenticate(SslClient stream, User user)
        {
            string response;

            response = await stream.ReceiveStringAsync();

            if (response == "user-doesnt-exist")
            {
                AuthenticationError(response);
            }
            else if (response == "premission-denied")
            {
                AuthenticationError(response);
            }
            else if (response != "permission-granted")
            {
                UnknownCommandError("permission-granted", response);
            }
            return(true);
        }
        public async static Task<bool> CreateNewGroup(Group group, UserCertificate certificate)
        {
            string response;

            using (SslClient stream = new SslClient(_configuration.IP, _configuration.Port, certificate))
            {
                await stream.SendStringAsync("login");
                await Authenticate(stream, new User(certificate));
                await stream.SendStringAsync("new-group");
                response = await stream.ReceiveStringAsync();
                if (response != "provide-group-name")
                {
                    UnknownCommandError("provide-group-name", response);
                }
                await stream.SendStringAsync("group-name");
                await stream.SendStringAsync(group.Name);
                response = await stream.ReceiveStringAsync();
                if (response != "provide-group-password")
                {
                    UnknownCommandError("provide-group-password", response);
                }
                await stream.SendStringAsync("group-password");
                await stream.SendStringAsync(group.Password);
                response = await stream.ReceiveStringAsync();
                if (response == "group-exists")
                {
                    ServerResponseError(response);
                }
                else if (response != "group-added")
                {
                    UnknownCommandError("group-added", response);
                }
            }

            return true;

        }
 public async static Task<bool> Connect(UserCertificate certificate)
 {
     try
     {
         using (SslClient stream = new SslClient(_configuration.IP, _configuration.Port, certificate))
         {
             await stream.SendStringAsync("connect");
             await Authenticate(stream, new User(certificate));
         }
     }
     catch (AuthenticationError error)
     {
         return false;
     }
     return true;
 }
Exemple #8
0
        public async static Task <bool> CreateNewUser(CertificateInfo certificateInformation, string outputPath)
        {
            string response;

            using (SslClient stream = new SslClient(_configuration.IP, _configuration.Port))
            {
                await stream.SendStringAsync("new-user");

                response = await stream.ReceiveStringAsync();

                if (response != "provide-user-name")
                {
                    UnknownCommandError("provide-user-name", response);
                }
                await stream.SendStringAsync("user-name");

                await stream.SendStringAsync(certificateInformation.CommonName);

                response = await stream.ReceiveStringAsync();

                if (response != "provide-user-mail")
                {
                    UnknownCommandError("provide-user-mail", response);
                }
                await stream.SendStringAsync("user-mail");

                await stream.SendStringAsync(certificateInformation.Email);

                response = await stream.ReceiveStringAsync();

                if (response == "user-exists")
                {
                    ServerResponseError(response);
                }
                else if (response != "provide-user-data")
                {
                    UnknownCommandError("provide-user-data", response);
                }
                await stream.SendStringAsync("user-data");

                await stream.SendStringAsync(certificateInformation.ToString());

                response = await stream.ReceiveStringAsync();

                if (response == "problem-while-adding-user")
                {
                    ServerResponseError(response);
                }
                else if (response != "user-added")
                {
                    UnknownCommandError("user-added", response);
                }
                response = await stream.ReceiveStringAsync();

                if (response != "certificate-file")
                {
                    UnknownCommandError("certificate-file", response);
                }
                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                await stream.ReceiveFileAsync(outputPath);

                await stream.SendStringAsync("everything-ok");
            }

            return(true);
        }