@After public void tearDown() throws Exception { TestUtil.createConfiguration(testDir).getKeyDerivationParametersFile().delete(); assertTrue("Directory not empty: <" + testDir.getAbsolutePath() + ">", testDir.delete()); }
@After public void tearDown() throws Exception { assertTrue("Can't delete file: " + identitiesFile.getAbsolutePath(), identitiesFile.delete()); File derivParamsFile = TestUtil.createConfiguration(testDir).getKeyDerivationParametersFile(); assertTrue("Can't delete file: " + derivParamsFile, derivParamsFile.delete()); assertTrue("Can't delete directory: " + testDir.getAbsolutePath(), testDir.delete()); }
@After public void tearDown() throws Exception { // Current tests don't cause this to be written out //assertTrue("Can't delete file: " + addressBookFile.getAbsolutePath(), addressBookFile.delete()); File derivParamsFile = TestUtil.createConfiguration(testDir).getKeyDerivationParametersFile(); assertTrue("Can't delete file: " + derivParamsFile, derivParamsFile.delete()); assertTrue("Can't delete directory: " + testDir.getAbsolutePath(), testDir.delete()); }
File derivParamFile = configuration.getKeyDerivationParametersFile(); if (derivParamFile.exists()) derivedKey = FileEncryptionUtil.getEncryptionKey(password, derivParamFile);
@Test public void testGetKey() throws IOException, GeneralSecurityException { passwordCache.setPassword(PASSWORD); DerivedKey derivedKey = passwordCache.getKey(); assertEquals(derivedKey.scryptParams, FileEncryptionConstants.KDF_PARAMETERS); byte[] expectedKey = FileEncryptionUtil.getEncryptionKey(PASSWORD, derivedKey.salt, derivedKey.scryptParams); assertArrayEquals(expectedKey, derivedKey.key); // verify that the salt was cached in a file and is reused PasswordCache newPasswordCache = TestUtil.createPasswordCache(testDir); newPasswordCache = TestUtil.createPasswordCache(testDir); newPasswordCache.setPassword(PASSWORD); byte[] oldSalt = derivedKey.salt; byte[] newSalt = passwordCache.getKey().salt; assertArrayEquals(oldSalt, newSalt); // delete the cache file, clear the derived key, and verify that a new salt is generated Configuration configuration = TestUtil.createConfiguration(testDir); File derivParamsFile = configuration.getKeyDerivationParametersFile(); boolean deleted = derivParamsFile.delete(); assertTrue("Can't delete derivation parameters cache file: <" + derivParamsFile.getAbsolutePath() + ">", deleted); passwordCache.setPassword(PASSWORD); // clear the key newSalt = passwordCache.getKey().salt; assertFalse(Arrays.equals(oldSalt, newSalt)); }
atLeast(1).of(configuration).getKeyDerivationParametersFile(); will(returnValue(derivParametersFile)); }});