From c51262ccc2e177aec1e0c7f5e9a94aeccf8b63ee Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 16 May 2018 12:00:42 -0400 Subject: [PATCH] Complete security questions model. --- .../lyndir/masterpassword/MPResultType.java | 34 +++++++------- .../lyndir/masterpassword/model/MPSite.java | 10 ++-- .../model/impl/MPBasicSite.java | 20 ++++++-- .../masterpassword/model/impl/MPFileSite.java | 8 ++-- .../masterpassword/model/impl/MPJSONFile.java | 13 ++--- .../gui/model/MPIncognitoQuestion.java | 47 +++++++++++++++++++ .../gui/model/MPIncognitoSite.java | 12 +---- 7 files changed, 100 insertions(+), 44 deletions(-) create mode 100644 platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoQuestion.java diff --git a/core/java/algorithm/src/main/java/com/lyndir/masterpassword/MPResultType.java b/core/java/algorithm/src/main/java/com/lyndir/masterpassword/MPResultType.java index 6b0eb968..b6d09bed 100644 --- a/core/java/algorithm/src/main/java/com/lyndir/masterpassword/MPResultType.java +++ b/core/java/algorithm/src/main/java/com/lyndir/masterpassword/MPResultType.java @@ -39,7 +39,7 @@ public enum MPResultType { // bit 0-3 | MPResultTypeClass | MPSiteFeature /** - * pg^VMAUBk5x3p%HP%i4= + * 16: pg^VMAUBk5x3p%HP%i4= */ GeneratedMaximum( "maximum", "20 characters, contains symbols.", // ImmutableList.of( new MPTemplate( "anoxxxxxxxxxxxxxxxxx" ), @@ -47,7 +47,7 @@ public enum MPResultType { MPResultTypeClass.Template, 0x0 ), /** - * BiroYena8:Kixa + * 17: BiroYena8:Kixa */ GeneratedLong( "long", "Copy-friendly, 14 characters, contains symbols.", // ImmutableList.of( new MPTemplate( "CvcvnoCvcvCvcv" ), new MPTemplate( "CvcvCvcvnoCvcv" ), @@ -64,7 +64,7 @@ public enum MPResultType { MPResultTypeClass.Template, 0x1 ), /** - * BirSuj0- + * 18: BirSuj0- */ GeneratedMedium( "medium", "Copy-friendly, 8 characters, contains symbols.", // ImmutableList.of( new MPTemplate( "CvcnoCvc" ), @@ -72,7 +72,14 @@ public enum MPResultType { MPResultTypeClass.Template, 0x2 ), /** - * pO98MoD0 + * 19: Bir8 + */ + GeneratedShort( "short", "Copy-friendly, 4 characters, no symbols.", // + ImmutableList.of( new MPTemplate( "Cvcn" ) ), // + MPResultTypeClass.Template, 0x4 ), + + /** + * 20: pO98MoD0 */ GeneratedBasic( "basic", "8 characters, no symbols.", // ImmutableList.of( new MPTemplate( "aaanaaan" ), @@ -81,28 +88,21 @@ public enum MPResultType { MPResultTypeClass.Template, 0x3 ), /** - * Bir8 - */ - GeneratedShort( "short", "Copy-friendly, 4 characters, no symbols.", // - ImmutableList.of( new MPTemplate( "Cvcn" ) ), // - MPResultTypeClass.Template, 0x4 ), - - /** - * 2798 + * 21: 2798 */ GeneratedPIN( "pin", "4 numbers.", // ImmutableList.of( new MPTemplate( "nnnn" ) ), // MPResultTypeClass.Template, 0x5 ), /** - * birsujano + * 30: birsujano */ GeneratedName( "name", "9 letter name.", // ImmutableList.of( new MPTemplate( "cvccvcvcv" ) ), // MPResultTypeClass.Template, 0xE ), /** - * bir yennoquce fefi + * 31: bir yennoquce fefi */ GeneratedPhrase( "phrase", "20 character sentence.", // ImmutableList.of( new MPTemplate( "cvcc cvc cvccvcv cvc" ), @@ -111,21 +111,21 @@ public enum MPResultType { MPResultTypeClass.Template, 0xF ), /** - * Custom saved password. + * 1056: Custom saved password. */ StoredPersonal( "personal", "AES-encrypted, exportable.", // ImmutableList.of(), // MPResultTypeClass.Stateful, 0x0, MPSiteFeature.ExportContent ), /** - * Custom saved password that should not be exported from the device. + * 2081: Custom saved password that should not be exported from the device. */ StoredDevicePrivate( "device", "AES-encrypted, not exported.", // ImmutableList.of(), // MPResultTypeClass.Stateful, 0x1, MPSiteFeature.DevicePrivate ), /** - * Derive a unique binary key. + * 4160: Derive a unique binary key. */ DeriveKey( "key", "Encryption key.", // ImmutableList.of(), // diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java index e8a327f0..d11b5667 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java @@ -27,7 +27,7 @@ import javax.annotation.Nullable; /** * @author lhunath, 2018-05-14 */ -public interface MPSite extends Comparable { +public interface MPSite extends Comparable> { // - Meta @@ -61,7 +61,11 @@ public interface MPSite extends Comparable { // - Relations - MPUser getUser(); + MPUser> getUser(); - Collection getQuestions(); + void addQuestion(Q question); + + void deleteQuestion(Q question); + + Collection getQuestions(); } diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java index dcf0bf1b..288495a2 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java @@ -33,7 +33,7 @@ import org.jetbrains.annotations.NotNull; /** * @author lhunath, 14-12-16 */ -public abstract class MPBasicSite implements MPSite { +public abstract class MPBasicSite implements MPSite { private String name; private MPAlgorithm algorithm; @@ -41,7 +41,7 @@ public abstract class MPBasicSite implements MPSite { private MPResultType resultType; private MPResultType loginType; - private final Collection questions = new LinkedHashSet<>(); + private final Collection questions = new LinkedHashSet<>(); protected MPBasicSite(final String name, final MPAlgorithm algorithm) { this( name, algorithm, null, null, null ); @@ -139,7 +139,17 @@ public abstract class MPBasicSite implements MPSite { } @Override - public Collection getQuestions() { + public void addQuestion(final Q question) { + questions.add( question ); + } + + @Override + public void deleteQuestion(final Q question) { + questions.remove( question ); + } + + @Override + public Collection getQuestions() { return Collections.unmodifiableCollection( questions ); } @@ -150,11 +160,11 @@ public abstract class MPBasicSite implements MPSite { @Override public boolean equals(final Object obj) { - return (this == obj) || ((obj instanceof MPSite) && Objects.equals( getName(), ((MPSite) obj).getName() )); + return (this == obj) || ((obj instanceof MPSite) && Objects.equals( getName(), ((MPSite) obj).getName() )); } @Override - public int compareTo(@NotNull final MPSite o) { + public int compareTo(@NotNull final MPSite o) { return getName().compareTo( o.getName() ); } diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java index 26a54786..b833c410 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java @@ -20,6 +20,7 @@ package com.lyndir.masterpassword.model.impl; import com.google.common.primitives.UnsignedInteger; import com.lyndir.masterpassword.*; +import com.lyndir.masterpassword.model.MPSite; import com.lyndir.masterpassword.model.MPUser; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -30,7 +31,7 @@ import org.joda.time.ReadableInstant; /** * @author lhunath, 14-12-05 */ -public class MPFileSite extends MPBasicSite { +public class MPFileSite extends MPBasicSite { private final MPFileUser user; @@ -60,7 +61,8 @@ public class MPFileSite extends MPBasicSite { @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( name, (algorithm == null)? user.getAlgorithm(): algorithm, counter, resultType, loginType ); + super( name, (algorithm == null)? user.getAlgorithm(): algorithm, counter, + (resultType == null)? user.getDefaultType(): resultType, loginType ); this.user = user; this.resultState = resultState; @@ -144,7 +146,7 @@ public class MPFileSite extends MPBasicSite { } @Override - public MPUser getUser() { + public MPFileUser getUser() { return user; } } diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java index 00846456..b24fe955 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java @@ -191,26 +191,27 @@ public class MPJSONFile extends MPJSONAnyObject { String full_name; String last_used; @Nullable - String key_id; - @Nullable MPAlgorithm.Version algorithm; @Nullable + String key_id; + @Nullable MPResultType default_type; } public static class Site extends MPJSONAnyObject { - @Nullable - MPResultType type; long counter; MPAlgorithm.Version algorithm; @Nullable + MPResultType type; + @Nullable String password; @Nullable - String login_name; - @Nullable MPResultType login_type; + @Nullable + String login_name; + int uses; @Nullable String last_used; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoQuestion.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoQuestion.java new file mode 100644 index 00000000..a01921dc --- /dev/null +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoQuestion.java @@ -0,0 +1,47 @@ +//============================================================================== +// This file is part of Master Password. +// Copyright (c) 2011-2017, Maarten Billemont. +// +// Master Password is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Master Password is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You can find a copy of the GNU General Public License in the +// LICENSE file. Alternatively, see . +//============================================================================== + +package com.lyndir.masterpassword.gui.model; + +import static com.lyndir.lhunath.opal.system.util.ObjectUtils.ifNotNullElse; + +import com.lyndir.masterpassword.MPResultType; +import com.lyndir.masterpassword.model.impl.MPBasicQuestion; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + + +/** + * @author lhunath, 2018-05-16 + */ +public class MPIncognitoQuestion extends MPBasicQuestion { + + private final MPIncognitoSite site; + + public MPIncognitoQuestion(final MPIncognitoSite site, final String keyword, @Nullable final MPResultType type) { + super( keyword, ifNotNullElse( type, site.getAlgorithm().mpw_default_answer_type() ) ); + + this.site = site; + } + + @Nonnull + @Override + public MPIncognitoSite getSite() { + return site; + } +} diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoSite.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoSite.java index e560ab1e..a853b48e 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoSite.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoSite.java @@ -18,20 +18,17 @@ package com.lyndir.masterpassword.gui.model; -import com.google.common.collect.ImmutableList; import com.google.common.primitives.UnsignedInteger; import com.lyndir.masterpassword.MPAlgorithm; import com.lyndir.masterpassword.MPResultType; -import com.lyndir.masterpassword.model.*; import com.lyndir.masterpassword.model.impl.MPBasicSite; -import java.util.Collection; import javax.annotation.Nullable; /** * @author lhunath, 14-12-16 */ -public class MPIncognitoSite extends MPBasicSite { +public class MPIncognitoSite extends MPBasicSite { private final MPIncognitoUser user; @@ -48,12 +45,7 @@ public class MPIncognitoSite extends MPBasicSite { } @Override - public MPUser getUser() { + public MPIncognitoUser getUser() { return user; } - - @Override - public Collection getQuestions() { - return ImmutableList.of(); - } }