Exemplo n.º 1
0
        /// <summary>
        /// Only validate a masterkey with the given fortress.
        /// </summary>
        /// <param name="fortressFullPath"></param>
        /// <param name="fortressName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool ValidateMasterkey(string password, bool useDefaultValues = true, string fortressFullPath = "", string fortressName = "")
        {
            try
            {
                if (useDefaultValues)
                {
                    fortressFullPath = CurrentFortressData.FullPath;
                    fortressName     = CurrentFortressData.FortressName;
                }

                if (_xmlDatacache == null)
                {
                    _xmlDatacache = new XmlDataCache(fortressFullPath);
                }

                _xmlDatacache.ValidateMasterKey(fortressFullPath, fortressName, password);
                password = string.Empty;
                return(true);
            }
            catch (Exception ex)
            {
                password = string.Empty;
                Logger.log.Error($"Couldn't validate key: {ex}");
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Disposes sensible ressources
 /// </summary>
 /// <returns></returns>
 public bool DisposeCache()
 {
     try
     {
         _xmlDatacache.Dispose();
         _xmlDatacache = null;
         return(true);
     }
     catch (Exception ex)
     {
         Logger.log.Error($"Couldn't dispose cache: {ex}");
         return(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Starts the <see cref="FactoryQueue{T1, T2}"/>. If called when queue has already been built, it resets the queue.
        /// </summary>
        public bool StartFactoryQueue(string fortressPath)
        {
            try
            {
                _factoryQueue = new FactoryQueue <FactoryTaskType, object[]>();
                _xmlDatacache = new XmlDataCache(fortressPath);

                Thread continousThread = new Thread(new ThreadStart(ContinousThread));
                continousThread.IsBackground = true;
                continousThread.Name         = "FACTORY_THREAD";
                continousThread.Start();
                return(true);
            }
            catch (Exception ex)
            {
                Logger.log.Error($"Couldn't start the factory queue. Closing the application.. {Environment.NewLine}{ex}");
                Application.Current.Shutdown();
                return(false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Builds a fortress.
        /// </summary>
        /// <param name="fullPath"></param>
        /// <param name="fortressName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool BuildFortress(string fullPath, string fortressName, string password)
        {
            try
            {
                _xmlDatacache = new XmlDataCache(fullPath);
                _xmlDatacache.BuildFortress(fullPath, fortressName, password);
                password = string.Empty;
                CurrentFortressData.FullPath     = fullPath;
                CurrentFortressData.FortressName = fortressName;
                CurrentFortressData.IsLocked     = false;
                CurrentFortressData.FortressId   = _xmlDatacache.GetAllFromUnsecure <Fortress>().FirstOrDefault().Id;

                return(true);
            }
            catch (Exception ex)
            {
                _xmlDatacache = null;
                password      = string.Empty;
                Logger.log.Error($"Couldn't build fortress: {ex}");
                return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Builds a new fortress.
        /// </summary>
        /// <param name="fortess"></param>
        public void CreateNewFortress(Fortress fortess)
        {
            _xmlDatacache = new XmlDataCache(fortess.FullPath);

            // Store the example data:
            var rootBranch = new Branch {
                Name = "Example: Projects", ParentBranchId = Guid.Empty
            };
            var rootBranch2 = new Branch {
                Name = "Example: Projects2", ParentBranchId = Guid.Empty
            };
            var subBranch = new Branch {
                Name = "Example: Passwords", ParentBranchId = rootBranch.Id
            };
            var examplePw = ByteHelper.StringToByteArray("thisIsAnExamplePassword");
            var leaf      = new Leaf {
                Name = "Password1", Description = "Here you can describe this entry.", BranchId = subBranch.Id
            };
            var leafPw = new LeafPassword {
                ForeignId = leaf.Id, Value = examplePw
            };

            examplePw = null;
            _xmlDatacache.AddToUnsecureMemoryDC(fortess);
            _xmlDatacache.AddToUnsecureMemoryDC(rootBranch);
            _xmlDatacache.AddToUnsecureMemoryDC(rootBranch2);
            _xmlDatacache.AddToUnsecureMemoryDC(subBranch);
            _xmlDatacache.AddToUnsecureMemoryDC(leaf);
            var leafPwAsBytes = ByteHelper.ObjectToByteArray(leafPw);

            _xmlDatacache.AddToSecureMemoryDC(leafPw.ForeignId, leafPwAsBytes);
            leafPw = null;
            // end exampel data

            _xmlDatacache.WriteFortress(fortess);
        }