diff options
4 files changed, 40 insertions, 62 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index c5136b5cb..9dc8f8934 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -105,7 +105,6 @@ public class PgpEncryptDecryptTest { providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); } - /* @Test public void testSymmetricEncryptDecrypt() { @@ -117,9 +116,9 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncrypt.Builder( + Builder b = new PgpSignEncrypt.Builder(Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), + null, // new DummyPassphraseCache(mPassphrase, 0L) data, out); b.setSymmetricPassphrase(mPassphrase); @@ -136,9 +135,10 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder(Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), data, out); + null, // new DummyPassphraseCache(mPassphrase, 0L), + data, out); b.setPassphrase(mPassphrase); DecryptVerifyResult result = b.build().execute(); Assert.assertTrue("decryption must succeed", result.success()); @@ -154,8 +154,10 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), data, out); + null, // new DummyPassphraseCache(mPassphrase, 0L), + data, out); b.setPassphrase(mPassphrase + "x"); DecryptVerifyResult result = b.build().execute(); Assert.assertFalse("decryption must succeed", result.success()); @@ -170,8 +172,10 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), data, out); + null, // new DummyPassphraseCache(mPassphrase, 0L), + data, out); DecryptVerifyResult result = b.build().execute(); Assert.assertFalse("decryption must succeed", result.success()); Assert.assertEquals("decrypted plaintext should be empty", 0, out.size()); @@ -192,8 +196,9 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); Builder b = new PgpSignEncrypt.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mPassphrase, 0L), + null, // new DummyPassphraseCache(mPassphrase, 0L), data, out); b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); @@ -211,8 +216,10 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(null, null), data, out); + null, // new DummyPassphraseCache(null, null), + data, out); b.setPassphrase(mKeyPhrase1); DecryptVerifyResult result = b.build().execute(); Assert.assertTrue("decryption with provided passphrase must succeed", result.success()); @@ -221,37 +228,47 @@ public class PgpEncryptDecryptTest { Assert.assertNull("signature be empty", result.getSignatureResult()); } - { // decryption with passphrase cached should succeed + // TODO how to test passphrase cache? + + /*{ // decryption with passphrase cached should succeed ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); + PassphraseCacheService.addCachedPassphrase( + Robolectric.application, mStaticRing1.getMasterKeyId(), + mStaticRing1.getMasterKeyId(), mKeyPhrase1, "dummy"); + PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(mKeyPhrase1, null), data, out); + null, // new DummyPassphraseCache(mKeyPhrase1, null), + data, out); DecryptVerifyResult result = b.build().execute(); Assert.assertTrue("decryption with cached passphrase must succeed", result.success()); Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext", out.toByteArray(), plaintext.getBytes()); Assert.assertNull("signature should be empty", result.getSignatureResult()); - } + }*/ - { // decryption with no passphrase provided should return status pending + /*{ // decryption with no passphrase provided should return status pending ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); PgpDecryptVerify.Builder b = new PgpDecryptVerify.Builder( + Robolectric.application, new ProviderHelper(Robolectric.application), - new DummyPassphraseCache(null, null), data, out); + null, // new DummyPassphraseCache(null, null), + data, out); DecryptVerifyResult result = b.build().execute(); Assert.assertFalse("decryption with no passphrase must return pending", result.success()); Assert.assertTrue("decryption with no passphrase should return pending", result.isPending()); Assert.assertEquals("decryption with no passphrase should return pending passphrase", DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE, result.getResult()); - } + }*/ } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java index 0bd8ada5a..f42053bad 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java @@ -46,6 +46,7 @@ import org.sufficientlysecure.keychain.util.FileHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressScaler; +import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -289,6 +290,10 @@ public class ImportExportOperation extends BaseOperation { } */ + if ( ! BufferedOutputStream.class.isInstance(outStream)) { + outStream = new BufferedOutputStream(outStream); + } + int okSecret = 0, okPublic = 0, progress = 0; try { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 97fb7e7b4..63cb6494d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -145,7 +145,8 @@ public class PassphraseCacheService extends Service { * @return passphrase or null (if no passphrase is cached for this keyId) */ public static String getCachedPassphrase(Context context, long masterKeyId, long subKeyId) throws KeyNotFoundException { - Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphrase() get masterKeyId for " + masterKeyId); + Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphrase() for masterKeyId " + + masterKeyId + ", subKeyId " + subKeyId); Intent intent = new Intent(context, PassphraseCacheService.class); intent.setAction(ACTION_PASSPHRASE_CACHE_GET); @@ -194,6 +195,7 @@ public class PassphraseCacheService extends Service { case MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND: throw new KeyNotFoundException(); default: + Log.e(Constants.TAG, "timeout case!"); throw new KeyNotFoundException("should not happen!"); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 23b673bcc..8aa6db28d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -102,7 +102,6 @@ public class KeyListFragment extends LoaderFragment private KeyListAdapter mAdapter; private StickyListHeadersListView mStickyList; private ListAwareSwipeRefreshLayout mSwipeRefreshLayout; -// private Spinner mFilterSpinner; // saves the mode object for multiselect, needed for reset at some point private ActionMode mActionMode = null; @@ -220,15 +219,6 @@ public class KeyListFragment extends LoaderFragment } } - /* - @Override - public void onResume() { - String[] servers = Preferences.getPreferences(getActivity()).getKeyServers(); - mSwipeRefreshLayout.setIsLocked(servers == null || servers.length == 0 || servers[0] == null); - super.onResume(); - } - */ - /** * Define Adapter and Loader on create of Activity */ @@ -237,42 +227,6 @@ public class KeyListFragment extends LoaderFragment public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); -// mFilterSpinner = (Spinner) getActivity().findViewById(R.id.key_list_filter_spinner); - List<String> list = new ArrayList<String>(); - list.add(getString(R.string.key_list_filter_show_certified)); - list.add(getString(R.string.key_list_filter_show_all)); - - ArrayAdapter<String> dataAdapter = new ArrayAdapter<String> - (getActivity(), android.R.layout.simple_spinner_item, list); - - dataAdapter.setDropDownViewResource - (android.R.layout.simple_spinner_dropdown_item); - -// mFilterSpinner.setAdapter(dataAdapter); - -// mFilterSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { -// @Override -// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { -// switch (position) { -// case 0: { -// mShowAllKeys = false; -// getLoaderManager().restartLoader(0, null, KeyListFragment.this); -// break; -// } -// case 1: { -// mShowAllKeys = true; -// getLoaderManager().restartLoader(0, null, KeyListFragment.this); -// break; -// } -// } -// } -// -// @Override -// public void onNothingSelected(AdapterView<?> parent) { -// -// } -// }); - mStickyList.setOnItemClickListener(this); mStickyList.setAreHeadersSticky(true); mStickyList.setDrawingListUnderStickyHeader(false); |