Search in sources :

Example 1 with PasswordCache

use of i2p.bote.fileencryption.PasswordCache in project i2p.i2p-bote by i2p.

the class EmailFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "EmailFolderTest-" + System.currentTimeMillis());
    folderDir1 = new File(testDir, "folder1");
    folderDir2 = new File(testDir, "folder2");
    email1 = new Email(true);
    email1.setText("Und nun lag die Entscheidung schon nahe vor ihm, es\n" + "war alles klar geworden. Die Kunst war eine schöne Sache,\n" + "aber sie war keine Göttin und kein Ziel, für ihn nicht, nicht\n" + "der Kunst hatte er zu folgen, nur dem Ruf der Mutter. Was\n" + "konnte es nutzen, seine Finger noch immer geschickter zu\n" + "machen? Am Meister Niklaus konnte man sehen, wohin\n" + "das führte. Es führte zu Ruhm und Namen, zu Geld und\n" + "seßhaftem Leben, und zu einer Verdorrung und Verküm-\n" + "merung jener inneren Sinne, denen allein das Geheimnis\n" + "zugänglich ist. Es führte zum Herstellen hübscher kostba-\n" + "rer Spielwaren, zu allerlei reichen Altären und Kanzeln,\n" + "heiligen Sebastianen und hübsch gelockten Engels-\n" + "köpfchen, das Stück zu vier Talern. Oh, das Gold im Aug’\n" + "eines Karpfens und der süße dünne Silberflaum am Rand\n" + "eines Schmetterlingsflügels war unendlich viel schöner,\n" + "lebendiger, köstlicher als ein ganzer Saal voll von jenen\n" + "Kunstwerken.");
    email2 = new Email(false);
    email2.setText("\"And when the trial continued,\" he said in a weeping whisper, \"they asked Prak a most unfortunate thing.\n" + "They asked him,\" he paused and shivered, \"to tell the Truth, the Whole Truth and Nothing but the Truth.\n" + "Only, don't you see?\"\n" + "He suddenly hoisted himself up on to his elbows again and shouted at them.\n" + "\"They'd given him much too much of the drug!\"\n" + "He collapsed again, moaning quietly. \"Much too much too much too much too ...\"\n" + "The group gathered round his bedside glanced at each other. There were goose pimples on backs.\n" + "\"What happened?\" said Zaphod at last.\n" + "\"Oh, he told it all right,\" said the man savagely, \"for all I know he's still telling it now. Strange, terrible\n" + "things ... terrible, terrible!\" he screamed.\n" + "They tried to calm him, but he struggled to his elbows again.\n" + "\"Terrible things, incomprehensible things,\" he shouted, \"things that would drive a man mad!\"\n" + "He stared wildly at them.\n" + "\"Or in my case,\" he said, \"half-mad. I'm a journalist.\"\n" + "\"You mean,\" said Arthur quietly, \"that you are used to confronting the truth?\"\n" + "\"No,\" said the man with a puzzled frown. \"I mean that I made an excuse and left early.\"\n" + "He collapsed into a coma from which he recovered only once and briefly.");
    PasswordCache passwordCache = TestUtil.createPasswordCache(testDir);
    folder1 = new EmailFolder(folderDir1, passwordCache);
    folder2 = new EmailFolder(folderDir2, passwordCache);
}
Also used : PasswordCache(i2p.bote.fileencryption.PasswordCache) Email(i2p.bote.email.Email) File(java.io.File) Before(org.junit.Before)

Example 2 with PasswordCache

use of i2p.bote.fileencryption.PasswordCache in project i2p.i2p-bote by i2p.

the class IncompleteEmailFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "IncompleteEmailFolderTest-" + System.currentTimeMillis());
    PasswordCache passwordCache = TestUtil.createPasswordCache(testDir);
    inboxDir = new File(testDir, "inbox");
    inbox = new EmailFolder(inboxDir, passwordCache);
    File incompleteDir = new File(testDir, "incomplete");
    MessageIdCache messageIdCache = new MessageIdCache(new File(testDir, MSG_ID_CACHE_DIR), 1000);
    incompleteFolder = new IncompleteEmailFolder(incompleteDir, messageIdCache, inbox);
}
Also used : PasswordCache(i2p.bote.fileencryption.PasswordCache) File(java.io.File) Before(org.junit.Before)

Example 3 with PasswordCache

use of i2p.bote.fileencryption.PasswordCache in project i2p.i2p-bote by i2p.

the class MigrateTo026 method migrateIfNeeded.

/**
 * This method won't corrupt any data if the data has already been migrated to the latest version,
 * because only unencrypted files are converted.
 * @param configuration
 * @throws Exception
 */
