mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-30 05:43:00 -08:00
Support creating .kdbx databases.
This commit is contained in:
1 parent
8ee87ca3b9
commit
2a585e9fea
8 files changed
+95
-28
No files matched your search
@@ -1,6 +1,7 @@
|
||||
KeePassDroid (2.0.4beta1)
|
||||
* Fix notification icons (closes: #60)
|
||||
* Add warning about non-Latin1 characters (closes: #64)
|
||||
* Add support for creating .kdbx databases, make this the default
|
||||
|
||||
KeePassDroid (2.0.3)
|
||||
* Improve password font handling. Handle failure to load font gracefully
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
-->
|
||||
<resources>
|
||||
<string name="clipboard_error_url">http://code.google.com/p/android/issues/detail?id=35732</string>
|
||||
<string name="default_file_path">/keepass/keepass.kdb</string>
|
||||
<string name="default_file_path">/keepass/keepass.kdbx</string>
|
||||
<string name="donate_url"><![CDATA[https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8246230]]></string>
|
||||
<string name="homepage">http://www.keepassdroid.com</string>
|
||||
<string name="homepage_short">www.keepassdroid.com</string>
|
||||
|
||||
@@ -113,6 +113,14 @@ public class Database {
|
||||
|
||||
pm.populateGlobals(root);
|
||||
|
||||
LoadData(ctx, pm, password, keyfile, status);
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void LoadData(Context ctx, PwDatabase pm, String password, String keyfile, UpdateStatus status) {
|
||||
if ( pm != null ) {
|
||||
passwordEncodingError = !pm.validatePasswordEncoding(password);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,23 @@ public abstract class PwDatabase {
|
||||
public Map<UUID, PwEntry> entries = new HashMap<UUID, PwEntry>();
|
||||
|
||||
|
||||
private static boolean isKDBExtension(String filename) {
|
||||
if (filename == null) { return false; }
|
||||
|
||||
int extIdx = filename.lastIndexOf(".");
|
||||
if (extIdx == -1) return false;
|
||||
|
||||
return filename.substring(extIdx, filename.length()).equalsIgnoreCase(".kdb");
|
||||
}
|
||||
|
||||
public static PwDatabase getNewDBInstance(String filename) {
|
||||
if (isKDBExtension(filename)) {
|
||||
return new PwDatabaseV3();
|
||||
} else {
|
||||
return new PwDatabaseV4();
|
||||
}
|
||||
}
|
||||
|
||||
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, int numRounds) throws IOException {
|
||||
|
||||
// Write checksum Checksum
|
||||
@@ -379,4 +396,9 @@ public abstract class PwDatabase {
|
||||
return group != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a newly created database
|
||||
*/
|
||||
public abstract void initNew(String dbPath);
|
||||
|
||||
}
|
||||
@@ -50,6 +50,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.keepassdroid.database.exception.InvalidKeyFileException;
|
||||
|
||||
@@ -62,6 +63,8 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
// Constants
|
||||
// private static final int PWM_SESSION_KEY_SIZE = 12;
|
||||
|
||||
private final int DEFAULT_ENCRYPTION_ROUNDS = 300;
|
||||
|
||||
// Special entry for settings
|
||||
public PwEntry metaInfo;
|
||||
|
||||
@@ -333,4 +336,24 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
|
||||
return !(omitBackup && isBackup(group));
|
||||
}
|
||||
|
||||
private void initAndAddGroup(String name, int iconId, PwGroup parent) {
|
||||
PwGroup group = createGroup();
|
||||
group.initNewGroup(name, newGroupId());
|
||||
group.icon = iconFactory.getIcon(iconId);
|
||||
addGroupTo(group, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initNew(String dbPath) {
|
||||
algorithm = PwEncryptionAlgorithm.Rjindal;
|
||||
numKeyEncRounds = DEFAULT_ENCRYPTION_ROUNDS;
|
||||
name = "KeePass Password Manager";
|
||||
// Build the root group
|
||||
constructTree(null);
|
||||
|
||||
// Add a couple default groups
|
||||
initAndAddGroup("Internet", 1, rootGroup);
|
||||
initAndAddGroup("eMail", 19, rootGroup);
|
||||
}
|
||||
}
|
||||
@@ -39,9 +39,12 @@ import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import android.webkit.URLUtil;
|
||||
import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
import com.keepassdroid.crypto.CipherFactory;
|
||||
import com.keepassdroid.database.exception.InvalidKeyFileException;
|
||||
import com.keepassdroid.utils.EmptyUtils;
|
||||
|
||||
|
||||
public class PwDatabaseV4 extends PwDatabase {
|
||||
@@ -52,13 +55,13 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited
|
||||
private static final String RECYCLEBIN_NAME = "RecycleBin";
|
||||
|
||||
public UUID dataCipher;
|
||||
public PwCompressionAlgorithm compressionAlgorithm;
|
||||
public long numKeyEncRounds;
|
||||
public UUID dataCipher = CipherFactory.AES_CIPHER;
|
||||
public PwCompressionAlgorithm compressionAlgorithm = PwCompressionAlgorithm.Gzip;
|
||||
public long numKeyEncRounds = 6000;
|
||||
public Date nameChanged = DEFAULT_NOW;
|
||||
public String description;
|
||||
public String description = "";
|
||||
public Date descriptionChanged = DEFAULT_NOW;
|
||||
public String defaultUserName;
|
||||
public String defaultUserName = "";
|
||||
public Date defaultUserNameChanged = DEFAULT_NOW;
|
||||
|
||||
public Date keyLastChanged = DEFAULT_NOW;
|
||||
@@ -67,15 +70,15 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
|
||||
public long maintenanceHistoryDays = 365;
|
||||
public String color = "";
|
||||
public boolean recycleBinEnabled;
|
||||
public UUID recycleBinUUID = null;
|
||||
public boolean recycleBinEnabled = true;
|
||||
public UUID recycleBinUUID = UUID_ZERO;
|
||||
public Date recycleBinChanged = DEFAULT_NOW;
|
||||
public UUID entryTemplatesGroup;
|
||||
public UUID entryTemplatesGroup = UUID_ZERO;
|
||||
public Date entryTemplatesGroupChanged = DEFAULT_NOW;
|
||||
public int historyMaxItems = DEFAULT_HISTORY_MAX_ITEMS;
|
||||
public long historyMaxSize = DEFAULT_HISTORY_MAX_SIZE;
|
||||
public UUID lastSelectedGroup;
|
||||
public UUID lastTopVisibleGroup;
|
||||
public UUID lastSelectedGroup = UUID_ZERO;
|
||||
public UUID lastTopVisibleGroup = UUID_ZERO;
|
||||
public MemoryProtectionConfig memoryProtection = new MemoryProtectionConfig();
|
||||
public List<PwDeletedObject> deletedObjects = new ArrayList<PwDeletedObject>();
|
||||
public List<PwIconCustom> customIcons = new ArrayList<PwIconCustom>();
|
||||
@@ -365,5 +368,26 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public boolean validatePasswordEncoding(String key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initNew(String dbPath) {
|
||||
String filename = URLUtil.guessFileName(dbPath, null, null);
|
||||
|
||||
rootGroup = new PwGroupV4(true, true, dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER));
|
||||
}
|
||||
|
||||
private String dbNameFromPath(String dbPath) {
|
||||
String filename = URLUtil.guessFileName(dbPath, null, null);
|
||||
|
||||
if (EmptyUtils.isNullOrEmpty(filename)) {
|
||||
return "KeePass Database";
|
||||
}
|
||||
int lastExtDot = filename.lastIndexOf(".");
|
||||
if (lastExtDot == -1) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
return filename.substring(0, lastExtDot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 Brian Pellin.
|
||||
* Copyright 2010-2015 Brian Pellin.
|
||||
*
|
||||
* This file is part of KeePassDroid.
|
||||
*
|
||||
@@ -25,6 +25,7 @@ public class PwIconStandard extends PwIcon {
|
||||
public static PwIconStandard FIRST = new PwIconStandard(1);
|
||||
|
||||
public static final int TRASH_BIN = 43;
|
||||
public static final int FOLDER = 48;
|
||||
|
||||
public PwIconStandard(int iconId) {
|
||||
this.iconId = iconId;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009 Brian Pellin.
|
||||
* Copyright 2009-2015 Brian Pellin.
|
||||
*
|
||||
* This file is part of KeePassDroid.
|
||||
*
|
||||
@@ -22,6 +22,7 @@ package com.keepassdroid.database.edit;
|
||||
|
||||
import com.keepassdroid.Database;
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwDatabaseV3;
|
||||
import com.keepassdroid.database.PwEncryptionAlgorithm;
|
||||
|
||||
@@ -45,31 +46,18 @@ public class CreateDB extends RunnableOnFinish {
|
||||
Database db = new Database();
|
||||
App.setDB(db);
|
||||
|
||||
// Create the PwDatabaseV3
|
||||
PwDatabaseV3 pm = new PwDatabaseV3();
|
||||
pm.algorithm = PwEncryptionAlgorithm.Rjindal;
|
||||
pm.numKeyEncRounds = DEFAULT_ENCRYPTION_ROUNDS;
|
||||
pm.name = "KeePass Password Manager";
|
||||
// Build the root group
|
||||
pm.constructTree(null);
|
||||
PwDatabase pm = PwDatabase.getNewDBInstance(mFilename);
|
||||
pm.initNew(mFilename);
|
||||
|
||||
// Set Database state
|
||||
db.pm = pm;
|
||||
db.mFilename = mFilename;
|
||||
db.setLoaded();
|
||||
|
||||
// Add a couple default groups
|
||||
AddGroup internet = AddGroup.getInstance(db, "Internet", 1, pm.rootGroup, null, true);
|
||||
internet.run();
|
||||
AddGroup email = AddGroup.getInstance(db, "eMail", 19, pm.rootGroup, null, true);
|
||||
email.run();
|
||||
|
||||
// Commit changes
|
||||
SaveDB save = new SaveDB(db, mFinish, mDontSave);
|
||||
mFinish = null;
|
||||
save.run();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user