mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Re-encrypt the DB key with the stored key.
This commit is contained in:
@@ -118,6 +118,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(crypto).decryptWithPassword(encryptedKey, password,
|
||||
keyStoreConfig);
|
||||
will(returnValue(key.getBytes()));
|
||||
oneOf(crypto).isEncryptedWithStoredKey(encryptedKey);
|
||||
will(returnValue(true));
|
||||
}});
|
||||
|
||||
storeDatabaseKey(keyFile, encryptedKeyHex);
|
||||
@@ -136,6 +138,35 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
||||
assertEquals(encryptedKeyHex, loadDatabaseKey(keyBackupFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignInReEncryptsKey() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(crypto).decryptWithPassword(encryptedKey, password,
|
||||
keyStoreConfig);
|
||||
will(returnValue(key.getBytes()));
|
||||
oneOf(crypto).isEncryptedWithStoredKey(encryptedKey);
|
||||
will(returnValue(false));
|
||||
oneOf(crypto).encryptWithPassword(key.getBytes(), password,
|
||||
keyStoreConfig);
|
||||
will(returnValue(newEncryptedKey));
|
||||
}});
|
||||
|
||||
storeDatabaseKey(keyFile, encryptedKeyHex);
|
||||
storeDatabaseKey(keyBackupFile, encryptedKeyHex);
|
||||
|
||||
assertEquals(encryptedKeyHex, loadDatabaseKey(keyFile));
|
||||
assertEquals(encryptedKeyHex, loadDatabaseKey(keyBackupFile));
|
||||
|
||||
assertTrue(accountManager.signIn(password));
|
||||
assertTrue(accountManager.hasDatabaseKey());
|
||||
SecretKey decrypted = accountManager.getDatabaseKey();
|
||||
assertNotNull(decrypted);
|
||||
assertArrayEquals(key.getBytes(), decrypted.getBytes());
|
||||
|
||||
assertEquals(newEncryptedKeyHex, loadDatabaseKey(keyFile));
|
||||
assertEquals(newEncryptedKeyHex, loadDatabaseKey(keyBackupFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbKeyIsLoadedFromPrimaryFile() throws Exception {
|
||||
storeDatabaseKey(keyFile, encryptedKeyHex);
|
||||
@@ -316,6 +347,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(crypto).decryptWithPassword(encryptedKey, password,
|
||||
keyStoreConfig);
|
||||
will(returnValue(key.getBytes()));
|
||||
oneOf(crypto).isEncryptedWithStoredKey(encryptedKey);
|
||||
will(returnValue(true));
|
||||
oneOf(crypto).encryptWithPassword(key.getBytes(), newPassword,
|
||||
keyStoreConfig);
|
||||
will(returnValue(newEncryptedKey));
|
||||
|
||||
Reference in New Issue
Block a user