void migrateIfNeeded(Configuration configuration) throws Exception {
    log.debug("Migrating any pre-0.2.6 files...");
    passwordCache = new PasswordCache(configuration);
    // encrypt with the default password
    passwordCache.setPassword(new byte[0]);
    // convert the identities file
    File oldIdentitiesFile = new File(configuration.getIdentitiesFile().getParentFile(), "identities.txt");
    if (oldIdentitiesFile.exists()) {
        log.debug("Migrating identities file: <" + oldIdentitiesFile + ">");
        File newIdentitiesFile = configuration.getIdentitiesFile();
        encrypt(oldIdentitiesFile, newIdentitiesFile);
        oldIdentitiesFile.delete();
    }
    // convert the address book
    File oldAddrBookFile = new File(configuration.getAddressBookFile().getParentFile(), "addressBook.txt");
    if (oldAddrBookFile.exists()) {
        log.debug("Migrating address book: <" + oldIdentitiesFile + ">");
        File newAddrBookFile = configuration.getAddressBookFile();
        encrypt(oldAddrBookFile, newAddrBookFile);
        oldAddrBookFile.delete();
    }
    // convert email folders
    migrateEmailsIfNeeded(configuration.getInboxDir());
    migrateEmailsIfNeeded(configuration.getOutboxDir());
    migrateEmailsIfNeeded(configuration.getSentFolderDir());
    migrateEmailsIfNeeded(configuration.getTrashFolderDir());
}
Also used : PasswordCache(i2p.bote.fileencryption.PasswordCache) File(java.io.File)

Example 4 with PasswordCache

use of i2p.bote.fileencryption.PasswordCache in project i2p.i2p-bote by i2p.

the class MigrateTo027 method migrateIfNeeded.

/**
 * This method won't corrupt any data if the data has already been migrated to the latest version,
 * because only unencrypted files are converted.
 * @param configuration
 * @throws Exception
 */
void migrateIfNeeded(Configuration configuration) throws Exception {
    log.debug("Migrating any pre-0.2.7 files...");
    passwordCache = new PasswordCache(configuration);
    // encrypt with the default password
    passwordCache.setPassword(new byte[0]);
    // convert metadata in email folders
    migrateMetadataIfNeeded(configuration.getInboxDir());
    migrateMetadataIfNeeded(configuration.getOutboxDir());
    migrateMetadataIfNeeded(configuration.getSentFolderDir());
    migrateMetadataIfNeeded(configuration.getTrashFolderDir());
}
Also used : PasswordCache(i2p.bote.fileencryption.PasswordCache)

Example 5 with PasswordCache

use of i2p.bote.fileencryption.PasswordCache in project i2p.i2p-bote by i2p.

the class Migrator method migrateNonPasswordedDataIfNeeded.

/**
 * Migrates files that are not encrypted, or encrypted with the default password.
 */
public void migrateNonPasswordedDataIfNeeded() {
    if (VersionComparator.comp(lastMigrationVersion, currentVersion) >= 0) {
        log.debug("No plaintext migration needed.");
        return;
    }
    try {
        boolean migrationSucceeded = true;
        if (VersionComparator.comp(lastMigrationVersion, "0.2.6") < 0)
            new MigrateTo026().migrateIfNeeded(configuration);
        if (VersionComparator.comp(lastMigrationVersion, "0.2.7") < 0)
            new MigrateTo027().migrateIfNeeded(configuration);
        if (VersionComparator.comp(lastMigrationVersion, "0.2.8") < 0) {
            PasswordCache defaultPasswordHolder = new PasswordCache(configuration);
            try {
                new MigrateTo028().migrateIfNeeded(configuration, defaultPasswordHolder);
            } catch (PasswordException e) {
                log.debug("Non-default password in use, deferring migration of encrypted files to after password entry");
                migrationSucceeded = false;
            }
        }
        if (migrationSucceeded) {
            log.debug("Migration successful, setting last successful migration to <" + currentVersion + ">.");
            setLastSuccessfulMigration(currentVersion);
        }
    } catch (Exception e) {
        log.error("Error migrating to the latest version.", e);
    }
}
Also used : PasswordCache(i2p.bote.fileencryption.PasswordCache) PasswordException(i2p.bote.fileencryption.PasswordException) PasswordException(i2p.bote.fileencryption.PasswordException) IOException(java.io.IOException)

Aggregations

PasswordCache (i2p.bote.fileencryption.PasswordCache)7 File (java.io.File)4 DerivedKey (i2p.bote.fileencryption.DerivedKey)2 Before (org.junit.Before)2 Configuration (i2p.bote.Configuration)1 Email (i2p.bote.email.Email)1 EncryptedOutputStream (i2p.bote.fileencryption.EncryptedOutputStream)1 PasswordException (i2p.bote.fileencryption.PasswordException)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Properties (java.util.Properties)1 Test (org.junit.Test)1