mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-24 11:01:35 -08:00
Merge keepassdroid 2.2.0.8 and update changelog
This commit is contained in:
commit
ecdd744b8e
25 files changed
+372
-66
No files matched your search
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -49,6 +50,14 @@ public class BinaryPool {
|
||||
public Set<Entry<Integer, ProtectedBinary>> entrySet() {
|
||||
return pool.entrySet();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
pool.clear();
|
||||
}
|
||||
|
||||
public Collection<ProtectedBinary> binaries() {
|
||||
return pool.values();
|
||||
}
|
||||
|
||||
private class AddBinaries extends EntryHandler<PwEntryV4> {
|
||||
|
||||
@@ -72,7 +81,7 @@ public class BinaryPool {
|
||||
|
||||
}
|
||||
|
||||
private void poolAdd(ProtectedBinary pb) {
|
||||
public void poolAdd(ProtectedBinary pb) {
|
||||
assert(pb != null);
|
||||
|
||||
if (poolFind(pb) != -1) return;
|
||||
|
||||
@@ -73,6 +73,7 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public UUID dataCipher = AesEngine.CIPHER_UUID;
|
||||
public CipherEngine dataEngine = new AesEngine();
|
||||
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;
|
||||
@@ -103,7 +104,8 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public Map<String, String> customData = new HashMap<String, String>();
|
||||
public KdfParameters kdfParameters = KdfFactory.getDefaultParameters();
|
||||
public VariantDictionary publicCustomData = new VariantDictionary();
|
||||
|
||||
public BinaryPool binPool = new BinaryPool();
|
||||
|
||||
public String localizedAppName = "KeePassDroid";
|
||||
|
||||
public class MemoryProtectionConfig {
|
||||
@@ -175,13 +177,24 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
Arrays.fill(cmpKey, (byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP) throws IOException {
|
||||
makeFinalKey(masterSeed, kdfP, 0);
|
||||
}
|
||||
|
||||
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP, long roundsFix)
|
||||
throws IOException {
|
||||
|
||||
KdfEngine kdfEngine = KdfFactory.get(kdfP.kdfUUID);
|
||||
if (kdfEngine == null) {
|
||||
throw new IOException("Unknown key derivation function");
|
||||
}
|
||||
|
||||
// Set to 6000 rounds to open corrupted database
|
||||
if (roundsFix > 0 && kdfP.kdfUUID.equals(AesKdf.CIPHER_UUID)) {
|
||||
kdfP.setUInt32(AesKdf.ParamRounds, roundsFix);
|
||||
numKeyEncRounds = roundsFix;
|
||||
}
|
||||
|
||||
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfP);
|
||||
if (transformedMasterKey.length != 32) {
|
||||
transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey);
|
||||
|
||||
@@ -23,16 +23,8 @@ import android.annotation.SuppressLint;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public class PwDatabaseV4XML {
|
||||
|
||||
public static final SimpleDateFormat dateFormat;
|
||||
|
||||
static {
|
||||
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
|
||||
public static final String ElemDocNode = "KeePassFile";
|
||||
public static final String ElemMeta = "Meta";
|
||||
public static final String ElemRoot = "Root";
|
||||
@@ -134,4 +126,15 @@ public class PwDatabaseV4XML {
|
||||
|
||||
public static final String ElemCustomData = "CustomData";
|
||||
public static final String ElemStringDictExItem = "Item";
|
||||
|
||||
public static final ThreadLocal<SimpleDateFormat> dateFormatter =
|
||||
new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
SimpleDateFormat dateFormat;
|
||||
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
return dateFormat;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -95,7 +95,6 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
public byte[] streamStartBytes = new byte[32];
|
||||
public CrsAlgorithm innerRandomStream;
|
||||
public long version;
|
||||
public List<ProtectedBinary> binaries = new ArrayList<ProtectedBinary>();
|
||||
|
||||
public PwDbHeaderV4(PwDatabaseV4 d) {
|
||||
db = d;
|
||||
@@ -194,7 +193,9 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
if (!db.kdfParameters.kdfUUID.equals(kdfR.uuid)) {
|
||||
db.kdfParameters = kdfR.getDefaultParameters();
|
||||
}
|
||||
db.kdfParameters.setUInt64(AesKdf.ParamRounds, LEDataInputStream.readLong(fieldData, 0));
|
||||
long rounds = LEDataInputStream.readLong(fieldData, 0);
|
||||
db.kdfParameters.setUInt64(AesKdf.ParamRounds, rounds);
|
||||
db.numKeyEncRounds = rounds;
|
||||
break;
|
||||
|
||||
case PwDbHeaderV4Fields.EncryptionIV:
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class Importer {
|
||||
public abstract PwDatabase openDatabase( InputStream inStream, String password, InputStream keyInputStream)
|
||||
throws IOException, InvalidDBException;
|
||||
|
||||
public abstract PwDatabase openDatabase( InputStream inStream, String password, InputStream keyInputStream, UpdateStatus status )
|
||||
public abstract PwDatabase openDatabase( InputStream inStream, String password, InputStream keyInputStream, UpdateStatus status, long roundsFix)
|
||||
throws IOException, InvalidDBException;
|
||||
|
||||
|
||||
|
||||
@@ -125,10 +125,10 @@ public class ImporterV3 extends Importer {
|
||||
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
|
||||
throws IOException, InvalidDBException
|
||||
{
|
||||
return openDatabase(inStream, password, kfIs, new UpdateStatus());
|
||||
return openDatabase(inStream, password, kfIs, new UpdateStatus(), 0);
|
||||
}
|
||||
|
||||
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs, UpdateStatus status )
|
||||
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs, UpdateStatus status, long roundsFix)
|
||||
throws IOException, InvalidDBException
|
||||
{
|
||||
PwDatabaseV3 newManager;
|
||||
|
||||
@@ -35,9 +35,10 @@ public class ImporterV3Debug extends ImporterV3 {
|
||||
|
||||
@Override
|
||||
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream, UpdateStatus status) throws IOException,
|
||||
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException,
|
||||
InvalidDBException {
|
||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status);
|
||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
|
||||
roundsFix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,11 +78,11 @@ public class ImporterV4 extends Importer {
|
||||
|
||||
private StreamCipher randomStream;
|
||||
private PwDatabaseV4 db;
|
||||
private BinaryPool binPool = new BinaryPool();
|
||||
|
||||
private byte[] hashOfHeader = null;
|
||||
private byte[] pbHeader = null;
|
||||
private long version;
|
||||
private int binNum = 0;
|
||||
Calendar utcCal;
|
||||
|
||||
public ImporterV4() {
|
||||
@@ -98,18 +98,17 @@ public class ImporterV4 extends Importer {
|
||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream) throws IOException, InvalidDBException {
|
||||
|
||||
return openDatabase(inStream, password, keyInputStream, new UpdateStatus());
|
||||
return openDatabase(inStream, password, keyInputStream, new UpdateStatus(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream, UpdateStatus status) throws IOException,
|
||||
InvalidDBException {
|
||||
|
||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException,
|
||||
InvalidDBException {
|
||||
db = createDB();
|
||||
|
||||
PwDbHeaderV4 header = new PwDbHeaderV4(db);
|
||||
header.binaries.clear();
|
||||
db.binPool.clear();
|
||||
|
||||
PwDbHeaderV4.HeaderAndHash hh = header.loadFromFile(inStream);
|
||||
version = header.version;
|
||||
@@ -118,7 +117,7 @@ public class ImporterV4 extends Importer {
|
||||
pbHeader = hh.header;
|
||||
|
||||
db.setMasterKey(password, keyInputStream);
|
||||
db.makeFinalKey(header.masterSeed, db.kdfParameters);
|
||||
db.makeFinalKey(header.masterSeed, db.kdfParameters, roundsFix);
|
||||
|
||||
CipherEngine engine;
|
||||
Cipher cipher;
|
||||
@@ -253,6 +252,7 @@ public class ImporterV4 extends Importer {
|
||||
byte[] bin = new byte[data.length - 1];
|
||||
System.arraycopy(data, 1, bin, 0, data.length-1);
|
||||
ProtectedBinary pb = new ProtectedBinary(prot, bin);
|
||||
db.binPool.poolAdd(pb);
|
||||
|
||||
if (prot) {
|
||||
Arrays.fill(data, (byte)0);
|
||||
@@ -511,7 +511,7 @@ public class ImporterV4 extends Importer {
|
||||
if ( key != null ) {
|
||||
ProtectedBinary pbData = ReadProtectedBinary(xpp);
|
||||
int id = Integer.parseInt(key);
|
||||
binPool.put(id, pbData);
|
||||
db.binPool.put(id, pbData);
|
||||
} else {
|
||||
ReadUnknown(xpp);
|
||||
}
|
||||
@@ -932,7 +932,7 @@ public class ImporterV4 extends Importer {
|
||||
} else {
|
||||
|
||||
try {
|
||||
utcDate = PwDatabaseV4XML.dateFormat.parse(sDate);
|
||||
utcDate = PwDatabaseV4XML.dateFormatter.get().parse(sDate);
|
||||
} catch (ParseException e) {
|
||||
// Catch with null test below
|
||||
}
|
||||
@@ -1061,7 +1061,7 @@ public class ImporterV4 extends Importer {
|
||||
xpp.next(); // Consume end tag
|
||||
|
||||
int id = Integer.parseInt(ref);
|
||||
return binPool.get(id);
|
||||
return db.binPool.get(id);
|
||||
}
|
||||
|
||||
boolean compressed = false;
|
||||
|
||||
@@ -35,9 +35,10 @@ public class ImporterV4Debug extends ImporterV4 {
|
||||
|
||||
@Override
|
||||
public PwDatabaseV4Debug openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputFile, UpdateStatus status) throws IOException,
|
||||
InputStream keyInputFile, UpdateStatus status, long roundsFix) throws IOException,
|
||||
InvalidDBException {
|
||||
return (PwDatabaseV4Debug) super.openDatabase(inStream, password, keyInputFile, status);
|
||||
return (PwDatabaseV4Debug) super.openDatabase(inStream, password, keyInputFile, status,
|
||||
roundsFix);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class PwDbInnerHeaderOutputV4 {
|
||||
los.writeInt(streamKeySize);
|
||||
los.write(header.innerRandomStreamKey);
|
||||
|
||||
for (ProtectedBinary bin : header.binaries) {
|
||||
for (ProtectedBinary bin : db.binPool.binaries()) {
|
||||
byte flag = KdbxBinaryFlags.None;
|
||||
if (bin.isProtected()) {
|
||||
flag |= KdbxBinaryFlags.Protected;
|
||||
|
||||
@@ -82,7 +82,6 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
|
||||
PwDatabaseV4 mPM;
|
||||
private StreamCipher randomStream;
|
||||
private BinaryPool binPool;
|
||||
private XmlSerializer xml;
|
||||
private PwDbHeaderV4 header;
|
||||
private byte[] hashOfHeader;
|
||||
@@ -201,8 +200,7 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
}
|
||||
|
||||
private void outputDatabase(OutputStream os) throws IllegalArgumentException, IllegalStateException, IOException {
|
||||
binPool = new BinaryPool((PwGroupV4)mPM.rootGroup);
|
||||
|
||||
|
||||
xml = Xml.newSerializer();
|
||||
|
||||
xml.setOutput(os, "UTF-8");
|
||||
@@ -420,7 +418,7 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
xml.startTag(null, ElemValue);
|
||||
String strRef = null;
|
||||
if (allowRef) {
|
||||
int ref = binPool.poolFind(value);
|
||||
int ref = mPM.binPool.poolFind(value);
|
||||
strRef = Integer.toString(ref);
|
||||
}
|
||||
|
||||
@@ -480,7 +478,7 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
|
||||
private void writeObject(String name, Date value) throws IllegalArgumentException, IllegalStateException, IOException {
|
||||
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
|
||||
writeObject(name, PwDatabaseV4XML.dateFormat.format(value));
|
||||
writeObject(name, PwDatabaseV4XML.dateFormatter.get().format(value));
|
||||
} else {
|
||||
DateTime dt = new DateTime(value);
|
||||
long seconds = DateUtil.convertDateToKDBX4Time(dt);
|
||||
@@ -720,7 +718,7 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
private void writeBinPool() throws IllegalArgumentException, IllegalStateException, IOException {
|
||||
xml.startTag(null, ElemBinaries);
|
||||
|
||||
for (Entry<Integer, ProtectedBinary> pair : binPool.entrySet()) {
|
||||
for (Entry<Integer, ProtectedBinary> pair : mPM.binPool.entrySet()) {
|
||||
xml.startTag(null, ElemBinary);
|
||||
xml.attribute(null, AttrId, Integer.toString(pair.getKey()));
|
||||
|
||||
|
||||
Reference in new issue
Block a user