mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-01 22:32:47 -08:00
Implement KDBX V4 read support
This commit is contained in:
1 parent
8bcf9b8978
commit
ea2c0ebd90
17 files changed
+663
-98
No files matched your search
@@ -21,6 +21,7 @@ package com.keepassdroid.tests;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
@@ -191,4 +192,20 @@ public class TypesTest extends TestCase {
|
||||
|
||||
assertArrayEquals("UUID match failed", bUUID, eUUID);
|
||||
}
|
||||
|
||||
public void testULongMax() throws Exception {
|
||||
byte[] ulongBytes = new byte[8];
|
||||
for (int i = 0; i < ulongBytes.length; i++) {
|
||||
ulongBytes[i] = -1;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
LEDataOutputStream leos = new LEDataOutputStream(bos);
|
||||
leos.writeLong(Types.ULONG_MAX_VALUE);
|
||||
leos.close();
|
||||
|
||||
byte[] uLongMax = bos.toByteArray();
|
||||
|
||||
assertArrayEquals(ulongBytes, uLongMax);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 Brian Pellin.
|
||||
* Copyright 2013-2017 Brian Pellin.
|
||||
*
|
||||
* This file is part of KeePassDroid.
|
||||
*
|
||||
@@ -38,6 +38,8 @@ import javax.crypto.NoSuchPaddingException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.keepassdroid.crypto.CipherFactory;
|
||||
import com.keepassdroid.crypto.engine.AesEngine;
|
||||
import com.keepassdroid.crypto.engine.CipherEngine;
|
||||
import com.keepassdroid.stream.BetterCipherInputStream;
|
||||
import com.keepassdroid.stream.LEDataInputStream;
|
||||
|
||||
@@ -54,9 +56,10 @@ public class CipherTest extends TestCase {
|
||||
rand.nextBytes(iv);
|
||||
rand.nextBytes(plaintext);
|
||||
|
||||
Cipher encrypt = CipherFactory.getInstance(CipherFactory.AES_CIPHER, Cipher.ENCRYPT_MODE, key, iv);
|
||||
Cipher decrypt = CipherFactory.getInstance(CipherFactory.AES_CIPHER, Cipher.DECRYPT_MODE, key, iv);
|
||||
|
||||
CipherEngine aes = CipherFactory.getInstance(AesEngine.CIPHER_UUID);
|
||||
Cipher encrypt = aes.getCipher(Cipher.ENCRYPT_MODE, key, iv);
|
||||
Cipher decrypt = aes.getCipher(Cipher.DECRYPT_MODE, key, iv);
|
||||
|
||||
byte[] secrettext = encrypt.doFinal(plaintext);
|
||||
byte[] decrypttext = decrypt.doFinal(secrettext);
|
||||
|
||||
@@ -74,10 +77,11 @@ public class CipherTest extends TestCase {
|
||||
rand.nextBytes(key);
|
||||
rand.nextBytes(iv);
|
||||
rand.nextBytes(plaintext);
|
||||
|
||||
Cipher encrypt = CipherFactory.getInstance(CipherFactory.AES_CIPHER, Cipher.ENCRYPT_MODE, key, iv);
|
||||
Cipher decrypt = CipherFactory.getInstance(CipherFactory.AES_CIPHER, Cipher.DECRYPT_MODE, key, iv);
|
||||
|
||||
|
||||
CipherEngine aes = CipherFactory.getInstance(AesEngine.CIPHER_UUID);
|
||||
Cipher encrypt = aes.getCipher(Cipher.ENCRYPT_MODE, key, iv);
|
||||
Cipher decrypt = aes.getCipher(Cipher.DECRYPT_MODE, key, iv);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
CipherOutputStream cos = new CipherOutputStream(bos, encrypt);
|
||||
cos.write(plaintext);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 Brian Pellin.
|
||||
* Copyright 2010-2017 Brian Pellin.
|
||||
*
|
||||
* This file is part of KeePassDroid.
|
||||
*
|
||||
@@ -26,6 +26,7 @@ import android.content.res.AssetManager;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.keepassdroid.crypto.CipherFactory;
|
||||
import com.keepassdroid.crypto.engine.AesEngine;
|
||||
import com.keepassdroid.database.PwDatabaseV4;
|
||||
import com.keepassdroid.database.load.ImporterV4;
|
||||
|
||||
@@ -42,7 +43,7 @@ public class Kdb4Header extends AndroidTestCase {
|
||||
|
||||
assertEquals(6000, db.numKeyEncRounds);
|
||||
|
||||
assertTrue(db.dataCipher.equals(CipherFactory.AES_CIPHER));
|
||||
assertTrue(db.dataCipher.equals(AesEngine.CIPHER_UUID));
|
||||
|
||||
is.close();
|
||||
|
||||
|
||||
Reference in new issue
Block a user