Add a test for authentication subkey selection with a keyring created as

such:
- add 3 auth subkeys
- revoke the 1st & 3rd subkey
- add an encryption subkey
This commit is contained in:
Christian Hagau 2018-10-02 00:00:00 +00:00
parent e8bbdc2339
commit 047a409164
2 changed files with 67 additions and 0 deletions

View file

@ -49,6 +49,7 @@ import org.sufficientlysecure.keychain.ssh.AuthenticationOperation;
import org.sufficientlysecure.keychain.ssh.AuthenticationParcel;
import org.sufficientlysecure.keychain.ssh.AuthenticationResult;
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Passphrase;
@RunWith(KeychainTestRunner.class)
@ -58,6 +59,7 @@ public class AuthenticationOperationTest {
private static UncachedKeyRing mStaticRingEcDsa;
private static UncachedKeyRing mStaticRingEdDsa;
private static UncachedKeyRing mStaticRingDsa;
private static UncachedKeyRing mStaticRingRevoked;
private static Passphrase mKeyPhrase;
private static PrintStream oldShadowStream;
@ -132,6 +134,8 @@ public class AuthenticationOperationTest {
mStaticRingEcDsa = KeyringTestingHelper.readRingFromResource("/test-keys/authenticate_ecdsa.sec");
mStaticRingEdDsa = KeyringTestingHelper.readRingFromResource("/test-keys/authenticate_eddsa.sec");
mStaticRingDsa = KeyringTestingHelper.readRingFromResource("/test-keys/authenticate_dsa.sec");
mStaticRingRevoked = KeyringTestingHelper.readRingFromResource("/test-keys/authenticate_multisub_with_revoked.asc");
}
@Before
@ -395,4 +399,19 @@ public class AuthenticationOperationTest {
}
}
@Test
public void testKeySelection() throws Exception {
String expectedAuthSubKeyId = "0xcf64ee600f6fec9c";
KeyRepository keyRepository = KeyRepository.create(RuntimeEnvironment.application);
long masterKeyId = mStaticRingRevoked.getMasterKeyId();
Long authSubKeyId = keyRepository.getSecretAuthenticationId(masterKeyId);
String authSubKeyIdString = KeyFormattingUtils.convertKeyIdToHex(authSubKeyId);
boolean isRightKey = authSubKeyIdString.equals(expectedAuthSubKeyId);
Assert.assertTrue("selected key must be the same: " + authSubKeyIdString + " != " + expectedAuthSubKeyId, isRightKey);
}
}

View file

@ -0,0 +1,48 @@
-----BEGIN PGP PRIVATE KEY BLOCK-----
lDsEW6ShJxYJKwYBBAHaRw8BAQdAQPz2gpnMGAwzYohDbb/yEf3rxm+tfONk3Q3p
utXnINH/AGUAR05VAbQrbl9hdXRoX3Jldm9jX3RvbyA8bl9hdXRoX3Jldm9jX3Rv
b0Bmb28uYmFyPoiQBBMWCgA4FiEENhM25ruHCJ1cKh7WVipcf28HvXYFAlumQNMC
GwEFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AACgkQVipcf28HvXZxnQEA2gAU3673
0z8A4ACBLjKVKAfMiIXz0DobABsku+btINgBALFPCvFqQ9PtX05FZrdenu37GlRg
Ln+xKG/XHj51SQEOtB9uX2F1dGhfcmV2b2MgPG5fYXV0aF9yZXZvY0B4Lnk+iJAE
ExYKADgWIQQ2Ezbmu4cInVwqHtZWKlx/bwe9dgUCW6ShJwIbAQULCQgHAwUVCgkI
CwUWAgMBAAIeAQIXgAAKCRBWKlx/bwe9di8mAP9iY2+oHeiUGy++9Z6QHXqroaVD
YNDBXZdDcesrWyy8SQEAo4K6+YrXEXDJ/yuF7nsfqM8w36CdVFKsi+FIJTSnXA2c
hgRbpKE9FgkrBgEEAdpHDwEBB0BFJ/Pffb7R8UUiJGvQVdyEzpN+x5DNRfyFKAVv
BgPuCP4HAwItU2EpssU0AugT4uu7KPhnn9Axg8IJAmqkgxUt3o1JxZoqFqyfCMhN
lNHbIf1zuBZDbN452nBckNK72V3V0UDYyjLlkBRELyaoEl3whfZRiHgEKBYKACAW
IQQ2Ezbmu4cInVwqHtZWKlx/bwe9dgUCW6UG6wIdAAAKCRBWKlx/bwe9dkhMAQCb
ja1KTcl7Vw10Ow85nBGgb2zLCzJwmbV4qr0NbC9pOgD/R1ayoZJ18FIhGFADCsRn
tnlxzU3vFZj1O4Yaq3cXmguIeAQYFgoAIBYhBDYTNua7hwidXCoe1lYqX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