|
|
@@ -45,9 +45,10 @@ import info.knacki.pass.git.entities.GitRef;
|
|
|
import info.knacki.pass.io.FileInterfaceFactory;
|
|
|
import info.knacki.pass.io.FileMigratoryUtils;
|
|
|
import info.knacki.pass.io.FileUtils;
|
|
|
+import info.knacki.pass.io.OnResponseListener;
|
|
|
+import info.knacki.pass.io.PathUtils;
|
|
|
import info.knacki.pass.io.pgp.GPGStorageEngine;
|
|
|
import info.knacki.pass.io.pgp.GPGUtil;
|
|
|
-import info.knacki.pass.io.OnResponseListener;
|
|
|
import info.knacki.pass.settings.SettingsManager;
|
|
|
import info.knacki.pass.ui.GitPullActivity;
|
|
|
import info.knacki.pass.ui.alertPrompt.AlertPromptGenerator;
|
|
|
@@ -234,6 +235,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
}
|
|
|
|
|
|
public static class VCSPreferenceFragment extends PreferenceFragment {
|
|
|
+ private static final int ACTIVITY_REQUEST_CODE_BROWSE_PRIVATE_KEY = 2;
|
|
|
+
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
@@ -254,10 +257,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
findPreference(getResources().getString(R.string.id_vcs_enable)).setOnPreferenceChangeListener(new PrefListener() {
|
|
|
@Override
|
|
|
void savePref(Preference preference, Object o) {
|
|
|
- if ((Boolean) o)
|
|
|
- SettingsManager.SetVCS(getActivity(), new SettingsManager.Git());
|
|
|
- else
|
|
|
- SettingsManager.SetVCS(getActivity(), null);
|
|
|
+ Context ctx = getActivity();
|
|
|
+ SettingsManager.SetVCS(ctx, (boolean) o ? new SettingsManager.Git(ctx) : null);
|
|
|
}
|
|
|
});
|
|
|
findPreference(getResources().getString(R.string.id_vcs_list)).setOnPreferenceChangeListener(new PrefListener() {
|
|
|
@@ -268,7 +269,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
|
|
|
switch (Integer.parseInt((String) o)) {
|
|
|
case 0:
|
|
|
- newVcs = new SettingsManager.Git();
|
|
|
+ newVcs = new SettingsManager.Git(getActivity());
|
|
|
break;
|
|
|
default:
|
|
|
return;
|
|
|
@@ -300,9 +301,20 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
void savePref(Preference preference, Object o) {
|
|
|
SettingsManager.Git git = (SettingsManager.Git) SettingsManager.GetVCS(getActivity());
|
|
|
git.SetPassword(((String) o).trim());
|
|
|
+ git.SetPrivateKey(false);
|
|
|
SettingsManager.SetVCS(getActivity(), git);
|
|
|
}
|
|
|
});
|
|
|
+ findPreference(getResources().getString(R.string.id_vcs_git_private_key)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onPreferenceClick(Preference preference) {
|
|
|
+ Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
+ i.setType("*/*");
|
|
|
+ i.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
+ VCSPreferenceFragment.this.startActivityForResult(i, ACTIVITY_REQUEST_CODE_BROWSE_PRIVATE_KEY);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
findPreference(getResources().getString(R.string.id_vcs_git_ci_username)).setOnPreferenceChangeListener(new PrefListener() {
|
|
|
@Override
|
|
|
void savePref(Preference preference, Object o) {
|
|
|
@@ -381,6 +393,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
gitPass.setSummary(((SettingsManager.Git) versioning).GetPassword().length() == 0 ? "" : "******");
|
|
|
gitPass.setText(((SettingsManager.Git) versioning).GetPassword());
|
|
|
|
|
|
+ Preference sshKey = FindPreference(R.string.id_vcs_git_private_key);
|
|
|
+ sshKey.setSummary(((SettingsManager.Git) versioning).HasPrivateKey() ? R.string.pref_vcs_git_private_key_change : R.string.pref_vcs_git_private_key_set);
|
|
|
+
|
|
|
FindPreference(R.string.id_vcs_git_commit_info_category);
|
|
|
ListPreference gitBranches = (ListPreference) FindPreference(R.string.id_vcs_git_branches);
|
|
|
populateBranches(gitBranches, (SettingsManager.Git) versioning);
|
|
|
@@ -397,6 +412,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
} else {
|
|
|
RemovePrefs(R.string.id_vcs_git_url,
|
|
|
R.string.id_vcs_git_user,
|
|
|
+ R.string.id_vcs_git_private_key,
|
|
|
R.string.id_vcs_git_pass,
|
|
|
R.string.id_vcs_git_branches,
|
|
|
R.string.id_vcs_git_pull,
|
|
|
@@ -414,6 +430,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
RemovePrefs(R.string.id_vcs_git_url,
|
|
|
R.string.id_vcs_git_user,
|
|
|
R.string.id_vcs_git_pass,
|
|
|
+ R.string.id_vcs_git_private_key,
|
|
|
R.string.id_vcs_git_branches,
|
|
|
R.string.id_vcs_git_pull,
|
|
|
R.string.id_vcs_git_ci_username,
|
|
|
@@ -472,6 +489,41 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
}
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
+
|
|
|
+ private boolean SetPrivateKeyFile(InputStream in) {
|
|
|
+ SettingsManager.Git git = (SettingsManager.Git) SettingsManager.GetVCS(getActivity());
|
|
|
+ if (in != null) {
|
|
|
+ try {
|
|
|
+ File fout = new File(PathUtils.GetPrivateRSAKey(getActivity()));
|
|
|
+ if (!fout.exists() && !fout.createNewFile()) {
|
|
|
+ throw new FileNotFoundException();
|
|
|
+ }
|
|
|
+ FileUtils.pipe(in, new FileOutputStream(fout));
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.log(Level.SEVERE, "Cannot import private key: " + e.getMessage(), e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ git.SetPrivateKey(in != null);
|
|
|
+ git.SetPassword("");
|
|
|
+ SettingsManager.SetVCS(getActivity(), git);
|
|
|
+ VCSPreferenceFragment.this.reload();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ if (requestCode == ACTIVITY_REQUEST_CODE_BROWSE_PRIVATE_KEY && resultCode == RESULT_OK) {
|
|
|
+ try {
|
|
|
+ final Uri intentData = data.getData();
|
|
|
+ boolean importStatus = SetPrivateKeyFile(intentData == null ? null : getActivity().getContentResolver().openInputStream(intentData));
|
|
|
+ Toast.makeText(getActivity(), getResources().getString(importStatus ? R.string.gpg_import_ok : R.string.gpg_import_ko), Toast.LENGTH_LONG).show();
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ Toast.makeText(getActivity(), getResources().getString(R.string.file_not_found), Toast.LENGTH_LONG).show();
|
|
|
+ GPGStorageEngine.GetDefaultEngine(getActivity()).RemoveGpgKey();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static class GPGPreferenceFragment extends PreferenceFragment {
|