Example #1
0
        static bool GeneratePrivateKeyPublicKey(string pw)
        {
            var ok = false;

            Console.Clear();
            ConsoleEx.TitleBar(0, "Generate new private/public key", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            Console.Clear();
            ConsoleEx.TitleBar(0, "Generate Private/Public Key", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            var keyInfo = ConsoleEx.Question(3, "Re generate the private key and publick key Y)es N)o", new List <char> {
                'Y', 'N'
            });

            if (keyInfo == 'N')
            {
                return(ok);
            }

            keyInfo = ConsoleEx.Question(3, "Are you sure you want to generate Private/Public Key Y)es N)o", new List <char> {
                'Y', 'N'
            });
            if (keyInfo == 'N')
            {
                return(ok);
            }

            ConsoleEx.WriteLine(0, 4, "Formatting...", ConsoleColor.Yellow);
            var ppk = new PrivatePublicKeyHelper(true);

            if (!_sfsManager.Format())
            {
                ConsoleEx.WriteLine(0, 3, "Format failed", ConsoleColor.Red);
            }

            ConsoleEx.WriteLine(0, 5, "Loading and saving files...", ConsoleColor.Yellow);
            var privatek = _sfsManager.AddFile("PrivateKey");

            privatek.SetContentAsString(ppk.PrivateKey);
            var publicK = _sfsManager.AddFile("PublicKey");

            publicK.SetContentAsString(ppk.PublicKey);
            var readmeTxt = _sfsManager.AddFile("ReadMe.txt");

            readmeTxt.SetContentAsString(LoremIpsum);
            var rr = _sfsManager.UpdateFileSystem();

            if (rr)
            {
                Console.WriteLine(string.Format("Keys were generated"), ConsoleColor.Cyan);
                ok = ReloadFileSystem(pw, ppk);
            }
            else
            {
                Console.WriteLine(string.Format("Error generating the keys"), ConsoleColor.Red);
            }

            Pause();
            return(ok);
        }
 public string CopyFileCommand(CopyCommandInfo c)
 {
     try
     {
         var srcByte = LoadFileInMemory(c.SourceFile);
         if (IsFileFromWindowsFileSystem(c.DestinationFile))
         {
             File.WriteAllBytes(c.DestinationFile, srcByte);
             return(SFS_COMMAND_MESSAGE_ONE_FILE_COPIED);
         }
         else
         {
             var fi = _sFsManager.AddFile(c.DestinationFile, srcByte);
             if (fi == null)
             {
                 Console.WriteLine(SFS_COMMAND_ERR_COPYING_FILE);
             }
             else
             {
                 if (_sFsManager.UpdateFileSystem())
                 {
                     return(SFS_COMMAND_MESSAGE_ONE_FILE_COPIED);
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
     }
     finally
     {
         _sFsManager.Clean();
     }
     return(SFS_COMMAND_ERR_ZERO_FILE_COPIED);
 }
Example #3
0
        static bool FormatAndInitDisk()
        {
            var ok = false;

            Console.Clear();
            ConsoleEx.TitleBar(0, "Format and initialization", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            var keyInfo = ConsoleEx.Question(3, "Format and initialize disk Y)es N)o", new List <char> {
                'Y', 'N'
            });

            if (keyInfo == 'N')
            {
                return(ok);
            }

            ConsoleEx.WriteLine(0, 4, "Formatting...", ConsoleColor.Yellow);
            if (!_sfsManager.Format())
            {
                ConsoleEx.WriteLine(0, 3, "Format failed", ConsoleColor.Red);
                return(false);
            }

            ConsoleEx.WriteLine(0, 5, "Loading and saving files...", ConsoleColor.Yellow);
            _sfsManager.AddFile(@".\files\Readme.txt");
            _sfsManager.AddFile(@".\files\Shadow.jpg");
            var rr = _sfsManager.UpdateFileSystem();

            if (rr)
            {
                Console.WriteLine(string.Format("Keys were generated"), ConsoleColor.Cyan);
                ok = ReloadFileSystem();
            }
            else
            {
                Console.WriteLine(string.Format("Error generating the keys"), ConsoleColor.Red);
            }

            Pause();
            return(ok);
        }
Example #4
0
        public static void Run(string[] args)
        {
            SecureString pw;

            Console.WriteLine("Nusbio initialization");
            Nusbio.ActivateFastMode();
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("nusbio not detected");
                return;
            }

            using (var nusbio = new Nusbio(serialNumber))
            {
                pw              = AskForPW(nusbio, VolumeName);
                _sfsManager     = new sFs.sFsManager(VolumeName, pw, nusbio: nusbio, clockPin: NusbioGpio.Gpio0, mosiPin: NusbioGpio.Gpio1, misoPin: NusbioGpio.Gpio2, selectPin: NusbioGpio.Gpio3);
                _sFsREPLCommand = new sFs.sFsREPLCommand(_sfsManager);

                Cls(nusbio, true);
                Console.WriteLine(Environment.NewLine + Environment.NewLine);

                var ok = ReloadFileSystem();
                if (!ok)
                {
                    Cls(nusbio, true);
                    if (ConsoleEx.Question(3, string.Format("Cannot access {0} with this password, retry password Y)es N)o",
                                                            _sfsManager.VolumeName), new List <char> {
                        'Y', 'N'
                    }) == 'Y')
                    {
                        Environment.Exit(1);
                    }

                    Cls(nusbio, true); // Re format - re init key
                    var keyInfo = ConsoleEx.Question(4, string.Format("Would you like to format {0} Y)es N)o", _sfsManager.VolumeName), new List <char> {
                        'Y', 'N'
                    });
                    if (keyInfo == 'N')
                    {
                        return;
                    }
                    FormatAndInitDisk();
                }

                Cls(nusbio);

                while (nusbio.Loop())
                {
                    Console.Write(string.Format(@"{0}:\>", _sfsManager.VolumeName));
                    var cmd    = Console.ReadLine();
                    var cmdLC  = cmd.ToLowerInvariant();
                    var tokens = cmdLC.Split(' ');
                    if (tokens.Length > 0)
                    {
                        if (tokens[0] == "exit")
                        {
                            nusbio.ExitLoop();
                        }
                        if (tokens[0] == "format")
                        {
                            FormatAndInitDisk();
                        }
                        if (tokens[0] == "cls")
                        {
                            Console.Clear();
                        }
                        if (tokens[0] == "help")
                        {
                            Console.WriteLine(COMMAND_HELP);
                        }
                        if (tokens[0] == "del")
                        {
                            if (_sfsManager.Delete(cmd.Substring(4)))
                            {
                                if (_sfsManager.UpdateFileSystem())
                                {
                                    Console.WriteLine(SFS_COMMAND_MESSAGE_FILE_DELETED);
                                }
                                else
                                {
                                    Console.WriteLine(SFS_COMMAND_ERR_SAVING_FAT);
                                }
                            }
                            else
                            {
                                Console.WriteLine(SFS_COMMAND_ERR_CANNOT_FIND_FILE);
                            }
                        }
                        if (tokens[0] == "compact")
                        {
                            if (_sfsManager.Compact())
                            {
                                Console.WriteLine(SFS_COMMAND_MESSAGE_COMPACTAGE_DONE);
                            }
                            else
                            {
                                Console.WriteLine(SFS_COMMAND_ERR_COMPACTAGE_FAILED);
                            }
                        }
                        if (tokens[0] == "type")
                        {
                            Console.WriteLine(_sFsREPLCommand.TypeCommand(cmd.Substring(5)));
                        }
                        if (tokens[0] == "open")
                        {
                            Console.WriteLine(_sFsREPLCommand.OpenCommand(cmd.Substring(5)));
                        }
                        if (tokens[0] == "dir")
                        {
                            Console.WriteLine(_sFsREPLCommand.DirCommand());
                        }
                        if (tokens[0] == "dirall")
                        {
                            Console.WriteLine(_sFsREPLCommand.DirCommand(true));
                        }
                        if (tokens[0] == "copy")
                        {
                            Console.WriteLine(_sFsREPLCommand.CopyFileCommand(cmd.Substring(5)));
                        }
                    }
                }
            }
            Console.Clear();
        }