aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain-Test/src
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-10-02 19:25:20 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-10-02 19:26:39 +0200
commitb6916a9b40ab6edf6396471a966c455f6054da74 (patch)
tree5eccf1a26d22838e0b554a9a5fbb6f059cca10a0 /OpenKeychain-Test/src
parent37cb5c4c78880b5b4737cffdaa4ead76506a3843 (diff)
downloadopen-keychain-b6916a9b40ab6edf6396471a966c455f6054da74.tar.gz
open-keychain-b6916a9b40ab6edf6396471a966c455f6054da74.tar.bz2
open-keychain-b6916a9b40ab6edf6396471a966c455f6054da74.zip
add test case for stripped master key, correct signing subkey should still be selected
Diffstat (limited to 'OpenKeychain-Test/src')
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java40
-rw-r--r--OpenKeychain-Test/src/test/resources/test-keys/stripped_flags.asc60
2 files changed, 95 insertions, 5 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java
index 3dc107daa..a47d57a69 100644
--- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java
@@ -89,14 +89,12 @@ public class ProviderHelperSaveTest {
CachedPublicKeyRing cachedRing = mProviderHelper.getCachedPublicKeyRing(keyId);
CanonicalizedPublicKeyRing pubRing = mProviderHelper.getCanonicalizedPublicKeyRing(keyId);
- Assert.assertEquals("master key should be signing key", pubRing.getSignId(), keyId);
- Assert.assertEquals("master key should be signing key (cached)", cachedRing.getSignId(), keyId);
- Assert.assertEquals("master key should be encryption key", pubRing.getEncryptId(), keyId);
- Assert.assertEquals("master key should be signing key (cached)", cachedRing.getEncryptId(), keyId);
+ Assert.assertEquals("master key should be encryption key", keyId, pubRing.getEncryptId());
+ Assert.assertEquals("master key should be encryption key (cached)", keyId, cachedRing.getEncryptId());
Assert.assertNull("canonicalized key flags should be null", pubRing.getPublicKey().getKeyUsage());
Assert.assertTrue("master key should be able to certify", pubRing.getPublicKey().canCertify());
- Assert.assertTrue("master key should be able to sign", pubRing.getPublicKey().canSign());
+ Assert.assertTrue("master key should be allowed to sign", pubRing.getPublicKey().canSign());
Assert.assertTrue("master key should be able to encrypt", pubRing.getPublicKey().canEncrypt());
}
@@ -188,6 +186,38 @@ public class ProviderHelperSaveTest {
Assert.assertTrue("import of the badly encoded user id should succeed", found);
}
+ @Test
+ /** Tests a master key which may sign, but is stripped. In this case, if there is a different
+ * subkey available which can sign, that one should be selected.
+ */
+ public void testImportStrippedFlags() throws Exception {
+
+ UncachedKeyRing key = readRingFromResource("/test-keys/stripped_flags.asc");
+ long masterKeyId = key.getMasterKeyId();
+
+ SaveKeyringResult result;
+
+ result = mProviderHelper.saveSecretKeyRing(key, new ProgressScaler());
+ Assert.assertTrue("import of keyring should succeed", result.success());
+
+ long signId;
+ {
+ CanonicalizedSecretKeyRing ring = mProviderHelper.getCanonicalizedSecretKeyRing(masterKeyId);
+ Assert.assertTrue("master key should have sign flag", ring.getPublicKey().canSign());
+ Assert.assertTrue("master key should have encrypt flag", ring.getPublicKey().canEncrypt());
+
+ signId = ring.getSecretSignId();
+ Assert.assertNotEquals("encrypt id should not be 0", 0, signId);
+ Assert.assertNotEquals("encrypt key should be different from master key", masterKeyId, signId);
+ }
+
+ {
+ CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(masterKeyId);
+ Assert.assertEquals("signing key should be same id cached as uncached", signId, ring.getSecretSignId());
+ }
+
+ }
+
UncachedKeyRing readRingFromResource(String name) throws Exception {
return UncachedKeyRing.fromStream(ProviderHelperSaveTest.class.getResourceAsStream(name)).next();
}
diff --git a/OpenKeychain-Test/src/test/resources/test-keys/stripped_flags.asc b/OpenKeychain-Test/src/test/resources/test-keys/stripped_flags.asc
new file mode 100644
index 000000000..0f4728297
--- /dev/null
+++ b/OpenKeychain-Test/src/test/resources/test-keys/stripped_flags.asc
@@ -0,0 +1,60 @@
+-----BEGIN PGP PRIVATE KEY BLOCK-----
+
+lQIVBFQtfsYBEADhyTqxezePQuP9PCmzdXYavyaaBPCJLpfNhrufe++7xMmkIzGO
+l7X8hVrrnqhRs1pVe/rpaSJ8iUVpsMN2BWRrrsmpysf/idjE4OXDGvA5dCRJOhqy
+waHA7dO94x2mvcUCVWo5V4cu5+Qv2GejhorPsTNuXXUZrFKWSgEwLpg9lY7M39wB
+1SIeQLxMLwixCod87b0A0p9UBCU+QeBx4WFl0NPE3qneQgmFe1Idk6nfwSZFEfYM
+6iWepEzhv3GQjdNfXZxLIPqeo4Jowen53HlYYNp/d5fIOpyJ7FxWsutltcGA4GrD
+FSfhi/Wh+1/KKwRwCqhFQEZIQjWbmaiQlf3anERfL8Dy+WWiJmZt9W4TDZGY+3Ay
+3nDyqVHZJVo4gE+BUiNdx6oITM/mhwVJYpaOnHGMAmWz0Nj0OO5pa86Un/V25gaG
+/lmpkvrzHeTpM109xHJt4/WBWt+gUClDd32KCVaSx1b+ECagAf/PJJWpbQspLsNq
+DwJCyE8pYnGcoChIVIAPvE5wrAH890FgE43f0utlYW13vp76TXSwuk18XYYCglMl
+zuOTFSOkOEflZP4UvJTTjlHoKMJ+iOW4yIS+vvt9jCIYAGp6Fso4pcjakTZ1iSSD
+j5QN0ybcJHxKN+fSXZspuW2LijK8aZS2xhWjWwhWJWMDvl5pu9Nx5u4SwwARAQAB
+/wNlAkdOVQG0FVN0cmlwcGVkIFRlc3QgPHhAeS56PokCNwQTAQoAIQULCQgHAwYV
+CgkLCAMEFgIDAQIZAQWCVC1+xgKeAQKbDwAKCRCf3UpNJ7bxZ9GDEADDEsKrTKvz
+c1H6MbBNqsKOWI6Wc8D5MgggphuBmZwXP1FSYVsYTf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