corrected a major bug with kitkat when selecting sshkey

This commit is contained in:
knuthy 2014-09-20 20:30:24 +02:00
parent ac6522cb94
commit c73517056c
2 changed files with 16 additions and 5 deletions

View File

@ -75,6 +75,8 @@ public class GitHandler extends Activity {
public static final int REQUEST_CLONE = 103;
public static final int REQUEST_INIT = 104;
private static final int GET_SSH_KEY = 201;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -582,7 +584,7 @@ public class GitHandler extends Activity {
public void onClick(DialogInterface dialog, int id) {
try {
Intent intent = new Intent(getApplicationContext(), UserPreference.class);
startActivity(intent);
startActivityForResult(intent, GET_SSH_KEY);
} catch (Exception e) {
System.out.println("Exception caught :(");
e.printStackTrace();
@ -691,6 +693,8 @@ public class GitHandler extends Activity {
case REQUEST_PUSH:
authenticateAndRun("pushOperation");
break;
case GET_SSH_KEY:
authenticateAndRun("pullOperation");
}
}

View File

@ -15,8 +15,11 @@ import com.zeapo.pwdstore.crypto.PgpHandler;
import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URI;
public class UserPreference extends PreferenceActivity implements Preference.OnPreferenceClickListener {
@ -49,7 +52,6 @@ public class UserPreference extends PreferenceActivity implements Preference.OnP
@Override
public boolean onPreferenceClick(Preference pref) {
System.out.println(pref);
if (pref.getKey().equals("openpgp_key_id")) {
Intent intent = new Intent(this, PgpHandler.class);
intent.putExtra("Operation", "GET_KEY_ID");
@ -66,11 +68,16 @@ public class UserPreference extends PreferenceActivity implements Preference.OnP
Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Uri sshFile = data.getData();
// Uri sshFile = data.getData();
try {
FileUtils.copyFile(new File(sshFile.getPath()), new File(getFilesDir() + "/.ssh_key"));
} catch (Exception e) {
byte[] privateKey = IOUtils.toByteArray(this.getContentResolver().openInputStream(data.getData()));
FileUtils.writeByteArrayToFile(new File(getFilesDir() + "/.ssh_key"), privateKey);
Log.i("PREF", "Got key");
setResult(RESULT_OK);
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
}