mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Handle non-ascii passwords correctly.
This commit is contained in:
BIN
assets/accent.kdb
Normal file
BIN
assets/accent.kdb
Normal file
Binary file not shown.
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.keepass;
|
package com.android.keepass;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -142,7 +143,13 @@ public class EntryEditActivity extends LockingActivity {
|
|||||||
newEntry.url = Util.getEditText(act, R.id.entry_url);
|
newEntry.url = Util.getEditText(act, R.id.entry_url);
|
||||||
newEntry.username = Util.getEditText(act, R.id.entry_user_name);
|
newEntry.username = Util.getEditText(act, R.id.entry_user_name);
|
||||||
newEntry.additional = Util.getEditText(act, R.id.entry_comment);
|
newEntry.additional = Util.getEditText(act, R.id.entry_comment);
|
||||||
byte[] password = pass.getBytes();
|
byte[] password;
|
||||||
|
try {
|
||||||
|
password = pass.getBytes("UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
assert false;
|
||||||
|
password = pass.getBytes();
|
||||||
|
}
|
||||||
newEntry.setPassword(password, 0, password.length);
|
newEntry.setPassword(password, 0, password.length);
|
||||||
|
|
||||||
if ( newEntry.title.equals(mEntry.title) ) {
|
if ( newEntry.title.equals(mEntry.title) ) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.bouncycastle.crypto.digests.SHA256Digest;
|
import org.bouncycastle.crypto.digests.SHA256Digest;
|
||||||
@@ -195,7 +196,14 @@ public class PwManager {
|
|||||||
throw new IllegalArgumentException( "Key cannot be empty." );
|
throw new IllegalArgumentException( "Key cannot be empty." );
|
||||||
|
|
||||||
SHA256Digest md = new SHA256Digest();
|
SHA256Digest md = new SHA256Digest();
|
||||||
md.update( key.getBytes(), 0, key.getBytes().length );
|
byte[] bKey;
|
||||||
|
try {
|
||||||
|
bKey = key.getBytes("ISO-8859-1");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
assert false;
|
||||||
|
bKey = key.getBytes();
|
||||||
|
}
|
||||||
|
md.update(bKey, 0, bKey.length );
|
||||||
masterKey = new byte[md.getDigestSize()];
|
masterKey = new byte[md.getDigestSize()];
|
||||||
md.doFinal(masterKey, 0);
|
md.doFinal(masterKey, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,27 +37,34 @@ public class TestData {
|
|||||||
private static final String TEST1_KDB = "test1.kdb";
|
private static final String TEST1_KDB = "test1.kdb";
|
||||||
private static final String TEST1_PASSWORD = "12345";
|
private static final String TEST1_PASSWORD = "12345";
|
||||||
|
|
||||||
private static Database mDb;
|
private static Database mDb1;
|
||||||
|
|
||||||
|
|
||||||
public static Database GetDb1(Context ctx) throws IOException, InvalidCipherTextException, InvalidKeyFileException {
|
public static Database GetDb1(Context ctx) throws IOException, InvalidCipherTextException, InvalidKeyFileException {
|
||||||
if ( mDb == null ) {
|
if ( mDb1 == null ) {
|
||||||
AssetManager am = ctx.getAssets();
|
mDb1 = GetDb(ctx, TEST1_KDB, TEST1_PASSWORD, TEST1_KEYFILE, "/sdcard/test1.kdb");
|
||||||
InputStream is = am.open(TEST1_KDB, AssetManager.ACCESS_STREAMING);
|
|
||||||
|
|
||||||
mDb = new Database();
|
|
||||||
mDb.LoadData(ctx, is, TEST1_PASSWORD, TEST1_KEYFILE, ImporterV3.DEBUG);
|
|
||||||
mDb.mFilename = "/sdcard/test1.kdb";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mDb;
|
return mDb1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Database GetDb(Context ctx, String asset, String password, String keyfile, String filename) throws IOException, InvalidCipherTextException, InvalidKeyFileException {
|
||||||
|
AssetManager am = ctx.getAssets();
|
||||||
|
InputStream is = am.open(asset, AssetManager.ACCESS_STREAMING);
|
||||||
|
|
||||||
|
Database Db = new Database();
|
||||||
|
Db.LoadData(ctx, is, password, keyfile, ImporterV3.DEBUG);
|
||||||
|
Db.mFilename = filename;
|
||||||
|
|
||||||
|
return Db;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PwManager GetTest1(Context ctx) throws InvalidCipherTextException, IOException, InvalidKeyFileException {
|
public static PwManager GetTest1(Context ctx) throws InvalidCipherTextException, IOException, InvalidKeyFileException {
|
||||||
if ( mDb == null ) {
|
if ( mDb1 == null ) {
|
||||||
GetDb1(ctx);
|
GetDb1(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mDb.mPM;
|
return mDb1.mPM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user