Marshal refactoring to prepare for new format.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package com.lyndir.masterpassword.gui.model;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.lyndir.masterpassword.MasterKey;
|
||||
import com.lyndir.masterpassword.model.IncorrectMasterPasswordException;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -29,8 +30,6 @@ import javax.annotation.Nullable;
|
||||
public class IncognitoUser extends User {
|
||||
|
||||
private final String fullName;
|
||||
@Nullable
|
||||
private char[] masterPassword;
|
||||
|
||||
public IncognitoUser(final String fullName) {
|
||||
this.fullName = fullName;
|
||||
@@ -41,16 +40,10 @@ public class IncognitoUser extends User {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected char[] getMasterPassword() {
|
||||
return masterPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticate(final char[] masterPassword)
|
||||
throws IncorrectMasterPasswordException {
|
||||
this.masterPassword = masterPassword.clone();
|
||||
this.key = new MasterKey( getFullName(), masterPassword );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -34,9 +34,6 @@ public class ModelUser extends User {
|
||||
|
||||
private final MPUser model;
|
||||
|
||||
@Nullable
|
||||
private char[] masterPassword;
|
||||
|
||||
public ModelUser(final MPUser model) {
|
||||
this.model = model;
|
||||
}
|
||||
@@ -50,12 +47,6 @@ public class ModelUser extends User {
|
||||
return model.getFullName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected char[] getMasterPassword() {
|
||||
return masterPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvatar() {
|
||||
return model.getAvatar();
|
||||
@@ -69,21 +60,10 @@ public class ModelUser extends User {
|
||||
@Override
|
||||
public void authenticate(final char[] masterPassword)
|
||||
throws IncorrectMasterPasswordException {
|
||||
putKey( model.authenticate( masterPassword ) );
|
||||
this.masterPassword = masterPassword.clone();
|
||||
key = model.authenticate( masterPassword );
|
||||
MPUserFileManager.get().save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
|
||||
if (masterPassword != null) {
|
||||
Arrays.fill( masterPassword, (char) 0 );
|
||||
masterPassword = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Site> findSitesByName(final String siteName) {
|
||||
return FluentIterable.from( model.findSitesByName( siteName ) ).transform( new Function<MPSiteResult, Site>() {
|
||||
|
@@ -19,7 +19,6 @@
|
||||
package com.lyndir.masterpassword.gui.model;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.lyndir.masterpassword.MasterKey;
|
||||
import com.lyndir.masterpassword.model.IncorrectMasterPasswordException;
|
||||
import java.util.*;
|
||||
@@ -32,14 +31,11 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public abstract class User {
|
||||
|
||||
@Nonnull
|
||||
private final Map<MasterKey.Version, MasterKey> keyByVersion = Maps.newEnumMap( MasterKey.Version.class );
|
||||
@Nullable
|
||||
protected MasterKey key;
|
||||
|
||||
public abstract String getFullName();
|
||||
|
||||
@Nullable
|
||||
protected abstract char[] getMasterPassword();
|
||||
|
||||
@SuppressWarnings("MethodCanBeVariableArityMethod")
|
||||
public abstract void authenticate(char[] masterPassword)
|
||||
throws IncorrectMasterPasswordException;
|
||||
@@ -49,31 +45,12 @@ public abstract class User {
|
||||
}
|
||||
|
||||
public boolean isKeyAvailable() {
|
||||
return getMasterPassword() != null;
|
||||
return key != null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public MasterKey getKey(final MasterKey.Version algorithmVersion) {
|
||||
char[] masterPassword = Preconditions.checkNotNull( getMasterPassword(), "User is not authenticated: " + getFullName() );
|
||||
|
||||
MasterKey key = keyByVersion.get( algorithmVersion );
|
||||
if (key == null)
|
||||
putKey( key = MasterKey.create( algorithmVersion, getFullName(), masterPassword ) );
|
||||
if (!key.isValid())
|
||||
key.revalidate( masterPassword );
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
protected void putKey(final MasterKey masterKey) {
|
||||
MasterKey oldKey = keyByVersion.put( masterKey.getAlgorithmVersion(), masterKey );
|
||||
if (oldKey != null)
|
||||
oldKey.invalidate();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (final MasterKey key : keyByVersion.values())
|
||||
key.invalidate();
|
||||
public MasterKey getKey() {
|
||||
return Preconditions.checkNotNull( key, "User is not authenticated: " + getFullName() );
|
||||
}
|
||||
|
||||
public abstract Iterable<Site> findSitesByName(String siteName);
|
||||
|
@@ -257,8 +257,8 @@ public class PasswordFrame extends JFrame implements DocumentListener {
|
||||
@Override
|
||||
public String call()
|
||||
throws Exception {
|
||||
return user.getKey( site.getAlgorithmVersion() )
|
||||
.siteResult( site.getSiteName(), site.getSiteCounter(), MPKeyPurpose.Authentication, null, site.getResultType(), null );
|
||||
return user.getKey()
|
||||
.siteResult( site.getSiteName(), site.getSiteCounter(), MPKeyPurpose.Authentication, null, site.getResultType(), null, site.getAlgorithmVersion() );
|
||||
}
|
||||
} );
|
||||
Futures.addCallback( passwordFuture, new FutureCallback<String>() {
|
||||
|
Reference in New Issue
Block a user