mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-06 00:32:32 -08:00
Keyfile fix.
This commit is contained in:
1 parent
ae136fb816
commit
8081d88656
8 files changed
+145
-62
No files matched your search
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -29,6 +30,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
import com.keepassdroid.database.exception.InvalidKeyFileException;
|
||||
|
||||
|
||||
@@ -110,6 +122,56 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public byte[] getPasswordKey(String key) throws IOException {
|
||||
return getPasswordKey(key, "UTF-8");
|
||||
}
|
||||
|
||||
private static final String RootElementName = "KeyFile";
|
||||
//private static final String MetaElementName = "Meta";
|
||||
//private static final String VersionElementName = "Version";
|
||||
private static final String KeyElementName = "Key";
|
||||
private static final String KeyDataElementName = "Data";
|
||||
|
||||
@Override
|
||||
protected byte[] loadXmlKeyFile(String fileName) {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
FileInputStream fis = new FileInputStream(fileName);
|
||||
Document doc = db.parse(fis);
|
||||
|
||||
Element el = doc.getDocumentElement();
|
||||
if (el == null || ! el.getNodeName().equalsIgnoreCase(RootElementName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NodeList children = el.getChildNodes();
|
||||
if (children.getLength() < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < children.getLength(); i++ ) {
|
||||
Node child = children.item(i);
|
||||
|
||||
if ( child.getNodeName().equalsIgnoreCase(KeyElementName) ) {
|
||||
NodeList keyChildren = child.getChildNodes();
|
||||
for ( int j = 0; j < keyChildren.getLength(); j++ ) {
|
||||
Node keyChild = keyChildren.item(j);
|
||||
if ( keyChild.getNodeName().equalsIgnoreCase(KeyDataElementName) ) {
|
||||
NodeList children2 = keyChild.getChildNodes();
|
||||
for ( int k = 0; k < children2.getLength(); k++) {
|
||||
Node text = children2.item(k);
|
||||
if (text.getNodeType() == Node.TEXT_NODE) {
|
||||
Text txt = (Text) text;
|
||||
return Base64Coder.decode(txt.getNodeValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PwGroup> getGroups() {
|
||||
@@ -172,5 +234,4 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
public PwGroup createGroup() {
|
||||
return new PwGroupV4();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user