aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-03-22 07:21:27 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-03-22 07:21:27 +0100
commit5d5e06cabdd6400530f6dcef940ed8a72ab94fac (patch)
treee25ed53a114a2fe7cd3b317d27529068e097f298
parent2e838e4cce32a5926466b6069a58c6a3579c12bf (diff)
downloadopen-keychain-5d5e06cabdd6400530f6dcef940ed8a72ab94fac.tar.gz
open-keychain-5d5e06cabdd6400530f6dcef940ed8a72ab94fac.tar.bz2
open-keychain-5d5e06cabdd6400530f6dcef940ed8a72ab94fac.zip
fix unit test and add new for divert-to-card promotion
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java35
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java4
2 files changed, 33 insertions, 6 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java
index 34a4bed25..617b5762c 100644
--- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java
@@ -27,9 +27,12 @@ import org.robolectric.RobolectricTestRunner;
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.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult;
+import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
+import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
@@ -101,7 +104,7 @@ public class PromoteKeyOperationTest {
PromoteKeyOperation op = new PromoteKeyOperation(Robolectric.application,
new ProviderHelper(Robolectric.application), null, null);
- PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId());
+ PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId(), null);
Assert.assertTrue("promotion must succeed", result.success());
@@ -113,15 +116,35 @@ public class PromoteKeyOperationTest {
Iterator<UncachedPublicKey> it = mStaticRing.getPublicKeys();
while (it.hasNext()) {
long keyId = it.next().getKeyId();
- Assert.assertEquals("all subkeys must be divert-to-card",
+ Assert.assertEquals("all subkeys must be gnu dummy",
SecretKeyType.GNU_DUMMY, ring.getSecretKeyType(keyId));
}
}
- // second attempt should fail
- result = op.execute(mStaticRing.getMasterKeyId());
- Assert.assertFalse("promotion of secret key must fail", result.success());
-
}
+ @Test
+ public void testPromoteDivert() throws Exception {
+ PromoteKeyOperation op = new PromoteKeyOperation(Robolectric.application,
+ new ProviderHelper(Robolectric.application), null, null);
+
+ byte[] aid = Hex.decode("D2760001240102000000012345670000");
+
+ PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId(), aid);
+
+ Assert.assertTrue("promotion must succeed", result.success());
+
+ {
+ CanonicalizedSecretKeyRing ring = new ProviderHelper(Robolectric.application)
+ .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
+
+ for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
+ Assert.assertEquals("all subkeys must be divert-to-card",
+ SecretKeyType.DIVERT_TO_CARD, key.getSecretKeyType());
+ Assert.assertArrayEquals("all subkeys must have correct iv",
+ aid, key.getIv());
+ }
+
+ }
+ }
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
index 21b6e551b..30be72dd5 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
@@ -278,6 +278,10 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
}
}
+ public byte[] getIv() {
+ return mSecretKey.getIV();
+ }
+
static class PrivateKeyNotUnlockedException extends RuntimeException {
// this exception is a programming error which happens when an operation which requires
// the private key is called without a previous call to unlock()