diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-09-23 14:53:44 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-09-23 14:53:44 +0200 |
commit | 675e8e2015000ae406758436628a5c9f67212e8b (patch) | |
tree | 7f5a20c354684927f1d60d51b2273a59e337ae17 /OpenKeychain-Test | |
parent | 9d9d71f3db93302483f1142851462b989270abd8 (diff) | |
download | open-keychain-675e8e2015000ae406758436628a5c9f67212e8b.tar.gz open-keychain-675e8e2015000ae406758436628a5c9f67212e8b.tar.bz2 open-keychain-675e8e2015000ae406758436628a5c9f67212e8b.zip |
add test case to make sure s2k IVs are different per subkey
Diffstat (limited to 'OpenKeychain-Test')
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java index de8ab1693..6a1caa0db 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java @@ -54,9 +54,11 @@ import org.sufficientlysecure.keychain.util.TestingUtils; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.ByteBuffer; import java.security.Security; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -924,6 +926,23 @@ public class PgpKeyOperationTest { parcel.mNewPassphrase = otherPassphrase; modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB, ""); + Assert.assertEquals("exactly three packets should have been modified (the secret keys)", + 3, onlyB.size()); + + { // quick check to make sure no two secret keys have the same IV + HashSet<ByteBuffer> ivs = new HashSet<ByteBuffer>(); + for (int i = 0; i < 3; i++) { + SecretKeyPacket p = (SecretKeyPacket) new BCPGInputStream( + new ByteArrayInputStream(onlyB.get(i).buf)).readPacket(); + ByteBuffer iv = ByteBuffer.wrap(p.getIV()); + Assert.assertFalse( + "no two secret keys should have the same s2k iv (slightly non-deterministic!)", + ivs.contains(iv) + ); + ivs.add(iv); + } + } + RawPacket sKeyWithPassphrase = onlyB.get(1); Assert.assertEquals("extracted packet should be a secret subkey", PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag); |