use of i2p.bote.fileencryption.PasswordIncorrectException 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);
}
}
Aggregations