From 7b24ee7b55db99467dd63e631ba55a27d08587d5 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 1 Feb 2015 23:14:26 +0100 Subject: rewrite PgpSignEncrypt data flow - introduce high-level SignEncryptOperation for uri to uri signing/encryption - use SignEncryptParcel for high-level operation parameters - use PgpSignEncryptInput plus streams for low-level operation parameters - get rid of all sign/encrypt logic in KeychainIntentService --- .../keychain/pgp/PgpEncryptDecryptTest.java | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'OpenKeychain-Test/src/test/java') 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 b8205a792..568f04ab8 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 @@ -29,13 +29,12 @@ import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.openpgp.PGPEncryptedData; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; -import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt.Builder; +import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; -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; @@ -132,14 +131,14 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncrypt.Builder(Robolectric.application, + Builder b = new PgpSignEncryptOperation.Builder(Robolectric.application, new ProviderHelper(Robolectric.application), null, data, out); b.setSymmetricPassphrase(mPassphrase); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - SignEncryptResult result = b.build().execute(); + PgpSignEncryptResult result = b.build().execute(); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -211,7 +210,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncrypt.Builder( + Builder b = new PgpSignEncryptOperation.Builder( Robolectric.application, new ProviderHelper(Robolectric.application), null, // new DummyPassphraseCache(mPassphrase, 0L), @@ -219,7 +218,7 @@ public class PgpEncryptDecryptTest { b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - SignEncryptResult result = b.build().execute(); + PgpSignEncryptResult result = b.build().execute(); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -287,7 +286,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncrypt.Builder( + Builder b = new PgpSignEncryptOperation.Builder( Robolectric.application, new ProviderHelper(Robolectric.application), null, // new DummyPassphraseCache(mPassphrase, 0L), @@ -298,7 +297,7 @@ public class PgpEncryptDecryptTest { mStaticRing2.getMasterKeyId() }); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - SignEncryptResult result = b.build().execute(); + PgpSignEncryptResult result = b.build().execute(); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -376,7 +375,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncrypt.Builder( + Builder b = new PgpSignEncryptOperation.Builder( Robolectric.application, new ProviderHelper(Robolectric.application), null, // new DummyPassphraseCache(mPassphrase, 0L), @@ -390,7 +389,7 @@ public class PgpEncryptDecryptTest { b.setSignatureSubKeyId(KeyringTestingHelper.getSubkeyId(mStaticRing1, 1)); b.setSignaturePassphrase(mKeyPhrase1); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - SignEncryptResult result = b.build().execute(); + PgpSignEncryptResult result = b.build().execute(); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -454,7 +453,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaindata); InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncrypt.Builder( + Builder b = new PgpSignEncryptOperation.Builder( Robolectric.application, new ProviderHelper(Robolectric.application), null, // new DummyPassphraseCache(mPassphrase, 0L), @@ -465,7 +464,7 @@ public class PgpEncryptDecryptTest { // this only works with ascii armored output! b.setEnableAsciiArmorOutput(true); b.setCharset("iso-2022-jp"); - SignEncryptResult result = b.build().execute(); + PgpSignEncryptResult result = b.build().execute(); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); -- cgit v1.2.3 From d125149bf77769c45c9c896e4475b04ed444e5cd Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 2 Feb 2015 12:29:37 +0100 Subject: fix tests for new PgpSignEncryptInput --- .../keychain/pgp/PgpEncryptDecryptTest.java | 58 +++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'OpenKeychain-Test/src/test/java') 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 568f04ab8..ba7a31e65 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 @@ -130,15 +130,17 @@ public class PgpEncryptDecryptTest { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, + new ProviderHelper(Robolectric.application), null); + InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncryptOperation.Builder(Robolectric.application, - new ProviderHelper(Robolectric.application), - null, - data, out); + PgpSignEncryptInput b = new PgpSignEncryptInput(); b.setSymmetricPassphrase(mPassphrase); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = b.build().execute(); + + PgpSignEncryptResult result = op.execute(b, data, out); + Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -209,16 +211,15 @@ public class PgpEncryptDecryptTest { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, + new ProviderHelper(Robolectric.application), null); + InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncryptOperation.Builder( - Robolectric.application, - new ProviderHelper(Robolectric.application), - null, // new DummyPassphraseCache(mPassphrase, 0L), - data, out); + PgpSignEncryptInput b = new PgpSignEncryptInput(); b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = b.build().execute(); + PgpSignEncryptResult result = op.execute(b, data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -285,19 +286,19 @@ public class PgpEncryptDecryptTest { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, + new ProviderHelper(Robolectric.application), null); + InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncryptOperation.Builder( - Robolectric.application, - new ProviderHelper(Robolectric.application), - null, // new DummyPassphraseCache(mPassphrase, 0L), - data, out); + PgpSignEncryptInput b = new PgpSignEncryptInput(); b.setEncryptionMasterKeyIds(new long[] { mStaticRing1.getMasterKeyId(), mStaticRing2.getMasterKeyId() }); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = b.build().execute(); + + PgpSignEncryptResult result = op.execute(b, data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -374,12 +375,11 @@ public class PgpEncryptDecryptTest { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, + new ProviderHelper(Robolectric.application), null); + InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncryptOperation.Builder( - Robolectric.application, - new ProviderHelper(Robolectric.application), - null, // new DummyPassphraseCache(mPassphrase, 0L), - data, out); + PgpSignEncryptInput b = new PgpSignEncryptInput(); b.setEncryptionMasterKeyIds(new long[] { mStaticRing1.getMasterKeyId(), @@ -389,7 +389,8 @@ public class PgpEncryptDecryptTest { b.setSignatureSubKeyId(KeyringTestingHelper.getSubkeyId(mStaticRing1, 1)); b.setSignaturePassphrase(mKeyPhrase1); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = b.build().execute(); + + PgpSignEncryptResult result = op.execute(b, data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -452,19 +453,18 @@ public class PgpEncryptDecryptTest { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(plaindata); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, + new ProviderHelper(Robolectric.application), null); + InputData data = new InputData(in, in.available()); - Builder b = new PgpSignEncryptOperation.Builder( - Robolectric.application, - new ProviderHelper(Robolectric.application), - null, // new DummyPassphraseCache(mPassphrase, 0L), - data, out); + PgpSignEncryptInput b = new PgpSignEncryptInput(); b.setEncryptionMasterKeyIds(new long[]{ mStaticRing1.getMasterKeyId() }); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); // this only works with ascii armored output! b.setEnableAsciiArmorOutput(true); b.setCharset("iso-2022-jp"); - PgpSignEncryptResult result = b.build().execute(); + PgpSignEncryptResult result = op.execute(b, data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); -- cgit v1.2.3