Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FrmKeyManager"/> class.
        /// </summary>
        public FrmKeyManager(FileSystemInterface fileSystemInterface, ConfigHandling config, KeySelect keySelect)
        {
            _fileSystemInterface = fileSystemInterface;
            _config    = config;
            _keySelect = keySelect;
            InitializeComponent();
            GpgInterface.ExePath = _config["GPGEXE"];

            ListDirectory(treeView1);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FrmKeyManager"/> class.
        /// </summary>
        public FrmKeyManager(FileSystemInterface fileSystemInterface, ConfigHandling config, KeySelect keySelect)
        {
            _fileSystemInterface = fileSystemInterface;
            _config = config;
            _keySelect = keySelect;
            InitializeComponent();
            GpgInterface.ExePath = _config["GPGEXE"];

            ListDirectory(treeView1);
        }
Exemple #3
0
        /// <summary>
        ///     Inits the repo, gpg etc
        /// </summary>
        public FrmMain(FileSystemInterface fileSystemInterface, KeySelect keySelect, ConfigHandling config)
        {
            log.Debug("Init variables");
            fsi        = fileSystemInterface;
            _keySelect = keySelect;
            _config    = config;
            InitializeComponent();
            toolStripStatusLabel1.Text = "";

            log.Debug("init Bugsnag");
            var bugsnag = new BaseClient("23814316a6ecfe8ff344b6a467f07171");

            this.enableTray = false;

            // Getting actual version
            log.Debug("Getting program version");
            var assembly = Assembly.GetExecutingAssembly();
            var fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
            var version  = fvi.FileVersion;

            _config["version"] = version.Remove(5);
            Text = @"Pass4Win " + Strings.Version + @" " + _config["version"];
            // check config input
            log.Debug("Checking config validity");
            try
            {
                bool ChkBool = Directory.Exists(_config["PassDirectory"]);
                if (!ChkBool)
                {
                    throw new Exception("Pass directory fail");
                }
                ChkBool = File.Exists(_config["GPGEXE"]);
                if (!ChkBool)
                {
                    throw new Exception("GPG location fail");
                }
                if (_config["UseGitRemote"] || _config["ExternalGit"])
                {
                    // nobody cares, we want the exception and it's auto generated due to a null value or not a boolean
                }
            }
            catch
            {
                // no matter if it's a first run or a corrupt entry, let them fix it.
                log.Debug("Config corrupt or first run");
                _config["FirstRun"] = true;
                Program.Scope.Resolve <FrmConfig>().ShowDialog();
            }

            // checking for update in the background
            log.Debug("Checking online for latest release");
            LatestPass4WinRelease();

            // making new git object
            if (_config["ExternalGit"])
            {
                log.Debug("Using an external git executable");
                GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"], _config["ExternalGitLocation"]);
            }
            else
            {
                log.Debug("Using the internal git executable");
                GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"]);
            }

            //checking git status
            if (_config["UseGitRemote"] == true || _config["ExternalGit"])
            {
                if (GitRepo.ConnectToRepo() || (_config["ExternalGit"]))
                {
                    log.Debug("Remote Git is valid and active");
                    this.gitRepoOffline      = false;
                    toolStripOffline.Visible = false;
                    if (!GitRepo.Fetch(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win")))
                    {
                        // Something failed which shouldn't fail, rechecking online status
                        CheckOnline(false);
                    }
                }
                // checking if we can clone, otherwise make a new one
                else if (!GitRepo.GitClone(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win")))
                {
                    log.Debug("Making a new git repo");
                    Repository.Init(_config["PassDirectory"], false);
                    GitRepo.ConnectToRepo();
                    toolStripOffline.Visible = true;
                }
            }
            // no connection, no repo. So make a new one
            else if (!GitHandling.IsValid(_config["PassDirectory"]))
            {
                log.Debug("Making a new git repo");
                Repository.Init(_config["PassDirectory"], false);
                GitRepo.ConnectToRepo();
                toolStripOffline.Visible = true;
            }

            // Init GPG if needed
            string gpgfile = _config["PassDirectory"];

            gpgfile += "\\.gpg-id";
            // Check if we need to init the directory
            if (!File.Exists(gpgfile))
            {
                log.Debug("Creating .gpg-id");
                // ReSharper disable once AssignNullToNotNullAttribute
                Directory.CreateDirectory(Path.GetDirectoryName(gpgfile));
                if (_keySelect.ShowDialog() == DialogResult.OK)
                {
                    using (var w = new StreamWriter(gpgfile))
                    {
                        w.Write(_keySelect.Gpgkey);
                    }

                    if (!GitRepo.Commit(gpgfile))
                    {
                        MessageBox.Show(
                            Strings.FrmMain_EncryptCallback_Commit_failed_,
                            Strings.Error,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    _keySelect.Close();
                    MessageBox.Show(Strings.Error_nokey, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
            }
            // Setting the exe location for the GPG Dll
            GpgInterface.ExePath = _config["GPGEXE"];

            // Fill tree
            CreateNodes();

            this.enableTray = true;
        }
Exemple #4
0
        /// <summary>
        ///     Inits the repo, gpg etc
        /// </summary>
        public FrmMain()
        {
            InitializeComponent();
            toolStripStatusLabel1.Text = "";

            // ReSharper disable once UnusedVariable
            var bugsnag = new BaseClient("23814316a6ecfe8ff344b6a467f07171");

            this.enableTray = false;

            // Getting actual version
            var assembly = Assembly.GetExecutingAssembly();
            var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
            var version = fvi.FileVersion;
            Cfg["version"] = version.Remove(5, 2);

            Text = @"Pass4Win " + Strings.Version + @" " + Cfg["version"];


            // checking for update this an async operation
#pragma warning disable 4014
            LatestPass4WinRelease();
#pragma warning restore 4014

            // Do we have a valid password store and settings
            try
            {
                if (Cfg["PassDirectory"] == "")
                {
                    // this will fail, I know ugly hack
                }
            }
            catch (Exception)
            {
                Cfg["FirstRun"] = true;
                var config = new FrmConfig();
                config.ShowDialog();
            }
            //checking git status
            if (!IsValid(Cfg["PassDirectory"]))
            {
                // Remote or generate a new one
                if (Cfg["UseGitRemote"] == true)
                {
                    // check if server is alive
                    if (IsGitAlive(Cfg["UseGitRemote"]) || IsHttpsAlive(Cfg["UseGitRemote"]))
                    {
                        // clone the repo and catch any error
                        try
                        {
                            Clone(Cfg["GitRemote"], Cfg["PassDirectory"],
                                new CloneOptions
                                {
                                    CredentialsProvider = (url, user, cred) => new UsernamePasswordCredentials
                                    {
                                        Username = Cfg["GitUser"],
                                        Password = DecryptConfig(Cfg["GitPass"], "pass4win")
                                    }
                                });
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(Strings.Error_connection, Strings.Error, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            this.toolStripOffline.Visible = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show(Strings.Error_git_unreachable, Strings.Error, MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        toolStripOffline.Visible = true;
                    }
                }
                else
                {
                    // creating new Git
                    Repository.Init(Cfg["PassDirectory"], false);
                    toolStripOffline.Visible = true;
                }
            }
            else
            {
                // Do we do remote or not
                CheckOnline(true);
            }

            // Making sure core.autocrlf = true
            using (var repo = new Repository(Cfg["PassDirectory"]))
            {
                repo.Config.Set("core.autocrlf", true);
            }

            // Init GPG if needed
            string gpgfile = Cfg["PassDirectory"];
            gpgfile += "\\.gpg-id";
            // Check if we need to init the directory
            if (!File.Exists(gpgfile))
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                Directory.CreateDirectory(Path.GetDirectoryName(gpgfile));
                var newKeySelect = new KeySelect();
                if (newKeySelect.ShowDialog() == DialogResult.OK)
                {
                    using (var w = new StreamWriter(gpgfile))
                    {
                        w.Write(newKeySelect.Gpgkey);
                    }
                    using (var repo = new Repository(Cfg["PassDirectory"]))
                    {
                        repo.Stage(gpgfile);
                        repo.Commit("gpgid added",
                            new Signature("pass4win", "pass4win", DateTimeOffset.Now),
                            new Signature("pass4win", "pass4win", DateTimeOffset.Now));
                    }
                }
                else
                {
                    newKeySelect.Close();
                    MessageBox.Show(Strings.Error_nokey, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
            }
            // Setting the exe location for the GPG Dll
            GpgInterface.ExePath = Cfg["GPGEXE"];

            // init FileSystemInterface class
            fsi = new FileSystemInterface(Cfg["PassDirectory"]);

            // Fill tree
            CreateNodes();
    
            this.enableTray = true;
        }
Exemple #5
0
        /// <summary>
        /// Filles the treenode.
        /// </summary>
        /// <param name="treeView">Which treeview to fill</param>
        /// <param name="rootDirectoryInfo">Which directory</param>
        private void ListDirectory(TreeView treeView, DirectoryInfo rootDirectoryInfo)
        {
            // Get the TreeView ready for node creation.
            treeView.BeginUpdate();
            treeView.Nodes.Clear();
            FileSystemInterface fsi = new FileSystemInterface(rootDirectoryInfo.FullName);
            TreeNode[] nodes = fsi.UpdateDirectoryTree(rootDirectoryInfo);
            treeView.Nodes.AddRange(nodes);

            // Notify the TreeView to resume painting.
            treeView.EndUpdate();
        }
Exemple #6
0
        /// <summary>
        ///     Inits the repo, gpg etc
        /// </summary>
        public FrmMain(FileSystemInterface fileSystemInterface, KeySelect keySelect, ConfigHandling config)
        {
            log.Debug("Init variables");
            fsi = fileSystemInterface;
            _keySelect = keySelect;
            _config = config;
            InitializeComponent();
            toolStripStatusLabel1.Text = "";

            log.Debug("init Bugsnag");
            var bugsnag = new BaseClient("23814316a6ecfe8ff344b6a467f07171");

            this.enableTray = false;
            // Getting actual version
            log.Debug("Getting program version");
            var assembly = Assembly.GetExecutingAssembly();
            var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
            var version = fvi.FileVersion;
            _config["version"] = version.Remove(5);
            Text = @"Pass4Win " + Strings.Version + @" " + _config["version"];
            // check config input
            log.Debug("Checking config validity");
            try
            {
                bool ChkBool = Directory.Exists(_config["PassDirectory"]);
                if (!ChkBool)
                    throw new Exception("Pass directory fail");
                ChkBool = File.Exists(_config["GPGEXE"]);
                if (!ChkBool)
                    throw new Exception("GPG location fail");
                if (_config["UseGitRemote"] || _config["ExternalGit"])
                {
                    // nobody cares, we want the exception and it's auto generated due to a null value or not a boolean
                }
            }
            catch
            {
                // no matter if it's a first run or a corrupt entry, let them fix it.
                log.Debug("Config corrupt or first run");
                _config["FirstRun"] = true;
                Program.Scope.Resolve<FrmConfig>().ShowDialog();
            }

            // checking for update in the background
            log.Debug("Checking online for latest release");
            LatestPass4WinRelease();

            // making new git object
            if (_config["ExternalGit"] && !Program.NoGit)
            {
                log.Debug("Using an external git executable");
                GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"], _config["ExternalGitLocation"]);
            }
            else if (!Program.NoGit)
            {
                log.Debug("Using the internal git executable");
                GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"]);
            }

            //checking git status
            if (_config["UseGitRemote"] == true || _config["ExternalGit"])
            {
                if (!Program.NoGit)
                {
                    if (GitRepo.ConnectToRepo() || (_config["ExternalGit"]))
                    {
                        log.Debug("Remote Git is valid and active");
                        this.gitRepoOffline = false;
                        toolStripOffline.Visible = false;
                        if (!GitRepo.Fetch(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win")))
                        {
                            // Something failed which shouldn't fail, rechecking online status
                            CheckOnline(false);
                        }
                    }
                    // checking if we can clone, otherwise make a new one
                    else if (!GitRepo.GitClone(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win")))
                    {
                        log.Debug("Making a new git repo");
                        Repository.Init(_config["PassDirectory"], false);
                        GitRepo.ConnectToRepo();
                        toolStripOffline.Visible = true;
                    }
                    // no connection, no repo. So make a new one
                    else if (!GitHandling.IsValid(_config["PassDirectory"]))
                    {
                        log.Debug("Making a new git repo");
                        Repository.Init(_config["PassDirectory"], false);
                        GitRepo.ConnectToRepo();
                        toolStripOffline.Visible = true;
                    }
                }
            }

            // Init GPG if needed
            string gpgfile = _config["PassDirectory"];
            gpgfile += "\\.gpg-id";
            // Check if we need to init the directory
            if (!File.Exists(gpgfile))
            {
                log.Debug("Creating .gpg-id");
                // ReSharper disable once AssignNullToNotNullAttribute
                Directory.CreateDirectory(Path.GetDirectoryName(gpgfile));
                if (_keySelect.ShowDialog() == DialogResult.OK)
                {
                    using (var w = new StreamWriter(gpgfile))
                    {
                        w.Write(_keySelect.Gpgkey);
                    }

                    if (!Program.NoGit)
                    {
                        if (!GitRepo.Commit(gpgfile))
                        {
                            MessageBox.Show(
                                Strings.FrmMain_EncryptCallback_Commit_failed_,
                                Strings.Error,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
                else
                {
                    _keySelect.Close();
                    MessageBox.Show(Strings.Error_nokey, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }
            }
            // Setting the exe location for the GPG Dll
            GpgInterface.ExePath = _config["GPGEXE"];

            // Fill tree
            CreateNodes();

            this.enableTray = true;
        }