initial support for openpgp-api v7

This commit is contained in:
Mohamed Zenadi 2015-05-12 22:31:17 +02:00
parent af80c6b045
commit a58d435e0c
5 changed files with 38 additions and 64 deletions

View File

@ -4,7 +4,7 @@ apply plugin: 'eclipse'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.zeapo.pwdstore"
minSdkVersion 15
@ -25,10 +25,11 @@ android {
}
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.0.0'
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libraries:openpgp-api-lib')
// compile project(':libraries:openpgp-api-lib')
compile 'org.sufficientlysecure:openpgp-api:7.0'
compile 'org.eclipse.jgit:org.eclipse.jgit:3.7.0.201502260915-r'
compile 'com.jcraft:jsch:0.1.52'
compile 'org.apache.commons:commons-io:1.3.2'

View File

@ -24,7 +24,6 @@ import com.zeapo.pwdstore.utils.PasswordItem;
import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter;
import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
@ -191,25 +190,14 @@ public class PasswordStore extends ActionBarActivity {
}
private void createRepository() {
final String keyId = settings.getString("openpgp_key_ids", "");
// final String keyId = settings.getString("openpgp_key_ids", "");
File localDir = new File(getFilesDir() + "/store/");
localDir.mkdir();
try {
PasswordRepository.createRepository(localDir);
// 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));
Git git = new Git(PasswordRepository.getRepository(new File("")));
GitAsyncTask tasks = new GitAsyncTask(this, false, false, CommitCommand.class);
tasks.execute(
git.add().addFilepattern("."),
git.commit().setMessage(R.string.initialization_commit_text + keyId)
);
settings.edit().putBoolean("repository_initialized", true).commit();
settings.edit().putBoolean("repository_initialized", true).apply();
} catch (Exception e) {
e.printStackTrace();
localDir.delete();
@ -221,7 +209,7 @@ public class PasswordStore extends ActionBarActivity {
public void initRepository(View view) {
final String keyId = settings.getString("openpgp_key_ids", "");
if (keyId.isEmpty())
if (keyId != null && keyId.isEmpty())
new AlertDialog.Builder(this)
.setMessage(this.getResources().getString(R.string.key_dialog_text))
.setPositiveButton(this.getResources().getString(R.string.dialog_positive), new DialogInterface.OnClickListener() {
@ -239,29 +227,7 @@ public class PasswordStore extends ActionBarActivity {
})
.show();
else {
new AlertDialog.Builder(this)
.setMessage(this.getResources().getString(R.string.connection_dialog_text))
.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();
}
createRepository();
}
private void checkLocalRepository() {

View File

@ -8,7 +8,7 @@ import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.Toast;
@ -18,15 +18,17 @@ import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.openintents.openpgp.util.OpenPgpKeyPreference;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
public class UserPreference extends ActionBarActivity implements Preference.OnPreferenceClickListener {
public class UserPreference extends AppCompatActivity implements Preference.OnPreferenceClickListener {
private final static int IMPORT_SSH_KEY = 1;
private final static int IMPORT_PGP_KEY = 2;
private final static int EDIT_GIT_INFO = 3;
private OpenPgpKeyPreference mKey;
public static class PrefsFragment extends PreferenceFragment {
@Override
@ -34,12 +36,24 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preference);
Preference keyPref = findPreference("openpgp_key_id");
keyPref.setSummary(getPreferenceManager().getSharedPreferences().getString("openpgp_key_ids", "No key selected"));
keyPref.setOnPreferenceClickListener((UserPreference) getActivity());
// Preference keyPref = findPreference("openpgp_key_id");
// keyPref.setSummary(getPreferenceManager().getSharedPreferences().getString("openpgp_key_ids", "No key selected"));
// keyPref.setOnPreferenceClickListener((UserPreference) getActivity());
findPreference("ssh_key").setOnPreferenceClickListener((UserPreference) getActivity());
findPreference("git_server_info").setOnPreferenceClickListener((UserPreference) getActivity());
findPreference("git_delete_repo").setOnPreferenceClickListener((UserPreference) getActivity());
// ((UserPreference) getActivity()).mKey = (OpenPgpKeyPreference) findPreference("openpgp_key");
// if (getPreferenceManager().getSharedPreferences().getString("openpgp_provider_list", null) != null)
// ((UserPreference) getActivity()).mKey.setOpenPgpProvider(getPreferenceManager().getSharedPreferences().getString("openpgp_provider_list", ""));
// findPreference("openpgp_provider_list").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
// @Override
// public boolean onPreferenceChange(Preference preference, Object o) {
// ((UserPreference) getActivity()).mKey.setOpenPgpProvider((String) o);
// return false;
// }
// });
}
}
@ -179,6 +193,14 @@ public class UserPreference extends ActionBarActivity implements Preference.OnPr
case EDIT_GIT_INFO:
{
}
break;
case OpenPgpKeyPreference.REQUEST_CODE_KEY_PREFERENCE:
{
if (mKey.handleOnActivityResult(requestCode, resultCode, data)) {
// handled by OpenPgpKeyPreference
return;
}
}
break;
default:

View File

@ -14,7 +14,7 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
@ -47,7 +47,7 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConnection.OnBound{
public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConnection.OnBound{
private OpenPgpServiceConnection mServiceConnection;
@ -422,21 +422,13 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
public void getKeyIds(Intent data) {
accountName = settings.getString("openpgp_account_name", "");
if (accountName.isEmpty())
showToast(this.getResources().getString(R.string.name_settings_toast_text));
data.setAction(OpenPgpApi.ACTION_GET_KEY_IDS);
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{accountName.isEmpty() ? "default" : accountName});
OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());
api.executeApiAsync(data, null, null, new PgpCallback(false, null, PgpHandler.REQUEST_CODE_GET_KEY_IDS));
}
public void decryptAndVerify(Intent data) {
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
try {
InputStream is = FileUtils.openInputStream(new File(getIntent().getExtras().getString("FILE_PATH")));

View File

@ -7,15 +7,8 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_crypto_title">
<org.openintents.openpgp.util.OpenPgpListPreference
<org.openintents.openpgp.util.OpenPgpAppPreference
android:key="openpgp_provider_list" android:title="@string/pref_provider_title" />
<EditTextPreference android:title="@string/pref_provider_account_title"
android:hint="@string/pref_provider_account_hint" android:key="openpgp_account_name"
android:inputType="textEmailAddress" />
<Preference android:title="@string/pref_key_title"
android:key="openpgp_key_id" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_general_title">