Search in sources :

Example 1 with PasswordMismatchException

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

the class I2PBote method changePassword.

/**
 * Reencrypts all encrypted files with a new password
 * @param oldPassword
 * @param newPassword
 * @param confirmNewPassword
 * @param lsnr A StatusListener to report progress to
 * @throws IOException
 * @throws GeneralSecurityException
 * @throws PasswordException if the old password is incorrect or two new passwords don't match
 */
public void changePassword(byte[] oldPassword, byte[] newPassword, byte[] confirmNewPassword, StatusListener<ChangePasswordStatus> lsnr) throws IOException, GeneralSecurityException, PasswordException {
    File passwordFile = configuration.getPasswordFile();
    lsnr.updateStatus(ChangePasswordStatus.CHECKING_PASSWORD);
    if (!FileEncryptionUtil.isPasswordCorrect(oldPassword, passwordFile))
        throw new PasswordIncorrectException();
    if (!Arrays.equals(newPassword, confirmNewPassword))
        throw new PasswordMismatchException();
    // lock so no files are encrypted with the old password while the password is being changed
    synchronized (passwordCache) {
        passwordCache.setPassword(newPassword);
        DerivedKey newKey = passwordCache.getKey();
        lsnr.updateStatus(ChangePasswordStatus.RE_ENCRYPTING_IDENTITIES);
        identities.changePassword(oldPassword, newKey);
        lsnr.updateStatus(ChangePasswordStatus.RE_ENCRYPTING_ADDRESS_BOOK);
        addressBook.changePassword(oldPassword, newKey);
        for (EmailFolder folder : getEmailFolders()) {
            lsnr.updateStatus(ChangePasswordStatus.RE_ENCRYPTING_FOLDER, folder.getName());
            folder.changePassword(oldPassword, newKey);
        }
        lsnr.updateStatus(ChangePasswordStatus.UPDATING_PASSWORD_FILE);
        FileEncryptionUtil.writePasswordFile(passwordFile, passwordCache.getPassword(), newKey);
    }
}
Also used : PasswordMismatchException(i2p.bote.fileencryption.PasswordMismatchException) PasswordIncorrectException(i2p.bote.fileencryption.PasswordIncorrectException) SecureFile(net.i2p.util.SecureFile) File(java.io.File) DerivedKey(i2p.bote.fileencryption.DerivedKey) EmailFolder(i2p.bote.folder.EmailFolder) IncompleteEmailFolder(i2p.bote.folder.IncompleteEmailFolder)

Aggregations

DerivedKey (i2p.bote.fileencryption.DerivedKey)1 PasswordIncorrectException (i2p.bote.fileencryption.PasswordIncorrectException)1 PasswordMismatchException (i2p.bote.fileencryption.PasswordMismatchException)1 EmailFolder (i2p.bote.folder.EmailFolder)1 IncompleteEmailFolder (i2p.bote.folder.IncompleteEmailFolder)1 File (java.io.File)1 SecureFile (net.i2p.util.SecureFile)1