2
0

Support resetting user's master password.

This commit is contained in:
Maarten Billemont
2018-07-28 21:53:08 -04:00
parent 978b758079
commit 37a7cfa530
9 changed files with 96 additions and 13 deletions

View File

@@ -77,8 +77,18 @@ public interface MPUser<S extends MPSite<?>> extends Comparable<MPUser<?>> {
void authenticate(MPMasterKey masterKey)
throws MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException;
/**
* Clear all authentication tokens and secrets from memory, effectively logging the user out.
*/
void invalidate();
/**
* Wipe the key ID, allowing the user to {@link #authenticate(char[])} with any master password.
*
* Note: Authenticating with a different master password will cause all of the user's results to change.
*/
void reset();
boolean isMasterKeyAvailable();
@Nonnull

View File

@@ -97,12 +97,14 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
@Override
public byte[] getKeyID() {
try {
return getMasterKey().getKeyID( getAlgorithm() );
if (isMasterKeyAvailable())
return getMasterKey().getKeyID( getAlgorithm() );
}
catch (final MPException e) {
logger.wrn( e, "While deriving key ID for user: %s", this );
return null;
}
return null;
}
@Nullable
@@ -143,23 +145,29 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
public void invalidate() {
if (masterKey == null)
return;
this.masterKey = null;
masterKey.invalidate();
masterKey = null;
for (final Listener listener : listeners)
listener.onUserInvalidated( this );
}
@Override
public void reset() {
invalidate();
}
@Override
public boolean isMasterKeyAvailable() {
return masterKey != null;
return (masterKey != null) && masterKey.isValid();
}
@Nonnull
@Override
public MPMasterKey getMasterKey()
throws MPKeyUnavailableException {
if (masterKey == null)
if ((masterKey == null) || !masterKey.isValid())
throw new MPKeyUnavailableException( "Master key was not yet set for: " + this );
return masterKey;

View File

@@ -169,6 +169,13 @@ public class MPFileUser extends MPBasicUser<MPFileSite> {
}
}
@Override
public void reset() {
keyID = null;
super.reset();
}
@Override
public MPFileSite addSite(final String siteName) {
return addSite( new MPFileSite( this, siteName ) );