Change progress dialog title, and remove code

This commit is contained in:
J-Jamet
2018-05-02 13:49:03 +02:00
parent ec08f3430d
commit 60e2d786dd
6 changed files with 63 additions and 54 deletions

View File

@@ -100,25 +100,6 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
return finalKey; return finalKey;
} }
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
// Write checksum Checksum
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new IOException("SHA-256 not implemented here.");
}
NullOutputStream nos = new NullOutputStream();
DigestOutputStream dos = new DigestOutputStream(nos, md);
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
dos.write(masterSeed);
dos.write(transformedMasterKey);
finalKey = md.digest();
}
/** /**
* Encrypt the master key a few times to make brute-force key-search harder * Encrypt the master key a few times to make brute-force key-search harder
* @throws IOException * @throws IOException

View File

@@ -47,9 +47,13 @@ package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf; import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.stream.NullOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@@ -250,6 +254,25 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
} }
} }
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
// Write checksum Checksum
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new IOException("SHA-256 not implemented here.");
}
NullOutputStream nos = new NullOutputStream();
DigestOutputStream dos = new DigestOutputStream(nos, md);
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
dos.write(masterSeed);
dos.write(transformedMasterKey);
finalKey = md.digest();
}
@Override @Override
protected String getPasswordEncoding() { protected String getPasswordEncoding() {
return "ISO-8859-1"; return "ISO-8859-1";

View File

@@ -359,28 +359,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return md.digest(fKey); return md.digest(fKey);
} }
@Override
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
byte[] cmpKey = new byte[65];
System.arraycopy(masterSeed, 0, cmpKey, 0, 32);
System.arraycopy(transformedMasterKey, 0, cmpKey, 32, 32);
finalKey = CryptoUtil.resizeKey(cmpKey, 0, 64, dataEngine.keyLength());
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-512");
cmpKey[64] = 1;
hmacKey = md.digest(cmpKey);
} catch (NoSuchAlgorithmException e) {
throw new IOException("No SHA-512 implementation");
} finally {
Arrays.fill(cmpKey, (byte)0);
}
}
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP) throws IOException { public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP) throws IOException {
makeFinalKey(masterSeed, kdfP, 0); makeFinalKey(masterSeed, kdfP, 0);
} }

View File

@@ -47,13 +47,14 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre
private @StringRes int title = UNDEFINED; private @StringRes int title = UNDEFINED;
private @StringRes int message = UNDEFINED; private @StringRes int message = UNDEFINED;
private TextView titleView;
private TextView messageView; private TextView messageView;
private ProgressBar progressView; private ProgressBar progressView;
public static ProgressTaskDialogFragment start(FragmentManager fragmentManager, @StringRes int titleId) { public static ProgressTaskDialogFragment start(FragmentManager fragmentManager, @StringRes int titleId) {
// Create an instance of the dialog fragment and show it // Create an instance of the dialog fragment and show it
ProgressTaskDialogFragment dialog = new ProgressTaskDialogFragment(); ProgressTaskDialogFragment dialog = new ProgressTaskDialogFragment();
dialog.setTitle(titleId); dialog.updateTitle(titleId);
dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG); dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG);
return dialog; return dialog;
} }
@@ -71,12 +72,12 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
View root = inflater.inflate(R.layout.progress_dialog, null); View root = inflater.inflate(R.layout.progress_dialog, null);
builder.setView(root); builder.setView(root);
if (title != UNDEFINED)
builder.setTitle(title);
titleView = root.findViewById(R.id.progress_dialog_title);
messageView = root.findViewById(R.id.progress_dialog_message); messageView = root.findViewById(R.id.progress_dialog_message);
progressView = root.findViewById(R.id.progress_dialog_bar); progressView = root.findViewById(R.id.progress_dialog_bar);
updateTitle(title);
updateMessage(message); updateMessage(message);
setCancelable(false); setCancelable(false);
@@ -119,16 +120,25 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre
this.title = titleId; this.title = titleId;
} }
@Override private void updateView(TextView textView, @StringRes int resId) {
public void updateMessage(int resId) { if (textView != null) {
this.message = resId; if (resId == UNDEFINED) {
if (messageView != null) { textView.setVisibility(View.GONE);
if (message == UNDEFINED) {
messageView.setVisibility(View.GONE);
} else { } else {
messageView.setText(message); textView.setText(resId);
messageView.setVisibility(View.VISIBLE); textView.setVisibility(View.VISIBLE);
} }
} }
} }
public void updateTitle(int resId) {
this.title = resId;
updateView(titleView, title);
}
@Override
public void updateMessage(int resId) {
this.message = resId;
updateView(messageView, message);
}
} }

View File

@@ -9,7 +9,7 @@ public class SaveDatabaseProgressTaskDialogFragment extends ProgressTaskDialogFr
public static SaveDatabaseProgressTaskDialogFragment start(FragmentManager fragmentManager) { public static SaveDatabaseProgressTaskDialogFragment start(FragmentManager fragmentManager) {
// Create an instance of the dialog fragment and show it // Create an instance of the dialog fragment and show it
SaveDatabaseProgressTaskDialogFragment dialog = new SaveDatabaseProgressTaskDialogFragment(); SaveDatabaseProgressTaskDialogFragment dialog = new SaveDatabaseProgressTaskDialogFragment();
dialog.setTitle(R.string.saving_database); dialog.updateTitle(R.string.saving_database);
dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG); dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG);
return dialog; return dialog;
} }

View File

@@ -3,11 +3,27 @@
android:orientation="vertical" android:layout_width="match_parent" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextView
android:id="@+id/progress_dialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
style="@style/KeepassDXStyle.TextAppearance.Title"
android:textColor="?android:attr/textColor"/>
<TextView <TextView
android:id="@+id/progress_dialog_message" android:id="@+id/progress_dialog_message"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="20dp" android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/> style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
<ProgressBar <ProgressBar
@@ -15,6 +31,7 @@
style="?android:attr/progressBarStyleHorizontal" style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:indeterminate="true" android:indeterminate="true"
android:max="100"/> android:max="100"/>