From 3a1b9803842e124f448b2c9d4ef74e4198743a8a Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sat, 16 Dec 2017 14:46:00 +0000 Subject: [PATCH] Improve error message when using the wrong password on account creation. --- .../ui/setup/BaseConfigurationFinder.java | 2 + .../ui/setup/SetupEncryptionFragment.java | 40 ++++++++++++------- app/src/main/res/values/strings.xml | 2 + 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/setup/BaseConfigurationFinder.java b/app/src/main/java/com/etesync/syncadapter/ui/setup/BaseConfigurationFinder.java index 23110052..957e6c41 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/setup/BaseConfigurationFinder.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/setup/BaseConfigurationFinder.java @@ -107,6 +107,8 @@ public class BaseConfigurationFinder { public final String logs; + public Throwable error; + @Getter private final boolean failed; } diff --git a/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupEncryptionFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupEncryptionFragment.java index f400c414..19aa9616 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupEncryptionFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/setup/SetupEncryptionFragment.java @@ -89,23 +89,37 @@ public class SetupEncryptionFragment extends DialogFragment { @Override protected void onPostExecute(Configuration result) { - try { - if (createAccount(config.userName, config)) { - getActivity().setResult(Activity.RESULT_OK); - getActivity().finish(); - } - } catch (InvalidAccountException e) { - App.log.severe("Account creation failed!"); + if ((config.error != null) && (config.error instanceof Exceptions.IntegrityException)) { + App.log.severe("Wrong encryption password."); new AlertDialog.Builder(getActivity()) - .setTitle(R.string.account_creation_failed) + .setTitle(R.string.wrong_encryption_password) .setIcon(R.drawable.ic_error_dark) - .setMessage(e.getLocalizedMessage()) + .setMessage(getString(R.string.wrong_encryption_password_content, config.error.getLocalizedMessage())) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // dismiss } }).show(); + } else { + try { + if (createAccount(config.userName, config)) { + getActivity().setResult(Activity.RESULT_OK); + getActivity().finish(); + } + } catch (InvalidAccountException e) { + App.log.severe("Account creation failed!"); + new AlertDialog.Builder(getActivity()) + .setTitle(R.string.account_creation_failed) + .setIcon(R.drawable.ic_error_dark) + .setMessage(e.getLocalizedMessage()) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // dismiss + } + }).show(); + } } dismissAllowingStateLoss(); @@ -116,6 +130,7 @@ public class SetupEncryptionFragment extends DialogFragment { App.log.info("Started deriving key"); config.password = Crypto.deriveKey(config.userName, config.rawPassword); App.log.info("Finished deriving key"); + config.error = null; try { Crypto.CryptoManager cryptoManager; @@ -129,12 +144,9 @@ public class SetupEncryptionFragment extends DialogFragment { userInfo.verify(cryptoManager); config.keyPair = new Crypto.AsymmetricKeyPair(userInfo.getContent(cryptoManager), userInfo.getPubkey()); } - } catch (Exceptions.HttpException e) { - e.printStackTrace(); - } catch (Exceptions.IntegrityException e) { - e.printStackTrace(); - } catch (Exceptions.VersionTooNewException e) { + } catch (Exception e) { e.printStackTrace(); + config.error = e; } return config; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8a7b3a6..02a114e0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -194,6 +194,8 @@ Please wait, setting up encryption… Account creation failed + Wrong encryption password + Got an integrity error while accessing your account, which most likely means you put in the wrong encryption password.\n\n%s Encryption Error