From d4c1b781db6198fc8a99b29173d872d418032a67 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sat, 12 Jul 2014 01:28:27 +0200 Subject: test: add algorithm choice tests --- .../keychain/tests/PgpKeyOperationTest.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java') diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java index 0cf16843a..e866e77c0 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java @@ -68,6 +68,8 @@ public class PgpKeyOperationTest { OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog(); staticRing = op.createSecretKeyRing(parcel, log, 0); + Assert.assertNotNull("initial test key creation must succeed", staticRing); + // we sleep here for a second, to make sure all new certificates have different timestamps Thread.sleep(1000); } @@ -87,6 +89,78 @@ public class PgpKeyOperationTest { } + @Test + public void testAlgorithmChoice() { + + OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog(); + + { + parcel.reset(); + parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( + Constants.choice.algorithm.rsa, new Random().nextInt(256)+255, KeyFlags.CERTIFY_OTHER, null)); + parcel.mAddUserIds.add("shy"); + parcel.mNewPassphrase = "swag"; + + UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0); + + Assert.assertNull("creating ring with < 512 bytes keysize should fail", ring); + } + + { + parcel.reset(); + parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( + Constants.choice.algorithm.elgamal, 1024, KeyFlags.CERTIFY_OTHER, null)); + parcel.mAddUserIds.add("shy"); + parcel.mNewPassphrase = "swag"; + + UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0); + + Assert.assertNull("creating ring with ElGamal master key should fail", ring); + } + + { + parcel.reset(); + parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( + 12345, 1024, KeyFlags.CERTIFY_OTHER, null)); + parcel.mAddUserIds.add("shy"); + parcel.mNewPassphrase = "swag"; + + UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0); + Assert.assertNull("creating ring with bad algorithm choice should fail", ring); + } + + { + parcel.reset(); + parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( + Constants.choice.algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null)); + parcel.mAddUserIds.add("shy"); + parcel.mNewPassphrase = "swag"; + + UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0); + Assert.assertNull("creating ring with non-certifying master key should fail", ring); + } + + { + parcel.reset(); + parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( + Constants.choice.algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null)); + parcel.mNewPassphrase = "swag"; + + UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0); + Assert.assertNull("creating ring without user ids should fail", ring); + } + + { + parcel.reset(); + parcel.mAddUserIds.add("shy"); + parcel.mNewPassphrase = "swag"; + + UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0); + Assert.assertNull("creating ring without subkeys should fail", ring); + } + + } + @Test // this is a special case since the flags are in user id certificates rather than // subkey binding certificates -- cgit v1.2.3