diff options
| author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-07-12 02:01:21 +0200 | 
|---|---|---|
| committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-07-12 02:01:21 +0200 | 
| commit | 22b0e5a1fcf36e7d0ea4a81eda23ac1f0ae1fe7f (patch) | |
| tree | 0ffe8ace41e894d3f7e4c8d6f7a81481862652c4 | |
| parent | 0e3327c65c670a0d910abd6760ed0ece298dcfbb (diff) | |
| download | open-keychain-22b0e5a1fcf36e7d0ea4a81eda23ac1f0ae1fe7f.tar.gz open-keychain-22b0e5a1fcf36e7d0ea4a81eda23ac1f0ae1fe7f.tar.bz2 open-keychain-22b0e5a1fcf36e7d0ea4a81eda23ac1f0ae1fe7f.zip  | |
test: add test for bad key sanity check
| -rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java | 68 | 
1 files changed, 67 insertions, 1 deletions
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 e866e77c0..7282af0e5 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 @@ -32,6 +32,7 @@ import org.sufficientlysecure.keychain.support.KeyringBuilder;  import org.sufficientlysecure.keychain.support.KeyringTestingHelper;  import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket;  import org.sufficientlysecure.keychain.support.TestDataUtil; +import org.sufficientlysecure.keychain.util.ProgressScaler;  import java.io.ByteArrayInputStream;  import java.io.IOException; @@ -80,7 +81,7 @@ public class PgpKeyOperationTest {          ring = staticRing;          // setting up some parameters just to reduce code duplication -        op = new PgpKeyOperation(null); +        op = new PgpKeyOperation(new ProgressScaler(null, 0, 100, 100));          // set this up, gonna need it more than once          parcel = new SaveKeyringParcel(); @@ -225,6 +226,71 @@ public class PgpKeyOperationTest {      }      @Test +    public void testBadKeyModification() throws Exception { + +        { +            SaveKeyringParcel parcel = new SaveKeyringParcel(); +            // off by one +            parcel.mMasterKeyId = ring.getMasterKeyId() -1; +            parcel.mFingerprint = ring.getFingerprint(); + +            WrappedSecretKeyRing secretRing = new WrappedSecretKeyRing(ring.getEncoded(), false, 0); +            OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog(); +            UncachedKeyRing modified = op.modifySecretKeyRing(secretRing, parcel, "swag", log, 0); + +            Assert.assertNull("keyring modification with bad master key id should fail", modified); +        } + +        { +            SaveKeyringParcel parcel = new SaveKeyringParcel(); +            // off by one +            parcel.mMasterKeyId = null; +            parcel.mFingerprint = ring.getFingerprint(); + +            WrappedSecretKeyRing secretRing = new WrappedSecretKeyRing(ring.getEncoded(), false, 0); +            OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog(); +            UncachedKeyRing modified = op.modifySecretKeyRing(secretRing, parcel, "swag", log, 0); + +            Assert.assertNull("keyring modification with null master key id should fail", modified); +        } + +        { +            SaveKeyringParcel parcel = new SaveKeyringParcel(); +            parcel.mMasterKeyId = ring.getMasterKeyId(); +            parcel.mFingerprint = ring.getFingerprint(); +            // some byte, off by one +            parcel.mFingerprint[5] += 1; + +            WrappedSecretKeyRing secretRing = new WrappedSecretKeyRing(ring.getEncoded(), false, 0); +            OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog(); +            UncachedKeyRing modified = op.modifySecretKeyRing(secretRing, parcel, "swag", log, 0); + +            Assert.assertNull("keyring modification with bad fingerprint should fail", modified); +        } + +        { +            SaveKeyringParcel parcel = new SaveKeyringParcel(); +            parcel.mMasterKeyId = ring.getMasterKeyId(); +            parcel.mFingerprint = null; + +            WrappedSecretKeyRing secretRing = new WrappedSecretKeyRing(ring.getEncoded(), false, 0); +            OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog(); +            UncachedKeyRing modified = op.modifySecretKeyRing(secretRing, parcel, "swag", log, 0); + +            Assert.assertNull("keyring modification with null fingerprint should fail", modified); +        } + +        { +            WrappedSecretKeyRing secretRing = new WrappedSecretKeyRing(ring.getEncoded(), false, 0); +            OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog(); +            UncachedKeyRing modified = op.modifySecretKeyRing(secretRing, parcel, "bad passphrase", log, 0); + +            Assert.assertNull("keyring modification with bad passphrase should fail", modified); +        } + +    } + +    @Test      public void testSubkeyAdd() throws Exception {          long expiry = new Date().getTime() / 1000 + 159;  | 
