private void SetKeys(LocalBox localBox)
        {
            var explorer = new RemoteExplorer(localBox);
            var user     = explorer.GetUser();

            if (user != null && !(string.IsNullOrEmpty(user.PrivateKey) || string.IsNullOrEmpty(user.PublicKey)))
            {
                localBox.PrivateKey = Convert.FromBase64String(user.PrivateKey);
                localBox.PublicKey  = Convert.FromBase64String(user.PublicKey);
            }
            DataLayer.Instance.AddOrUpdateLocalBox(localBox);
        }
Esempio n. 2
0
        public Task <TreeNode> GetFolder(string path, bool refresh = false)
        {
            return(Task.Run(() =>
            {
                if (refresh)
                {
                    RefreshFolder(path);
                }
                var result = database.GetTree(path);

                if (result != null && result.Children.Count == 0)
                {
                    RefreshFolder(path);
                    result = database.GetTree(path);
                    UpdateFolderKey(result);
                }
                else // root is null
                {
                    if (result == null && (path.Equals("/") || path.Equals("")))
                    {
                        int boxId = Waardes.Instance.GeselecteerdeBox;

                        var node = new TreeNode()
                        {
                            Name = "Root",
                            Path = "/",
                            ParentId = 0,
                            IsDirectory = true,
                            LocalBoxId = boxId
                        };
                        database.AddNode(node);

                        //Create unencrypted public folder in empty root directory
                        var explorer = new RemoteExplorer();
                        string nameOfUser = explorer.GetUser().Name;
                        CreateFolder("/Publiek - " + nameOfUser, false);

                        RefreshFolder(node.Path);
                        result = database.GetTree(path);
                    }
                }
                return result;
            }));
        }
        private List <AesKeyPost> AddKeys(string path, List <Identity> usersToShareWith, List <Identity> toAdd)
        {
            List <AesKeyPost> result = new List <AesKeyPost> ();

            try {
                LocalBox box      = DataLayer.Instance.GetSelectedOrDefaultBox();
                var      explorer = new RemoteExplorer(box);

                var node = DataLayer.Instance.GetFolder(path).Result;

                if (node.HasCryptoKeys)
                {
                    foreach (var identity in toAdd)
                    {
                        var user = explorer.GetUser(identity.Username);
                        if (!string.IsNullOrEmpty(user.PublicKey))
                        {
                            byte[] pkey = Convert.FromBase64String(user.PublicKey);
                            result.Add(new AesKeyPost()
                            {
                                User = identity.Username,
                                Key  = Convert.ToBase64String(CryptoHelper.EncryptPgp(node.Key, pkey)),
                                IV   = Convert.ToBase64String(CryptoHelper.EncryptPgp(node.IV, pkey))
                            });
                        }
                        else
                        {
                            var u = identity;
                            usersToShareWith.RemoveAll(e => e.Id.Equals(u.Id));
                        }
                    }
                }
                return(result);
            }
            catch (Exception ex) {
                Insights.Report(ex);
                return(result);
            }
        }