From d26379da3a4379ad260f3e68bf264d7a3530e376 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 30 Jun 2015 16:28:55 +0200 Subject: make timeout method in PassphraseCacheService more robust against nullpointers --- .../keychain/service/PassphraseCacheService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'OpenKeychain/src') 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 a0b470add..7c0b7eaef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -459,11 +459,16 @@ public class PassphraseCacheService extends Service { * Called when one specific passphrase for keyId timed out */ private void timeout(long keyId) { + CachedPassphrase cPass = mPassphraseCache.get(keyId); - // clean internal char[] from memory! - cPass.getPassphrase().removeFromMemory(); - // remove passphrase object - mPassphraseCache.remove(keyId); + if (cPass != null) { + if (cPass.getPassphrase() != null) { + // clean internal char[] from memory! + cPass.getPassphrase().removeFromMemory(); + } + // remove passphrase object + mPassphraseCache.remove(keyId); + } Log.d(Constants.TAG, "PassphraseCacheService Timeout of keyId " + keyId + ", removed from memory!"); -- cgit v1.2.3 From 440797311086869b054a221668da22d06a78f86a Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 30 Jun 2015 16:40:00 +0200 Subject: small layout fix in EncryptTextFragment --- OpenKeychain/src/main/res/layout/encrypt_text_fragment.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src') diff --git a/OpenKeychain/src/main/res/layout/encrypt_text_fragment.xml b/OpenKeychain/src/main/res/layout/encrypt_text_fragment.xml index 7645918f4..13b85dd88 100644 --- a/OpenKeychain/src/main/res/layout/encrypt_text_fragment.xml +++ b/OpenKeychain/src/main/res/layout/encrypt_text_fragment.xml @@ -6,15 +6,16 @@ -- cgit v1.2.3 From f29d8351bad70b3c3aa80f899c3a90030bd67e17 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 30 Jun 2015 17:10:28 +0200 Subject: instrument: add filesize check to text encryption test --- .../keychain/ui/AsymmetricTextOperationTests.java | 33 ++++------------------ 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'OpenKeychain/src') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java index 6b226142c..cb3d2cb17 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java @@ -32,15 +32,14 @@ import org.junit.runner.RunWith; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.util.Notify.Style; +import org.sufficientlysecure.keychain.util.FileHelper; import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.pressBack; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.typeText; -import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist; import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.contrib.DrawerActions.openDrawer; import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant; import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA; @@ -115,33 +114,13 @@ public class AsymmetricTextOperationTests { onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); onView(withText(R.string.btn_unlock)).perform(click()); - onView(isRecyclerItemView(R.id.decrypted_files_list, hasDescendant(withText(R.string.filename_unknown_text)))) - .check(matches(allOf(withEncryptionStatus(true), withSignatureNone()))); - - } - - } - - @Test - public void testTextEncryptDecryptFromKeyView() throws Exception { - - String cleartext = randomString(10, 30); - - pressBack(); - - { // encrypt - - // navigate to edit key dialog - onData(withKeyItemId(0x9D604D2F310716A3L)) - .inAdapterView(allOf(isAssignableFrom(AdapterView.class), - isDescendantOfA(withId(R.id.key_list_list)))) - .perform(click()); - onView(withId(R.id.view_key_action_encrypt_text)).perform(click()); - - // make sure the encrypt is correctly set - onView(withId(R.id.result_encryption_icon)).check(matches(withDisplayedChild(1))); + .check(matches(allOf( + hasDescendant(withText(FileHelper.readableFileSize(cleartext.length()))), + withEncryptionStatus(true), + withSignatureNone() + ))); } -- cgit v1.2.3