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 =
settings.getString("git_remote_username", "")
+ "@" +
settings.getString("git_remote_server", "")
settings.getString("git_remote_server", "").trim()
+ ":" +
settings.getString("git_remote_location", "");
@ -483,7 +483,7 @@ public class GitHandler extends Activity {
// check that the remote origin is here, else add it
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"));
@ -507,7 +507,7 @@ public class GitHandler extends Activity {
public void pushOperation(UsernamePasswordCredentialsProvider provider) {
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() )
new AlertDialog.Builder(this)
.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
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"));

View file

@ -15,6 +15,7 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
@ -138,12 +139,30 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
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) {
String keyId = settings.getString("openpgp_key_ids", "");
final String keyId = settings.getString("openpgp_key_ids", "");
if (keyId.isEmpty())
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() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
@ -160,19 +179,27 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
.show();
else {
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();
new AlertDialog.Builder(this)
.setMessage("Which connection method do you prefer?")
.setPositiveButton("ssh-key", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
settings.edit().putString("git_remote_auth", "ssh-key").apply();
createRepository();
}
})
.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);
break;
}
case REQUEST_CODE_GET_KEY_IDS:
getKeyIds(data);
break;
}
} else if (resultCode == RESULT_CANCELED) {
bindingDialog.dismiss();
@ -332,13 +335,14 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB
}
keyIDs = StringUtils.join(keys, ", ");
settings.edit().putString("openpgp_key_ids", keyIDs).commit();
if (!keyIDs.isEmpty()) {
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;
}
@ -481,12 +485,13 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB
((TextView) findViewById(R.id.crypto_password_category)).setText(cat);
} else if (extra.getString("Operation").equals("GET_KEY_ID")) {
bindingDialog.dismiss();
getKeyIds(new Intent());
setContentView(R.layout.key_id);
if (!keyIDs.isEmpty()) {
String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0];
((TextView) findViewById(R.id.crypto_key_ids)).setText(keys);
}
// setContentView(R.layout.key_id);
// if (!keyIDs.isEmpty()) {
// String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0];
// ((TextView) findViewById(R.id.crypto_key_ids)).setText(keys);
// }
}
}

View file

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