From c6882ea39c3d0649b1a0928f97c5e37b60723588 Mon Sep 17 00:00:00 2001 From: zeapo Date: Tue, 4 Nov 2014 22:23:47 +0100 Subject: added an error when unable to open/access ssh-key --- app/app-release.apk | Bin 2015049 -> 2019209 bytes .../java/com/zeapo/pwdstore/UserPreference.java | 35 ++++++++++++++++----- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/app-release.apk b/app/app-release.apk index befb03a8..7a39caad 100644 Binary files a/app/app-release.apk and b/app/app-release.apk differ diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index f49d463b..ab3fc0e1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -1,6 +1,8 @@ package com.zeapo.pwdstore; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -19,9 +21,12 @@ import com.zeapo.pwdstore.utils.PasswordRepository; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.eclipse.jgit.api.CloneCommand; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -68,12 +73,23 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr return super.onOptionsItemSelected(item); } + /** + * Opens a file explorer to import the private key + */ public void getSshKey() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); startActivityForResult(intent, 1); } + + private void copySshKey(Uri uri) throws IOException { + InputStream sshKey = this.getContentResolver().openInputStream(uri); + byte[] privateKey = IOUtils.toByteArray(sshKey); + FileUtils.writeByteArrayToFile(new File(getFilesDir() + "/.ssh_key"), privateKey); + sshKey.close(); + } + @Override public boolean onPreferenceClick(Preference pref) { if (pref.getKey().equals("openpgp_key_id")) { @@ -92,16 +108,21 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr if (requestCode == 1) { // Uri sshFile = data.getData(); try { - InputStream sshKey = this.getContentResolver().openInputStream(data.getData()); - byte[] privateKey = IOUtils.toByteArray(sshKey); - FileUtils.writeByteArrayToFile(new File(getFilesDir() + "/.ssh_key"), privateKey); - sshKey.close(); - + copySshKey(data.getData()); Log.i("PREF", "Got key"); setResult(RESULT_OK); finish(); - } catch (Exception e) { - e.printStackTrace(); + } catch (IOException e) + { + new AlertDialog.Builder(this). + setTitle(this.getResources().getString(R.string.ssh_key_error_dialog_title)). + setMessage(this.getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage()). + setPositiveButton(this.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + //pass + } + }).show(); } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0b2a3b3f..819b6eb4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,8 @@ Set the time you want the password to be in clipboard Automatically Copy Password Automatically copy the password to the clipboard after decryption was successful. + Error while trying to import the ssh-key + Message : /n OK -- cgit v1.2.3