2
0

Move identicon and toID to mpw native.

Clean out all unused Java MPAlgorithm stuff.

Fix master password entries stuck in memory.
This commit is contained in:
Maarten Billemont
2020-04-15 19:09:02 -04:00
parent ff9596aef0
commit 1c3ea3826f
17 changed files with 264 additions and 282 deletions

View File

@@ -49,10 +49,7 @@ public interface MPUser<S extends MPSite<?>> extends Comparable<MPUser<?>> {
void setAlgorithm(MPAlgorithm algorithm);
@Nullable
byte[] getKeyID();
@Nullable
String exportKeyID();
String getKeyID();
/**
* Performs an authentication attempt against the keyID for this user.

View File

@@ -100,7 +100,7 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
@Nullable
@Override
public byte[] getKeyID() {
public String getKeyID() {
try {
if (isMasterKeyAvailable())
return getMasterKey().getKeyID( getAlgorithm() );
@@ -112,12 +112,6 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
return null;
}
@Nullable
@Override
public String exportKeyID() {
return CodeUtils.encodeHex( getKeyID() );
}
@Override
public void authenticate(final char[] masterPassword)
throws MPIncorrectMasterPasswordException, MPAlgorithmException {
@@ -136,8 +130,8 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
throw new IllegalArgumentException(
"Master key (for " + masterKey.getFullName() + ") is not for this user (" + getFullName() + ")." );
byte[] keyID = getKeyID();
if ((keyID != null) && !Arrays.equals( masterKey.getKeyID( getAlgorithm() ), keyID ))
String keyID = getKeyID();
if (keyID != null && !keyID.equalsIgnoreCase( masterKey.getKeyID( getAlgorithm() ) ))
throw new MPIncorrectMasterPasswordException( this );
this.masterKey = masterKey;

View File

@@ -39,7 +39,7 @@ public class MPFileUser extends MPBasicUser<MPFileSite> {
private static final Logger logger = Logger.get( MPFileUser.class );
@Nullable
private byte[] keyID;
private String keyID;
private File file;
private MPMarshalFormat format;
private MPMarshaller.ContentMode contentMode;
@@ -62,18 +62,18 @@ public class MPFileUser extends MPBasicUser<MPFileSite> {
this( fullName, null, MPAlgorithm.Version.CURRENT, location );
}
public MPFileUser(final String fullName, @Nullable final byte[] keyID, final MPAlgorithm algorithm, final File location) {
public MPFileUser(final String fullName, @Nullable final String keyID, final MPAlgorithm algorithm, final File location) {
this( fullName, keyID, algorithm, 0, null, new Instant(), false,
MPMarshaller.ContentMode.PROTECTED, MPMarshalFormat.DEFAULT, location );
}
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
public MPFileUser(final String fullName, @Nullable final byte[] keyID, final MPAlgorithm algorithm, final int avatar,
public MPFileUser(final String fullName, @Nullable final String keyID, final MPAlgorithm algorithm, final int avatar,
@Nullable final MPResultType defaultType, final ReadableInstant lastUsed, final boolean hidePasswords,
final MPMarshaller.ContentMode contentMode, final MPMarshalFormat format, final File location) {
super( avatar, fullName, algorithm );
this.keyID = (keyID != null)? keyID.clone(): null;
this.keyID = keyID;
this.lastUsed = lastUsed;
this.preferences = new MPFileUserPreferences( this, defaultType, hidePasswords );
this.format = format;
@@ -87,8 +87,8 @@ public class MPFileUser extends MPBasicUser<MPFileSite> {
@Nullable
@Override
public byte[] getKeyID() {
return (keyID == null)? null: keyID.clone();
public String getKeyID() {
return keyID;
}
@Nonnull

View File

@@ -54,7 +54,7 @@ public class MPFlatMarshaller implements MPMarshaller {
content.append( "# User Name: " ).append( user.getFullName() ).append( '\n' );
content.append( "# Full Name: " ).append( user.getFullName() ).append( '\n' );
content.append( "# Avatar: " ).append( user.getAvatar() ).append( '\n' );
content.append( "# Key ID: " ).append( user.exportKeyID() ).append( '\n' );
content.append( "# Key ID: " ).append( user.getKeyID() ).append( '\n' );
content.append( "# Algorithm: " ).append( user.getAlgorithm().version().toInt() ).append( '\n' );
content.append( "# Default Type: " ).append( user.getPreferences().getDefaultType().getType() ).append( '\n' );
content.append( "# Passwords: " ).append( user.getContentMode().name() ).append( '\n' );

View File

@@ -51,7 +51,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller {
public MPFileUser readUser(@Nonnull final File file)
throws IOException, MPMarshalException {
try (Reader reader = new InputStreamReader( new FileInputStream( file ), Charsets.UTF_8 )) {
byte[] keyID = null;
String keyID = null;
String fullName = null;
int mpVersion = 0, avatar = 0;
boolean clearContent = false, headerStarted = false;
@@ -84,7 +84,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller {
if ("Full Name".equalsIgnoreCase( name ) || "User Name".equalsIgnoreCase( name ))
fullName = value;
else if ("Key ID".equalsIgnoreCase( name ))
keyID = CodeUtils.decodeHex( value );
keyID = value;
else if ("Algorithm".equalsIgnoreCase( name ))
mpVersion = ConversionUtils.toIntegerNN( value );
else if ("Avatar".equalsIgnoreCase( name ))

View File

@@ -61,7 +61,7 @@ public class MPJSONFile extends MPJSONAnyObject {
user.avatar = modelUser.getAvatar();
user.full_name = modelUser.getFullName();
user.last_used = MPModelConstants.dateTimeFormatter.print( modelUser.getLastUsed() );
user.key_id = modelUser.exportKeyID();
user.key_id = modelUser.getKeyID();
user.algorithm = modelUser.getAlgorithm().version();
user._ext_mpw = new User.Ext() {
{
@@ -131,7 +131,7 @@ public class MPJSONFile extends MPJSONAnyObject {
MPAlgorithm algorithm = ifNotNullElse( user.algorithm, MPAlgorithm.Version.CURRENT );
return new MPFileUser(
user.full_name, CodeUtils.decodeHex( user.key_id ), algorithm, user.avatar,
user.full_name, user.key_id, algorithm, user.avatar,
(user._ext_mpw != null)? user._ext_mpw.default_type: null,
(user.last_used != null)? MPModelConstants.dateTimeFormatter.parseDateTime( user.last_used ): new Instant(),
(user._ext_mpw != null) && user._ext_mpw.hide_passwords,