mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-21 17:41:50 -08:00
Temp Merge branch 'feature/RefactorModel' to correct serializable crash
This commit is contained in:
commit
a5cb5ed896
47 files changed
+1338
-1516
No files matched your search
@@ -42,7 +42,7 @@ public class PwEntryTestV3 extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
assertTrue("Name was " + mPE.title, mPE.title.equals("Amazon"));
|
||||
assertTrue("Name was " + mPE.getTitle(), mPE.getTitle().equals("Amazon"));
|
||||
}
|
||||
|
||||
public void testPassword() throws UnsupportedEncodingException {
|
||||
@@ -54,7 +54,7 @@ public class PwEntryTestV3 extends AndroidTestCase {
|
||||
|
||||
public void testCreation() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(mPE.tCreation.getJDate());
|
||||
cal.setTime(mPE.getCreationTime().getDate());
|
||||
|
||||
assertEquals("Incorrect year.", cal.get(Calendar.YEAR), 2009);
|
||||
assertEquals("Incorrect month.", cal.get(Calendar.MONTH), 3);
|
||||
|
||||
@@ -19,10 +19,7 @@
|
||||
*/
|
||||
package com.keepassdroid.tests;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.keepassdroid.database.AutoType;
|
||||
import com.keepassdroid.database.PwEntryV4;
|
||||
import com.keepassdroid.database.PwGroupV4;
|
||||
import com.keepassdroid.database.PwIconCustom;
|
||||
@@ -30,29 +27,33 @@ import com.keepassdroid.database.PwIconStandard;
|
||||
import com.keepassdroid.database.security.ProtectedBinary;
|
||||
import com.keepassdroid.database.security.ProtectedString;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PwEntryTestV4 extends TestCase {
|
||||
public void testAssign() {
|
||||
PwEntryV4 entry = new PwEntryV4();
|
||||
|
||||
entry.additional = "test223";
|
||||
entry.setAdditional("test223");
|
||||
|
||||
entry.autoType = entry.new AutoType();
|
||||
entry.autoType.defaultSequence = "1324";
|
||||
entry.autoType.enabled = true;
|
||||
entry.autoType.obfuscationOptions = 123412432109L;
|
||||
entry.autoType.put("key", "value");
|
||||
entry.setAutoType(new AutoType());
|
||||
entry.getAutoType().defaultSequence = "1324";
|
||||
entry.getAutoType().enabled = true;
|
||||
entry.getAutoType().obfuscationOptions = 123412432109L;
|
||||
entry.getAutoType().put("key", "value");
|
||||
|
||||
entry.backgroupColor = "blue";
|
||||
entry.binaries.put("key1", new ProtectedBinary(false, new byte[] {0,1}));
|
||||
entry.customIcon = new PwIconCustom(UUID.randomUUID(), new byte[0]);
|
||||
entry.foregroundColor = "red";
|
||||
entry.history.add(new PwEntryV4());
|
||||
entry.icon = new PwIconStandard(5);
|
||||
entry.overrideURL = "override";
|
||||
entry.parent = new PwGroupV4();
|
||||
entry.setBackgroupColor("blue");
|
||||
entry.putProtectedBinary("key1", new ProtectedBinary(false, new byte[] {0,1}));
|
||||
entry.setCustomIcon(new PwIconCustom(UUID.randomUUID(), new byte[0]));
|
||||
entry.setForegroundColor("red");
|
||||
entry.addToHistory(new PwEntryV4());
|
||||
entry.setIcon(new PwIconStandard(5));
|
||||
entry.setOverrideURL("override");
|
||||
entry.setParent(new PwGroupV4());
|
||||
entry.addField("key2", new ProtectedString(false, "value2"));
|
||||
entry.url = "http://localhost";
|
||||
entry.uuid = UUID.randomUUID();
|
||||
entry.setUrl("http://localhost");
|
||||
entry.setUUID(UUID.randomUUID());
|
||||
|
||||
PwEntryV4 target = new PwEntryV4();
|
||||
target.assign(entry);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class PwGroupTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void testGroupName() {
|
||||
assertTrue("Name was " + mPG.name, mPG.name.equals("Internet"));
|
||||
assertTrue("Name was " + mPG.getName(), mPG.getName().equals("Internet"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,19 +32,21 @@ public class EntryV4 extends TestCase {
|
||||
db.historyMaxItems = 2;
|
||||
|
||||
PwEntryV4 entry = new PwEntryV4();
|
||||
entry.setTitle("Title1", db);
|
||||
entry.setUsername("User1", db);
|
||||
entry.startToDecodeReference(db);
|
||||
entry.setTitle("Title1");
|
||||
entry.setUsername("User1");
|
||||
entry.createBackup(db);
|
||||
|
||||
entry.setTitle("Title2", db);
|
||||
entry.setUsername("User2", db);
|
||||
entry.setTitle("Title2");
|
||||
entry.setUsername("User2");
|
||||
entry.createBackup(db);
|
||||
|
||||
entry.setTitle("Title3", db);
|
||||
entry.setUsername("User3", db);
|
||||
entry.setTitle("Title3");
|
||||
entry.setUsername("User3");
|
||||
entry.createBackup(db);
|
||||
|
||||
PwEntryV4 backup = entry.history.get(0);
|
||||
PwEntryV4 backup = entry.getHistory().get(0);
|
||||
entry.endToDecodeReference(db);
|
||||
assertEquals("Title2", backup.getTitle());
|
||||
assertEquals("User2", backup.getUsername());
|
||||
}
|
||||
|
||||
@@ -27,15 +27,16 @@ import android.content.res.AssetManager;
|
||||
import android.test.AndroidTestCase;
|
||||
import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwDatabaseV4;
|
||||
import com.keepassdroid.database.PwEntryV4;
|
||||
import com.keepassdroid.database.load.ImporterV4;
|
||||
import com.keepassdroid.utils.SprEngine;
|
||||
import com.keepassdroid.utils.SprEngineV4;
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
public class SprEngineTest extends AndroidTestCase {
|
||||
private PwDatabaseV4 db;
|
||||
private SprEngine spr;
|
||||
private SprEngineV4 spr;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -51,7 +52,7 @@ public class SprEngineTest extends AndroidTestCase {
|
||||
|
||||
is.close();
|
||||
|
||||
spr = SprEngine.getInstance(db);
|
||||
spr = new SprEngineV4();
|
||||
}
|
||||
|
||||
private final String REF = "{REF:P@I:2B1D56590D961F48A8CE8C392CE6CD35}";
|
||||
@@ -69,7 +70,7 @@ public class SprEngineTest extends AndroidTestCase {
|
||||
|
||||
private UUID decodeUUID(String encoded) {
|
||||
if (encoded == null || encoded.length() == 0 ) {
|
||||
return PwDatabaseV4.UUID_ZERO;
|
||||
return PwDatabase.UUID_ZERO;
|
||||
}
|
||||
|
||||
byte[] buf = Base64Coder.decode(encoded);
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.keepassdroid.database.Database;
|
||||
import com.keepassdroid.database.PwGroup;
|
||||
import com.keepassdroid.tests.database.TestData;
|
||||
@@ -66,7 +65,7 @@ public class SearchTest extends AndroidTestCase {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
|
||||
editor.putBoolean(ctx.getString(R.string.settings_omitbackup_key), setting);
|
||||
editor.putBoolean("settings_omitbackup_key", setting);
|
||||
editor.commit();
|
||||
|
||||
}
|
||||
|
||||
@@ -146,6 +146,8 @@ public class EntryActivity extends LockingHideActivity {
|
||||
fillData();
|
||||
invalidateOptionsMenu();
|
||||
|
||||
// TODO Start decode
|
||||
|
||||
// If notifications enabled in settings
|
||||
// Don't if application timeout
|
||||
if (firstLaunchOfActivity && !App.isShutdown() && isClipboardNotificationsEnable(getApplicationContext())) {
|
||||
@@ -179,7 +181,7 @@ public class EntryActivity extends LockingHideActivity {
|
||||
if (mEntry.allowExtraFields()) {
|
||||
try {
|
||||
int anonymousFieldNumber = 0;
|
||||
for (Map.Entry<String, String> entry : mEntry.getExtraFields(App.getDB().pm).entrySet()) {
|
||||
for (Map.Entry<String, String> entry : mEntry.getExtraFields().entrySet()) {
|
||||
notificationFields.add(
|
||||
new NotificationField(
|
||||
NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber],
|
||||
@@ -198,6 +200,7 @@ public class EntryActivity extends LockingHideActivity {
|
||||
|
||||
startService(intent);
|
||||
}
|
||||
// TODO end decode
|
||||
}
|
||||
firstLaunchOfActivity = false;
|
||||
}
|
||||
@@ -211,34 +214,36 @@ public class EntryActivity extends LockingHideActivity {
|
||||
Database db = App.getDB();
|
||||
PwDatabase pm = db.pm;
|
||||
|
||||
mEntry.startToDecodeReference(pm);
|
||||
|
||||
// Assign title
|
||||
populateTitle(db.drawFactory.getIconDrawable(getResources(), mEntry.getIcon()),
|
||||
mEntry.getTitle(true, pm));
|
||||
mEntry.getTitle());
|
||||
|
||||
// Assign basic fields
|
||||
entryContentsView.assignUserName(mEntry.getUsername(true, pm));
|
||||
entryContentsView.assignUserName(mEntry.getUsername());
|
||||
entryContentsView.assignUserNameCopyListener(view ->
|
||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(true, App.getDB().pm),
|
||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
|
||||
getString(R.string.copy_field, getString(R.string.entry_user_name)))
|
||||
);
|
||||
|
||||
entryContentsView.assignPassword(mEntry.getPassword(true, pm));
|
||||
entryContentsView.assignPassword(mEntry.getPassword());
|
||||
if (PreferencesUtil.allowCopyPassword(this)) {
|
||||
entryContentsView.assignPasswordCopyListener(view ->
|
||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(true, App.getDB().pm),
|
||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(),
|
||||
getString(R.string.copy_field, getString(R.string.entry_password)))
|
||||
);
|
||||
}
|
||||
|
||||
entryContentsView.assignURL(mEntry.getUrl(true, pm));
|
||||
entryContentsView.assignURL(mEntry.getUrl());
|
||||
|
||||
entryContentsView.setHiddenPasswordStyle(!mShowPassword);
|
||||
entryContentsView.assignComment(mEntry.getNotes(true, pm));
|
||||
entryContentsView.assignComment(mEntry.getNotes());
|
||||
|
||||
// Assign custom fields
|
||||
if (mEntry.allowExtraFields()) {
|
||||
entryContentsView.clearExtraFields();
|
||||
for (Map.Entry<String, String> field : mEntry.getExtraFields(pm).entrySet()) {
|
||||
for (Map.Entry<String, String> field : mEntry.getExtraFields().entrySet()) {
|
||||
final String label = field.getKey();
|
||||
final String value = field.getValue();
|
||||
entryContentsView.addExtraField(label, value, view ->
|
||||
@@ -247,15 +252,17 @@ public class EntryActivity extends LockingHideActivity {
|
||||
}
|
||||
|
||||
// Assign dates
|
||||
entryContentsView.assignCreationDate(mEntry.getCreationTime());
|
||||
entryContentsView.assignModificationDate(mEntry.getLastModificationTime());
|
||||
entryContentsView.assignLastAccessDate(mEntry.getLastAccessTime());
|
||||
Date expires = mEntry.getExpiryTime();
|
||||
entryContentsView.assignCreationDate(mEntry.getCreationTime().getDate());
|
||||
entryContentsView.assignModificationDate(mEntry.getLastModificationTime().getDate());
|
||||
entryContentsView.assignLastAccessDate(mEntry.getLastAccessTime().getDate());
|
||||
Date expires = mEntry.getExpiryTime().getDate();
|
||||
if ( mEntry.expires() ) {
|
||||
entryContentsView.assignExpiresDate(expires);
|
||||
} else {
|
||||
entryContentsView.assignExpiresDate(getString(R.string.never));
|
||||
}
|
||||
|
||||
mEntry.endToDecodeReference(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,9 +38,8 @@ import android.widget.Toast;
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.database.Database;
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwDatabaseV4;
|
||||
import com.keepassdroid.database.PwDate;
|
||||
import com.keepassdroid.database.PwEntry;
|
||||
import com.keepassdroid.database.PwEntryV4;
|
||||
import com.keepassdroid.database.PwGroup;
|
||||
import com.keepassdroid.database.PwGroupId;
|
||||
import com.keepassdroid.database.PwIconStandard;
|
||||
@@ -60,9 +59,6 @@ import com.keepassdroid.utils.Util;
|
||||
import com.keepassdroid.view.EntryEditNewField;
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -245,21 +241,18 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
}
|
||||
|
||||
protected PwEntry populateNewEntry() {
|
||||
if (mEntry instanceof PwEntryV4) {
|
||||
// TODO backup
|
||||
PwEntryV4 newEntry = (PwEntryV4) mEntry.clone(true);
|
||||
newEntry.history = (ArrayList<PwEntryV4>) newEntry.history.clone();
|
||||
newEntry.createBackup((PwDatabaseV4) App.getDB().pm);
|
||||
}
|
||||
|
||||
PwEntry newEntry = mEntry.clone(true);
|
||||
|
||||
Date now = Calendar.getInstance().getTime();
|
||||
newEntry.setLastAccessTime(now);
|
||||
newEntry.setLastModificationTime(now);
|
||||
|
||||
PwDatabase db = App.getDB().pm;
|
||||
newEntry.setTitle(entryTitleView.getText().toString(), db);
|
||||
|
||||
PwEntry newEntry = mEntry.clone();
|
||||
|
||||
newEntry.startToDecodeReference(db);
|
||||
|
||||
newEntry.createBackup(db);
|
||||
|
||||
newEntry.setLastAccessTime(new PwDate());
|
||||
newEntry.setLastModificationTime(new PwDate());
|
||||
|
||||
newEntry.setTitle(entryTitleView.getText().toString());
|
||||
if(mSelectedIconID != -1)
|
||||
// or TODO icon factory newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(mSelectedIconID));
|
||||
newEntry.setIcon(new PwIconStandard(mSelectedIconID));
|
||||
@@ -269,13 +262,13 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
}
|
||||
else {
|
||||
// Keep previous icon, if no new one was selected
|
||||
newEntry.setIcon(mEntry.icon);
|
||||
newEntry.setIcon(mEntry.getIconStandard());
|
||||
}
|
||||
}
|
||||
newEntry.setUrl(entryUrlView.getText().toString(), db);
|
||||
newEntry.setUsername(entryUserNameView.getText().toString(), db);
|
||||
newEntry.setNotes(entryCommentView.getText().toString(), db);
|
||||
newEntry.setPassword(entryPasswordView.getText().toString(), db);
|
||||
newEntry.setUrl(entryUrlView.getText().toString());
|
||||
newEntry.setUsername(entryUserNameView.getText().toString());
|
||||
newEntry.setNotes(entryCommentView.getText().toString());
|
||||
newEntry.setPassword(entryPasswordView.getText().toString());
|
||||
|
||||
if (newEntry.allowExtraFields()) {
|
||||
// Delete all new standard strings
|
||||
@@ -290,6 +283,8 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
}
|
||||
}
|
||||
|
||||
newEntry.endToDecodeReference(db);
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
@@ -370,12 +365,13 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
public void finish() {
|
||||
// Assign entry callback as a result in all case
|
||||
if (mCallbackNewEntry != null) {
|
||||
Bundle bundle = new Bundle();
|
||||
Intent intentEntry = new Intent();
|
||||
bundle.putSerializable(ADD_OR_UPDATE_ENTRY_KEY, mCallbackNewEntry);
|
||||
intentEntry.putExtras(bundle);
|
||||
if (mIsNew) {
|
||||
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, mCallbackNewEntry);
|
||||
setResult(ADD_ENTRY_RESULT_CODE, intentEntry);
|
||||
} else {
|
||||
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, mCallbackNewEntry);
|
||||
setResult(UPDATE_ENTRY_RESULT_CODE, intentEntry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class AutoType implements Cloneable, Serializable {
|
||||
private static final long OBF_OPT_NONE = 0;
|
||||
|
||||
public boolean enabled = true;
|
||||
public long obfuscationOptions = OBF_OPT_NONE;
|
||||
public String defaultSequence = "";
|
||||
|
||||
private HashMap<String, String> windowSeqPairs = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public AutoType clone() {
|
||||
AutoType auto;
|
||||
try {
|
||||
auto = (AutoType) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
auto.windowSeqPairs = (HashMap<String, String>) windowSeqPairs.clone();
|
||||
return auto;
|
||||
}
|
||||
|
||||
public void put(String key, String value) {
|
||||
windowSeqPairs.put(key, value);
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, String>> entrySet() {
|
||||
return windowSeqPairs.entrySet();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import java.util.Set;
|
||||
import com.keepassdroid.database.security.ProtectedBinary;
|
||||
|
||||
public class BinaryPool {
|
||||
private HashMap<Integer, ProtectedBinary> pool = new HashMap<Integer, ProtectedBinary>();
|
||||
private HashMap<Integer, ProtectedBinary> pool = new HashMap<>();
|
||||
|
||||
public BinaryPool() {
|
||||
|
||||
@@ -63,12 +63,10 @@ public class BinaryPool {
|
||||
|
||||
@Override
|
||||
public boolean operate(PwEntryV4 entry) {
|
||||
for (PwEntryV4 histEntry : entry.history) {
|
||||
poolAdd(histEntry.binaries);
|
||||
|
||||
for (PwEntryV4 histEntry : entry.getHistory()) {
|
||||
poolAdd(histEntry.getBinaries());
|
||||
}
|
||||
|
||||
poolAdd(entry.binaries);
|
||||
poolAdd(entry.getBinaries());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class EntrySearchHandler extends EntryHandler<PwEntry> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sp.excludeExpired && entry.expires() && now.after(entry.getExpiryTime())) {
|
||||
if (sp.excludeExpired && entry.expires() && now.after(entry.getExpiryTime().getDate())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class EntrySearchHandlerAll extends EntryHandler<PwEntry> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sp.excludeExpired && entry.expires() && now.after(entry.getExpiryTime())) {
|
||||
if (sp.excludeExpired && entry.expires() && now.after(entry.getExpiryTime().getDate())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class EntrySearchHandlerV4 extends EntrySearchHandler {
|
||||
protected boolean searchID(PwEntry e) {
|
||||
PwEntryV4 entry = (PwEntryV4) e;
|
||||
if (sp.searchInUUIDs) {
|
||||
String hex = UuidUtil.toHexString(entry.uuid);
|
||||
String hex = UuidUtil.toHexString(entry.getUUID());
|
||||
return StrUtil.indexOfIgnoreCase(hex, sp.searchString, Locale.ENGLISH) >= 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.keepassdroid.database;
|
||||
|
||||
public interface ISmallTimeLogger {
|
||||
|
||||
PwDate getLastModificationTime();
|
||||
void setLastModificationTime(PwDate date);
|
||||
|
||||
PwDate getCreationTime();
|
||||
void setCreationTime(PwDate date);
|
||||
|
||||
PwDate getLastAccessTime();
|
||||
void setLastAccessTime(PwDate date);
|
||||
|
||||
PwDate getExpiryTime();
|
||||
void setExpiryTime(PwDate date);
|
||||
|
||||
boolean expires();
|
||||
void setExpires(boolean exp);
|
||||
}
|
||||
@@ -19,28 +19,12 @@
|
||||
*/
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import java.util.Date;
|
||||
public interface ITimeLogger extends ISmallTimeLogger {
|
||||
|
||||
public interface ITimeLogger {
|
||||
Date getLastModificationTime();
|
||||
void setLastModificationTime(Date date);
|
||||
|
||||
Date getCreationTime();
|
||||
void setCreationTime(Date date);
|
||||
|
||||
Date getLastAccessTime();
|
||||
void setLastAccessTime(Date date);
|
||||
|
||||
Date getExpiryTime();
|
||||
void setExpiryTime(Date date);
|
||||
|
||||
boolean expires();
|
||||
void setExpires(boolean exp);
|
||||
|
||||
long getUsageCount();
|
||||
void setUsageCount(long count);
|
||||
|
||||
Date getLocationChanged();
|
||||
void setLocationChanged(Date date);
|
||||
|
||||
PwDate getLocationChanged();
|
||||
void setLocationChanged(PwDate date);
|
||||
|
||||
}
|
||||
@@ -41,13 +41,14 @@ import com.keepassdroid.utils.Util;
|
||||
|
||||
public abstract class PwDatabase {
|
||||
|
||||
public static final UUID UUID_ZERO = new UUID(0,0);
|
||||
public byte masterKey[] = new byte[32];
|
||||
public byte[] finalKey;
|
||||
public String name = "KeePass database";
|
||||
public PwGroup rootGroup;
|
||||
public PwIconFactory iconFactory = new PwIconFactory();
|
||||
public Map<PwGroupId, PwGroup> groups = new HashMap<PwGroupId, PwGroup>();
|
||||
public Map<UUID, PwEntry> entries = new HashMap<UUID, PwEntry>();
|
||||
public Map<PwGroupId, PwGroup> groups = new HashMap<>();
|
||||
public Map<UUID, PwEntry> entries = new HashMap<>();
|
||||
|
||||
|
||||
private static boolean isKDBExtension(String filename) {
|
||||
@@ -317,8 +318,8 @@ public abstract class PwDatabase {
|
||||
|
||||
public void populateGlobals(PwGroup currentGroup) {
|
||||
|
||||
List<PwGroup> childGroups = currentGroup.childGroups;
|
||||
List<PwEntry> childEntries = currentGroup.childEntries;
|
||||
List<PwGroup> childGroups = currentGroup.getChildGroups();
|
||||
List<PwEntry> childEntries = currentGroup.getChildEntries();
|
||||
|
||||
for (int i = 0; i < childEntries.size(); i++ ) {
|
||||
PwEntry cur = childEntries.get(i);
|
||||
|
||||
@@ -69,9 +69,9 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
public PwEntry metaInfo;
|
||||
|
||||
// all entries
|
||||
public List<PwEntry> entries = new ArrayList<PwEntry>();
|
||||
public List<PwEntry> entries = new ArrayList<>();
|
||||
// all groups
|
||||
public List<PwGroup> groups = new ArrayList<PwGroup>();
|
||||
public List<PwGroup> groups = new ArrayList<>();
|
||||
// Algorithm used to encrypt the database
|
||||
public PwEncryptionAlgorithm algorithm;
|
||||
public int numKeyEncRounds;
|
||||
@@ -105,7 +105,7 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
List<PwGroup> kids = new ArrayList<PwGroup>();
|
||||
for (int i = 0; i < groups.size(); i++) {
|
||||
PwGroupV3 grp = (PwGroupV3) groups.get(i);
|
||||
if (grp.level == target)
|
||||
if (grp.getLevel() == target)
|
||||
kids.add(grp);
|
||||
}
|
||||
return kids;
|
||||
@@ -114,8 +114,8 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
public int getRootGroupId() {
|
||||
for (int i = 0; i < groups.size(); i++) {
|
||||
PwGroupV3 grp = (PwGroupV3) groups.get(i);
|
||||
if (grp.level == 0) {
|
||||
return grp.groupId;
|
||||
if (grp.getLevel() == 0) {
|
||||
return grp.getGroupId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,13 +124,13 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
|
||||
public List<PwGroup> getGrpChildren(PwGroupV3 parent) {
|
||||
int idx = groups.indexOf(parent);
|
||||
int target = parent.level + 1;
|
||||
int target = parent.getLevel() + 1;
|
||||
List<PwGroup> kids = new ArrayList<PwGroup>();
|
||||
while (++idx < groups.size()) {
|
||||
PwGroupV3 grp = (PwGroupV3) groups.get(idx);
|
||||
if (grp.level < target)
|
||||
if (grp.getLevel() < target)
|
||||
break;
|
||||
else if (grp.level == target)
|
||||
else if (grp.getLevel() == target)
|
||||
kids.add(grp);
|
||||
}
|
||||
return kids;
|
||||
@@ -145,7 +145,7 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
*/
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
PwEntryV3 ent = (PwEntryV3) entries.get(i);
|
||||
if (ent.groupId == parent.groupId)
|
||||
if (ent.getGroupId() == parent.getGroupId())
|
||||
kids.add(ent);
|
||||
}
|
||||
return kids;
|
||||
@@ -163,11 +163,11 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
|
||||
List<PwGroup> rootChildGroups = getGrpRoots();
|
||||
root.setGroups(rootChildGroups);
|
||||
root.childEntries = new ArrayList<>();
|
||||
root.level = -1;
|
||||
root.setEntries(new ArrayList<>());
|
||||
root.setLevel(-1);
|
||||
for (int i = 0; i < rootChildGroups.size(); i++) {
|
||||
PwGroupV3 grp = (PwGroupV3) rootChildGroups.get(i);
|
||||
grp.parent = root;
|
||||
grp.setParent(root);
|
||||
constructTree(grp);
|
||||
}
|
||||
return;
|
||||
@@ -176,18 +176,18 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
// I'm in non-root
|
||||
// get child groups
|
||||
currentGroup.setGroups(getGrpChildren(currentGroup));
|
||||
currentGroup.childEntries = getEntries(currentGroup);
|
||||
currentGroup.setEntries(getEntries(currentGroup));
|
||||
|
||||
// set parent in child entries
|
||||
for (int i = 0; i < currentGroup.numbersOfChildEntries(); i++) {
|
||||
PwEntryV3 entry = (PwEntryV3) currentGroup.childEntries.get(i);
|
||||
entry.parent = currentGroup;
|
||||
PwEntryV3 entry = (PwEntryV3) currentGroup.getChildEntryAt(i);
|
||||
entry.setParent(currentGroup);
|
||||
}
|
||||
// recursively construct child groups
|
||||
for (int i = 0; i < currentGroup.numbersOfChildGroups(); i++) {
|
||||
PwGroupV3 grp = (PwGroupV3) currentGroup.childGroups.get(i);
|
||||
grp.parent = currentGroup;
|
||||
constructTree((PwGroupV3) currentGroup.childGroups.get(i));
|
||||
PwGroupV3 grp = (PwGroupV3) currentGroup.getChildGroupAt(i);
|
||||
grp.setParent(currentGroup);
|
||||
constructTree((PwGroupV3) currentGroup.getChildGroupAt(i));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -316,11 +316,11 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
public boolean isBackup(PwGroup group) {
|
||||
PwGroupV3 g = (PwGroupV3) group;
|
||||
while (g != null) {
|
||||
if (g.level == 0 && g.name.equalsIgnoreCase("Backup")) {
|
||||
if (g.getLevel() == 0 && g.getName().equalsIgnoreCase("Backup")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
g = g.parent;
|
||||
g = (PwGroupV3) g.getParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -338,7 +338,7 @@ public class PwDatabaseV3 extends PwDatabase {
|
||||
private void initAndAddGroup(String name, int iconId, PwGroup parent) {
|
||||
PwGroup group = createGroup();
|
||||
group.initNewGroup(name, newGroupId());
|
||||
group.icon = iconFactory.getIcon(iconId);
|
||||
group.setIcon(iconFactory.getIcon(iconId));
|
||||
addGroupTo(group, parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +58,6 @@ import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
public class PwDatabaseV4 extends PwDatabase {
|
||||
|
||||
public static final Date DEFAULT_NOW = new Date();
|
||||
public static final UUID UUID_ZERO = new UUID(0,0);
|
||||
public static final int DEFAULT_ROUNDS = 6000;
|
||||
private static final int DEFAULT_HISTORY_MAX_ITEMS = 10; // -1 unlimited
|
||||
private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited
|
||||
@@ -71,14 +69,14 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public PwCompressionAlgorithm compressionAlgorithm = PwCompressionAlgorithm.Gzip;
|
||||
// TODO: Refactor me away to get directly from kdfParameters
|
||||
public long numKeyEncRounds = 6000;
|
||||
public Date nameChanged = DEFAULT_NOW;
|
||||
public Date settingsChanged = DEFAULT_NOW;
|
||||
public Date nameChanged = new Date();
|
||||
public Date settingsChanged = new Date();
|
||||
public String description = "";
|
||||
public Date descriptionChanged = DEFAULT_NOW;
|
||||
public Date descriptionChanged = new Date();
|
||||
public String defaultUserName = "";
|
||||
public Date defaultUserNameChanged = DEFAULT_NOW;
|
||||
public Date defaultUserNameChanged = new Date();
|
||||
|
||||
public Date keyLastChanged = DEFAULT_NOW;
|
||||
public Date keyLastChanged = new Date();
|
||||
public long keyChangeRecDays = -1;
|
||||
public long keyChangeForceDays = 1;
|
||||
public boolean keyChangeForceOnce = false;
|
||||
@@ -87,17 +85,17 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public String color = "";
|
||||
public boolean recycleBinEnabled = true;
|
||||
public UUID recycleBinUUID = UUID_ZERO;
|
||||
public Date recycleBinChanged = DEFAULT_NOW;
|
||||
public Date recycleBinChanged = new Date();
|
||||
public UUID entryTemplatesGroup = UUID_ZERO;
|
||||
public Date entryTemplatesGroupChanged = DEFAULT_NOW;
|
||||
public Date entryTemplatesGroupChanged = new Date();
|
||||
public int historyMaxItems = DEFAULT_HISTORY_MAX_ITEMS;
|
||||
public long historyMaxSize = DEFAULT_HISTORY_MAX_SIZE;
|
||||
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>();
|
||||
public Map<String, String> customData = new HashMap<String, String>();
|
||||
public List<PwDeletedObject> deletedObjects = new ArrayList<>();
|
||||
public List<PwIconCustom> customIcons = new ArrayList<>();
|
||||
public Map<String, String> customData = new HashMap<>();
|
||||
public KdfParameters kdfParameters = KdfFactory.getDefaultParameters();
|
||||
public VariantDictionary publicCustomData = new VariantDictionary();
|
||||
public BinaryPool binPool = new BinaryPool();
|
||||
@@ -269,25 +267,42 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public List<PwGroup> getGroups() {
|
||||
List<PwGroup> list = new ArrayList<PwGroup>();
|
||||
PwGroupV4 root = (PwGroupV4) rootGroup;
|
||||
root.buildChildGroupsRecursive(list);
|
||||
buildChildGroupsRecursive(root, list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void buildChildGroupsRecursive(PwGroupV4 root, List<PwGroup> list) {
|
||||
list.add(root);
|
||||
for ( int i = 0; i < root.numbersOfChildGroups(); i++) {
|
||||
PwGroupV4 child = (PwGroupV4) root.getChildGroupAt(i);
|
||||
buildChildGroupsRecursive(child, list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PwGroup> getGrpRoots() {
|
||||
return rootGroup.childGroups;
|
||||
return rootGroup.getChildGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PwEntry> getEntries() {
|
||||
List<PwEntry> list = new ArrayList<PwEntry>();
|
||||
PwGroupV4 root = (PwGroupV4) rootGroup;
|
||||
root.buildChildEntriesRecursive(list);
|
||||
|
||||
buildChildEntriesRecursive(root, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void buildChildEntriesRecursive(PwGroupV4 root, List<PwEntry> list) {
|
||||
for ( int i = 0; i < root.numbersOfChildEntries(); i++ ) {
|
||||
list.add(root.getChildEntryAt(i));
|
||||
}
|
||||
for ( int i = 0; i < root.numbersOfChildGroups(); i++ ) {
|
||||
PwGroupV4 child = (PwGroupV4) root.getChildGroupAt(i);
|
||||
buildChildEntriesRecursive(child, list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNumRounds() {
|
||||
return numKeyEncRounds;
|
||||
@@ -351,13 +366,13 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
if (getRecycleBin() == null) {
|
||||
// Create recycle bin
|
||||
|
||||
PwGroupV4 recycleBin = new PwGroupV4(true, true, RECYCLEBIN_NAME, iconFactory.getIcon(PwIconStandard.TRASH_BIN));
|
||||
recycleBin.enableAutoType = false;
|
||||
recycleBin.enableSearching = false;
|
||||
recycleBin.isExpanded = false;
|
||||
PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getIcon(PwIconStandard.TRASH_BIN));
|
||||
recycleBin.setEnableAutoType(false);
|
||||
recycleBin.setEnableSearching(false);
|
||||
recycleBin.setExpanded(false);
|
||||
addGroupTo(recycleBin, rootGroup);
|
||||
|
||||
recycleBinUUID = recycleBin.uuid;
|
||||
recycleBinUUID = recycleBin.getUUID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,7 +495,7 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public void initNew(String dbPath) {
|
||||
String filename = URLUtil.guessFileName(dbPath, null, null);
|
||||
|
||||
rootGroup = new PwGroupV4(true, true, dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER));
|
||||
rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER));
|
||||
groups.put(rootGroup.getId(), rootGroup);
|
||||
}
|
||||
|
||||
@@ -508,7 +523,7 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
return true;
|
||||
}
|
||||
PwGroupV4 g4 = (PwGroupV4) group;
|
||||
if (g4.customData.size() > 0) {
|
||||
if (g4.containsCustomData()) {
|
||||
hasCustomData = true;
|
||||
return false;
|
||||
}
|
||||
@@ -528,7 +543,7 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
}
|
||||
|
||||
PwEntryV4 e4 = (PwEntryV4)entry;
|
||||
if (e4.customData.size() > 0) {
|
||||
if (e4.containsCustomData()) {
|
||||
hasCustomData = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
*/
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
/** Converting from the C Date format to the Java data format is
|
||||
* expensive when done for every record at once. I use this class to
|
||||
* allow lazy conversions between the formats.
|
||||
@@ -34,7 +34,7 @@ import com.keepassdroid.utils.Types;
|
||||
*
|
||||
*/
|
||||
public class PwDate implements Cloneable, Serializable {
|
||||
|
||||
|
||||
private static final int DATE_SIZE = 5;
|
||||
|
||||
private boolean cDateBuilt = false;
|
||||
@@ -42,6 +42,56 @@ public class PwDate implements Cloneable, Serializable {
|
||||
|
||||
private Date jDate;
|
||||
private byte[] cDate;
|
||||
|
||||
public static final Date NEVER_EXPIRE = getNeverExpire();
|
||||
public static final Date NEVER_EXPIRE_BUG = getNeverExpireBug();
|
||||
|
||||
public static final Date DEFAULT_DATE = getDefaultDate();
|
||||
public static final PwDate PW_NEVER_EXPIRE = new PwDate(NEVER_EXPIRE);
|
||||
public static final PwDate PW_NEVER_EXPIRE_BUG = new PwDate(NEVER_EXPIRE_BUG);
|
||||
public static final PwDate DEFAULT_PWDATE = new PwDate(DEFAULT_DATE);
|
||||
|
||||
private static Date getDefaultDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 2004);
|
||||
cal.set(Calendar.MONTH, Calendar.JANUARY);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
cal.set(Calendar.HOUR, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
private static Date getNeverExpire() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 2999);
|
||||
cal.set(Calendar.MONTH, 11);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 28);
|
||||
cal.set(Calendar.HOUR, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/** This date was was accidentally being written
|
||||
* out when an entry was supposed to be marked as
|
||||
* expired. We'll use this to silently correct those
|
||||
* entries.
|
||||
* @return
|
||||
*/
|
||||
private static Date getNeverExpireBug() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 2999);
|
||||
cal.set(Calendar.MONTH, 11);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 30);
|
||||
cal.set(Calendar.HOUR, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public PwDate(byte[] buf, int offset) {
|
||||
cDate = new byte[DATE_SIZE];
|
||||
@@ -59,12 +109,13 @@ public class PwDate implements Cloneable, Serializable {
|
||||
jDateBuilt = true;
|
||||
}
|
||||
|
||||
private PwDate() {
|
||||
|
||||
public PwDate() {
|
||||
jDate = new Date();
|
||||
jDateBuilt = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
public PwDate clone() {
|
||||
PwDate copy = new PwDate();
|
||||
|
||||
if ( cDateBuilt ) {
|
||||
@@ -82,9 +133,7 @@ public class PwDate implements Cloneable, Serializable {
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Date getJDate() {
|
||||
public Date getDate() {
|
||||
if ( ! jDateBuilt ) {
|
||||
jDate = readTime(cDate, 0, App.getCalendar());
|
||||
jDateBuilt = true;
|
||||
@@ -102,7 +151,6 @@ public class PwDate implements Cloneable, Serializable {
|
||||
return cDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unpack date from 5 byte format. The five bytes at 'offset' are unpacked
|
||||
* to a java.util.Date instance.
|
||||
@@ -189,7 +237,7 @@ public class PwDate implements Cloneable, Serializable {
|
||||
} else if ( cDateBuilt && date.jDateBuilt ) {
|
||||
return Arrays.equals(date.getCDate(), cDate);
|
||||
} else {
|
||||
return IsSameDate(date.getJDate(), jDate);
|
||||
return IsSameDate(date.getDate(), jDate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,18 +22,22 @@ package com.keepassdroid.database;
|
||||
import com.keepassdroid.database.iterator.EntrySearchStringIterator;
|
||||
import com.keepassdroid.database.security.ProtectedString;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
|
||||
protected static final String PMS_TAN_ENTRY = "<TAN>";
|
||||
|
||||
public PwIconStandard icon = PwIconStandard.FIRST;
|
||||
|
||||
private static final String PMS_TAN_ENTRY = "<TAN>";
|
||||
|
||||
protected UUID uuid = PwDatabase.UUID_ZERO;
|
||||
|
||||
@Override
|
||||
protected void construct() {
|
||||
super.construct();
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public static PwEntry getInstance(PwGroup parent) {
|
||||
if (parent instanceof PwGroupV3) {
|
||||
return new PwEntryV3((PwGroupV3)parent);
|
||||
@@ -45,23 +49,23 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
throw new RuntimeException("Unknown PwGroup instance.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
public PwEntry clone() {
|
||||
PwEntry newEntry;
|
||||
try {
|
||||
newEntry = (PwEntry) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
assert(false);
|
||||
throw new RuntimeException("Clone should be supported");
|
||||
}
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
public PwEntry clone(boolean deepStrings) {
|
||||
return (PwEntry) clone();
|
||||
}
|
||||
@Override
|
||||
protected void addCloneAttributesToNewEntry(PwEntry newEntry) {
|
||||
super.addCloneAttributesToNewEntry(newEntry);
|
||||
// uuid is clone automatically (IMMUTABLE)
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
@@ -69,65 +73,41 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
}
|
||||
|
||||
public void assign(PwEntry source) {
|
||||
icon = source.icon;
|
||||
}
|
||||
|
||||
public abstract UUID getUUID();
|
||||
public abstract void setUUID(UUID u);
|
||||
|
||||
public String getTitle() {
|
||||
return getTitle(false, null);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return getUsername(false, null);
|
||||
super.assign(source);
|
||||
uuid = source.uuid;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return getPassword(false, null);
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return getUrl(false, null);
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return getNotes(false, null);
|
||||
}
|
||||
|
||||
public abstract String getTitle(boolean decodeRef, PwDatabase db);
|
||||
public abstract String getUsername(boolean decodeRef, PwDatabase db);
|
||||
public abstract String getPassword(boolean decodeRef, PwDatabase db);
|
||||
public abstract String getUrl(boolean decodeRef, PwDatabase db);
|
||||
public abstract String getNotes(boolean decodeRef, PwDatabase db);
|
||||
public abstract Date getLastModificationTime();
|
||||
public abstract Date getLastAccessTime();
|
||||
public abstract Date getExpiryTime();
|
||||
public abstract boolean expires();
|
||||
|
||||
public abstract void setTitle(String title, PwDatabase db);
|
||||
public abstract void setUsername(String user, PwDatabase db);
|
||||
public abstract void setPassword(String pass, PwDatabase db);
|
||||
public abstract void setUrl(String url, PwDatabase db);
|
||||
public abstract void setNotes(String notes, PwDatabase db);
|
||||
public abstract void setCreationTime(Date create);
|
||||
public abstract void setLastModificationTime(Date mod);
|
||||
public abstract void setLastAccessTime(Date access);
|
||||
public abstract void setExpires(boolean exp);
|
||||
public abstract void setExpiryTime(Date expires);
|
||||
|
||||
public PwIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(PwIconStandard icon) {
|
||||
this.icon = icon;
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUUID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public void startToDecodeReference(PwDatabase db) {}
|
||||
public void endToDecodeReference(PwDatabase db) {}
|
||||
|
||||
public abstract String getTitle();
|
||||
public abstract void setTitle(String title);
|
||||
|
||||
public abstract String getUsername();
|
||||
public abstract void setUsername(String user);
|
||||
|
||||
public abstract String getPassword();
|
||||
public abstract void setPassword(String pass);
|
||||
|
||||
public abstract String getUrl();
|
||||
public abstract void setUrl(String url);
|
||||
|
||||
public abstract String getNotes();
|
||||
public abstract void setNotes(String notes);
|
||||
|
||||
public boolean isTan() {
|
||||
private boolean isTan() {
|
||||
return getTitle().equals(PMS_TAN_ENTRY) && (getUsername().length() > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayTitle() {
|
||||
if ( isTan() ) {
|
||||
return PMS_TAN_ENTRY + " " + getUsername();
|
||||
@@ -148,10 +128,9 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
|
||||
/**
|
||||
* Retrieve extra fields to show, key is the label, value is the value of field
|
||||
* @param pm Database
|
||||
* @return Map of label/value
|
||||
*/
|
||||
public Map<String, String> getExtraFields(PwDatabase pm) {
|
||||
public Map<String, String> getExtraFields() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -191,13 +170,18 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a backup of entry
|
||||
*/
|
||||
public void createBackup(PwDatabase db) {}
|
||||
|
||||
public EntrySearchStringIterator stringIterator() {
|
||||
return EntrySearchStringIterator.getInstance(this);
|
||||
}
|
||||
|
||||
public void touch(boolean modified, boolean touchParents) {
|
||||
Date now = new Date();
|
||||
|
||||
PwDate now = new PwDate();
|
||||
|
||||
setLastAccessTime(now);
|
||||
|
||||
if (modified) {
|
||||
@@ -230,69 +214,4 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
public int hashCode() {
|
||||
return getUUID() != null ? getUUID().hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Name
|
||||
*/
|
||||
public static class EntryNameComparator implements Comparator<PwEntry> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public EntryNameComparator() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public EntryNameComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwEntry object1, PwEntry object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int entryTitleComp = object1.getTitle().compareToIgnoreCase(object2.getTitle());
|
||||
// If same title, can be different
|
||||
if (entryTitleComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
entryTitleComp = -entryTitleComp;
|
||||
|
||||
return entryTitleComp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Creation
|
||||
*/
|
||||
public static class EntryCreationComparator implements Comparator<PwEntry> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public EntryCreationComparator() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public EntryCreationComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwEntry object1, PwEntry object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int entryCreationComp = object1.getCreationTime().compareTo(object2.getCreationTime());
|
||||
// If same creation, can be different
|
||||
if (entryCreationComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
entryCreationComp = -entryCreationComp;
|
||||
|
||||
return entryCreationComp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,13 +42,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
package com.keepassdroid.database;
|
||||
|
||||
// PhoneID
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@@ -71,137 +65,204 @@ import java.util.UUID;
|
||||
* @author Naomaru Itoi <[email protected]>
|
||||
* @author Bill Zwicky <[email protected]>
|
||||
* @author Dominik Reichl <[email protected]>
|
||||
* @author Jeremy Jamet <[email protected]>
|
||||
*/
|
||||
public class PwEntryV3 extends PwEntry {
|
||||
|
||||
public static final Date NEVER_EXPIRE = getNeverExpire();
|
||||
public static final Date NEVER_EXPIRE_BUG = getNeverExpireBug();
|
||||
public static final Date DEFAULT_DATE = getDefaultDate();
|
||||
public static final PwDate PW_NEVER_EXPIRE = new PwDate(NEVER_EXPIRE);
|
||||
public static final PwDate PW_NEVER_EXPIRE_BUG = new PwDate(NEVER_EXPIRE_BUG);
|
||||
public static final PwDate DEFAULT_PWDATE = new PwDate(DEFAULT_DATE);
|
||||
|
||||
|
||||
/** Size of byte buffer needed to hold this struct. */
|
||||
public static final String PMS_ID_BINDESC = "bin-stream";
|
||||
public static final String PMS_ID_TITLE = "Meta-Info";
|
||||
public static final String PMS_ID_USER = "SYSTEM";
|
||||
public static final String PMS_ID_URL = "$";
|
||||
private static final String PMS_ID_BINDESC = "bin-stream";
|
||||
private static final String PMS_ID_TITLE = "Meta-Info";
|
||||
private static final String PMS_ID_USER = "SYSTEM";
|
||||
private static final String PMS_ID_URL = "$";
|
||||
|
||||
// for tree traversing
|
||||
private PwGroupV3 parent = null;
|
||||
private int groupId;
|
||||
|
||||
|
||||
public int groupId;
|
||||
public String username;
|
||||
private byte[] password;
|
||||
private byte[] uuid;
|
||||
public String title;
|
||||
public String url;
|
||||
public String additional;
|
||||
|
||||
|
||||
public PwDate tCreation;
|
||||
public PwDate tLastMod;
|
||||
public PwDate tLastAccess;
|
||||
public PwDate tExpire;
|
||||
private String title;
|
||||
private String username;
|
||||
private byte[] password;
|
||||
private String url;
|
||||
private String additional;
|
||||
|
||||
/** A string describing what is in pBinaryData */
|
||||
public String binaryDesc;
|
||||
private String binaryDesc;
|
||||
private byte[] binaryData;
|
||||
|
||||
private static Date getDefaultDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 2004);
|
||||
cal.set(Calendar.MONTH, Calendar.JANUARY);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
cal.set(Calendar.HOUR, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
private static Date getNeverExpire() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 2999);
|
||||
cal.set(Calendar.MONTH, 11);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 28);
|
||||
cal.set(Calendar.HOUR, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/** This date was was accidentally being written
|
||||
* out when an entry was supposed to be marked as
|
||||
* expired. We'll use this to silently correct those
|
||||
* entries.
|
||||
* @return
|
||||
*/
|
||||
private static Date getNeverExpireBug() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 2999);
|
||||
cal.set(Calendar.MONTH, 11);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 30);
|
||||
cal.set(Calendar.HOUR, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public static boolean IsNever(Date date) {
|
||||
return PwDate.IsSameDate(NEVER_EXPIRE, date);
|
||||
}
|
||||
|
||||
// for tree traversing
|
||||
public PwGroupV3 parent = null;
|
||||
|
||||
|
||||
public PwEntryV3() {
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
public PwEntryV3(PwEntryV3 source) {
|
||||
assign(source);
|
||||
}
|
||||
*/
|
||||
|
||||
public PwEntryV3(PwGroupV3 p) {
|
||||
this(p, true, true);
|
||||
}
|
||||
|
||||
public PwEntryV3(PwGroupV3 p, boolean initId, boolean initDates) {
|
||||
|
||||
construct();
|
||||
parent = p;
|
||||
groupId = ((PwGroupIdV3)parent.getId()).getId();
|
||||
|
||||
if (initId) {
|
||||
Random random = new Random();
|
||||
uuid = new byte[16];
|
||||
random.nextBytes(uuid);
|
||||
}
|
||||
|
||||
if (initDates) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Date now = cal.getTime();
|
||||
tCreation = new PwDate(now);
|
||||
tLastAccess = new PwDate(now);
|
||||
tLastMod = new PwDate(now);
|
||||
tExpire = new PwDate(NEVER_EXPIRE);
|
||||
}
|
||||
groupId = ((PwGroupIdV3)parent.getId()).getId(); // TODO remove
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assign(PwEntry source) {
|
||||
if ( ! (source instanceof PwEntryV3) ) {
|
||||
throw new RuntimeException("DB version mix");
|
||||
}
|
||||
super.assign(source);
|
||||
PwEntryV3 src = (PwEntryV3) source;
|
||||
parent = src.parent;
|
||||
groupId = src.groupId;
|
||||
|
||||
title = src.title;
|
||||
username = src.username;
|
||||
int passLen = src.password.length;
|
||||
password = new byte[passLen];
|
||||
System.arraycopy(src.password, 0, password, 0, passLen);
|
||||
url = src.url;
|
||||
additional = src.additional;
|
||||
|
||||
binaryDesc = src.binaryDesc;
|
||||
if ( src.binaryData != null ) {
|
||||
int descLen = src.binaryData.length;
|
||||
binaryData = new byte[descLen];
|
||||
System.arraycopy(src.binaryData, 0, binaryData, 0, descLen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwEntryV3 clone() {
|
||||
PwEntryV3 newEntry = (PwEntryV3) super.clone();
|
||||
|
||||
// Attributes in parent
|
||||
addCloneAttributesToNewEntry(newEntry);
|
||||
|
||||
// Attributes here
|
||||
// newEntry.parent stay the same in copy
|
||||
// newEntry.groupId stay the same in copy
|
||||
// newEntry.title stay the same in copy
|
||||
// newEntry.username stay the same in copy
|
||||
if (password != null) {
|
||||
int passLen = password.length;
|
||||
password = new byte[passLen];
|
||||
System.arraycopy(password, 0, newEntry.password, 0, passLen);
|
||||
}
|
||||
// newEntry.url stay the same in copy
|
||||
// newEntry.additional stay the same in copy
|
||||
|
||||
// newEntry.binaryDesc stay the same in copy
|
||||
if ( binaryData != null ) {
|
||||
int descLen = binaryData.length;
|
||||
newEntry.binaryData = new byte[descLen];
|
||||
System.arraycopy(binaryData, 0, newEntry.binaryData, 0, descLen);
|
||||
}
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroupV3 getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(PwGroup parent) {
|
||||
this.parent = (PwGroupV3) parent;
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(int groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
if (username == null) {
|
||||
return "";
|
||||
}
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsername(String user) {
|
||||
username = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNotes() {
|
||||
return additional;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotes(String notes) {
|
||||
additional = notes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void populateBlankFields(PwDatabaseV3 db) {
|
||||
// TODO verify and remove
|
||||
if (icon == null) {
|
||||
icon = db.iconFactory.getIcon(1);
|
||||
}
|
||||
|
||||
if (username == null) {
|
||||
username = "";
|
||||
}
|
||||
|
||||
if (password == null) {
|
||||
password = new byte[0];
|
||||
}
|
||||
|
||||
if (uuid == null) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
if (title == null) {
|
||||
title = "";
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
url = "";
|
||||
}
|
||||
|
||||
if (additional == null) {
|
||||
additional = "";
|
||||
}
|
||||
|
||||
if (binaryDesc == null) {
|
||||
binaryDesc = "";
|
||||
}
|
||||
|
||||
if (binaryData == null) {
|
||||
binaryData = new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actual password byte array.
|
||||
*/
|
||||
@Override
|
||||
public String getPassword(boolean decodeRef, PwDatabase db) {
|
||||
public String getPassword() {
|
||||
if (password == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return new String(password);
|
||||
}
|
||||
|
||||
@@ -209,7 +270,6 @@ public class PwEntryV3 extends PwEntry {
|
||||
return password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fill byte array
|
||||
*/
|
||||
@@ -230,10 +290,8 @@ public class PwEntryV3 extends PwEntry {
|
||||
System.arraycopy( buf, offset, password, 0, len );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setPassword(String pass, PwDatabase db) {
|
||||
public void setPassword(String pass) {
|
||||
byte[] password;
|
||||
try {
|
||||
password = pass.getBytes("UTF-8");
|
||||
@@ -252,8 +310,6 @@ public class PwEntryV3 extends PwEntry {
|
||||
return binaryData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Securely erase old data before copying new. */
|
||||
public void setBinaryData( byte[] buf, int offset, int len ) {
|
||||
if( binaryData != null ) {
|
||||
@@ -264,6 +320,14 @@ public class PwEntryV3 extends PwEntry {
|
||||
System.arraycopy( buf, offset, binaryData, 0, len );
|
||||
}
|
||||
|
||||
public String getBinaryDesc() {
|
||||
return binaryDesc;
|
||||
}
|
||||
|
||||
public void setBinaryDesc(String binaryDesc) {
|
||||
this.binaryDesc = binaryDesc;
|
||||
}
|
||||
|
||||
// Determine if this is a MetaStream entry
|
||||
@Override
|
||||
public boolean isMetaStream() {
|
||||
@@ -280,249 +344,4 @@ public class PwEntryV3 extends PwEntry {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assign(PwEntry source) {
|
||||
|
||||
if ( ! (source instanceof PwEntryV3) ) {
|
||||
throw new RuntimeException("DB version mix");
|
||||
}
|
||||
|
||||
super.assign(source);
|
||||
|
||||
PwEntryV3 src = (PwEntryV3) source;
|
||||
assign(src);
|
||||
|
||||
}
|
||||
|
||||
private void assign(PwEntryV3 source) {
|
||||
title = source.title;
|
||||
url = source.url;
|
||||
groupId = source.groupId;
|
||||
username = source.username;
|
||||
additional = source.additional;
|
||||
uuid = source.uuid;
|
||||
|
||||
int passLen = source.password.length;
|
||||
password = new byte[passLen];
|
||||
System.arraycopy(source.password, 0, password, 0, passLen);
|
||||
|
||||
tCreation = (PwDate) source.tCreation.clone();
|
||||
tLastMod = (PwDate) source.tLastMod.clone();
|
||||
tLastAccess = (PwDate) source.tLastAccess.clone();
|
||||
tExpire = (PwDate) source.tExpire.clone();
|
||||
|
||||
binaryDesc = source.binaryDesc;
|
||||
|
||||
if ( source.binaryData != null ) {
|
||||
int descLen = source.binaryData.length;
|
||||
binaryData = new byte[descLen];
|
||||
System.arraycopy(source.binaryData, 0, binaryData, 0, descLen);
|
||||
}
|
||||
|
||||
parent = source.parent;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
PwEntryV3 newEntry = (PwEntryV3) super.clone();
|
||||
|
||||
if (password != null) {
|
||||
int passLen = password.length;
|
||||
password = new byte[passLen];
|
||||
System.arraycopy(password, 0, newEntry.password, 0, passLen);
|
||||
}
|
||||
|
||||
newEntry.tCreation = (PwDate) tCreation.clone();
|
||||
newEntry.tLastMod = (PwDate) tLastMod.clone();
|
||||
newEntry.tLastAccess = (PwDate) tLastAccess.clone();
|
||||
newEntry.tExpire = (PwDate) tExpire.clone();
|
||||
|
||||
newEntry.binaryDesc = binaryDesc;
|
||||
|
||||
if ( binaryData != null ) {
|
||||
int descLen = binaryData.length;
|
||||
newEntry.binaryData = new byte[descLen];
|
||||
System.arraycopy(binaryData, 0, newEntry.binaryData, 0, descLen);
|
||||
}
|
||||
|
||||
newEntry.parent = parent;
|
||||
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastAccessTime() {
|
||||
return tLastAccess.getJDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreationTime() {
|
||||
return tCreation.getJDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getExpiryTime() {
|
||||
return tExpire.getJDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastModificationTime() {
|
||||
return tLastMod.getJDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreationTime(Date create) {
|
||||
tCreation = new PwDate(create);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastModificationTime(Date mod) {
|
||||
tLastMod = new PwDate(mod);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastAccessTime(Date access) {
|
||||
tLastAccess = new PwDate(access);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpires(boolean expires) {
|
||||
if (!expires) {
|
||||
tExpire = PW_NEVER_EXPIRE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpiryTime(Date expires) {
|
||||
tExpire = new PwDate(expires);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroupV3 getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return Types.bytestoUUID(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUUID(UUID u) {
|
||||
uuid = Types.UUIDtoBytes(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername(boolean decodeRef, PwDatabase db) {
|
||||
if (username == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsername(String user, PwDatabase db) {
|
||||
username = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(boolean decodeRef, PwDatabase db) {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title, PwDatabase db) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNotes(boolean decodeRef, PwDatabase db) {
|
||||
return additional;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotes(String notes, PwDatabase db) {
|
||||
additional = notes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(boolean decodeRef, PwDatabase db) {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUrl(String url, PwDatabase db) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expires() {
|
||||
return ! IsNever(tExpire.getJDate());
|
||||
}
|
||||
|
||||
public void populateBlankFields(PwDatabaseV3 db) {
|
||||
if (icon == null) {
|
||||
icon = db.iconFactory.getIcon(1);
|
||||
}
|
||||
|
||||
if (username == null) {
|
||||
username = "";
|
||||
}
|
||||
|
||||
if (password == null) {
|
||||
password = new byte[0];
|
||||
}
|
||||
|
||||
if (uuid == null) {
|
||||
uuid = Types.UUIDtoBytes(UUID.randomUUID());
|
||||
}
|
||||
|
||||
if (title == null) {
|
||||
title = "";
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
url = "";
|
||||
}
|
||||
|
||||
if (additional == null) {
|
||||
additional = "";
|
||||
}
|
||||
|
||||
if (tCreation == null) {
|
||||
tCreation = DEFAULT_PWDATE;
|
||||
}
|
||||
|
||||
if (tLastMod == null) {
|
||||
tLastMod = DEFAULT_PWDATE;
|
||||
}
|
||||
|
||||
if (tLastAccess == null) {
|
||||
tLastAccess = DEFAULT_PWDATE;
|
||||
}
|
||||
|
||||
if (tExpire == null) {
|
||||
tExpire = PW_NEVER_EXPIRE;
|
||||
}
|
||||
|
||||
if (binaryDesc == null) {
|
||||
binaryDesc = "";
|
||||
}
|
||||
|
||||
if (binaryData == null) {
|
||||
binaryData = new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(PwGroup parent) {
|
||||
this.parent = (PwGroupV3) parent;
|
||||
}
|
||||
}
|
||||
@@ -21,293 +21,205 @@ package com.keepassdroid.database;
|
||||
|
||||
import com.keepassdroid.database.security.ProtectedBinary;
|
||||
import com.keepassdroid.database.security.ProtectedString;
|
||||
import com.keepassdroid.utils.SprEngine;
|
||||
import com.keepassdroid.utils.SprEngineV4;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
|
||||
public static final String STR_TITLE = "Title";
|
||||
public static final String STR_USERNAME = "UserName";
|
||||
public static final String STR_PASSWORD = "Password";
|
||||
public static final String STR_URL = "URL";
|
||||
public static final String STR_NOTES = "Notes";
|
||||
|
||||
public PwGroupV4 parent;
|
||||
public UUID uuid = PwDatabaseV4.UUID_ZERO;
|
||||
private HashMap<String, ProtectedString> fields = new HashMap<>();
|
||||
public HashMap<String, ProtectedBinary> binaries = new HashMap<>();
|
||||
public PwIconCustom customIcon = PwIconCustom.ZERO;
|
||||
public String foregroundColor = "";
|
||||
public String backgroupColor = "";
|
||||
public String overrideURL = "";
|
||||
public AutoType autoType = new AutoType();
|
||||
public ArrayList<PwEntryV4> history = new ArrayList<>();
|
||||
|
||||
private Date parentGroupLastMod = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date creation = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date lastMod = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date lastAccess = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date expireDate = PwDatabaseV4.DEFAULT_NOW;
|
||||
private boolean expires = false;
|
||||
private long usageCount = 0;
|
||||
public String url = "";
|
||||
public String additional = "";
|
||||
public String tags = "";
|
||||
public Map<String, String> customData = new HashMap<String, String>();
|
||||
|
||||
public class AutoType implements Cloneable, Serializable {
|
||||
private static final long OBF_OPT_NONE = 0;
|
||||
|
||||
public boolean enabled = true;
|
||||
public long obfuscationOptions = OBF_OPT_NONE;
|
||||
public String defaultSequence = "";
|
||||
|
||||
private HashMap<String, String> windowSeqPairs = new HashMap<String, String>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object clone() {
|
||||
AutoType auto;
|
||||
try {
|
||||
auto = (AutoType) super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
assert(false);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
auto.windowSeqPairs = (HashMap<String, String>) windowSeqPairs.clone();
|
||||
|
||||
return auto;
|
||||
|
||||
}
|
||||
|
||||
public void put(String key, String value) {
|
||||
windowSeqPairs.put(key, value);
|
||||
}
|
||||
|
||||
public Set<Entry<String, String>> entrySet() {
|
||||
return windowSeqPairs.entrySet();
|
||||
}
|
||||
|
||||
}
|
||||
// To decode each field not serializable
|
||||
private transient PwDatabase mDatabase = null;
|
||||
private transient boolean mDecodeRef = false;
|
||||
|
||||
private PwGroupV4 parent;
|
||||
private PwIconCustom customIcon = PwIconCustom.ZERO;
|
||||
private long usageCount = 0;
|
||||
private PwDate parentGroupLastMod = new PwDate();
|
||||
private Map<String, String> customData = new HashMap<>();
|
||||
|
||||
private HashMap<String, ProtectedString> fields = new HashMap<>();
|
||||
private HashMap<String, ProtectedBinary> binaries = new HashMap<>();
|
||||
private String foregroundColor = "";
|
||||
private String backgroupColor = "";
|
||||
private String overrideURL = "";
|
||||
private AutoType autoType = new AutoType();
|
||||
private ArrayList<PwEntryV4> history = new ArrayList<>();
|
||||
|
||||
private String url = "";
|
||||
private String additional = "";
|
||||
private String tags = "";
|
||||
|
||||
public PwEntryV4() {
|
||||
|
||||
super();
|
||||
}
|
||||
|
||||
public PwEntryV4(PwGroupV4 p) {
|
||||
this(p, true, true);
|
||||
}
|
||||
|
||||
public PwEntryV4(PwGroupV4 p, boolean initId, boolean initDates) {
|
||||
construct();
|
||||
parent = p;
|
||||
|
||||
if (initId) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
if (initDates) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Date now = cal.getTime();
|
||||
creation = now;
|
||||
lastAccess = now;
|
||||
lastMod = now;
|
||||
expires = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assign(PwEntry source) {
|
||||
if ( ! (source instanceof PwEntryV4) ) {
|
||||
throw new RuntimeException("DB version mix.");
|
||||
}
|
||||
super.assign(source);
|
||||
PwEntryV4 src = (PwEntryV4) source;
|
||||
parent = src.parent;
|
||||
customIcon = src.customIcon;
|
||||
usageCount = src.usageCount;
|
||||
parentGroupLastMod = src.parentGroupLastMod;
|
||||
// TODO customData
|
||||
|
||||
fields = src.fields;
|
||||
binaries = src.binaries;
|
||||
foregroundColor = src.foregroundColor;
|
||||
backgroupColor = src.backgroupColor;
|
||||
overrideURL = src.overrideURL;
|
||||
autoType = src.autoType;
|
||||
history = src.history;
|
||||
|
||||
url = src.url;
|
||||
additional = src.additional;
|
||||
tags = src.tags;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public PwEntryV4 clone() {
|
||||
PwEntryV4 newEntry = (PwEntryV4) super.clone();
|
||||
|
||||
// Attributes in parent
|
||||
addCloneAttributesToNewEntry(newEntry);
|
||||
|
||||
// Attributes here
|
||||
// newEntry.parent stay the same in copy
|
||||
newEntry.customIcon = new PwIconCustom(this.customIcon);
|
||||
// newEntry.usageCount stay the same in copy
|
||||
newEntry.parentGroupLastMod = this.parentGroupLastMod.clone();
|
||||
// TODO customData make copy from hashmap
|
||||
|
||||
newEntry.fields = (HashMap<String, ProtectedString>) this.fields.clone();
|
||||
newEntry.binaries = (HashMap<String, ProtectedBinary>) this.binaries.clone();
|
||||
// newEntry.foregroundColor stay the same in copy
|
||||
// newEntry.backgroupColor stay the same in copy
|
||||
// newEntry.overrideURL stay the same in copy
|
||||
newEntry.autoType = autoType.clone();
|
||||
newEntry.history = (ArrayList<PwEntryV4>) this.history.clone();
|
||||
|
||||
// newEntry.url stay the same in copy
|
||||
// newEntry.additional stay the same in copy
|
||||
// newEntry.tags stay the same in copy
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public PwEntry clone(boolean deepStrings) {
|
||||
PwEntryV4 entry = (PwEntryV4) super.clone(deepStrings);
|
||||
|
||||
if (deepStrings) {
|
||||
entry.fields = (HashMap<String, ProtectedString>) fields.clone();
|
||||
}
|
||||
|
||||
return entry;
|
||||
public void startToDecodeReference(PwDatabase db) {
|
||||
this.mDatabase = db;
|
||||
this.mDecodeRef = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assign(PwEntry source) {
|
||||
|
||||
if ( ! (source instanceof PwEntryV4) ) {
|
||||
throw new RuntimeException("DB version mix.");
|
||||
}
|
||||
|
||||
super.assign(source);
|
||||
|
||||
PwEntryV4 src = (PwEntryV4) source;
|
||||
assign(src);
|
||||
}
|
||||
|
||||
private void assign(PwEntryV4 source) {
|
||||
parent = source.parent;
|
||||
uuid = source.uuid;
|
||||
fields = source.fields;
|
||||
binaries = source.binaries;
|
||||
customIcon = source.customIcon;
|
||||
foregroundColor = source.foregroundColor;
|
||||
backgroupColor = source.backgroupColor;
|
||||
overrideURL = source.overrideURL;
|
||||
autoType = source.autoType;
|
||||
history = source.history;
|
||||
parentGroupLastMod = source.parentGroupLastMod;
|
||||
creation = source.creation;
|
||||
lastMod = source.lastMod;
|
||||
lastAccess = source.lastAccess;
|
||||
expireDate = source.expireDate;
|
||||
expires = source.expires;
|
||||
usageCount = source.usageCount;
|
||||
url = source.url;
|
||||
additional = source.additional;
|
||||
|
||||
public void endToDecodeReference(PwDatabase db) {
|
||||
this.mDatabase = null;
|
||||
this.mDecodeRef = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
PwEntryV4 newEntry = (PwEntryV4) super.clone();
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
private String decodeRefKey(boolean decodeRef, String key, PwDatabase db) {
|
||||
private String decodeRefKey(boolean decodeRef, String key) {
|
||||
String text = getString(key);
|
||||
if (decodeRef) {
|
||||
text = decodeRef(text, db);
|
||||
text = decodeRef(text, mDatabase);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private String decodeRef(String text, PwDatabase db) {
|
||||
if (db == null) { return text; }
|
||||
|
||||
SprEngine spr = SprEngine.getInstance(db);
|
||||
SprEngineV4 spr = new SprEngineV4();
|
||||
return spr.compile(text, this, db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername(boolean decodeRef, PwDatabase db) {
|
||||
return decodeRefKey(decodeRef, STR_USERNAME, db);
|
||||
public String getUsername() {
|
||||
return decodeRefKey(mDecodeRef, STR_USERNAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(boolean decodeRef, PwDatabase db) {
|
||||
return decodeRefKey(decodeRef, STR_TITLE, db);
|
||||
public String getTitle() {
|
||||
return decodeRefKey(mDecodeRef, STR_TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword(boolean decodeRef, PwDatabase db) {
|
||||
return decodeRefKey(decodeRef, STR_PASSWORD, db);
|
||||
public String getPassword() {
|
||||
return decodeRefKey(mDecodeRef, STR_PASSWORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastAccessTime() {
|
||||
return lastAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreationTime() {
|
||||
return creation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getExpiryTime() {
|
||||
return expireDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastModificationTime() {
|
||||
return lastMod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title, PwDatabase d) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) d;
|
||||
public void setTitle(String title) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) mDatabase;
|
||||
boolean protect = db.memoryProtection.protectTitle;
|
||||
|
||||
setString(STR_TITLE, title, protect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsername(String user, PwDatabase d) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) d;
|
||||
public void setUsername(String user) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) mDatabase;
|
||||
boolean protect = db.memoryProtection.protectUserName;
|
||||
|
||||
setString(STR_USERNAME, user, protect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(String pass, PwDatabase d) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) d;
|
||||
public void setPassword(String pass) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) mDatabase;
|
||||
boolean protect = db.memoryProtection.protectPassword;
|
||||
|
||||
setString(STR_PASSWORD, pass, protect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUrl(String url, PwDatabase d) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) d;
|
||||
public void setUrl(String url) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) mDatabase;
|
||||
boolean protect = db.memoryProtection.protectUrl;
|
||||
|
||||
setString(STR_URL, url, protect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotes(String notes, PwDatabase d) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) d;
|
||||
public void setNotes(String notes) {
|
||||
PwDatabaseV4 db = (PwDatabaseV4) mDatabase;
|
||||
boolean protect = db.memoryProtection.protectNotes;
|
||||
|
||||
setString(STR_NOTES, notes, protect);
|
||||
}
|
||||
|
||||
public void setCreationTime(Date date) {
|
||||
creation = date;
|
||||
}
|
||||
|
||||
public void setExpiryTime(Date date) {
|
||||
expireDate = date;
|
||||
}
|
||||
|
||||
public void setLastAccessTime(Date date) {
|
||||
lastAccess = date;
|
||||
}
|
||||
|
||||
public void setLastModificationTime(Date date) {
|
||||
lastMod = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroupV4 getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
@Override
|
||||
public void setParent(PwGroup parent) {
|
||||
this.parent = (PwGroupV4) parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUUID(UUID u) {
|
||||
uuid = u;
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
ProtectedString value = fields.get(key);
|
||||
|
||||
if ( value == null ) return new String("");
|
||||
if ( value == null ) return "";
|
||||
|
||||
return value.toString();
|
||||
}
|
||||
@@ -317,7 +229,15 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
fields.put(key, ps);
|
||||
}
|
||||
|
||||
public Date getLocationChanged() {
|
||||
public PwIconCustom getCustomIcon() {
|
||||
return customIcon;
|
||||
}
|
||||
|
||||
public void setCustomIcon(PwIconCustom icon) {
|
||||
this.customIcon = icon;
|
||||
}
|
||||
|
||||
public PwDate getLocationChanged() {
|
||||
return parentGroupLastMod;
|
||||
}
|
||||
|
||||
@@ -325,109 +245,32 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
return usageCount;
|
||||
}
|
||||
|
||||
public void setLocationChanged(Date date) {
|
||||
public void setLocationChanged(PwDate date) {
|
||||
parentGroupLastMod = date;
|
||||
}
|
||||
|
||||
public void setUsageCount(long count) {
|
||||
usageCount = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
public void setExpires(boolean exp) {
|
||||
expires = exp;
|
||||
@Override
|
||||
public String getNotes() {
|
||||
return decodeRefKey(mDecodeRef, STR_NOTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNotes(boolean decodeRef, PwDatabase db) {
|
||||
return decodeRefKey(decodeRef, STR_NOTES, db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(boolean decodeRef, PwDatabase db) {
|
||||
return decodeRefKey(decodeRef, STR_URL, db);
|
||||
public String getUrl() {
|
||||
return decodeRefKey(mDecodeRef, STR_URL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwIcon getIcon() {
|
||||
if (customIcon == null || customIcon.uuid.equals(PwDatabaseV4.UUID_ZERO)) {
|
||||
if (customIcon == null || customIcon.uuid.equals(PwDatabase.UUID_ZERO)) {
|
||||
return super.getIcon();
|
||||
} else {
|
||||
return customIcon;
|
||||
}
|
||||
}
|
||||
|
||||
public void createBackup(PwDatabaseV4 db) {
|
||||
PwEntryV4 copy = cloneDeep();
|
||||
copy.history = new ArrayList<>();
|
||||
history.add(copy);
|
||||
|
||||
if (db != null) maintainBackups(db);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PwEntryV4 cloneDeep() {
|
||||
PwEntryV4 entry = (PwEntryV4) clone(true);
|
||||
|
||||
entry.binaries = (HashMap<String, ProtectedBinary>) binaries.clone();
|
||||
entry.history = (ArrayList<PwEntryV4>) history.clone();
|
||||
entry.autoType = (AutoType) autoType.clone();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
private boolean maintainBackups(PwDatabaseV4 db) {
|
||||
boolean deleted = false;
|
||||
|
||||
int maxItems = db.historyMaxItems;
|
||||
if (maxItems >= 0) {
|
||||
while (history.size() > maxItems) {
|
||||
removeOldestBackup();
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
long maxSize = db.historyMaxSize;
|
||||
if (maxSize >= 0) {
|
||||
while(true) {
|
||||
long histSize = 0;
|
||||
for (PwEntryV4 entry : history) {
|
||||
histSize += entry.getSize();
|
||||
}
|
||||
|
||||
if (histSize > maxSize) {
|
||||
removeOldestBackup();
|
||||
deleted = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
||||
private void removeOldestBackup() {
|
||||
Date min = null;
|
||||
int index = -1;
|
||||
|
||||
for (int i = 0; i < history.size(); i++) {
|
||||
PwEntry entry = history.get(i);
|
||||
Date lastMod = entry.getLastModificationTime();
|
||||
if ((min == null) || lastMod.before(min)) {
|
||||
index = i;
|
||||
min = lastMod;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != -1) {
|
||||
history.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowExtraFields() {
|
||||
@@ -444,7 +287,7 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
if (fields.size() > 0) {
|
||||
for (Map.Entry<String, ProtectedString> pair : fields.entrySet()) {
|
||||
String key = pair.getKey();
|
||||
if (!PwEntryV4.IsStandardField(key)) {
|
||||
if (!PwEntryV4.isStandardField(key)) {
|
||||
protectedFields.put(key, pair.getValue());
|
||||
}
|
||||
}
|
||||
@@ -453,23 +296,23 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtraFields(PwDatabase pm) {
|
||||
Map<String, String> extraFields = super.getExtraFields(pm);
|
||||
SprEngine spr = SprEngine.getInstance(pm);
|
||||
public Map<String, String> getExtraFields() {
|
||||
Map<String, String> extraFields = super.getExtraFields();
|
||||
SprEngineV4 spr = new SprEngineV4();
|
||||
// Display custom fields
|
||||
if (fields.size() > 0) {
|
||||
for (Map.Entry<String, ProtectedString> pair : fields.entrySet()) {
|
||||
String key = pair.getKey();
|
||||
// TODO Add hidden style for protection field
|
||||
if (!PwEntryV4.IsStandardField(key)) {
|
||||
extraFields.put(key, spr.compile(pair.getValue().toString(), this, pm));
|
||||
if (!PwEntryV4.isStandardField(key)) {
|
||||
extraFields.put(key, spr.compile(pair.getValue().toString(), this, mDatabase));
|
||||
}
|
||||
}
|
||||
}
|
||||
return extraFields;
|
||||
}
|
||||
|
||||
public static boolean IsStandardField(String key) {
|
||||
private static boolean isStandardField(String key) {
|
||||
return key.equals(STR_TITLE) || key.equals(STR_USERNAME)
|
||||
|| key.equals(STR_PASSWORD) || key.equals(STR_URL)
|
||||
|| key.equals(STR_NOTES);
|
||||
@@ -484,13 +327,93 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
Iterator<Entry<String, ProtectedString>> iter = fields.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, ProtectedString> pair = iter.next();
|
||||
if (!PwEntryV4.IsStandardField(pair.getKey())) {
|
||||
if (!PwEntryV4.isStandardField(pair.getKey())) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final long FIXED_LENGTH_SIZE = 128; // Approximate fixed length size
|
||||
|
||||
public HashMap<String, ProtectedBinary> getBinaries() {
|
||||
return binaries;
|
||||
}
|
||||
|
||||
public void putProtectedBinary(String key, ProtectedBinary value) {
|
||||
binaries.put(key, value);
|
||||
}
|
||||
|
||||
public String getForegroundColor() {
|
||||
return foregroundColor;
|
||||
}
|
||||
|
||||
public void setForegroundColor(String color) {
|
||||
this.foregroundColor = color;
|
||||
}
|
||||
|
||||
public String getBackgroupColor() {
|
||||
return backgroupColor;
|
||||
}
|
||||
|
||||
public void setBackgroupColor(String color) {
|
||||
this.backgroupColor = color;
|
||||
}
|
||||
|
||||
public String getOverrideURL() {
|
||||
return overrideURL;
|
||||
}
|
||||
|
||||
public void setOverrideURL(String overrideURL) {
|
||||
this.overrideURL = overrideURL;
|
||||
}
|
||||
|
||||
public AutoType getAutoType() {
|
||||
return autoType;
|
||||
}
|
||||
|
||||
public void setAutoType(AutoType autoType) {
|
||||
this.autoType = autoType;
|
||||
}
|
||||
|
||||
public ArrayList<PwEntryV4> getHistory() {
|
||||
return history;
|
||||
}
|
||||
|
||||
public void setHistory(ArrayList<PwEntryV4> history) {
|
||||
this.history = history;
|
||||
}
|
||||
|
||||
public void addToHistory(PwEntryV4 entry) {
|
||||
history.add(entry);
|
||||
}
|
||||
|
||||
public int sizeOfHistory() {
|
||||
return history.size();
|
||||
}
|
||||
|
||||
public String getAdditional() {
|
||||
return additional;
|
||||
}
|
||||
|
||||
public void setAdditional(String additional) {
|
||||
this.additional = additional;
|
||||
}
|
||||
|
||||
public String getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(String tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public void putCustomData(String key, String value) {
|
||||
customData.put(key, value);
|
||||
}
|
||||
|
||||
public boolean containsCustomData() {
|
||||
return customData.size() > 0;
|
||||
}
|
||||
|
||||
private static final long FIXED_LENGTH_SIZE = 128; // Approximate fixed length size
|
||||
public long getSize() {
|
||||
long size = FIXED_LENGTH_SIZE;
|
||||
|
||||
@@ -520,6 +443,68 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createBackup(PwDatabase db) {
|
||||
super.createBackup(db);
|
||||
|
||||
PwEntryV4 copy = clone();
|
||||
copy.history = new ArrayList<>();
|
||||
history.add(copy);
|
||||
|
||||
if (db != null)
|
||||
if (db instanceof PwDatabaseV4)
|
||||
maintainBackups((PwDatabaseV4) db);
|
||||
}
|
||||
|
||||
private boolean maintainBackups(PwDatabaseV4 db) {
|
||||
boolean deleted = false;
|
||||
|
||||
int maxItems = db.historyMaxItems;
|
||||
if (maxItems >= 0) {
|
||||
while (history.size() > maxItems) {
|
||||
removeOldestBackup();
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
long maxSize = db.historyMaxSize;
|
||||
if (maxSize >= 0) {
|
||||
while(true) {
|
||||
long histSize = 0;
|
||||
for (PwEntryV4 entry : history) {
|
||||
histSize += entry.getSize();
|
||||
}
|
||||
|
||||
if (histSize > maxSize) {
|
||||
removeOldestBackup();
|
||||
deleted = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
||||
private void removeOldestBackup() {
|
||||
Date min = null;
|
||||
int index = -1;
|
||||
|
||||
for (int i = 0; i < history.size(); i++) {
|
||||
PwEntry entry = history.get(i);
|
||||
Date lastMod = entry.getLastModificationTime().getDate();
|
||||
if ((min == null) || lastMod.before(min)) {
|
||||
index = i;
|
||||
min = lastMod;
|
||||
}
|
||||
}
|
||||
|
||||
if (index != -1) {
|
||||
history.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touch(boolean modified, boolean touchParents) {
|
||||
super.touch(modified, touchParents);
|
||||
@@ -529,19 +514,13 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
||||
|
||||
@Override
|
||||
public void touchLocation() {
|
||||
parentGroupLastMod = new Date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(PwGroup parent) {
|
||||
this.parent = (PwGroupV4) parent;
|
||||
parentGroupLastMod = new PwDate();
|
||||
}
|
||||
|
||||
public boolean isSearchingEnabled() {
|
||||
if (parent != null) {
|
||||
return parent.isSearchEnabled();
|
||||
}
|
||||
|
||||
return PwGroupV4.DEFAULT_SEARCHING_ENABLED;
|
||||
}
|
||||
}
|
||||
@@ -24,24 +24,36 @@ import com.keepassdroid.utils.StrUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PwGroup extends PwNode {
|
||||
|
||||
// TODO Change dependency and make private
|
||||
public List<PwGroup> childGroups = new ArrayList<>();
|
||||
public List<PwEntry> childEntries = new ArrayList<>();
|
||||
public String name = "";
|
||||
public PwIconStandard icon;
|
||||
protected String name = "";
|
||||
|
||||
private List<PwNode> children = new ArrayList<>();
|
||||
protected List<PwGroup> childGroups = new ArrayList<>();
|
||||
protected List<PwEntry> childEntries = new ArrayList<>();
|
||||
|
||||
public void initNewGroup(String nm, PwGroupId newId) {
|
||||
setId(newId);
|
||||
name = nm;
|
||||
}
|
||||
|
||||
public List<PwGroup> getChildGroups() {
|
||||
return childGroups;
|
||||
}
|
||||
|
||||
public List<PwEntry> getChildEntries() {
|
||||
return childEntries;
|
||||
}
|
||||
|
||||
public void setGroups(List<PwGroup> groups) {
|
||||
childGroups = groups;
|
||||
}
|
||||
|
||||
public void setEntries(List<PwEntry> entries) {
|
||||
childEntries = entries;
|
||||
}
|
||||
|
||||
public void addChildGroup(PwGroup group) {
|
||||
this.childGroups.add(group);
|
||||
}
|
||||
@@ -50,6 +62,15 @@ public abstract class PwGroup extends PwNode {
|
||||
this.childEntries.add(entry);
|
||||
}
|
||||
|
||||
// Todo parameter type
|
||||
public PwGroup getChildGroupAt(int number) {
|
||||
return this.childGroups.get(number);
|
||||
}
|
||||
|
||||
public PwEntry getChildEntryAt(int number) {
|
||||
return this.childEntries.get(number);
|
||||
}
|
||||
|
||||
public void removeChildGroup(PwGroup group) {
|
||||
this.childGroups.remove(group);
|
||||
}
|
||||
@@ -76,7 +97,7 @@ public abstract class PwGroup extends PwNode {
|
||||
* @return List of direct children (one level below) as PwNode
|
||||
*/
|
||||
public List<PwNode> getDirectChildren() {
|
||||
children.clear();
|
||||
List<PwNode> children = new ArrayList<>();
|
||||
children.addAll(childGroups);
|
||||
for(PwEntry child : childEntries) {
|
||||
if (!child.isMetaStream())
|
||||
@@ -85,14 +106,6 @@ public abstract class PwGroup extends PwNode {
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of direct elements in Node (one level below)
|
||||
* @return Size of child elements, default is 0
|
||||
*/
|
||||
public int numberOfDirectChildren() {
|
||||
return childGroups.size() + childEntries.size();
|
||||
}
|
||||
|
||||
public boolean isContainedIn(PwGroup container) {
|
||||
PwGroup cur = this;
|
||||
while (cur != null) {
|
||||
@@ -112,24 +125,20 @@ public abstract class PwGroup extends PwNode {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract Date getLastMod();
|
||||
|
||||
public PwIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public abstract void setLastAccessTime(Date date);
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public abstract void setLastModificationTime(Date date);
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean allowAddEntryIfIsRoot() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void touch(boolean modified, boolean touchParents) {
|
||||
Date now = new Date();
|
||||
PwDate now = new PwDate();
|
||||
setLastAccessTime(now);
|
||||
|
||||
if (modified) {
|
||||
@@ -247,68 +256,4 @@ public abstract class PwGroup extends PwNode {
|
||||
PwGroupId groupId = getId();
|
||||
return groupId != null ? groupId.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by name
|
||||
*/
|
||||
public static class GroupNameComparator implements Comparator<PwGroup> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public GroupNameComparator() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public GroupNameComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwGroup object1, PwGroup object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int groupNameComp = object1.getName().compareToIgnoreCase(object2.getName());
|
||||
// If same name, can be different
|
||||
if (groupNameComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
groupNameComp = -groupNameComp;
|
||||
|
||||
return groupNameComp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by name
|
||||
*/
|
||||
public static class GroupCreationComparator implements Comparator<PwGroup> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public GroupCreationComparator() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public GroupCreationComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwGroup object1, PwGroup object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int groupCreationComp = object1.getCreationTime().compareTo(object2.getCreationTime());
|
||||
// If same creation, can be different
|
||||
if (groupCreationComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
groupCreationComp = -groupCreationComp;
|
||||
|
||||
return groupCreationComp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,6 @@ public class PwGroupIdV3 extends PwGroupId {
|
||||
if ( ! (compare instanceof PwGroupIdV3) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PwGroupIdV3 cmp = (PwGroupIdV3) compare;
|
||||
return id == cmp.id;
|
||||
}
|
||||
@@ -46,6 +45,4 @@ public class PwGroupIdV3 extends PwGroupId {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,9 +14,7 @@ public class PwGroupIdV4 extends PwGroupId {
|
||||
if ( ! (id instanceof PwGroupIdV4) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PwGroupIdV4 v4 = (PwGroupIdV4) id;
|
||||
|
||||
return uuid.equals(v4.uuid);
|
||||
}
|
||||
|
||||
@@ -28,5 +26,4 @@ public class PwGroupIdV4 extends PwGroupId {
|
||||
public UUID getId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
|
||||
This file was derived from
|
||||
|
||||
Copyright 2007 Naomaru Itoi <[email protected]>
|
||||
|
||||
This file was derived from
|
||||
|
||||
Java clone of KeePass - A KeePass file viewer for Java
|
||||
Copyright 2006 Bill Zwicky <[email protected]>
|
||||
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
@@ -30,15 +20,6 @@ Copyright 2006 Bill Zwicky <[email protected]>
|
||||
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Brian Pellin <[email protected]>
|
||||
* @author Naomaru Itoi <[email protected]>
|
||||
@@ -47,39 +28,46 @@ import java.util.List;
|
||||
*/
|
||||
public class PwGroupV3 extends PwGroup {
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static final Date NEVER_EXPIRE = PwEntryV3.NEVER_EXPIRE;
|
||||
|
||||
/** Size of byte buffer needed to hold this struct. */
|
||||
public static final int BUF_SIZE = 124;
|
||||
|
||||
// for tree traversing
|
||||
public PwGroupV3 parent = null;
|
||||
private PwGroupV3 parent = null;
|
||||
private int groupId;
|
||||
|
||||
public int groupId;
|
||||
|
||||
public PwDate tCreation;
|
||||
public PwDate tLastMod;
|
||||
public PwDate tLastAccess;
|
||||
public PwDate tExpire;
|
||||
|
||||
public int level; // short
|
||||
private int level = 0; // short
|
||||
|
||||
/** Used by KeePass internally, don't use */
|
||||
public int flags;
|
||||
|
||||
public void setGroups(List<PwGroup> groups) {
|
||||
childGroups = groups;
|
||||
}
|
||||
|
||||
private int flags;
|
||||
|
||||
public PwGroupV3() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroup getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(PwGroup prt) {
|
||||
parent = (PwGroupV3) prt;
|
||||
level = parent.getLevel() + 1;
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(int groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroupId getId() {
|
||||
return new PwGroupIdV3(groupId);
|
||||
@@ -91,76 +79,27 @@ public class PwGroupV3 extends PwGroup {
|
||||
groupId = id3.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public int getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(int flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastMod() {
|
||||
return tLastMod.getJDate();
|
||||
}
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(PwGroup prt) {
|
||||
parent = (PwGroupV3) prt;
|
||||
level = parent.level + 1;
|
||||
|
||||
}
|
||||
public void populateBlankFields(PwDatabaseV3 db) {
|
||||
// TODO populate blanck field
|
||||
if (icon == null) {
|
||||
icon = db.iconFactory.getIcon(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initNewGroup(String nm, PwGroupId newId) {
|
||||
super.initNewGroup(nm, newId);
|
||||
|
||||
Date now = Calendar.getInstance().getTime();
|
||||
tCreation = new PwDate(now);
|
||||
tLastAccess = new PwDate(now);
|
||||
tLastMod = new PwDate(now);
|
||||
tExpire = new PwDate(PwGroupV3.NEVER_EXPIRE);
|
||||
|
||||
}
|
||||
|
||||
public void populateBlankFields(PwDatabaseV3 db) {
|
||||
if (icon == null) {
|
||||
icon = db.iconFactory.getIcon(1);
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
|
||||
if (tCreation == null) {
|
||||
tCreation = PwEntryV3.DEFAULT_PWDATE;
|
||||
}
|
||||
|
||||
if (tLastMod == null) {
|
||||
tLastMod = PwEntryV3.DEFAULT_PWDATE;
|
||||
}
|
||||
|
||||
if (tLastAccess == null) {
|
||||
tLastAccess = PwEntryV3.DEFAULT_PWDATE;
|
||||
}
|
||||
|
||||
if (tExpire == null) {
|
||||
tExpire = PwEntryV3.DEFAULT_PWDATE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastAccessTime(Date date) {
|
||||
tLastAccess = new PwDate(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastModificationTime(Date date) {
|
||||
tLastMod = new PwDate(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreationTime() {
|
||||
if(tCreation != null)
|
||||
return tCreation.getJDate();
|
||||
else
|
||||
return new Date();
|
||||
}
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,46 +19,37 @@
|
||||
*/
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
|
||||
//public static final int FOLDER_ICON = 48;
|
||||
public static final boolean DEFAULT_SEARCHING_ENABLED = true;
|
||||
|
||||
public PwGroupV4 parent = null;
|
||||
public UUID uuid = PwDatabaseV4.UUID_ZERO;
|
||||
public String notes = "";
|
||||
public PwIconCustom customIcon = PwIconCustom.ZERO;
|
||||
public boolean isExpanded = true;
|
||||
public String defaultAutoTypeSequence = "";
|
||||
public Boolean enableAutoType = null;
|
||||
public Boolean enableSearching = null;
|
||||
public UUID lastTopVisibleEntry = PwDatabaseV4.UUID_ZERO;
|
||||
private Date parentGroupLastMod = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date creation = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date lastMod = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date lastAccess = PwDatabaseV4.DEFAULT_NOW;
|
||||
private Date expireDate = PwDatabaseV4.DEFAULT_NOW;
|
||||
private boolean expires = false;
|
||||
private long usageCount = 0;
|
||||
public Map<String, String> customData = new HashMap<String, String>();
|
||||
|
||||
public PwGroupV4() {}
|
||||
private PwGroupV4 parent = null;
|
||||
private UUID uuid = PwDatabase.UUID_ZERO;
|
||||
private PwIconCustom customIcon = PwIconCustom.ZERO;
|
||||
private long usageCount = 0;
|
||||
private PwDate parentGroupLastMod = new PwDate();
|
||||
private Map<String, String> customData = new HashMap<>();
|
||||
|
||||
private boolean expires = false;
|
||||
|
||||
private String notes = "";
|
||||
private boolean isExpanded = true;
|
||||
private String defaultAutoTypeSequence = "";
|
||||
private Boolean enableAutoType = null;
|
||||
private Boolean enableSearching = null;
|
||||
private UUID lastTopVisibleEntry = PwDatabase.UUID_ZERO;
|
||||
|
||||
public PwGroupV4() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PwGroupV4(boolean createUUID, boolean setTimes, String name, PwIconStandard icon) {
|
||||
if (createUUID) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
if (setTimes) {
|
||||
creation = lastMod = lastAccess = new Date();
|
||||
}
|
||||
|
||||
public PwGroupV4(String name, PwIconStandard icon) {
|
||||
super.construct();
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
}
|
||||
@@ -66,65 +57,46 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
@Override
|
||||
public void initNewGroup(String nm, PwGroupId newId) {
|
||||
super.initNewGroup(nm, newId);
|
||||
|
||||
lastAccess = lastMod = creation = parentGroupLastMod = new Date();
|
||||
parentGroupLastMod = new PwDate();
|
||||
}
|
||||
|
||||
public void AddGroup(PwGroupV4 subGroup, boolean takeOwnership) {
|
||||
AddGroup(subGroup, takeOwnership, false);
|
||||
}
|
||||
|
||||
public void AddGroup(PwGroupV4 subGroup, boolean takeOwnership, boolean updateLocationChanged) {
|
||||
public void AddGroup(PwGroupV4 subGroup) {
|
||||
if ( subGroup == null ) throw new RuntimeException("subGroup");
|
||||
|
||||
childGroups.add(subGroup);
|
||||
|
||||
if ( takeOwnership ) subGroup.parent = this;
|
||||
|
||||
if ( updateLocationChanged ) subGroup.parentGroupLastMod = new Date(System.currentTimeMillis());
|
||||
|
||||
}
|
||||
subGroup.parent = this;
|
||||
}
|
||||
|
||||
public void AddEntry(PwEntryV4 pe, boolean takeOwnership) {
|
||||
AddEntry(pe, takeOwnership, false);
|
||||
}
|
||||
|
||||
public void AddEntry(PwEntryV4 pe, boolean takeOwnership, boolean updateLocationChanged) {
|
||||
public void AddEntry(PwEntryV4 pe) {
|
||||
assert(pe != null);
|
||||
|
||||
addChildEntry(pe);
|
||||
|
||||
if ( takeOwnership ) pe.parent = this;
|
||||
|
||||
if ( updateLocationChanged ) pe.setLocationChanged(new Date(System.currentTimeMillis()));
|
||||
}
|
||||
pe.setParent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroup getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void buildChildGroupsRecursive(List<PwGroup> list) {
|
||||
list.add(this);
|
||||
|
||||
for ( int i = 0; i < numbersOfChildGroups(); i++) {
|
||||
PwGroupV4 child = (PwGroupV4) childGroups.get(i);
|
||||
child.buildChildGroupsRecursive(list);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void buildChildEntriesRecursive(List<PwEntry> list) {
|
||||
for ( int i = 0; i < numbersOfChildEntries(); i++ ) {
|
||||
list.add(childEntries.get(i));
|
||||
}
|
||||
|
||||
for ( int i = 0; i < numbersOfChildGroups(); i++ ) {
|
||||
PwGroupV4 child = (PwGroupV4) childGroups.get(i);
|
||||
child.buildChildEntriesRecursive(list);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void setParent(PwGroup prt) {
|
||||
parent = (PwGroupV4) prt;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUUID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public PwIconCustom getCustomIcon() {
|
||||
return customIcon;
|
||||
}
|
||||
|
||||
public void setCustomIcon(PwIconCustom icon) {
|
||||
this.customIcon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroupId getId() {
|
||||
@@ -138,78 +110,35 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastMod() {
|
||||
public PwDate getLocationChanged() {
|
||||
return parentGroupLastMod;
|
||||
}
|
||||
|
||||
public Date getCreationTime() {
|
||||
return creation;
|
||||
}
|
||||
|
||||
public Date getExpiryTime() {
|
||||
return expireDate;
|
||||
}
|
||||
|
||||
public Date getLastAccessTime() {
|
||||
return lastAccess;
|
||||
}
|
||||
|
||||
public Date getLastModificationTime() {
|
||||
return lastMod;
|
||||
}
|
||||
|
||||
public Date getLocationChanged() {
|
||||
return parentGroupLastMod;
|
||||
}
|
||||
|
||||
public long getUsageCount() {
|
||||
return usageCount;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date date) {
|
||||
creation = date;
|
||||
}
|
||||
|
||||
public void setExpiryTime(Date date) {
|
||||
expireDate = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastAccessTime(Date date) {
|
||||
lastAccess = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastModificationTime(Date date) {
|
||||
lastMod = date;
|
||||
}
|
||||
|
||||
public void setLocationChanged(Date date) {
|
||||
public void setLocationChanged(PwDate date) {
|
||||
parentGroupLastMod = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUsageCount() {
|
||||
return usageCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsageCount(long count) {
|
||||
usageCount = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expires() {
|
||||
return expires;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpires(boolean exp) {
|
||||
expires = exp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(PwGroup prt) {
|
||||
parent = (PwGroupV4) prt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowAddEntryIfIsRoot() {
|
||||
return true;
|
||||
@@ -217,14 +146,70 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
|
||||
@Override
|
||||
public PwIcon getIcon() {
|
||||
if (customIcon == null || customIcon.uuid.equals(PwDatabaseV4.UUID_ZERO)) {
|
||||
if (customIcon == null || customIcon.uuid.equals(PwDatabase.UUID_ZERO)) {
|
||||
return super.getIcon();
|
||||
} else {
|
||||
return customIcon;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSearchEnabled() {
|
||||
|
||||
public void putCustomData(String key, String value) {
|
||||
customData.put(key, value);
|
||||
}
|
||||
|
||||
public boolean containsCustomData() {
|
||||
return customData.size() > 0;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public boolean isExpanded() {
|
||||
return isExpanded;
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded) {
|
||||
isExpanded = expanded;
|
||||
}
|
||||
|
||||
public String getDefaultAutoTypeSequence() {
|
||||
return defaultAutoTypeSequence;
|
||||
}
|
||||
|
||||
public void setDefaultAutoTypeSequence(String defaultAutoTypeSequence) {
|
||||
this.defaultAutoTypeSequence = defaultAutoTypeSequence;
|
||||
}
|
||||
|
||||
public Boolean getEnableAutoType() {
|
||||
return enableAutoType;
|
||||
}
|
||||
|
||||
public void setEnableAutoType(Boolean enableAutoType) {
|
||||
this.enableAutoType = enableAutoType;
|
||||
}
|
||||
|
||||
public Boolean getEnableSearching() {
|
||||
return enableSearching;
|
||||
}
|
||||
|
||||
public void setEnableSearching(Boolean enableSearching) {
|
||||
this.enableSearching = enableSearching;
|
||||
}
|
||||
|
||||
public UUID getLastTopVisibleEntry() {
|
||||
return lastTopVisibleEntry;
|
||||
}
|
||||
|
||||
public void setLastTopVisibleEntry(UUID lastTopVisibleEntry) {
|
||||
this.lastTopVisibleEntry = lastTopVisibleEntry;
|
||||
}
|
||||
|
||||
public boolean isSearchEnabled() {
|
||||
PwGroupV4 group = this;
|
||||
while (group != null) {
|
||||
Boolean search = group.enableSearching;
|
||||
|
||||
@@ -3,12 +3,8 @@ package com.keepassdroid.database;
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class PwIcon implements Serializable {
|
||||
|
||||
|
||||
public boolean isMetaStreamIcon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void writeBytes() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ package com.keepassdroid.database;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PwIconCustom extends PwIcon {
|
||||
public static final PwIconCustom ZERO = new PwIconCustom(PwDatabaseV4.UUID_ZERO, new byte[0]);
|
||||
public static final PwIconCustom ZERO = new PwIconCustom(PwDatabase.UUID_ZERO, new byte[0]);
|
||||
|
||||
public final UUID uuid;
|
||||
public byte[] imageData;
|
||||
@@ -32,6 +32,11 @@ public class PwIconCustom extends PwIcon {
|
||||
imageData = data;
|
||||
}
|
||||
|
||||
public PwIconCustom(PwIconCustom icon) {
|
||||
uuid = icon.uuid;
|
||||
imageData = icon.imageData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -32,6 +32,10 @@ public class PwIconStandard extends PwIcon {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
public PwIconStandard(PwIconStandard icon) {
|
||||
this.iconId = icon.iconId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetaStreamIcon() {
|
||||
return iconId == 0;
|
||||
|
||||
@@ -21,12 +21,42 @@
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.keepassdroid.database.PwDate.NEVER_EXPIRE;
|
||||
import static com.keepassdroid.database.PwDate.PW_NEVER_EXPIRE;
|
||||
|
||||
/**
|
||||
* Abstract class who manage Groups and Entries
|
||||
*/
|
||||
public abstract class PwNode implements Serializable {
|
||||
public abstract class PwNode implements ISmallTimeLogger, Serializable {
|
||||
|
||||
protected PwIconStandard icon = PwIconStandard.FIRST;
|
||||
|
||||
protected PwDate creation = new PwDate();
|
||||
protected PwDate lastMod = new PwDate();
|
||||
protected PwDate lastAccess = new PwDate();
|
||||
protected PwDate expireDate = new PwDate(NEVER_EXPIRE);
|
||||
|
||||
protected void construct() {
|
||||
}
|
||||
|
||||
public void assign(PwNode source) {
|
||||
this.icon = source.icon;
|
||||
|
||||
this.creation = source.creation;
|
||||
this.lastMod = source.lastMod;
|
||||
this.lastAccess = source.lastAccess;
|
||||
this.expireDate = source.expireDate;
|
||||
}
|
||||
|
||||
protected void addCloneAttributesToNewEntry(PwEntry newEntry) {
|
||||
newEntry.icon = new PwIconStandard(this.icon);
|
||||
|
||||
newEntry.creation = creation.clone();
|
||||
newEntry.lastMod = lastMod.clone();
|
||||
newEntry.lastAccess = lastAccess.clone();
|
||||
newEntry.expireDate = expireDate.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of available Nodes
|
||||
@@ -48,12 +78,17 @@ public abstract class PwNode implements Serializable {
|
||||
/**
|
||||
* @return Visual icon
|
||||
*/
|
||||
public abstract PwIcon getIcon();
|
||||
public PwIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Creation date and time of the node
|
||||
*/
|
||||
public abstract Date getCreationTime();
|
||||
public PwIconStandard getIconStandard() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(PwIconStandard icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the parent node
|
||||
@@ -66,6 +101,48 @@ public abstract class PwNode implements Serializable {
|
||||
*/
|
||||
public abstract void setParent(PwGroup parent);
|
||||
|
||||
public PwDate getCreationTime() {
|
||||
return creation;
|
||||
}
|
||||
|
||||
public void setCreationTime(PwDate date) {
|
||||
creation = date;
|
||||
}
|
||||
|
||||
public PwDate getLastModificationTime() {
|
||||
return lastMod;
|
||||
}
|
||||
|
||||
public void setLastModificationTime(PwDate date) {
|
||||
lastMod = date;
|
||||
}
|
||||
|
||||
public PwDate getLastAccessTime() {
|
||||
return lastAccess;
|
||||
}
|
||||
|
||||
public void setLastAccessTime(PwDate date) {
|
||||
lastAccess = date;
|
||||
}
|
||||
|
||||
public PwDate getExpiryTime() {
|
||||
return expireDate;
|
||||
}
|
||||
|
||||
public void setExpiryTime(PwDate date) {
|
||||
expireDate = date;
|
||||
}
|
||||
|
||||
public void setExpires(boolean expires) {
|
||||
if (!expires) {
|
||||
expireDate = PW_NEVER_EXPIRE;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean expires() {
|
||||
return ! PwDate.IsSameDate(NEVER_EXPIRE, expireDate.getDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* If the content (type, title, icon) is visually the same
|
||||
* @param o Node to compare
|
||||
|
||||
@@ -47,14 +47,6 @@ public enum SortNodeEnum {
|
||||
boolean ascending;
|
||||
boolean groupsBefore;
|
||||
|
||||
NodeComparator() {
|
||||
this(true, true);
|
||||
}
|
||||
|
||||
NodeComparator(boolean groupsBefore) {
|
||||
this(true, groupsBefore);
|
||||
}
|
||||
|
||||
NodeComparator(boolean ascending, boolean groupsBefore) {
|
||||
this.ascending = ascending;
|
||||
this.groupsBefore = groupsBefore;
|
||||
@@ -66,14 +58,6 @@ public enum SortNodeEnum {
|
||||
*/
|
||||
public static class NodeTitleComparator extends NodeComparator {
|
||||
|
||||
public NodeTitleComparator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NodeTitleComparator(boolean groupsBefore) {
|
||||
super(groupsBefore);
|
||||
}
|
||||
|
||||
public NodeTitleComparator(boolean ascending, boolean groupsBefore) {
|
||||
super(ascending, groupsBefore);
|
||||
}
|
||||
@@ -84,7 +68,7 @@ public enum SortNodeEnum {
|
||||
|
||||
if (object1 instanceof PwGroup) {
|
||||
if (object2 instanceof PwGroup) {
|
||||
return new PwGroup.GroupNameComparator(ascending)
|
||||
return new GroupNameComparator(ascending)
|
||||
.compare((PwGroup) object1, (PwGroup) object2);
|
||||
} else if (object2 instanceof PwEntry) {
|
||||
if(groupsBefore)
|
||||
@@ -96,7 +80,7 @@ public enum SortNodeEnum {
|
||||
}
|
||||
} else if (object1 instanceof PwEntry) {
|
||||
if(object2 instanceof PwEntry) {
|
||||
return new PwEntry.EntryNameComparator(ascending)
|
||||
return new EntryNameComparator(ascending)
|
||||
.compare((PwEntry) object1, (PwEntry) object2);
|
||||
} else if (object2 instanceof PwGroup) {
|
||||
if(groupsBefore)
|
||||
@@ -121,14 +105,6 @@ public enum SortNodeEnum {
|
||||
*/
|
||||
public static class NodeCreationComparator extends NodeComparator {
|
||||
|
||||
public NodeCreationComparator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NodeCreationComparator(boolean groupsBefore) {
|
||||
super(groupsBefore);
|
||||
}
|
||||
|
||||
|
||||
public NodeCreationComparator(boolean ascending, boolean groupsBefore) {
|
||||
super(ascending, groupsBefore);
|
||||
@@ -141,7 +117,7 @@ public enum SortNodeEnum {
|
||||
|
||||
if (object1 instanceof PwGroup) {
|
||||
if (object2 instanceof PwGroup) {
|
||||
return new PwGroup.GroupCreationComparator(ascending)
|
||||
return new GroupCreationComparator(ascending)
|
||||
.compare((PwGroup) object1, (PwGroup) object2);
|
||||
} else if (object2 instanceof PwEntry) {
|
||||
if(groupsBefore)
|
||||
@@ -153,7 +129,7 @@ public enum SortNodeEnum {
|
||||
}
|
||||
} else if (object1 instanceof PwEntry) {
|
||||
if(object2 instanceof PwEntry) {
|
||||
return new PwEntry.EntryCreationComparator(ascending)
|
||||
return new EntryCreationComparator(ascending)
|
||||
.compare((PwEntry) object1, (PwEntry) object2);
|
||||
} else if (object2 instanceof PwGroup) {
|
||||
if(groupsBefore)
|
||||
@@ -164,8 +140,8 @@ public enum SortNodeEnum {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
int nodeCreationComp = object1.getCreationTime()
|
||||
.compareTo(object2.getCreationTime());
|
||||
int nodeCreationComp = object1.getCreationTime().getDate()
|
||||
.compareTo(object2.getCreationTime().getDate());
|
||||
// If same creation, can be different
|
||||
if (nodeCreationComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
@@ -173,4 +149,118 @@ public enum SortNodeEnum {
|
||||
return nodeCreationComp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by name
|
||||
*/
|
||||
public static class GroupNameComparator implements Comparator<PwGroup> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public GroupNameComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwGroup object1, PwGroup object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int groupNameComp = object1.getName().compareToIgnoreCase(object2.getName());
|
||||
// If same name, can be different
|
||||
if (groupNameComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
groupNameComp = -groupNameComp;
|
||||
|
||||
return groupNameComp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by name
|
||||
*/
|
||||
public static class GroupCreationComparator implements Comparator<PwGroup> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public GroupCreationComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwGroup object1, PwGroup object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int groupCreationComp = object1.getCreationTime().getDate()
|
||||
.compareTo(object2.getCreationTime().getDate());
|
||||
// If same creation, can be different
|
||||
if (groupCreationComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
groupCreationComp = -groupCreationComp;
|
||||
|
||||
return groupCreationComp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Name
|
||||
*/
|
||||
public static class EntryNameComparator implements Comparator<PwEntry> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public EntryNameComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwEntry object1, PwEntry object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int entryTitleComp = object1.getTitle().compareToIgnoreCase(object2.getTitle());
|
||||
// If same title, can be different
|
||||
if (entryTitleComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
entryTitleComp = -entryTitleComp;
|
||||
|
||||
return entryTitleComp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Creation
|
||||
*/
|
||||
public static class EntryCreationComparator implements Comparator<PwEntry> {
|
||||
|
||||
private boolean ascending;
|
||||
|
||||
public EntryCreationComparator(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
public int compare(PwEntry object1, PwEntry object2) {
|
||||
if (object1.equals(object2))
|
||||
return 0;
|
||||
|
||||
int entryCreationComp = object1.getCreationTime().getDate()
|
||||
.compareTo(object2.getCreationTime().getDate());
|
||||
// If same creation, can be different
|
||||
if (entryCreationComp == 0) {
|
||||
return object1.hashCode() - object2.hashCode();
|
||||
}
|
||||
// If descending
|
||||
if (!ascending)
|
||||
entryCreationComp = -entryCreationComp;
|
||||
|
||||
return entryCreationComp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class AddGroup extends RunnableOnFinish {
|
||||
// Generate new group
|
||||
mGroup = pm.createGroup();
|
||||
mGroup.initNewGroup(mName, pm.newGroupId());
|
||||
mGroup.icon = mDb.pm.iconFactory.getIcon(mIconID);
|
||||
mGroup.setIcon(mDb.pm.iconFactory.getIcon(mIconID));
|
||||
pm.addGroupTo(mGroup, mParent);
|
||||
|
||||
// Commit to disk
|
||||
|
||||
@@ -72,14 +72,14 @@ public class DeleteGroup extends RunnableOnFinish {
|
||||
else {
|
||||
// TODO tests
|
||||
// Remove child entries
|
||||
List<PwEntry> childEnt = new ArrayList<>(mGroup.childEntries);
|
||||
List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries());
|
||||
for ( int i = 0; i < childEnt.size(); i++ ) {
|
||||
DeleteEntry task = new DeleteEntry(mContext, mDb, childEnt.get(i), null, true);
|
||||
task.run();
|
||||
}
|
||||
|
||||
// Remove child groups
|
||||
List<PwGroup> childGrp = new ArrayList<>(mGroup.childGroups);
|
||||
List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
|
||||
for ( int i = 0; i < childGrp.size(); i++ ) {
|
||||
DeleteGroup task = new DeleteGroup(mContext, mDb, childGrp.get(i), null, true);
|
||||
task.run();
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UpdateEntry extends RunnableOnFinish {
|
||||
|
||||
// Keep backup of original values in case save fails
|
||||
PwEntry backup;
|
||||
backup = (PwEntry) mOldE.clone();
|
||||
backup = mOldE.clone();
|
||||
|
||||
mFinish = new AfterUpdate(backup, finish);
|
||||
}
|
||||
|
||||
@@ -340,31 +340,31 @@ public class ImporterV3 extends Importer {
|
||||
// Ignore field
|
||||
break;
|
||||
case 0x0001 :
|
||||
grp.groupId = LEDataInputStream.readInt(buf, offset);
|
||||
grp.setGroupId(LEDataInputStream.readInt(buf, offset));
|
||||
break;
|
||||
case 0x0002 :
|
||||
grp.name = Types.readCString(buf, offset);
|
||||
grp.setName(Types.readCString(buf, offset));
|
||||
break;
|
||||
case 0x0003 :
|
||||
grp.tCreation = new PwDate(buf, offset);
|
||||
grp.setCreationTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x0004 :
|
||||
grp.tLastMod = new PwDate(buf, offset);
|
||||
grp.setLastModificationTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x0005 :
|
||||
grp.tLastAccess = new PwDate(buf, offset);
|
||||
grp.setLastAccessTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x0006 :
|
||||
grp.tExpire = new PwDate(buf, offset);
|
||||
grp.setExpiryTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x0007 :
|
||||
grp.icon = db.iconFactory.getIcon(LEDataInputStream.readInt(buf, offset));
|
||||
grp.setIcon(db.iconFactory.getIcon(LEDataInputStream.readInt(buf, offset)));
|
||||
break;
|
||||
case 0x0008 :
|
||||
grp.level = LEDataInputStream.readUShort(buf, offset);
|
||||
grp.setLevel(LEDataInputStream.readUShort(buf, offset));
|
||||
break;
|
||||
case 0x0009 :
|
||||
grp.flags = LEDataInputStream.readInt(buf, offset);
|
||||
grp.setFlags(LEDataInputStream.readInt(buf, offset));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -387,7 +387,7 @@ public class ImporterV3 extends Importer {
|
||||
ent.setUUID(Types.bytestoUUID(buf, offset));
|
||||
break;
|
||||
case 0x0002 :
|
||||
ent.groupId = LEDataInputStream.readInt(buf, offset);
|
||||
ent.setGroupId(LEDataInputStream.readInt(buf, offset));
|
||||
break;
|
||||
case 0x0003 :
|
||||
int iconId = LEDataInputStream.readInt(buf, offset);
|
||||
@@ -397,37 +397,37 @@ public class ImporterV3 extends Importer {
|
||||
iconId = 0;
|
||||
}
|
||||
|
||||
ent.icon = db.iconFactory.getIcon(iconId);
|
||||
ent.setIcon(db.iconFactory.getIcon(iconId));
|
||||
break;
|
||||
case 0x0004 :
|
||||
ent.title = Types.readCString(buf, offset);
|
||||
ent.setTitle(Types.readCString(buf, offset));
|
||||
break;
|
||||
case 0x0005 :
|
||||
ent.url = Types.readCString(buf, offset);
|
||||
ent.setUrl(Types.readCString(buf, offset));
|
||||
break;
|
||||
case 0x0006 :
|
||||
ent.username = Types.readCString(buf, offset);
|
||||
ent.setUsername(Types.readCString(buf, offset));
|
||||
break;
|
||||
case 0x0007 :
|
||||
ent.setPassword(buf, offset, Types.strlen(buf, offset));
|
||||
break;
|
||||
case 0x0008 :
|
||||
ent.additional = Types.readCString(buf, offset);
|
||||
ent.setNotes(Types.readCString(buf, offset));
|
||||
break;
|
||||
case 0x0009 :
|
||||
ent.tCreation = new PwDate(buf, offset);
|
||||
ent.setCreationTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x000A :
|
||||
ent.tLastMod = new PwDate(buf, offset);
|
||||
ent.setLastModificationTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x000B :
|
||||
ent.tLastAccess = new PwDate(buf, offset);
|
||||
ent.setLastAccessTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x000C :
|
||||
ent.tExpire = new PwDate(buf, offset);
|
||||
ent.setExpiryTime(new PwDate(buf, offset));
|
||||
break;
|
||||
case 0x000D :
|
||||
ent.binaryDesc = Types.readCString(buf, offset);
|
||||
ent.setBinaryDesc(Types.readCString(buf, offset));
|
||||
break;
|
||||
case 0x000E :
|
||||
ent.setBinaryData(buf, offset, fieldSize);
|
||||
|
||||
@@ -46,6 +46,8 @@ import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwDate;
|
||||
import com.keepassdroid.tasks.UpdateStatus;
|
||||
import com.keepassdroid.crypto.CipherFactory;
|
||||
import com.keepassdroid.crypto.PwStreamCipherFactory;
|
||||
@@ -308,7 +310,7 @@ public class ImporterV4 extends Importer {
|
||||
private boolean entryInHistory = false;
|
||||
private PwEntryV4 ctxHistoryBase = null;
|
||||
private PwDeletedObject ctxDeletedObject = null;
|
||||
private UUID customIconID = PwDatabaseV4.UUID_ZERO;
|
||||
private UUID customIconID = PwDatabase.UUID_ZERO;
|
||||
private byte[] customIconData;
|
||||
private String customDataKey = null;
|
||||
private String customDataValue = null;
|
||||
@@ -557,38 +559,38 @@ public class ImporterV4 extends Importer {
|
||||
|
||||
case Group:
|
||||
if ( name.equalsIgnoreCase(ElemUuid) ) {
|
||||
ctxGroup.uuid = ReadUuid(xpp);
|
||||
ctxGroup.setUUID(ReadUuid(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemName) ) {
|
||||
ctxGroup.name = ReadString(xpp);
|
||||
ctxGroup.setName(ReadString(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemNotes) ) {
|
||||
ctxGroup.notes = ReadString(xpp);
|
||||
ctxGroup.setNotes(ReadString(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemIcon) ) {
|
||||
ctxGroup.icon = db.iconFactory.getIcon((int)ReadUInt(xpp, 0));
|
||||
ctxGroup.setIcon(db.iconFactory.getIcon((int)ReadUInt(xpp, 0)));
|
||||
} else if ( name.equalsIgnoreCase(ElemCustomIconID) ) {
|
||||
ctxGroup.customIcon = db.iconFactory.getIcon(ReadUuid(xpp));
|
||||
ctxGroup.setCustomIcon(db.iconFactory.getIcon(ReadUuid(xpp)));
|
||||
} else if ( name.equalsIgnoreCase(ElemTimes) ) {
|
||||
return SwitchContext(ctx, KdbContext.GroupTimes, xpp);
|
||||
} else if ( name.equalsIgnoreCase(ElemIsExpanded) ) {
|
||||
ctxGroup.isExpanded = ReadBool(xpp, true);
|
||||
ctxGroup.setExpanded(ReadBool(xpp, true));
|
||||
} else if ( name.equalsIgnoreCase(ElemGroupDefaultAutoTypeSeq) ) {
|
||||
ctxGroup.defaultAutoTypeSequence = ReadString(xpp);
|
||||
ctxGroup.setDefaultAutoTypeSequence(ReadString(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemEnableAutoType) ) {
|
||||
ctxGroup.enableAutoType = StringToBoolean(ReadString(xpp));
|
||||
ctxGroup.setEnableAutoType(StringToBoolean(ReadString(xpp)));
|
||||
} else if ( name.equalsIgnoreCase(ElemEnableSearching) ) {
|
||||
ctxGroup.enableSearching = StringToBoolean(ReadString(xpp));
|
||||
ctxGroup.setEnableSearching(StringToBoolean(ReadString(xpp)));
|
||||
} else if ( name.equalsIgnoreCase(ElemLastTopVisibleEntry) ) {
|
||||
ctxGroup.lastTopVisibleEntry = ReadUuid(xpp);
|
||||
ctxGroup.setLastTopVisibleEntry(ReadUuid(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemCustomData) ) {
|
||||
return SwitchContext(ctx, KdbContext.GroupCustomData, xpp);
|
||||
} else if ( name.equalsIgnoreCase(ElemGroup) ) {
|
||||
ctxGroup = new PwGroupV4();
|
||||
ctxGroups.peek().AddGroup(ctxGroup, true);
|
||||
ctxGroups.peek().AddGroup(ctxGroup);
|
||||
ctxGroups.push(ctxGroup);
|
||||
|
||||
return SwitchContext(ctx, KdbContext.Group, xpp);
|
||||
} else if ( name.equalsIgnoreCase(ElemEntry) ) {
|
||||
ctxEntry = new PwEntryV4();
|
||||
ctxGroup.AddEntry(ctxEntry, true);
|
||||
ctxGroup.AddEntry(ctxEntry);
|
||||
|
||||
entryInHistory = false;
|
||||
return SwitchContext(ctx, KdbContext.Entry, xpp);
|
||||
@@ -618,17 +620,17 @@ public class ImporterV4 extends Importer {
|
||||
if ( name.equalsIgnoreCase(ElemUuid) ) {
|
||||
ctxEntry.setUUID(ReadUuid(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemIcon) ) {
|
||||
ctxEntry.icon = db.iconFactory.getIcon((int)ReadUInt(xpp, 0));
|
||||
ctxEntry.setIcon(db.iconFactory.getIcon((int)ReadUInt(xpp, 0)));
|
||||
} else if ( name.equalsIgnoreCase(ElemCustomIconID) ) {
|
||||
ctxEntry.customIcon = db.iconFactory.getIcon(ReadUuid(xpp));
|
||||
ctxEntry.setCustomIcon(db.iconFactory.getIcon(ReadUuid(xpp)));
|
||||
} else if ( name.equalsIgnoreCase(ElemFgColor) ) {
|
||||
ctxEntry.foregroundColor = ReadString(xpp);
|
||||
ctxEntry.setForegroundColor(ReadString(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemBgColor) ) {
|
||||
ctxEntry.backgroupColor = ReadString(xpp);
|
||||
ctxEntry.setBackgroupColor(ReadString(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemOverrideUrl) ) {
|
||||
ctxEntry.overrideURL = ReadString(xpp);
|
||||
ctxEntry.setOverrideURL(ReadString(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemTags) ) {
|
||||
ctxEntry.tags = ReadString(xpp);
|
||||
ctxEntry.setTags(ReadString(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemTimes) ) {
|
||||
return SwitchContext(ctx, KdbContext.EntryTimes, xpp);
|
||||
} else if ( name.equalsIgnoreCase(ElemString) ) {
|
||||
@@ -679,19 +681,19 @@ public class ImporterV4 extends Importer {
|
||||
}
|
||||
|
||||
if ( name.equalsIgnoreCase(ElemLastModTime) ) {
|
||||
tl.setLastModificationTime(ReadTime(xpp));
|
||||
tl.setLastModificationTime(ReadPwTime(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemCreationTime) ) {
|
||||
tl.setCreationTime(ReadTime(xpp));
|
||||
tl.setCreationTime(ReadPwTime(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemLastAccessTime) ) {
|
||||
tl.setLastAccessTime(ReadTime(xpp));
|
||||
tl.setLastAccessTime(ReadPwTime(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemExpiryTime) ) {
|
||||
tl.setExpiryTime(ReadTime(xpp));
|
||||
tl.setExpiryTime(ReadPwTime(xpp));
|
||||
} else if ( name.equalsIgnoreCase(ElemExpires) ) {
|
||||
tl.setExpires(ReadBool(xpp, false));
|
||||
} else if ( name.equalsIgnoreCase(ElemUsageCount) ) {
|
||||
tl.setUsageCount(ReadULong(xpp, 0));
|
||||
} else if ( name.equalsIgnoreCase(ElemLocationChanged) ) {
|
||||
tl.setLocationChanged(ReadTime(xpp));
|
||||
tl.setLocationChanged(ReadPwTime(xpp));
|
||||
} else {
|
||||
ReadUnknown(xpp);
|
||||
}
|
||||
@@ -717,11 +719,11 @@ public class ImporterV4 extends Importer {
|
||||
|
||||
case EntryAutoType:
|
||||
if ( name.equalsIgnoreCase(ElemAutoTypeEnabled) ) {
|
||||
ctxEntry.autoType.enabled = ReadBool(xpp, true);
|
||||
ctxEntry.getAutoType().enabled = ReadBool(xpp, true);
|
||||
} else if ( name.equalsIgnoreCase(ElemAutoTypeObfuscation) ) {
|
||||
ctxEntry.autoType.obfuscationOptions = ReadUInt(xpp, 0);
|
||||
ctxEntry.getAutoType().obfuscationOptions = ReadUInt(xpp, 0);
|
||||
} else if ( name.equalsIgnoreCase(ElemAutoTypeDefaultSeq) ) {
|
||||
ctxEntry.autoType.defaultSequence = ReadString(xpp);
|
||||
ctxEntry.getAutoType().defaultSequence = ReadString(xpp);
|
||||
} else if ( name.equalsIgnoreCase(ElemAutoTypeItem) ) {
|
||||
return SwitchContext(ctx, KdbContext.EntryAutoTypeItem, xpp);
|
||||
} else {
|
||||
@@ -742,7 +744,7 @@ public class ImporterV4 extends Importer {
|
||||
case EntryHistory:
|
||||
if ( name.equalsIgnoreCase(ElemEntry) ) {
|
||||
ctxEntry = new PwEntryV4();
|
||||
ctxHistoryBase.history.add(ctxEntry);
|
||||
ctxHistoryBase.addToHistory(ctxEntry);
|
||||
|
||||
entryInHistory = true;
|
||||
return SwitchContext(ctx, KdbContext.Entry, xpp);
|
||||
@@ -795,13 +797,13 @@ public class ImporterV4 extends Importer {
|
||||
} else if ( ctx == KdbContext.CustomIcons && name.equalsIgnoreCase(ElemCustomIcons) ) {
|
||||
return KdbContext.Meta;
|
||||
} else if ( ctx == KdbContext.CustomIcon && name.equalsIgnoreCase(ElemCustomIconItem) ) {
|
||||
if ( ! customIconID.equals(PwDatabaseV4.UUID_ZERO) ) {
|
||||
if ( ! customIconID.equals(PwDatabase.UUID_ZERO) ) {
|
||||
PwIconCustom icon = new PwIconCustom(customIconID, customIconData);
|
||||
db.customIcons.add(icon);
|
||||
db.iconFactory.put(icon);
|
||||
} else assert(false);
|
||||
|
||||
customIconID = PwDatabaseV4.UUID_ZERO;
|
||||
customIconID = PwDatabase.UUID_ZERO;
|
||||
customIconData = null;
|
||||
|
||||
return KdbContext.CustomIcons;
|
||||
@@ -819,8 +821,8 @@ public class ImporterV4 extends Importer {
|
||||
|
||||
return KdbContext.CustomData;
|
||||
} else if ( ctx == KdbContext.Group && name.equalsIgnoreCase(ElemGroup) ) {
|
||||
if ( ctxGroup.uuid == null || ctxGroup.uuid.equals(PwDatabaseV4.UUID_ZERO) ) {
|
||||
ctxGroup.uuid = UUID.randomUUID();
|
||||
if ( ctxGroup.getUUID() == null || ctxGroup.getUUID().equals(PwDatabase.UUID_ZERO) ) {
|
||||
ctxGroup.setUUID(UUID.randomUUID());
|
||||
}
|
||||
|
||||
ctxGroups.pop();
|
||||
@@ -838,7 +840,7 @@ public class ImporterV4 extends Importer {
|
||||
return KdbContext.Group;
|
||||
} else if ( ctx == KdbContext.GroupCustomDataItem && name.equalsIgnoreCase(ElemStringDictExItem)) {
|
||||
if (groupCustomDataKey != null && groupCustomDataValue != null) {
|
||||
ctxGroup.customData.put(groupCustomDataKey, groupCustomDataKey);
|
||||
ctxGroup.putCustomData(groupCustomDataKey, groupCustomDataKey);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
@@ -849,8 +851,8 @@ public class ImporterV4 extends Importer {
|
||||
return KdbContext.GroupCustomData;
|
||||
|
||||
} else if ( ctx == KdbContext.Entry && name.equalsIgnoreCase(ElemEntry) ) {
|
||||
if ( ctxEntry.uuid == null || ctxEntry.uuid.equals(PwDatabaseV4.UUID_ZERO) ) {
|
||||
ctxEntry.uuid = UUID.randomUUID();
|
||||
if ( ctxEntry.getUUID() == null || ctxEntry.getUUID().equals(PwDatabase.UUID_ZERO) ) {
|
||||
ctxEntry.setUUID(UUID.randomUUID());
|
||||
}
|
||||
|
||||
if ( entryInHistory ) {
|
||||
@@ -868,7 +870,7 @@ public class ImporterV4 extends Importer {
|
||||
|
||||
return KdbContext.Entry;
|
||||
} else if ( ctx == KdbContext.EntryBinary && name.equalsIgnoreCase(ElemBinary) ) {
|
||||
ctxEntry.binaries.put(ctxBinaryName, ctxBinaryValue);
|
||||
ctxEntry.putProtectedBinary(ctxBinaryName, ctxBinaryValue);
|
||||
ctxBinaryName = null;
|
||||
ctxBinaryValue = null;
|
||||
|
||||
@@ -876,7 +878,7 @@ public class ImporterV4 extends Importer {
|
||||
} else if ( ctx == KdbContext.EntryAutoType && name.equalsIgnoreCase(ElemAutoType) ) {
|
||||
return KdbContext.Entry;
|
||||
} else if ( ctx == KdbContext.EntryAutoTypeItem && name.equalsIgnoreCase(ElemAutoTypeItem) ) {
|
||||
ctxEntry.autoType.put(ctxATName, ctxATSeq);
|
||||
ctxEntry.getAutoType().put(ctxATName, ctxATSeq);
|
||||
ctxATName = null;
|
||||
ctxATSeq = null;
|
||||
|
||||
@@ -885,7 +887,7 @@ public class ImporterV4 extends Importer {
|
||||
return KdbContext.Entry;
|
||||
} else if ( ctx == KdbContext.EntryCustomDataItem && name.equalsIgnoreCase(ElemStringDictExItem)) {
|
||||
if (entryCustomDataKey != null && entryCustomDataValue != null) {
|
||||
ctxEntry.customData.put(entryCustomDataKey, entryCustomDataValue);
|
||||
ctxEntry.putCustomData(entryCustomDataKey, entryCustomDataValue);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
@@ -912,6 +914,10 @@ public class ImporterV4 extends Importer {
|
||||
throw new RuntimeException("Invalid end element: Context " + contextName + "End element: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
private PwDate ReadPwTime(XmlPullParser xpp) throws IOException, XmlPullParserException {
|
||||
return new PwDate(ReadTime(xpp));
|
||||
}
|
||||
|
||||
private Date ReadTime(XmlPullParser xpp) throws IOException, XmlPullParserException {
|
||||
String sDate = ReadString(xpp);
|
||||
@@ -980,7 +986,7 @@ public class ImporterV4 extends Importer {
|
||||
String encoded = ReadString(xpp);
|
||||
|
||||
if (encoded == null || encoded.length() == 0 ) {
|
||||
return PwDatabaseV4.UUID_ZERO;
|
||||
return PwDatabase.UUID_ZERO;
|
||||
}
|
||||
|
||||
// TODO: Switch to framework Base64 once API level 8 is the minimum
|
||||
|
||||
@@ -261,7 +261,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
|
||||
// Recurse over children
|
||||
for ( int i = 0; i < group.numbersOfChildGroups(); i++ ) {
|
||||
sortGroup((PwGroupV3) group.childGroups.get(i), groupList);
|
||||
sortGroup((PwGroupV3) group.getChildGroupAt(i), groupList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import com.keepassdroid.database.PwDefsV4;
|
||||
import com.keepassdroid.database.PwDeletedObject;
|
||||
import com.keepassdroid.database.PwEntry;
|
||||
import com.keepassdroid.database.PwEntryV4;
|
||||
import com.keepassdroid.database.PwEntryV4.AutoType;
|
||||
import com.keepassdroid.database.AutoType;
|
||||
import com.keepassdroid.database.PwGroup;
|
||||
import com.keepassdroid.database.PwGroupV4;
|
||||
import com.keepassdroid.database.PwIconCustom;
|
||||
@@ -245,7 +245,7 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
|
||||
while(true) {
|
||||
try {
|
||||
if (group.parent == groupStack.peek()) {
|
||||
if (group.getParent() == groupStack.peek()) {
|
||||
groupStack.push(group);
|
||||
startGroup(group);
|
||||
break;
|
||||
@@ -434,21 +434,21 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
|
||||
private void startGroup(PwGroupV4 group) throws IllegalArgumentException, IllegalStateException, IOException {
|
||||
xml.startTag(null, ElemGroup);
|
||||
writeObject(ElemUuid, group.uuid);
|
||||
writeObject(ElemName, group.name);
|
||||
writeObject(ElemNotes, group.notes);
|
||||
writeObject(ElemIcon, group.icon.iconId);
|
||||
writeObject(ElemUuid, group.getUUID());
|
||||
writeObject(ElemName, group.getName());
|
||||
writeObject(ElemNotes, group.getNotes());
|
||||
writeObject(ElemIcon, group.getIconStandard().iconId);
|
||||
|
||||
if (!group.customIcon.equals(PwIconCustom.ZERO)) {
|
||||
writeObject(ElemCustomIconID, group.customIcon.uuid);
|
||||
if (!group.getCustomIcon().equals(PwIconCustom.ZERO)) {
|
||||
writeObject(ElemCustomIconID, group.getCustomIcon().uuid);
|
||||
}
|
||||
|
||||
writeList(ElemTimes, group);
|
||||
writeObject(ElemIsExpanded, group.isExpanded);
|
||||
writeObject(ElemGroupDefaultAutoTypeSeq, group.defaultAutoTypeSequence);
|
||||
writeObject(ElemEnableAutoType, group.enableAutoType);
|
||||
writeObject(ElemEnableSearching, group.enableSearching);
|
||||
writeObject(ElemLastTopVisibleEntry, group.lastTopVisibleEntry);
|
||||
writeObject(ElemIsExpanded, group.isExpanded());
|
||||
writeObject(ElemGroupDefaultAutoTypeSeq, group.getDefaultAutoTypeSequence());
|
||||
writeObject(ElemEnableAutoType, group.getEnableAutoType());
|
||||
writeObject(ElemEnableSearching, group.getEnableSearching());
|
||||
writeObject(ElemLastTopVisibleEntry, group.getLastTopVisibleEntry());
|
||||
|
||||
}
|
||||
|
||||
@@ -461,28 +461,28 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
|
||||
xml.startTag(null, ElemEntry);
|
||||
|
||||
writeObject(ElemUuid, entry.uuid);
|
||||
writeObject(ElemIcon, entry.icon.iconId);
|
||||
writeObject(ElemUuid, entry.getUUID());
|
||||
writeObject(ElemIcon, entry.getIconStandard().iconId);
|
||||
|
||||
if (!entry.customIcon.equals(PwIconCustom.ZERO)) {
|
||||
writeObject(ElemCustomIconID, entry.customIcon.uuid);
|
||||
if (!entry.getCustomIcon().equals(PwIconCustom.ZERO)) {
|
||||
writeObject(ElemCustomIconID, entry.getCustomIcon().uuid);
|
||||
}
|
||||
|
||||
writeObject(ElemFgColor, entry.foregroundColor);
|
||||
writeObject(ElemBgColor, entry.backgroupColor);
|
||||
writeObject(ElemOverrideUrl, entry.overrideURL);
|
||||
writeObject(ElemTags, entry.tags);
|
||||
writeObject(ElemFgColor, entry.getForegroundColor());
|
||||
writeObject(ElemBgColor, entry.getBackgroupColor());
|
||||
writeObject(ElemOverrideUrl, entry.getOverrideURL());
|
||||
writeObject(ElemTags, entry.getTags());
|
||||
|
||||
writeList(ElemTimes, entry);
|
||||
|
||||
writeList(entry.getFields(), true);
|
||||
writeList(entry.binaries);
|
||||
writeList(ElemAutoType, entry.autoType);
|
||||
writeList(entry.getBinaries());
|
||||
writeList(ElemAutoType, entry.getAutoType());
|
||||
|
||||
if (!isHistory) {
|
||||
writeList(ElemHistory, entry.history, true);
|
||||
writeList(ElemHistory, entry.getHistory(), true);
|
||||
} else {
|
||||
assert(entry.history.size() == 0);
|
||||
assert(entry.sizeOfHistory() == 0);
|
||||
}
|
||||
|
||||
xml.endTag(null, ElemEntry);
|
||||
@@ -755,13 +755,13 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
|
||||
xml.startTag(null, name);
|
||||
|
||||
writeObject(ElemLastModTime, it.getLastModificationTime());
|
||||
writeObject(ElemCreationTime, it.getCreationTime());
|
||||
writeObject(ElemLastAccessTime, it.getLastAccessTime());
|
||||
writeObject(ElemExpiryTime, it.getExpiryTime());
|
||||
writeObject(ElemLastModTime, it.getLastModificationTime().getDate());
|
||||
writeObject(ElemCreationTime, it.getCreationTime().getDate());
|
||||
writeObject(ElemLastAccessTime, it.getLastAccessTime().getDate());
|
||||
writeObject(ElemExpiryTime, it.getExpiryTime().getDate());
|
||||
writeObject(ElemExpires, it.expires());
|
||||
writeObject(ElemUsageCount, it.getUsageCount());
|
||||
writeObject(ElemLocationChanged, it.getLocationChanged());
|
||||
writeObject(ElemLocationChanged, it.getLocationChanged().getDate());
|
||||
|
||||
xml.endTag(null, name);
|
||||
}
|
||||
|
||||
@@ -79,27 +79,27 @@ public class PwEntryOutputV3 {
|
||||
// Group ID
|
||||
mOS.write(GROUPID_FIELD_TYPE);
|
||||
mOS.write(LONG_FOUR);
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPE.groupId));
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPE.getGroupId()));
|
||||
|
||||
// Image ID
|
||||
mOS.write(IMAGEID_FIELD_TYPE);
|
||||
mOS.write(LONG_FOUR);
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPE.icon.iconId));
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPE.getIconStandard().iconId));
|
||||
|
||||
// Title
|
||||
//byte[] title = mPE.title.getBytes("UTF-8");
|
||||
mOS.write(TITLE_FIELD_TYPE);
|
||||
int titleLen = Types.writeCString(mPE.title, mOS);
|
||||
int titleLen = Types.writeCString(mPE.getTitle(), mOS);
|
||||
outputBytes += titleLen;
|
||||
|
||||
// URL
|
||||
mOS.write(URL_FIELD_TYPE);
|
||||
int urlLen = Types.writeCString(mPE.url, mOS);
|
||||
int urlLen = Types.writeCString(mPE.getUrl(), mOS);
|
||||
outputBytes += urlLen;
|
||||
|
||||
// Username
|
||||
mOS.write(USERNAME_FIELD_TYPE);
|
||||
int userLen = Types.writeCString(mPE.username, mOS);
|
||||
int userLen = Types.writeCString(mPE.getUsername(), mOS);
|
||||
outputBytes += userLen;
|
||||
|
||||
// Password
|
||||
@@ -112,24 +112,24 @@ public class PwEntryOutputV3 {
|
||||
|
||||
// Additional
|
||||
mOS.write(ADDITIONAL_FIELD_TYPE);
|
||||
int addlLen = Types.writeCString(mPE.additional, mOS);
|
||||
int addlLen = Types.writeCString(mPE.getNotes(), mOS);
|
||||
outputBytes += addlLen;
|
||||
|
||||
// Create date
|
||||
writeDate(CREATE_FIELD_TYPE, mPE.tCreation.getCDate());
|
||||
writeDate(CREATE_FIELD_TYPE, mPE.getCreationTime().getCDate());
|
||||
|
||||
// Modification date
|
||||
writeDate(MOD_FIELD_TYPE, mPE.tLastMod.getCDate());
|
||||
writeDate(MOD_FIELD_TYPE, mPE.getLastModificationTime().getCDate());
|
||||
|
||||
// Access date
|
||||
writeDate(ACCESS_FIELD_TYPE, mPE.tLastAccess.getCDate());
|
||||
writeDate(ACCESS_FIELD_TYPE, mPE.getLastAccessTime().getCDate());
|
||||
|
||||
// Expiration date
|
||||
writeDate(EXPIRE_FIELD_TYPE, mPE.tExpire.getCDate());
|
||||
writeDate(EXPIRE_FIELD_TYPE, mPE.getExpiryTime().getCDate());
|
||||
|
||||
// Binary desc
|
||||
mOS.write(BINARY_DESC_FIELD_TYPE);
|
||||
int descLen = Types.writeCString(mPE.binaryDesc, mOS);
|
||||
int descLen = Types.writeCString(mPE.getBinaryDesc(), mOS);
|
||||
outputBytes += descLen;
|
||||
|
||||
// Binary data
|
||||
|
||||
@@ -65,46 +65,46 @@ public class PwGroupOutputV3 {
|
||||
// Group ID
|
||||
mOS.write(GROUPID_FIELD_TYPE);
|
||||
mOS.write(GROUPID_FIELD_SIZE);
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPG.groupId));
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPG.getGroupId()));
|
||||
|
||||
// Name
|
||||
mOS.write(NAME_FIELD_TYPE);
|
||||
Types.writeCString(mPG.name, mOS);
|
||||
Types.writeCString(mPG.getName(), mOS);
|
||||
|
||||
// Create date
|
||||
mOS.write(CREATE_FIELD_TYPE);
|
||||
mOS.write(DATE_FIELD_SIZE);
|
||||
mOS.write(mPG.tCreation.getCDate());
|
||||
mOS.write(mPG.getCreationTime().getCDate());
|
||||
|
||||
// Modification date
|
||||
mOS.write(MOD_FIELD_TYPE);
|
||||
mOS.write(DATE_FIELD_SIZE);
|
||||
mOS.write(mPG.tLastMod.getCDate());
|
||||
mOS.write(mPG.getLastModificationTime().getCDate());
|
||||
|
||||
// Access date
|
||||
mOS.write(ACCESS_FIELD_TYPE);
|
||||
mOS.write(DATE_FIELD_SIZE);
|
||||
mOS.write(mPG.tLastAccess.getCDate());
|
||||
mOS.write(mPG.getLastAccessTime().getCDate());
|
||||
|
||||
// Expiration date
|
||||
mOS.write(EXPIRE_FIELD_TYPE);
|
||||
mOS.write(DATE_FIELD_SIZE);
|
||||
mOS.write(mPG.tExpire.getCDate());
|
||||
mOS.write(mPG.getExpiryTime().getCDate());
|
||||
|
||||
// Image ID
|
||||
mOS.write(IMAGEID_FIELD_TYPE);
|
||||
mOS.write(IMAGEID_FIELD_SIZE);
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPG.icon.iconId));
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPG.getIconStandard().iconId));
|
||||
|
||||
// Level
|
||||
mOS.write(LEVEL_FIELD_TYPE);
|
||||
mOS.write(LEVEL_FIELD_SIZE);
|
||||
mOS.write(LEDataOutputStream.writeUShortBuf(mPG.level));
|
||||
mOS.write(LEDataOutputStream.writeUShortBuf(mPG.getLevel()));
|
||||
|
||||
// Flags
|
||||
mOS.write(FLAGS_FIELD_TYPE);
|
||||
mOS.write(FLAGS_FIELD_SIZE);
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPG.flags));
|
||||
mOS.write(LEDataOutputStream.writeIntBuf(mPG.getFlags()));
|
||||
|
||||
// End
|
||||
mOS.write(END_FIELD_TYPE);
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
*/
|
||||
package com.keepassdroid.database.security;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ProtectedBinary {
|
||||
public class ProtectedBinary implements Serializable {
|
||||
|
||||
public final static ProtectedBinary EMPTY = new ProtectedBinary();
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ public class ProtectedString implements Serializable {
|
||||
|
||||
public ProtectedString() {
|
||||
this(false, "");
|
||||
|
||||
}
|
||||
|
||||
public ProtectedString(boolean enableProtection, String string) {
|
||||
|
||||
@@ -66,8 +66,8 @@ public class SearchDbHelper {
|
||||
Log.d("SearchDbHelper", "Tried to search with unknown db");
|
||||
return null;
|
||||
}
|
||||
group.name = mCtx.getString(R.string.search_results);
|
||||
group.childEntries = new ArrayList<PwEntry>();
|
||||
group.setName(mCtx.getString(R.string.search_results));
|
||||
group.setEntries(new ArrayList<>());
|
||||
|
||||
// Search all entries
|
||||
Locale loc = Locale.getDefault();
|
||||
@@ -83,11 +83,11 @@ public class SearchDbHelper {
|
||||
PwGroup top = worklist.remove();
|
||||
|
||||
if (pm.isGroupSearchable(top, isOmitBackup)) {
|
||||
for (PwEntry entry : top.childEntries) {
|
||||
processEntries(entry, group.childEntries, qStr, loc);
|
||||
for (PwEntry entry : top.getChildEntries()) {
|
||||
processEntries(entry, group.getChildEntries(), qStr, loc);
|
||||
}
|
||||
|
||||
for (PwGroup childGroup : top.childGroups) {
|
||||
for (PwGroup childGroup : top.getChildGroups()) {
|
||||
if (childGroup != null) {
|
||||
worklist.add(childGroup);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ package com.keepassdroid.utils;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.keepassdroid.database.PwDate;
|
||||
import com.keepassdroid.database.PwEntryV3;
|
||||
|
||||
import static com.keepassdroid.database.PwDate.DEFAULT_PWDATE;
|
||||
|
||||
public class EmptyUtils {
|
||||
public static boolean isNullOrEmpty(String str) {
|
||||
@@ -34,7 +35,7 @@ public class EmptyUtils {
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(PwDate date) {
|
||||
return (date == null) || date.equals(PwEntryV3.DEFAULT_PWDATE);
|
||||
return (date == null) || date.equals(DEFAULT_PWDATE);
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(Uri uri) {
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.keepassdroid.utils;
|
||||
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwDatabaseV4;
|
||||
import com.keepassdroid.database.PwEntry;
|
||||
|
||||
public class SprEngine {
|
||||
|
||||
private static SprEngineV4 sprV4 = new SprEngineV4();
|
||||
private static SprEngine spr = new SprEngine();
|
||||
|
||||
public static SprEngine getInstance(PwDatabase db) {
|
||||
if (db instanceof PwDatabaseV4) {
|
||||
return sprV4;
|
||||
}
|
||||
else {
|
||||
return spr;
|
||||
}
|
||||
}
|
||||
|
||||
public String compile(String text, PwEntry entry, PwDatabase database) {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import com.keepassdroid.database.PwEntry;
|
||||
import com.keepassdroid.database.PwEntryV4;
|
||||
import com.keepassdroid.database.SearchParametersV4;
|
||||
|
||||
public class SprEngineV4 extends SprEngine {
|
||||
public class SprEngineV4 {
|
||||
private final int MAX_RECURSION_DEPTH = 12;
|
||||
private final String STR_REF_START = "{REF:";
|
||||
private final String STR_REF_END = "}";
|
||||
@@ -45,7 +45,6 @@ public class SprEngineV4 extends SprEngine {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String compile(String text, PwEntry entry, PwDatabase database) {
|
||||
SprContextV4 ctx = new SprContextV4((PwDatabaseV4)database, (PwEntryV4)entry);
|
||||
|
||||
|
||||
Reference in new issue
Block a user