diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-14 16:21:04 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-09-14 16:21:04 +0200 |
commit | 3814ae7d53a22ba89f1e39d7a4661016f76cf8c8 (patch) | |
tree | d83d41d3c424a784da144515665fb41ef650aa52 /OpenKeychain/src/test/java/org/sufficientlysecure | |
parent | dbaf7070ead596f5c70ad48fc55aada2f77a856a (diff) | |
parent | d5dd6a49c8156a699b3fbbbeef06658e1c232c16 (diff) | |
download | open-keychain-3814ae7d53a22ba89f1e39d7a4661016f76cf8c8.tar.gz open-keychain-3814ae7d53a22ba89f1e39d7a4661016f76cf8c8.tar.bz2 open-keychain-3814ae7d53a22ba89f1e39d7a4661016f76cf8c8.zip |
Merge branch 'master' into mime4j
Conflicts:
OpenKeychain/build.gradle
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java
OpenKeychain/src/main/res/values/strings.xml
Diffstat (limited to 'OpenKeychain/src/test/java/org/sufficientlysecure')
7 files changed, 127 insertions, 27 deletions
diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java index 472e4507a..c1aa5a76f 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -127,7 +127,7 @@ public class CertifyOperationTest { ShadowLog.stream = oldShadowStream; providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); - providerHelper.savePublicKeyRing(mStaticRing2.extractPublicKeyRing(), new ProgressScaler()); + providerHelper.savePublicKeyRing(mStaticRing2.extractPublicKeyRing(), new ProgressScaler(), null); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -158,7 +158,7 @@ public class CertifyOperationTest { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), - mStaticRing2.getPublicKey().getUnorderedUserIds())); + mStaticRing2.getPublicKey().getUnorderedUserIds(), null)); CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1)); Assert.assertTrue("certification must succeed", result.success()); @@ -208,7 +208,7 @@ public class CertifyOperationTest { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), - mStaticRing2.getPublicKey().getUnorderedUserIds())); + mStaticRing2.getPublicKey().getUnorderedUserIds(), null)); CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1)); @@ -227,7 +227,7 @@ public class CertifyOperationTest { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); ArrayList<String> uids = new ArrayList<String>(); uids.add("nonexistent"); - actions.add(new CertifyAction(1234L, uids)); + actions.add(new CertifyAction(1234L, uids, null)); CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1)); @@ -240,7 +240,7 @@ public class CertifyOperationTest { { CertifyActionsParcel actions = new CertifyActionsParcel(1234L); actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), - mStaticRing2.getPublicKey().getUnorderedUserIds())); + mStaticRing2.getPublicKey().getUnorderedUserIds(), null)); CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1)); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java index a4854d7b9..e6c8c0efe 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java @@ -98,7 +98,7 @@ public class PromoteKeyOperationTest { // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.savePublicKeyRing(mStaticRing.extractPublicKeyRing(), new ProgressScaler()); + providerHelper.savePublicKeyRing(mStaticRing.extractPublicKeyRing(), new ProgressScaler(), null); // ok NOW log verbosely! ShadowLog.stream = System.out; 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..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; @@ -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); @@ -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); @@ -318,7 +372,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 +400,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 +424,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 +573,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 +602,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 +625,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<Long>()); @@ -594,7 +648,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 +702,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 +729,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 +784,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 +850,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 +873,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) diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java index bb2c1323f..90189e377 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java @@ -304,7 +304,7 @@ public class UncachedKeyringMergeTest { ringB.getEncoded(), false, 0).getSecretKey(); secretKey.unlock(new Passphrase()); PgpCertifyOperation op = new PgpCertifyOperation(); - CertifyAction action = new CertifyAction(pubRing.getMasterKeyId(), publicRing.getPublicKey().getUnorderedUserIds()); + CertifyAction action = new CertifyAction(pubRing.getMasterKeyId(), publicRing.getPublicKey().getUnorderedUserIds(), null); // sign all user ids PgpCertifyResult result = op.certify(secretKey, publicRing, new OperationLog(), 0, action, null, new Date()); Assert.assertTrue("certification must succeed", result.success()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java index 04851ebbb..60cbe098c 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java @@ -201,7 +201,7 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; - result = mProviderHelper.savePublicKeyRing(key, new ProgressScaler()); + result = mProviderHelper.savePublicKeyRing(key, new ProgressScaler(), null); Assert.assertTrue("import of keyring should succeed", result.success()); CanonicalizedPublicKeyRing ring = mProviderHelper.getCanonicalizedPublicKeyRing(keyId); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java index 4ac994c99..262b4da28 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java @@ -59,7 +59,7 @@ public class KeyringTestingHelper { // Should throw an exception; key is not yet saved retrieveKeyAndExpectNotFound(providerHelper, masterKeyId); - SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring, new ProgressScaler()); + SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring, new ProgressScaler(), null); boolean saveSuccess = saveKeyringResult.success(); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/util/KeyFormattingUtilsTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/util/KeyFormattingUtilsTest.java new file mode 100644 index 000000000..44e383d85 --- /dev/null +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/util/KeyFormattingUtilsTest.java @@ -0,0 +1,46 @@ +package org.sufficientlysecure.keychain.util; + + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; +import org.sufficientlysecure.keychain.WorkaroundBuildConfig; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; + + +@RunWith(RobolectricGradleTestRunner.class) +@Config(constants = WorkaroundBuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml") +public class KeyFormattingUtilsTest { + + static final byte[] fp = new byte[] { + (byte) 0xD4, (byte) 0xAB, (byte) 0x19, (byte) 0x29, (byte) 0x64, + (byte) 0xF7, (byte) 0x6A, (byte) 0x7F, (byte) 0x8F, (byte) 0x8A, + (byte) 0x9B, (byte) 0x35, (byte) 0x7B, (byte) 0xD1, (byte) 0x83, + (byte) 0x20, (byte) 0xDE, (byte) 0xAD, (byte) 0xFA, (byte) 0x11 + }; + static final long keyId = 0x7bd18320deadfa11L; + + @Test + public void testStuff() { + Assert.assertEquals(KeyFormattingUtils.convertFingerprintToKeyId(fp), keyId); + + Assert.assertEquals( + "d4ab192964f76a7f8f8a9b357bd18320deadfa11", + KeyFormattingUtils.convertFingerprintToHex(fp) + ); + + Assert.assertEquals( + "0x7bd18320deadfa11", + KeyFormattingUtils.convertKeyIdToHex(keyId) + ); + + Assert.assertEquals( + "0xdeadfa11", + KeyFormattingUtils.convertKeyIdToHexShort(keyId) + ); + + } + +} |