aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain-Test
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-01-02 02:50:14 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-01-02 02:50:14 +0100
commit9cf800bcd8870961acc1719fc56f5e8dab21d0a3 (patch)
treedbef4d5089d545adcb27ca5da01cf7d5a574edfd /OpenKeychain-Test
parent920fbdfb427877d89d9a6bcf62b6dc9fba846c2e (diff)
downloadopen-keychain-9cf800bcd8870961acc1719fc56f5e8dab21d0a3.tar.gz
open-keychain-9cf800bcd8870961acc1719fc56f5e8dab21d0a3.tar.bz2
open-keychain-9cf800bcd8870961acc1719fc56f5e8dab21d0a3.zip
tests: add multiple keys with signature test case
Diffstat (limited to 'OpenKeychain-Test')
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java75
1 files changed, 75 insertions, 0 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 8d0c4ab80..d03375a61 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
@@ -22,6 +22,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.openintents.openpgp.OpenPgpSignatureResult;
import org.robolectric.*;
import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.sig.KeyFlags;
@@ -36,6 +37,7 @@ import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
+import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.ProgressScaler;
import org.sufficientlysecure.keychain.util.TestingUtils;
@@ -363,6 +365,79 @@ public class PgpEncryptDecryptTest {
}
+ @Test
+ public void testMultiAsymmetricSignEncryptDecryptVerify() {
+
+ String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true);
+ byte[] ciphertext;
+
+ { // encrypt data with a given passphrase
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
+
+ InputData data = new InputData(in, in.available());
+ Builder b = new PgpSignEncrypt.Builder(
+ Robolectric.application,
+ new ProviderHelper(Robolectric.application),
+ null, // new DummyPassphraseCache(mPassphrase, 0L),
+ data, out);
+
+ b.setEncryptionMasterKeyIds(new long[] {
+ mStaticRing1.getMasterKeyId(),
+ mStaticRing2.getMasterKeyId()
+ });
+ b.setSignatureMasterKeyId(mStaticRing1.getMasterKeyId());
+ b.setSignatureSubKeyId(KeyringTestingHelper.getSubkeyId(mStaticRing1, 1));
+ b.setSignaturePassphrase(mKeyPhrase1);
+ b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128);
+ SignEncryptResult result = b.build().execute();
+ Assert.assertTrue("encryption must succeed", result.success());
+
+ ciphertext = out.toByteArray();
+ }
+
+ { // decryption with passphrase cached should succeed for the first key
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
+ InputData data = new InputData(in, in.available());
+
+ PgpDecryptVerify.Builder b = builderWithFakePassphraseCache(data, out,
+ mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
+
+ DecryptVerifyResult result = b.build().execute();
+ Assert.assertTrue("decryption with cached passphrase must succeed for the first key", result.success());
+ Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
+ out.toByteArray(), plaintext.getBytes());
+ Assert.assertEquals("signature should be verified and certified",
+ OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED, result.getSignatureResult().getStatus());
+ }
+
+ { // decryption with passphrase cached should succeed for the other key if first is gone
+
+ // delete first key from database
+ new ProviderHelper(Robolectric.application).getContentResolver().delete(
+ KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
+ );
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
+ InputData data = new InputData(in, in.available());
+
+ PgpDecryptVerify.Builder b = builderWithFakePassphraseCache(data, out,
+ mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
+
+ 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.assertEquals("signature key should be missing",
+ OpenPgpSignatureResult.SIGNATURE_KEY_MISSING,
+ result.getSignatureResult().getStatus());
+ }
+
+ }
+
private PgpDecryptVerify.Builder builderWithFakePassphraseCache (
InputData data, OutputStream out,
final String passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) {