mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
add test case to make sure s2k IVs are different per subkey
This commit is contained in:
parent
9d9d71f3db
commit
675e8e2015
@ -54,9 +54,11 @@ import org.sufficientlysecure.keychain.util.TestingUtils;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -924,6 +926,23 @@ public class PgpKeyOperationTest {
|
|||||||
parcel.mNewPassphrase = otherPassphrase;
|
parcel.mNewPassphrase = otherPassphrase;
|
||||||
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB, "");
|
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);
|
RawPacket sKeyWithPassphrase = onlyB.get(1);
|
||||||
Assert.assertEquals("extracted packet should be a secret subkey",
|
Assert.assertEquals("extracted packet should be a secret subkey",
|
||||||
PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag);
|
PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag);
|
||||||
|
Loading…
Reference in New Issue
Block a user