Fix default type for new sites & site UI updating.
This commit is contained in:
parent
928b617ed0
commit
fe63a2756a
@ -28,6 +28,7 @@ import com.lyndir.lhunath.opal.system.MessageDigests;
|
||||
import com.lyndir.masterpassword.impl.*;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
@ -88,46 +89,55 @@ public abstract class MPAlgorithm {
|
||||
/**
|
||||
* The linear version identifier of this algorithm's implementation.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract Version version();
|
||||
|
||||
/**
|
||||
* mpw: defaults: initial counter value.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract UnsignedInteger mpw_default_counter();
|
||||
|
||||
/**
|
||||
* mpw: defaults: password result type.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract MPResultType mpw_default_result_type();
|
||||
|
||||
/**
|
||||
* mpw: defaults: login result type.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract MPResultType mpw_default_login_type();
|
||||
|
||||
/**
|
||||
* mpw: defaults: answer result type.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract MPResultType mpw_default_answer_type();
|
||||
|
||||
/**
|
||||
* mpw: Input character encoding.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract Charset mpw_charset();
|
||||
|
||||
/**
|
||||
* mpw: Platform-agnostic byte order.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract ByteOrder mpw_byteOrder();
|
||||
|
||||
/**
|
||||
* mpw: Key ID hash.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract MessageDigests mpw_hash();
|
||||
|
||||
/**
|
||||
* mpw: Site digest.
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract MessageAuthenticationDigests mpw_digest();
|
||||
|
||||
/**
|
||||
@ -167,12 +177,16 @@ public abstract class MPAlgorithm {
|
||||
|
||||
// Utilities
|
||||
|
||||
@Nonnull
|
||||
protected abstract byte[] toBytes(int number);
|
||||
|
||||
@Nonnull
|
||||
protected abstract byte[] toBytes(UnsignedInteger number);
|
||||
|
||||
@Nonnull
|
||||
protected abstract byte[] toBytes(char[] characters);
|
||||
|
||||
@Nonnull
|
||||
protected abstract byte[] toID(byte[] bytes);
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ import com.lyndir.masterpassword.*;
|
||||
import java.nio.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
@ -122,46 +123,55 @@ public class MPAlgorithmV0 extends MPAlgorithm {
|
||||
|
||||
// Configuration
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Version version() {
|
||||
return MPAlgorithm.Version.V0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UnsignedInteger mpw_default_counter() {
|
||||
return UnsignedInteger.ONE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MPResultType mpw_default_result_type() {
|
||||
return MPResultType.GeneratedLong;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MPResultType mpw_default_login_type() {
|
||||
return MPResultType.GeneratedName;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MPResultType mpw_default_answer_type() {
|
||||
return MPResultType.GeneratedPhrase;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Charset mpw_charset() {
|
||||
return Charsets.UTF_8;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ByteOrder mpw_byteOrder() {
|
||||
return ByteOrder.BIG_ENDIAN;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MessageDigests mpw_hash() {
|
||||
return MessageDigests.SHA256;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MessageAuthenticationDigests mpw_digest() {
|
||||
return MessageAuthenticationDigests.HmacSHA256;
|
||||
@ -211,16 +221,19 @@ public class MPAlgorithmV0 extends MPAlgorithm {
|
||||
|
||||
// Utilities
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public byte[] toBytes(final int number) {
|
||||
return ByteBuffer.allocate( Integer.SIZE / Byte.SIZE ).order( mpw_byteOrder() ).putInt( number ).array();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public byte[] toBytes(final UnsignedInteger number) {
|
||||
return ByteBuffer.allocate( Integer.SIZE / Byte.SIZE ).order( mpw_byteOrder() ).putInt( number.intValue() ).array();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public byte[] toBytes(final char[] characters) {
|
||||
ByteBuffer byteBuffer = mpw_charset().encode( CharBuffer.wrap( characters ) );
|
||||
@ -232,6 +245,7 @@ public class MPAlgorithmV0 extends MPAlgorithm {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public byte[] toID(final byte[] bytes) {
|
||||
return mpw_hash().of( bytes );
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.lyndir.masterpassword.impl;
|
||||
|
||||
import com.lyndir.masterpassword.*;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
/**
|
||||
@ -29,6 +30,7 @@ public class MPAlgorithmV1 extends MPAlgorithmV0 {
|
||||
|
||||
// Configuration
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Version version() {
|
||||
return MPAlgorithm.Version.V1;
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.lyndir.masterpassword.impl;
|
||||
|
||||
import com.lyndir.masterpassword.MPAlgorithm;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
/**
|
||||
@ -29,6 +30,7 @@ public class MPAlgorithmV2 extends MPAlgorithmV1 {
|
||||
|
||||
// Configuration
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Version version() {
|
||||
return MPAlgorithm.Version.V2;
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.lyndir.masterpassword.impl;
|
||||
|
||||
import com.lyndir.masterpassword.MPAlgorithm;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
/**
|
||||
@ -29,6 +30,7 @@ public class MPAlgorithmV3 extends MPAlgorithmV2 {
|
||||
|
||||
// Configuration
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Version version() {
|
||||
return MPAlgorithm.Version.V3;
|
||||
|
@ -10,6 +10,6 @@ import com.lyndir.masterpassword.model.impl.*;
|
||||
public class MPNewSite extends MPBasicSite<MPUser<?>, MPQuestion> {
|
||||
|
||||
public MPNewSite(final MPUser<?> user, final String siteName) {
|
||||
super( user, siteName, user.getAlgorithm() );
|
||||
super( user, siteName );
|
||||
}
|
||||
}
|
||||
|
@ -472,16 +472,11 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
sitesModel.registerList( sitesList );
|
||||
add( Box.createGlue() );
|
||||
|
||||
addComponentListener( new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(final ComponentEvent e) {
|
||||
user.addListener( AuthenticatedUserPanel.this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(final ComponentEvent e) {
|
||||
user.removeListener( AuthenticatedUserPanel.this );
|
||||
}
|
||||
addHierarchyListener( e -> {
|
||||
if (null != SwingUtilities.windowForComponent( this ))
|
||||
user.addListener( this );
|
||||
else
|
||||
user.removeListener( this );
|
||||
} );
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,11 @@ public interface MPUser<S extends MPSite<?>> extends Comparable<MPUser<?>> {
|
||||
|
||||
void setAlgorithm(MPAlgorithm algorithm);
|
||||
|
||||
@Nullable
|
||||
default MPResultType getDefaultType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
byte[] getKeyID();
|
||||
|
||||
|
@ -44,19 +44,20 @@ public abstract class MPBasicSite<U extends MPUser<?>, Q extends MPQuestion> ext
|
||||
private MPResultType resultType;
|
||||
private MPResultType loginType;
|
||||
|
||||
protected MPBasicSite(final U user, final String siteName, final MPAlgorithm algorithm) {
|
||||
this( user, siteName, algorithm, null, null, null );
|
||||
protected MPBasicSite(final U user, final String siteName) {
|
||||
this( user, siteName, null, null, null, null );
|
||||
}
|
||||
|
||||
protected MPBasicSite(final U user, final String siteName, final MPAlgorithm algorithm,
|
||||
@Nullable final UnsignedInteger counter,
|
||||
protected MPBasicSite(final U user, final String siteName,
|
||||
@Nullable final MPAlgorithm algorithm, @Nullable final UnsignedInteger counter,
|
||||
@Nullable final MPResultType resultType, @Nullable final MPResultType loginType) {
|
||||
this.user = user;
|
||||
this.siteName = siteName;
|
||||
this.algorithm = algorithm;
|
||||
this.counter = (counter == null)? algorithm.mpw_default_counter(): counter;
|
||||
this.resultType = (resultType == null)? algorithm.mpw_default_result_type(): resultType;
|
||||
this.loginType = (loginType == null)? algorithm.mpw_default_login_type(): loginType;
|
||||
this.algorithm = (algorithm != null)? algorithm: this.user.getAlgorithm();
|
||||
this.counter = (counter != null)? counter: this.algorithm.mpw_default_counter();
|
||||
this.resultType = (resultType != null)? resultType:
|
||||
ifNotNullElse( this.user.getDefaultType(), this.algorithm.mpw_default_result_type() );
|
||||
this.loginType = (loginType != null)? loginType: this.algorithm.mpw_default_login_type();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -45,14 +45,8 @@ public class MPFileSite extends MPBasicSite<MPFileUser, MPFileQuestion> {
|
||||
private String loginState;
|
||||
|
||||
public MPFileSite(final MPFileUser user, final String name) {
|
||||
this( user, name, null, null, null );
|
||||
}
|
||||
|
||||
public MPFileSite(final MPFileUser user, final String name,
|
||||
@Nullable final MPAlgorithm algorithm, @Nullable final UnsignedInteger counter,
|
||||
@Nullable final MPResultType resultType) {
|
||||
this( user, name, algorithm, counter, resultType, null,
|
||||
null, null, null, 0, new Instant() );
|
||||
this( user, name, null, null, null, null, null, null,
|
||||
null, 0, new Instant() );
|
||||
}
|
||||
|
||||
protected MPFileSite(final MPFileUser user, final String name,
|
||||
@ -60,8 +54,7 @@ public class MPFileSite extends MPBasicSite<MPFileUser, MPFileQuestion> {
|
||||
@Nullable final MPResultType resultType, @Nullable final String resultState,
|
||||
@Nullable final MPResultType loginType, @Nullable final String loginState,
|
||||
@Nullable final String url, final int uses, final ReadableInstant lastUsed) {
|
||||
super( user, name, (algorithm == null)? user.getAlgorithm(): algorithm, counter,
|
||||
(resultType == null)? user.getDefaultType(): resultType, loginType );
|
||||
super( user, name, algorithm, counter, resultType, loginType );
|
||||
|
||||
this.resultState = resultState;
|
||||
this.loginState = loginState;
|
||||
|
@ -135,6 +135,7 @@ public class MPFileUser extends MPBasicUser<MPFileSite> {
|
||||
setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPResultType getDefaultType() {
|
||||
return defaultType;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user