From 7a98ffc90a34a381a68c5b485183373ed307320a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 27 Aug 2015 12:34:54 +0200 Subject: Remove dead code --- .../keychain/pgp/PgpEncryptDecryptTest.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java') diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index cd6f115ec..041b660c2 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -196,7 +196,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application, + PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, new ProviderHelper(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); @@ -226,7 +226,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application, + PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, new ProviderHelper(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); @@ -248,7 +248,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application, + PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, new ProviderHelper(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); @@ -269,7 +269,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application, + PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, new ProviderHelper(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(false); @@ -318,7 +318,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache(null, null, null); + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out); @@ -346,7 +346,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( mKeyPhrase1, mStaticRing1.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out); @@ -370,7 +370,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( null, mStaticRing1.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out); @@ -519,7 +519,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( mKeyPhrase1, mStaticRing1.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out); @@ -548,7 +548,7 @@ public class PgpEncryptDecryptTest { allowed.add(mStaticRing2.getMasterKeyId()); // provide passphrase for the second, and check that the first is never asked for! - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( mKeyPhrase2, mStaticRing2.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowedKeyIds(allowed); @@ -571,7 +571,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); // provide passphrase for the second, and check that the first is never asked for! - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( mKeyPhrase2, mStaticRing2.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowedKeyIds(new HashSet()); @@ -594,7 +594,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( mKeyPhrase2, mStaticRing2.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out); @@ -648,7 +648,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( mKeyPhrase1, mStaticRing1.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out); @@ -675,7 +675,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache( + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache( mKeyPhrase2, mStaticRing2.getMasterKeyId(), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out); @@ -730,7 +730,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache(null, null, null); + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out); @@ -796,7 +796,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); InputData data = new InputData(in, in.available()); - PgpDecryptVerify op = operationWithFakePassphraseCache(null, null, null); + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(passphrase), data, out); @@ -819,10 +819,10 @@ public class PgpEncryptDecryptTest { } } - private PgpDecryptVerify operationWithFakePassphraseCache( + private PgpDecryptVerifyOperation operationWithFakePassphraseCache( final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { - return new PgpDecryptVerify(RuntimeEnvironment.application, + return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, new ProviderHelper(RuntimeEnvironment.application), null) { @Override public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) -- cgit v1.2.3 From cb067f748b0e07e7e96e5e04fc3d8e1ff74ceb45 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 10 Sep 2015 21:38:37 +0200 Subject: add test for signed binary data (#1507) --- .../keychain/pgp/PgpEncryptDecryptTest.java | 56 +++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java') diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 041b660c2..727464429 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -23,9 +23,9 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.security.Security; import java.util.ArrayList; +import java.util.Date; import java.util.HashSet; import java.util.Iterator; -import java.util.Date; import org.junit.Assert; import org.junit.Before; @@ -286,6 +286,60 @@ public class PgpEncryptDecryptTest { } + @Test + public void testAsymmetricSign() { + + String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); + byte[] ciphertext; + + { // encrypt data with key + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); + + PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, + new ProviderHelper(RuntimeEnvironment.application), null); + + InputData data = new InputData(in, in.available()); + PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(); + + // only sign, and not as cleartext + input.setSignatureMasterKeyId(mStaticRing1.getMasterKeyId()); + input.setSignatureSubKeyId(KeyringTestingHelper.getSubkeyId(mStaticRing1, 1)); + input.setCleartextSignature(false); + input.setDetachedSignature(false); + + PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out); + Assert.assertTrue("signing must succeed", result.success()); + + ciphertext = out.toByteArray(); + } + + { // verification should succeed + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); + InputData data = new InputData(in, in.available()); + + PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null); + PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); + DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out); + + Assert.assertTrue("verification must succeed", result.success()); + Assert.assertArrayEquals("verification text should equal plaintext", + out.toByteArray(), plaintext.getBytes()); + Assert.assertEquals("decryptionResult should be RESULT_NOT_ENCRYPTED", + OpenPgpDecryptionResult.RESULT_NOT_ENCRYPTED, result.getDecryptionResult().getResult()); + Assert.assertEquals("signatureResult should be RESULT_VALID_CONFIRMED", + OpenPgpSignatureResult.RESULT_VALID_CONFIRMED, result.getSignatureResult().getResult()); + + OpenPgpMetadata metadata = result.getDecryptionMetadata(); + Assert.assertEquals("filesize must be correct", + out.toByteArray().length, metadata.getOriginalSize()); + + } + + } + @Test public void testAsymmetricEncryptDecrypt() { -- cgit v1.2.3