store initialization supports ssh-key now

This commit is contained in:
zeapo
2014-08-23 21:22:05 +02:00
parent 9784af6d66
commit 6ba4acfc47
4 changed files with 66 additions and 31 deletions

View File

@@ -166,7 +166,7 @@ public class GitHandler extends Activity {
String hostname = String hostname =
settings.getString("git_remote_username", "") settings.getString("git_remote_username", "")
+ "@" + + "@" +
settings.getString("git_remote_server", "") settings.getString("git_remote_server", "").trim()
+ ":" + + ":" +
settings.getString("git_remote_location", ""); settings.getString("git_remote_location", "");
@@ -483,7 +483,7 @@ public class GitHandler extends Activity {
// check that the remote origin is here, else add it // check that the remote origin is here, else add it
PasswordRepository.addRemote("origin", settings.getString("git_remote_username", "user") PasswordRepository.addRemote("origin", settings.getString("git_remote_username", "user")
+ "@" + + "@" +
settings.getString("git_remote_server", "server.com") settings.getString("git_remote_server", "server.com").trim()
+ ":" + + ":" +
settings.getString("git_remote_location", "path/to/repository")); settings.getString("git_remote_location", "path/to/repository"));
@@ -507,7 +507,7 @@ public class GitHandler extends Activity {
public void pushOperation(UsernamePasswordCredentialsProvider provider) { public void pushOperation(UsernamePasswordCredentialsProvider provider) {
if (settings.getString("git_remote_username", "user").isEmpty() || if (settings.getString("git_remote_username", "user").isEmpty() ||
settings.getString("git_remote_server", "server.com").isEmpty() || settings.getString("git_remote_server", "server.com").trim().isEmpty() ||
settings.getString("git_remote_location", "path/to/repository").isEmpty() ) settings.getString("git_remote_location", "path/to/repository").isEmpty() )
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage("You have to set the information about the server before synchronizing with the server") .setMessage("You have to set the information about the server before synchronizing with the server")
@@ -532,7 +532,7 @@ public class GitHandler extends Activity {
// check that the remote origin is here, else add it // check that the remote origin is here, else add it
PasswordRepository.addRemote("origin", settings.getString("git_remote_username", "user") PasswordRepository.addRemote("origin", settings.getString("git_remote_username", "user")
+ "@" + + "@" +
settings.getString("git_remote_server", "server.com") settings.getString("git_remote_server", "server.com").trim()
+ ":" + + ":" +
settings.getString("git_remote_location", "path/to/repository")); settings.getString("git_remote_location", "path/to/repository"));

View File

@@ -15,6 +15,7 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@@ -138,12 +139,30 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
startActivity(intent); startActivity(intent);
} }
private void createRepository() {
final String keyId = settings.getString("openpgp_key_ids", "");
File localDir = new File(getFilesDir() + "/store/");
localDir.mkdir();
try {
// we take only the first key-id, we have to think about how to handle multiple keys, and why should we do that...
// also, for compatibility use short-version of the key-id
FileUtils.writeStringToFile(new File(localDir.getAbsolutePath() + "/.gpg-id"),
keyId.substring(keyId.length() - 8));
} catch (Exception e) {
localDir.delete();
return;
}
PasswordRepository.createRepository(localDir);
checkLocalRepository();
}
public void initRepository(View view) { public void initRepository(View view) {
String keyId = settings.getString("openpgp_key_ids", ""); final String keyId = settings.getString("openpgp_key_ids", "");
if (keyId.isEmpty()) if (keyId.isEmpty())
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage("You have to set the information about the server before synchronizing with the server") .setMessage("You have to select your \"PGP-Key ID\" before initializing the repository")
.setPositiveButton("On my way!", new DialogInterface.OnClickListener() { .setPositiveButton("On my way!", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
@@ -160,19 +179,27 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
.show(); .show();
else { else {
File localDir = new File(getFilesDir() + "/store/"); new AlertDialog.Builder(this)
localDir.mkdir(); .setMessage("Which connection method do you prefer?")
try { .setPositiveButton("ssh-key", new DialogInterface.OnClickListener() {
// we take only the first key-id, we have to think about how to handle multiple keys, and why should we do that... @Override
// also, for compatibility use short-version of the key-id public void onClick(DialogInterface dialogInterface, int i) {
FileUtils.writeStringToFile(new File(localDir.getAbsolutePath() + "/.gpg-id"), settings.edit().putString("git_remote_auth", "ssh-key").apply();
keyId.substring(keyId.length() - 8)); createRepository();
} catch (Exception e) {
localDir.delete();
return;
} }
PasswordRepository.createRepository(localDir); })
checkLocalRepository(); .setNegativeButton("username/password", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
settings.edit().putString("git_remote_auth", "username/password").apply();
createRepository();
}
})
.setCancelable(false)
.show();
} }
} }

View File

@@ -250,6 +250,9 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB
decryptAndVerify(data); decryptAndVerify(data);
break; break;
} }
case REQUEST_CODE_GET_KEY_IDS:
getKeyIds(data);
break;
} }
} else if (resultCode == RESULT_CANCELED) { } else if (resultCode == RESULT_CANCELED) {
bindingDialog.dismiss(); bindingDialog.dismiss();
@@ -332,13 +335,14 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB
} }
keyIDs = StringUtils.join(keys, ", "); keyIDs = StringUtils.join(keys, ", ");
settings.edit().putString("openpgp_key_ids", keyIDs).commit();
if (!keyIDs.isEmpty()) { if (!keyIDs.isEmpty()) {
String mKeys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0]; String mKeys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0];
((TextView) findViewById(R.id.crypto_key_ids)).setText(mKeys); // ((TextView) findViewById(R.id.crypto_key_ids)).setText(mKeys);
settings.edit().putString("openpgp_key_ids", keyIDs).apply();
Log.i("PGP", mKeys);
} }
setResult(RESULT_OK);
finish();
} }
break; break;
} }
@@ -481,12 +485,13 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB
((TextView) findViewById(R.id.crypto_password_category)).setText(cat); ((TextView) findViewById(R.id.crypto_password_category)).setText(cat);
} else if (extra.getString("Operation").equals("GET_KEY_ID")) { } else if (extra.getString("Operation").equals("GET_KEY_ID")) {
bindingDialog.dismiss(); bindingDialog.dismiss();
getKeyIds(new Intent());
setContentView(R.layout.key_id); // setContentView(R.layout.key_id);
if (!keyIDs.isEmpty()) { // if (!keyIDs.isEmpty()) {
String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0]; // String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0];
((TextView) findViewById(R.id.crypto_key_ids)).setText(keys); // ((TextView) findViewById(R.id.crypto_key_ids)).setText(keys);
} // }
} }
} }

View File

@@ -3,13 +3,16 @@
<PreferenceCategory android:title="Git"> <PreferenceCategory android:title="Git">
<EditTextPreference android:title="Server" <EditTextPreference android:title="Server"
android:key="git_remote_server" android:key="git_remote_server"
android:hint="server.com"/> android:hint="server.com"
android:inputType="textUri"/>
<EditTextPreference android:title="Remote location" <EditTextPreference android:title="Remote location"
android:key="git_remote_location" android:key="git_remote_location"
android:hint="path/to/repository"/> android:hint="path/to/repository"
android:inputType="textUri"/>
<EditTextPreference android:title="Username" <EditTextPreference android:title="Username"
android:key="git_remote_username" android:key="git_remote_username"
android:hint="username"/> android:hint="username"
android:inputType="textPersonName"/>
<Preference <Preference
android:title="SSH Key" android:title="SSH Key"
android:key="ssh_key"/> android:key="ssh_key"/>