Fix: Identities and address book still available after the Clear Password icon is clicked
This commit is contained in:
@@ -496,8 +496,33 @@ public class I2PBote implements NetworkStatusSource {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PasswordCache getPasswordCache() {
|
/**
|
||||||
return passwordCache;
|
* Tests if a password is correct and stores it in the cache if it is.
|
||||||
|
* If the password is not correct, a <code>PasswordException</code> is thrown.
|
||||||
|
* @param password
|
||||||
|
* @throws IOException
|
||||||
|
* @throws GeneralSecurityException
|
||||||
|
* @throws PasswordException
|
||||||
|
*/
|
||||||
|
public void tryPassword(byte[] password) throws IOException, GeneralSecurityException, PasswordException {
|
||||||
|
File passwordFile = I2PBote.getInstance().getConfiguration().getPasswordFile();
|
||||||
|
boolean correct = FileEncryptionUtil.isPasswordCorrect(password, passwordFile);
|
||||||
|
if (correct)
|
||||||
|
passwordCache.setPassword(password);
|
||||||
|
else
|
||||||
|
throw new PasswordException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns <code>true</code> if the password is currently cached. */
|
||||||
|
public boolean isPasswordInCache() {
|
||||||
|
return passwordCache.isPasswordInCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes the password from the password cache. If there is no password in the cache, nothing happens. */
|
||||||
|
public void clearPassword() {
|
||||||
|
passwordCache.clear();
|
||||||
|
identities.clearPasswordProtectedData();
|
||||||
|
addressBook.clearPasswordProtectedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<EmailFolder> getEmailFolders() {
|
private Collection<EmailFolder> getEmailFolders() {
|
||||||
|
|||||||
@@ -170,6 +170,10 @@ public class AddressBook implements Iterable<Contact> {
|
|||||||
FileEncryptionUtil.changePassword(addressFile, oldPassword, newKey);
|
FileEncryptionUtil.changePassword(addressFile, oldPassword, newKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearPasswordProtectedData() {
|
||||||
|
contacts = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up an {@link Contact} by its Base64 key. If none is found,
|
* Looks up an {@link Contact} by its Base64 key. If none is found,
|
||||||
* <code>null</code> is returned.
|
* <code>null</code> is returned.
|
||||||
|
|||||||
@@ -251,6 +251,11 @@ public class Identities implements Iterable<EmailIdentity> {
|
|||||||
FileEncryptionUtil.changePassword(identitiesFile, oldPassword, newKey);
|
FileEncryptionUtil.changePassword(identitiesFile, oldPassword, newKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearPasswordProtectedData() {
|
||||||
|
// TODO overwrite private keys
|
||||||
|
identities = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default identity. Assumes this <code>Identities</code> already
|
* Sets the default identity. Assumes this <code>Identities</code> already
|
||||||
* contains <code>defaultIdentity</code>.
|
* contains <code>defaultIdentity</code>.
|
||||||
|
|||||||
@@ -147,10 +147,7 @@ public class PasswordCache extends I2PBoteThread implements PasswordHolder {
|
|||||||
lastReset = System.currentTimeMillis();
|
lastReset = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns <code>true</code> if the password is currently cached. */
|
||||||
* Returns <code>true</code> if the password is being cached
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isPasswordInCache() {
|
public boolean isPasswordInCache() {
|
||||||
return password != null;
|
return password != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ public class ClearPasswordCacheTag extends SimpleTagSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doTag() {
|
public void doTag() {
|
||||||
I2PBote.getInstance().getPasswordCache().clear();
|
I2PBote.getInstance().clearPassword();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,8 +34,6 @@ import i2p.bote.email.EmailAttribute;
|
|||||||
import i2p.bote.email.EmailDestination;
|
import i2p.bote.email.EmailDestination;
|
||||||
import i2p.bote.email.EmailIdentity;
|
import i2p.bote.email.EmailIdentity;
|
||||||
import i2p.bote.email.Identities;
|
import i2p.bote.email.Identities;
|
||||||
import i2p.bote.fileencryption.FileEncryptionUtil;
|
|
||||||
import i2p.bote.fileencryption.PasswordCache;
|
|
||||||
import i2p.bote.fileencryption.PasswordException;
|
import i2p.bote.fileencryption.PasswordException;
|
||||||
import i2p.bote.folder.EmailFolder;
|
import i2p.bote.folder.EmailFolder;
|
||||||
import i2p.bote.folder.TrashFolder;
|
import i2p.bote.folder.TrashFolder;
|
||||||
@@ -548,16 +546,18 @@ public class JSPHelper {
|
|||||||
return RandomSource.getInstance().nextLong();
|
return RandomSource.getInstance().nextLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean tryPassword(String password) throws Exception {
|
public static boolean tryPassword(String password) throws IOException, GeneralSecurityException {
|
||||||
byte[] passwordBytes = password.getBytes();
|
byte[] passwordBytes = password.getBytes();
|
||||||
File passwordFile = I2PBote.getInstance().getConfiguration().getPasswordFile();
|
try {
|
||||||
boolean correct = FileEncryptionUtil.isPasswordCorrect(passwordBytes, passwordFile);
|
I2PBote.getInstance().tryPassword(passwordBytes);
|
||||||
if (correct)
|
return true;
|
||||||
I2PBote.getInstance().getPasswordCache().setPassword(passwordBytes);
|
}
|
||||||
return correct;
|
catch (PasswordException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String changePassword(String oldPassword, String newPassword, String confirmNewPassword) throws Exception {
|
public static String changePassword(String oldPassword, String newPassword, String confirmNewPassword) {
|
||||||
try {
|
try {
|
||||||
return I2PBote.getInstance().changePassword(oldPassword.getBytes(), newPassword.getBytes(), confirmNewPassword.getBytes());
|
return I2PBote.getInstance().changePassword(oldPassword.getBytes(), newPassword.getBytes(), confirmNewPassword.getBytes());
|
||||||
}
|
}
|
||||||
@@ -568,18 +568,12 @@ public class JSPHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see {@link PasswordCache#isPasswordInCache()}
|
|
||||||
*/
|
|
||||||
public boolean isPasswordInCache() {
|
public boolean isPasswordInCache() {
|
||||||
return I2PBote.getInstance().getPasswordCache().isPasswordInCache();
|
return I2PBote.getInstance().isPasswordInCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see {@link PasswordCache#clear()}
|
|
||||||
*/
|
|
||||||
public static void clearPassword() {
|
public static void clearPassword() {
|
||||||
I2PBote.getInstance().getPasswordCache().clear();
|
I2PBote.getInstance().clearPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateAvailable() {
|
public boolean isUpdateAvailable() {
|
||||||
|
|||||||
Reference in New Issue
Block a user