Search in sources :

Example 1 with Configuration

use of i2p.bote.Configuration in project i2p.i2p-bote by i2p.

the class PasswordCacheTest method testGetKey.

@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);
    // clear the key
    passwordCache.setPassword(PASSWORD);
    newSalt = passwordCache.getKey().salt;
    assertFalse(Arrays.equals(oldSalt, newSalt));
}
Also used : PasswordCache(i2p.bote.fileencryption.PasswordCache) Configuration(i2p.bote.Configuration) DerivedKey(i2p.bote.fileencryption.DerivedKey) File(java.io.File) Test(org.junit.Test)

Example 2 with Configuration

use of i2p.bote.Configuration in project i2p.i2p-bote by i2p.

the class NetworkPreferenceFragment method onPause.

@Override
public void onPause() {
    Configuration config = I2PBote.getInstance().getConfiguration();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    Map<String, ?> all = prefs.getAll();
    for (String x : all.keySet()) {
        if ("autoMailCheckEnabled".equals(x))
            config.setAutoMailCheckEnabled(prefs.getBoolean(x, true));
        else if ("mailCheckInterval".equals(x))
            config.setMailCheckInterval(prefs.getInt(x, 30));
        else if ("deliveryCheckEnabled".equals(x))
            config.setDeliveryCheckEnabled(prefs.getBoolean(x, true));
    }
    config.save();
    // Store the settings in Android
    super.onPause();
}
Also used : Configuration(i2p.bote.Configuration) SharedPreferences(android.content.SharedPreferences)

Example 3 with Configuration

use of i2p.bote.Configuration in project i2p.i2p-bote by i2p.

the class PrivacyPreferenceFragment method onPause.

@Override
public void onPause() {
    Configuration config = I2PBote.getInstance().getConfiguration();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    Map<String, ?> all = prefs.getAll();
    for (String x : all.keySet()) {
        if ("hideLocale".equals(x))
            config.setHideLocale(prefs.getBoolean(x, true));
        else if ("includeSentTime".equals(x))
            config.setIncludeSentTime(prefs.getBoolean(x, true));
        else if ("numSendHops".equals(x))
            config.setNumStoreHops(Integer.parseInt(prefs.getString(x, "0")));
        else if ("relayMinDelay".equals(x))
            config.setRelayMinDelay(prefs.getInt(x, 5));
        else if ("relayMaxDelay".equals(x))
            config.setRelayMaxDelay(prefs.getInt(x, 40));
    }
    config.save();
    // Store the settings in Android
    super.onPause();
}
Also used : Configuration(i2p.bote.Configuration) SharedPreferences(android.content.SharedPreferences)

Aggregations

Configuration (i2p.bote.Configuration)3 SharedPreferences (android.content.SharedPreferences)2 DerivedKey (i2p.bote.fileencryption.DerivedKey)1 PasswordCache (i2p.bote.fileencryption.PasswordCache)1 File (java.io.File)1 Test (org.junit.Test)1