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