added an error when unable to open/access ssh-key
This commit is contained in:
parent
7e0a8c6ce8
commit
c6882ea39c
3 changed files with 30 additions and 7 deletions
Binary file not shown.
|
@ -1,6 +1,8 @@
|
||||||
package com.zeapo.pwdstore;
|
package com.zeapo.pwdstore;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
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.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.eclipse.jgit.api.CloneCommand;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
@ -68,12 +73,23 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a file explorer to import the private key
|
||||||
|
*/
|
||||||
public void getSshKey() {
|
public void getSshKey() {
|
||||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
intent.setType("*/*");
|
intent.setType("*/*");
|
||||||
startActivityForResult(intent, 1);
|
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
|
@Override
|
||||||
public boolean onPreferenceClick(Preference pref) {
|
public boolean onPreferenceClick(Preference pref) {
|
||||||
if (pref.getKey().equals("openpgp_key_id")) {
|
if (pref.getKey().equals("openpgp_key_id")) {
|
||||||
|
@ -92,16 +108,21 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr
|
||||||
if (requestCode == 1) {
|
if (requestCode == 1) {
|
||||||
// Uri sshFile = data.getData();
|
// Uri sshFile = data.getData();
|
||||||
try {
|
try {
|
||||||
InputStream sshKey = this.getContentResolver().openInputStream(data.getData());
|
copySshKey(data.getData());
|
||||||
byte[] privateKey = IOUtils.toByteArray(sshKey);
|
|
||||||
FileUtils.writeByteArrayToFile(new File(getFilesDir() + "/.ssh_key"), privateKey);
|
|
||||||
sshKey.close();
|
|
||||||
|
|
||||||
Log.i("PREF", "Got key");
|
Log.i("PREF", "Got key");
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
finish();
|
finish();
|
||||||
} catch (Exception e) {
|
} catch (IOException e)
|
||||||
e.printStackTrace();
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,8 @@
|
||||||
<string name="pref_password_dialog_title">Set the time you want the password to be in clipboard</string>
|
<string name="pref_password_dialog_title">Set the time you want the password to be in clipboard</string>
|
||||||
<string name="pref_copy_title">Automatically Copy Password</string>
|
<string name="pref_copy_title">Automatically Copy Password</string>
|
||||||
<string name="pref_copy_dialog_title">Automatically copy the password to the clipboard after decryption was successful.</string>
|
<string name="pref_copy_dialog_title">Automatically copy the password to the clipboard after decryption was successful.</string>
|
||||||
|
<string name="ssh_key_error_dialog_title">Error while trying to import the ssh-key</string>
|
||||||
|
<string name="ssh_key_error_dialog_text">Message : /n</string>
|
||||||
|
|
||||||
<!-- Misc -->
|
<!-- Misc -->
|
||||||
<string name="dialog_ok">OK</string>
|
<string name="dialog_ok">OK</string>
|
||||||
|
|
Loading…
Reference in a new issue