From a58d435e0c9c9a32ff4db7a28029c5fb1b001c10 Mon Sep 17 00:00:00 2001 From: Mohamed Zenadi Date: Tue, 12 May 2015 22:31:17 +0200 Subject: initial support for openpgp-api v7 --- app/build.gradle | 7 ++-- .../java/com/zeapo/pwdstore/PasswordStore.java | 42 +++------------------- .../java/com/zeapo/pwdstore/UserPreference.java | 32 ++++++++++++++--- .../java/com/zeapo/pwdstore/crypto/PgpHandler.java | 12 ++----- app/src/main/res/xml/preference.xml | 9 +---- 5 files changed, 38 insertions(+), 64 deletions(-) (limited to 'app') diff --git a/app/build.gradle b/app/build.gradle index 00454893..46a69b1f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 40667564..c56df7b4 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -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() { diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index becf44ea..82c278df 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -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: diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java index 2f638847..2e676b46 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -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"))); diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 4c6e3157..c27f36f2 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -7,15 +7,8 @@ - - - - - -- cgit v1.2.3