예제 #1
0
        public static PwDatabase CreateKeePassDatabase(string databasePath, CompositeKey compositeKey)
        {
            if (!databasePath.EndsWith(".kdbx"))
                throw new FileNotFoundException("The database file must end with .kdbx");

            var directoryName = Path.GetDirectoryName(databasePath);
            var fileName = Path.GetFileName(databasePath);

            if (!Directory.Exists(directoryName))
                Directory.CreateDirectory(directoryName);

            var ioc = new IOConnectionInfo();
            ioc.Path = fileName;
            ioc.CredSaveMode = IOCredSaveMode.NoSave;

            var database = new PwDatabase();
            database.New(ioc, compositeKey);
            database.Save(null);

            return database;
        }
예제 #2
0
 public void Save(PwDatabase kpDatabase, Stream stream)
 {
     kpDatabase.Save(stream, null);
 }
예제 #3
0
 public static void CloseKeePassDatabase(PwDatabase database)
 {
     database.Save(null);
     database.Close();
 }
        public void ShouldHandleCyclesOfNodesInImportAndExport()
        {
            var exportPath = GetTestPath();
            m_syncManager.AddExportPath(exportPath);

            var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");
            m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrX), true);

            var existingEntry = new PwEntry(true, true);
            existingEntry.SetTitle("Entry Version 1");
            m_database.RootGroup.AddEntry(existingEntry, true);
            m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrX), true);

            m_treeManager.CorrectStructure();

            string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension;
            Assert.IsFalse(File.Exists(exportFile));

            m_syncManager.Export();

            var deltaDBInitial = new PwDatabase();
            deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
            Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1"));
            foreach(var entry in deltaDBInitial.RootGroup.GetEntries(true))
            {
                entry.SetTitle("Changed");
            }
            deltaDBInitial.Save(null);
            deltaDBInitial.Close();

            m_syncManager.AddImportPath(exportFile);
            m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword(userMrX.Strings.ReadSafe(KeeShare.KeeShare.PasswordField));

            m_syncManager.RefeshSourcesList();
            // Node normalEntry6 is within the user home and is relocated on export which changes the parent node - during import, the parents of
            // not "officially" relocated nodes is checked and an assertion is thrown
            Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Changed"));
        }