diff options
Diffstat (limited to 'OpenKeychain/src/test/java')
6 files changed, 190 insertions, 47 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 6984f126e..472e4507a 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -52,6 +52,7 @@ import org.sufficientlysecure.keychain.util.TestingUtils; import java.io.PrintStream; import java.security.Security; import java.util.ArrayList; +import java.util.Date; import java.util.Random; @RunWith(RobolectricGradleTestRunner.class) @@ -158,7 +159,7 @@ public class CertifyOperationTest { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), mStaticRing2.getPublicKey().getUnorderedUserIds())); - CertifyResult result = op.execute(actions, new CryptoInputParcel(mKeyPhrase1)); + CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1)); Assert.assertTrue("certification must succeed", result.success()); @@ -186,7 +187,7 @@ public class CertifyOperationTest { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), null, mStaticRing2.getPublicKey().getUnorderedUserAttributes())); - CertifyResult result = op.execute(actions, new CryptoInputParcel(mKeyPhrase1)); + CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1)); Assert.assertTrue("certification must succeed", result.success()); @@ -209,7 +210,7 @@ public class CertifyOperationTest { actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), mStaticRing2.getPublicKey().getUnorderedUserIds())); - CertifyResult result = op.execute(actions, new CryptoInputParcel(mKeyPhrase1)); + CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1)); Assert.assertFalse("certification with itself must fail!", result.success()); Assert.assertTrue("error msg must be about self certification", @@ -228,7 +229,8 @@ public class CertifyOperationTest { uids.add("nonexistent"); actions.add(new CertifyAction(1234L, uids)); - CertifyResult result = op.execute(actions, new CryptoInputParcel(mKeyPhrase1)); + CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), + mKeyPhrase1)); Assert.assertFalse("certification of nonexistent key must fail", result.success()); Assert.assertTrue("must contain error msg about not found", @@ -240,7 +242,8 @@ public class CertifyOperationTest { actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), mStaticRing2.getPublicKey().getUnorderedUserIds())); - CertifyResult result = op.execute(actions, new CryptoInputParcel(mKeyPhrase1)); + CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), + mKeyPhrase1)); Assert.assertFalse("certification of nonexistent key must fail", result.success()); Assert.assertTrue("must contain error msg about not found", 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 4eaee4c48..a4854d7b9 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java @@ -17,21 +17,23 @@ package org.sufficientlysecure.keychain.operations; + +import java.io.PrintStream; +import java.security.Security; +import java.util.Iterator; + import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.Robolectric; import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowLog; import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.util.encoders.Hex; -import org.sufficientlysecure.keychain.BuildConfig; import org.sufficientlysecure.keychain.WorkaroundBuildConfig; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult; @@ -43,6 +45,7 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel; @@ -51,10 +54,6 @@ import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.TestingUtils; -import java.io.PrintStream; -import java.security.Security; -import java.util.Iterator; - @RunWith(RobolectricGradleTestRunner.class) @Config(constants = WorkaroundBuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml") public class PromoteKeyOperationTest { @@ -110,7 +109,7 @@ public class PromoteKeyOperationTest { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, new ProviderHelper(RuntimeEnvironment.application), null, null); - PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId(), null, null); + PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null); Assert.assertTrue("promotion must succeed", result.success()); @@ -136,7 +135,7 @@ public class PromoteKeyOperationTest { byte[] aid = Hex.decode("D2760001240102000000012345670000"); - PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId(), aid, null); + PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), aid, null), null); Assert.assertTrue("promotion must succeed", result.success()); @@ -164,9 +163,9 @@ public class PromoteKeyOperationTest { // only promote the first, rest stays dummy long keyId = KeyringTestingHelper.getSubkeyId(mStaticRing, 1); - PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId(), aid, new long[] { + PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), aid, new long[] { keyId - }); + }), null); Assert.assertTrue("promotion must succeed", result.success()); 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 9c3636d07..edd7880fc 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -17,6 +17,16 @@ package org.sufficientlysecure.keychain.pgp; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.security.Security; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Date; + import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -24,14 +34,19 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpSignatureResult; -import org.robolectric.*; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowLog; +import org.spongycastle.bcpg.BCPGInputStream; +import org.spongycastle.bcpg.Packet; +import org.spongycastle.bcpg.PacketTags; +import org.spongycastle.bcpg.PublicKeyEncSessionPacket; import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.openpgp.PGPEncryptedData; -import org.sufficientlysecure.keychain.BuildConfig; import org.sufficientlysecure.keychain.WorkaroundBuildConfig; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; @@ -39,21 +54,19 @@ 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.service.SaveKeyringParcel.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType; import org.sufficientlysecure.keychain.support.KeyringTestingHelper; +import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.TestingUtils; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.security.Security; -import java.util.HashSet; +import static org.hamcrest.core.AnyOf.anyOf; +import static org.hamcrest.core.Is.is; + @RunWith(RobolectricGradleTestRunner.class) @Config(constants = WorkaroundBuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml") @@ -83,6 +96,8 @@ public class PgpEncryptDecryptTest { Algorithm.DSA, 1024, null, KeyFlags.SIGN_DATA, 0L)); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( Algorithm.ELGAMAL, 1024, null, KeyFlags.ENCRYPT_COMMS, 0L)); + parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( + Algorithm.RSA, 1024, null, KeyFlags.ENCRYPT_COMMS, 0L)); parcel.mAddUserIds.add("bloom"); parcel.mNewUnlock = new ChangeUnlockParcel(mKeyPhrase1); @@ -146,7 +161,8 @@ public class PgpEncryptDecryptTest { b.setSymmetricPassphrase(mPassphrase); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(), data, out); + PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(new Date()), + data, out); Assert.assertTrue("encryption must succeed", result.success()); @@ -255,7 +271,8 @@ public class PgpEncryptDecryptTest { input.setEncryptionMasterKeyIds(new long[] { mStaticRing1.getMasterKeyId() }); input.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(), data, out); + PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(new Date()), + data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -327,6 +344,104 @@ public class PgpEncryptDecryptTest { } @Test + public void testAsymmetricMultiSubkeyEncrypt() throws Exception { + + String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); + + { // encrypt data with key + byte[] ciphertext; + + 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(); + + input.setEncryptionMasterKeyIds(new long[] { mStaticRing1.getMasterKeyId() }); + input.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); + PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(new Date()), + data, out); + Assert.assertTrue("encryption must succeed", result.success()); + + ciphertext = out.toByteArray(); + + Iterator<RawPacket> packets = KeyringTestingHelper.parseKeyring(ciphertext); + + RawPacket enc1 = packets.next(), enc2 = packets.next(); + Assert.assertEquals("last packet must be encrypted data packet", + PacketTags.SYM_ENC_INTEGRITY_PRO, packets.next().tag); + Assert.assertFalse("no further packets", packets.hasNext()); + + Packet p; + p = new BCPGInputStream(new ByteArrayInputStream(enc1.buf)).readPacket(); + Assert.assertTrue("first packet must be session packet", p instanceof PublicKeyEncSessionPacket); + long encKeyId1 = ((PublicKeyEncSessionPacket) p).getKeyID(); + + p = new BCPGInputStream(new ByteArrayInputStream(enc2.buf)).readPacket(); + Assert.assertTrue("second packet must be session packet", p instanceof PublicKeyEncSessionPacket); + long encKeyId2 = ((PublicKeyEncSessionPacket) p).getKeyID(); + + Assert.assertNotEquals("encrypted-to subkey ids must not be equal", + encKeyId1, encKeyId2); + Assert.assertThat("first packet must be encrypted to one of the subkeys", + KeyringTestingHelper.getSubkeyId(mStaticRing1, 2), anyOf(is(encKeyId1), is(encKeyId2))); + Assert.assertThat("second packet must be encrypted to one of the subkeys", + KeyringTestingHelper.getSubkeyId(mStaticRing1, 3), anyOf(is(encKeyId1), is(encKeyId2))); + + } + + { // revoke first encryption subkey of keyring in database + SaveKeyringParcel parcel = new SaveKeyringParcel(mStaticRing1.getMasterKeyId(), mStaticRing1.getFingerprint()); + parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(mStaticRing1, 2)); + UncachedKeyRing modified = PgpKeyOperationTest.applyModificationWithChecks(parcel, mStaticRing1, + new ArrayList<RawPacket>(), new ArrayList<RawPacket>(), + new CryptoInputParcel(new Date(), mKeyPhrase1)); + + ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + providerHelper.saveSecretKeyRing(modified, new ProgressScaler()); + } + + { // encrypt to this keyring, make sure it's not encrypted to the revoked subkey + byte[] ciphertext; + + 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(); + + input.setEncryptionMasterKeyIds(new long[] { mStaticRing1.getMasterKeyId() }); + input.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); + PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(new Date()), + data, out); + Assert.assertTrue("encryption must succeed", result.success()); + + ciphertext = out.toByteArray(); + + Iterator<RawPacket> packets = KeyringTestingHelper.parseKeyring(ciphertext); + + RawPacket enc1 = packets.next(); + Assert.assertEquals("last packet must be encrypted data packet", + PacketTags.SYM_ENC_INTEGRITY_PRO, packets.next().tag); + Assert.assertFalse("no further packets", packets.hasNext()); + + Packet p; + p = new BCPGInputStream(new ByteArrayInputStream(enc1.buf)).readPacket(); + Assert.assertTrue("first packet must be session packet", p instanceof PublicKeyEncSessionPacket); + Assert.assertEquals("first packet must be encrypted to second enc subkey", + KeyringTestingHelper.getSubkeyId(mStaticRing1, 3), ((PublicKeyEncSessionPacket) p).getKeyID()); + + } + + } + + @Test public void testMultiAsymmetricEncryptDecrypt() { String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); @@ -348,7 +463,8 @@ public class PgpEncryptDecryptTest { }); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(), data, out); + PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(new Date()), + data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -466,7 +582,8 @@ public class PgpEncryptDecryptTest { b.setSignatureSubKeyId(KeyringTestingHelper.getSubkeyId(mStaticRing1, 1)); b.setSymmetricEncryptionAlgorithm(PGPEncryptedData.AES_128); - PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(mKeyPhrase1), data, out); + PgpSignEncryptResult result = op.execute(b, + new CryptoInputParcel(new Date(), mKeyPhrase1), data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); @@ -546,7 +663,8 @@ public class PgpEncryptDecryptTest { // this only works with ascii armored output! b.setEnableAsciiArmorOutput(true); b.setCharset("iso-2022-jp"); - PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(), data, out); + PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(new Date()), + data, out); Assert.assertTrue("encryption must succeed", result.success()); ciphertext = out.toByteArray(); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java index fcb458fbe..c0e28cd4b 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java @@ -94,11 +94,11 @@ public class PgpKeyOperationTest { SaveKeyringParcel parcel = new SaveKeyringParcel(); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( - Algorithm.RSA, 1024, null, KeyFlags.CERTIFY_OTHER, 0L)); + Algorithm.DSA, 1024, null, KeyFlags.CERTIFY_OTHER, 0L)); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( - Algorithm.DSA, 1024, null, KeyFlags.SIGN_DATA, 0L)); + Algorithm.RSA, 2048, null, KeyFlags.SIGN_DATA, 0L)); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( - Algorithm.RSA, 2048, null, KeyFlags.ENCRYPT_COMMS, 0L)); + Algorithm.RSA, 1024, null, KeyFlags.ENCRYPT_COMMS, 0L)); parcel.mAddUserIds.add("twi"); parcel.mAddUserIds.add("pink"); @@ -821,6 +821,15 @@ public class PgpKeyOperationTest { Assert.assertEquals("new packet should have GNU_DUMMY protection mode stripped", S2K.GNU_PROTECTION_MODE_NO_PRIVATE_KEY, ((SecretKeyPacket) p).getS2K().getProtectionMode()); } + + { // trying to edit a subkey with signing capability should fail + parcel.reset(); + parcel.mChangeSubKeys.add(new SubkeyChange(keyId, true)); + + assertModifyFailure("subkey modification for signing-enabled but stripped subkey should fail", + modified, parcel, LogType.MSG_MF_ERROR_SUB_STRIPPED); + } + } @Test @@ -829,7 +838,7 @@ public class PgpKeyOperationTest { UncachedKeyRing modified; { // keytocard should fail with BAD_NFC_SIZE when presented with the RSA-1024 key - long keyId = KeyringTestingHelper.getSubkeyId(ring, 0); + long keyId = KeyringTestingHelper.getSubkeyId(ring, 2); parcel.reset(); parcel.mChangeSubKeys.add(new SubkeyChange(keyId, false, true)); @@ -838,7 +847,7 @@ public class PgpKeyOperationTest { } { // keytocard should fail with BAD_NFC_ALGO when presented with the DSA-1024 key - long keyId = KeyringTestingHelper.getSubkeyId(ring, 1); + long keyId = KeyringTestingHelper.getSubkeyId(ring, 0); parcel.reset(); parcel.mChangeSubKeys.add(new SubkeyChange(keyId, false, true)); @@ -846,9 +855,10 @@ public class PgpKeyOperationTest { parcel, cryptoInput, LogType.MSG_MF_ERROR_BAD_NFC_ALGO); } + long keyId = KeyringTestingHelper.getSubkeyId(ring, 1); + { // keytocard should return a pending NFC_MOVE_KEY_TO_CARD result when presented with the RSA-2048 // key, and then make key divert-to-card when it gets a serial in the cryptoInputParcel. - long keyId = KeyringTestingHelper.getSubkeyId(ring, 2); parcel.reset(); parcel.mChangeSubKeys.add(new SubkeyChange(keyId, false, true)); @@ -880,7 +890,19 @@ public class PgpKeyOperationTest { S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD, ((SecretKeyPacket) p).getS2K().getProtectionMode()); Assert.assertArrayEquals("new packet should have correct serial number as iv", serial, ((SecretKeyPacket) p).getIV()); + } + + { // editing a signing subkey requires a primary key binding sig -> pendinginput + parcel.reset(); + parcel.mChangeSubKeys.add(new SubkeyChange(keyId, true)); + CanonicalizedSecretKeyRing secretRing = + new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0); + PgpKeyOperation op = new PgpKeyOperation(null); + PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcel); + Assert.assertTrue("keytocard operation should be pending", result.isPending()); + Assert.assertEquals("required input should be RequiredInputType.NFC_SIGN", + RequiredInputType.NFC_SIGN, result.getRequiredInputParcel().mType); } } @@ -1240,14 +1262,14 @@ public class PgpKeyOperationTest { Assert.assertFalse("non-restricted operations should fail without passphrase", result.success()); } - private static UncachedKeyRing applyModificationWithChecks(SaveKeyringParcel parcel, + public static UncachedKeyRing applyModificationWithChecks(SaveKeyringParcel parcel, UncachedKeyRing ring, ArrayList<RawPacket> onlyA, ArrayList<RawPacket> onlyB) { return applyModificationWithChecks(parcel, ring, onlyA, onlyB, cryptoInput, true, true); } - private static UncachedKeyRing applyModificationWithChecks(SaveKeyringParcel parcel, + public static UncachedKeyRing applyModificationWithChecks(SaveKeyringParcel parcel, UncachedKeyRing ring, ArrayList<RawPacket> onlyA, ArrayList<RawPacket> onlyB, @@ -1256,7 +1278,7 @@ public class PgpKeyOperationTest { } // applies a parcel modification while running some integrity checks - private static UncachedKeyRing applyModificationWithChecks(SaveKeyringParcel parcel, + public static UncachedKeyRing applyModificationWithChecks(SaveKeyringParcel parcel, UncachedKeyRing ring, ArrayList<RawPacket> onlyA, ArrayList<RawPacket> onlyB, diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java index 0143ae289..a0f3b6be6 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java @@ -554,12 +554,13 @@ public class UncachedKeyringCanonicalizeTest { CanonicalizedSecretKey masterSecretKey = canonicalized.getSecretKey(); masterSecretKey.unlock(new Passphrase()); PGPPublicKey masterPublicKey = masterSecretKey.getPublicKey(); - CryptoInputParcel cryptoInput = new CryptoInputParcel(); + CryptoInputParcel cryptoInput = new CryptoInputParcel(new Date()); PGPSignature cert = PgpKeyOperation.generateSubkeyBindingSignature( PgpKeyOperation.getSignatureGenerator(masterSecretKey.getSecretKey(), cryptoInput), cryptoInput.getSignatureTime(), - masterPublicKey, masterSecretKey.getPrivateKey(), masterSecretKey.getPrivateKey(), - masterPublicKey, masterSecretKey.getKeyUsage(), 0); + masterPublicKey, masterSecretKey.getPrivateKey(), + PgpKeyOperation.getSignatureGenerator(masterSecretKey.getSecretKey(), null), + masterSecretKey.getPrivateKey(), masterPublicKey, masterSecretKey.getKeyUsage(), 0); PGPPublicKey subPubKey = PGPPublicKey.addSubkeyBindingCertification(masterPublicKey, cert); PGPSecretKey sKey; 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 cc5c487bd..6755431d0 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java @@ -194,11 +194,11 @@ public class UncachedKeyringMergeTest { parcel.reset(); parcel.mAddUserIds.add("flim"); - modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Passphrase()), parcel).getRing(); + modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); parcel.reset(); parcel.mAddUserIds.add("flam"); - modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Passphrase()), parcel).getRing(); + modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); } { // merge A into base @@ -235,8 +235,8 @@ public class UncachedKeyringMergeTest { parcel.reset(); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( Algorithm.RSA, 1024, null, KeyFlags.SIGN_DATA, 0L)); - modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Passphrase()), parcel).getRing(); - modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Passphrase()), parcel).getRing(); + modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); + modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); subKeyIdA = KeyringTestingHelper.getSubkeyId(modifiedA, 2); subKeyIdB = KeyringTestingHelper.getSubkeyId(modifiedB, 2); @@ -277,7 +277,7 @@ public class UncachedKeyringMergeTest { parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(ringA, 1)); CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing( ringA.getEncoded(), false, 0); - modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Passphrase()), parcel).getRing(); + modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); } { @@ -376,7 +376,7 @@ public class UncachedKeyringMergeTest { CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing( ringA.getEncoded(), false, 0); - modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Passphrase()), parcel).getRing(); + modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); } { |