diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-10 21:38:37 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-10 21:38:37 +0200 |
commit | cb067f748b0e07e7e96e5e04fc3d8e1ff74ceb45 (patch) | |
tree | 2778b2ade656f1639c699f89c74379ec688f8827 /OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp | |
parent | cb9a66e2463768342415e36648a57f27ff797f99 (diff) | |
download | open-keychain-cb067f748b0e07e7e96e5e04fc3d8e1ff74ceb45.tar.gz open-keychain-cb067f748b0e07e7e96e5e04fc3d8e1ff74ceb45.tar.bz2 open-keychain-cb067f748b0e07e7e96e5e04fc3d8e1ff74ceb45.zip |
add test for signed binary data (#1507)
Diffstat (limited to 'OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp')
-rw-r--r-- | OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java | 56 |
1 files changed, 55 insertions, 1 deletions
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; @@ -287,6 +287,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() { String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); |