Example #1
0
 private void CollectExistingFiles()
 {
     if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + name))
     {
         root          = new MyFolder(Name, null, userInfo);
         UploadedFiles = new MyFolder("uploaded", root, userInfo);
         DirectorySearch(root);
     }
     else
     {
         root          = new MyFolder(name, null, userInfo);
         UploadedFiles = new MyFolder("uploaded", root, userInfo);
     }
 }
Example #2
0
 private void DirectorySearch(MyFolder dir)
 {
     foreach (string f in Directory.GetFiles(dir.RealPath))
     {
         var file = new MyFile(Path.GetFileName(f), dir, UserInfo);
         dir.AddChildren(file);
     }
     foreach (string d in Directory.GetDirectories(dir.RealPath))
     {
         var folder = new MyFolder(Path.GetFileName(d), dir, userInfo);
         dir.AddChildren(folder);
         if (!folder.Name.Equals("shared"))
         {
             DirectorySearch(folder);
         }
     }
 }
        static void Main()
        {
            CollectAllUsers();
            Console.Clear();
            bool end = false;

            while (!end)
            {
                String input = Console.ReadLine();
                Console.Clear();
                switch (input)
                {
                case "login":
                {
                    if (loggedUser != null)
                    {
                        EnterWorkingSpace();
                        break;
                    }
                    Console.WriteLine("Unesite korisnicko ime:");
                    string username = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine("Unesite lozinku");
                    String password = ReadPassword();
                    Console.Clear();
                    if (username.Equals(String.Empty) && password.Equals(String.Empty))
                    {
                        ErrorMessage("Pogresan unos");
                        break;
                    }
                    if (!IsUserNameFree(username))
                    {
                        var  values = generateHash(allUsersInfo.Find(x => x.Username.Equals(username)).HashAlgorithm, password, allUsersInfo.Find(x => x.Username.Equals(username)).Salt);
                        User user   = new User(username, values[3].TrimEnd('\n'), values[2], values[1], allUsers.Find(x => x.Name.Equals(username)).CryptoAlgorithm, DATABASE + "/" + username + "/" + username + ".key");
                        if (Exists(user))
                        {
                            if (!File.Exists(user.Certificate))
                            {
                                ErrorMessage("Ne postoji sertifikat za odabranog korisnika");
                            }
                            else
                            {
                                if (isCertificateValid(user.Certificate))
                                {
                                    loggedUser = user;
                                    executeCommand("/C openssl rsa -in " + loggedUser.PrivateKeyFile + " -pubout -out " + loggedUser.UserInfo.PublicKey + " > errors.txt");
                                    Console.Clear();
                                    currentFolder = loggedUser.Root;
                                    CollectSharedFiles();
                                    EnterWorkingSpace();
                                }
                                else
                                {
                                    ErrorMessage("Sertifikat unesenog korisnika nije validan");
                                }
                            }
                        }
                        else
                        {
                            ErrorMessage("Pogresan unos");
                        }
                    }
                    else
                    {
                        ErrorMessage("Pogresan unos");
                    }
                    break;
                }

                case "end":
                {
                    end = true;
                    SaveData();
                    break;
                }

                case "signup":
                {
                    Console.WriteLine("Unesite novo korisnicko ime:");
                    String name = Console.ReadLine();
                    Console.Clear();
                    if (IsUserNameFree(name))
                    {
                        Console.WriteLine("Unesite lozinku: ");
                        String firstPassword = ReadPassword();
                        Console.Clear();
                        Console.WriteLine("Ponovite lozinku: ");
                        String secondPassword = ReadPassword();
                        Console.Clear();
                        if (firstPassword == secondPassword)
                        {
                            Console.WriteLine("Odaberite hash algoritam koji zelite da koristite za hesiranje vase lozinke.\n SHA-256\n SHA-512\n md5");
                            var hashType = Console.ReadLine();
                            if (hashType == "md5")
                            {
                                hashType = "1";
                            }
                            else if (hashType == "SHA-512")
                            {
                                hashType = "6";
                            }
                            else if (hashType == "SHA-256")
                            {
                                hashType = "5";
                            }
                            else
                            {
                                ErrorMessage("Koristice se podrazumijevani hash algoritam(md5)");
                                hashType = "1";
                            }
                            Console.Clear();
                            Console.WriteLine("Odaberite algoritam koji zelite da koristite za kriptovanje vasih fajlova.\n des\n des3\n aes\n rc4");
                            var algorithm = Console.ReadLine();
                            if (algorithm != "aes" && algorithm != "des" && algorithm != "des3" && algorithm != "rc4")
                            {
                                ErrorMessage("Ovaj algoritam nije podrzan!Koristice se podrazumijevani algoritam za kriptovanje(aes)");
                                algorithm = "aes-128-cbc";
                            }
                            if (algorithm == "aes")
                            {
                                algorithm = "aes-128-cbc";
                            }
                            var  values = generateHash(hashType, secondPassword, "");
                            User user   = new User(name, values[3].TrimEnd('\n'), values[2], hashType, algorithm, "");
                            allUsers.Add(user);
                            allUsersInfo.Add(user.UserInfo);
                            SaveData();
                        }
                        else
                        {
                            ErrorMessage("Lozinke se ne poklapaju");
                        }
                    }
                    else
                    {
                        ErrorMessage("Korisnicko ime je zauzeto");
                    }
                    break;
                }

                case "shared":
                {
                    WriteHeading();
                    foreach (var file in sharedFiles)
                    {
                        if (!file.Name.Contains("messageFor#") && !file.Name.Contains(".otisak"))
                        {
                            Console.WriteLine("{0, -15} {1,-15} {2,-15}", file.Name, file.Owner.Username, file.User.Username);
                        }
                    }
                    break;
                }

                case "users":
                {
                    Console.WriteLine("Korisnicko ime:");
                    foreach (var user in allUsersInfo)
                    {
                        Console.WriteLine((allUsersInfo.IndexOf(user) + 1) + ". " + user.Username);
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
            SaveData();
        }