Search in sources :

Example 31 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class GerritPublicKeyCheckerTest method checkWithValidKeyButWrongExpectedUserInChecker.

@Test
public void checkWithValidKeyButWrongExpectedUserInChecker() throws Exception {
    // A---Bx
    // \
    // \---C---D
    // \
    // \---Ex
    // 
    // The server ultimately trusts B and D.
    // D and E trust C to be a valid introducer of depth 2.
    IdentifiedUser userB = addUser("userB");
    TestKey keyA = add(keyA(), user);
    TestKey keyB = add(keyB(), userB);
    add(keyC(), addUser("userC"));
    add(keyD(), addUser("userD"));
    add(keyE(), addUser("userE"));
    // Checker for A, checking B.
    PublicKeyChecker checkerA = checkerFactory.create(user, store);
    assertProblems(checkerA.check(keyB.getPublicKey()), Status.BAD, "Key is expired", "Key must contain a valid certification for one of the following" + " identities:\n" + "  gerrit:user\n" + "  mailto:testa@example.com\n" + "  testa@example.com\n" + "  username:user");
    // Checker for B, checking A.
    PublicKeyChecker checkerB = checkerFactory.create(userB, store);
    assertProblems(checkerB.check(keyA.getPublicKey()), Status.BAD, "Key must contain a valid certification for one of the following" + " identities:\n" + "  gerrit:userB\n" + "  mailto:testb@example.com\n" + "  testb@example.com\n" + "  username:userB");
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Test(org.junit.Test)

Example 32 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class GerritPublicKeyCheckerTest method checkTrustChainUsingCheckerWithoutExpectedKey.

@Test
public void checkTrustChainUsingCheckerWithoutExpectedKey() throws Exception {
    // A---Bx
    // \
    // \---C---D
    // \
    // \---Ex
    // 
    // The server ultimately trusts B and D.
    // D and E trust C to be a valid introducer of depth 2.
    TestKey keyA = add(keyA(), user);
    TestKey keyB = add(keyB(), addUser("userB"));
    TestKey keyC = add(keyC(), addUser("userC"));
    TestKey keyD = add(keyD(), addUser("userD"));
    TestKey keyE = add(keyE(), addUser("userE"));
    // This checker can check any key, so the only problems come from issues
    // with the keys themselves, not having invalid user IDs.
    PublicKeyChecker checker = checkerFactory.create().setStore(store);
    assertNoProblems(checker.check(keyA.getPublicKey()));
    assertProblems(checker.check(keyB.getPublicKey()), Status.BAD, "Key is expired");
    assertNoProblems(checker.check(keyC.getPublicKey()));
    assertNoProblems(checker.check(keyD.getPublicKey()));
    assertProblems(checker.check(keyE.getPublicKey()), Status.BAD, "Key is expired", "No path to a trusted key");
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 33 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class PublicKeyStoreTest method getSubkeyReturnsMasterKey.

@Test
public void getSubkeyReturnsMasterKey() throws Exception {
    TestKey key1 = validKeyWithoutExpirationWithSubkeyWithExpiration();
    PGPPublicKeyRing keyRing = key1.getPublicKeyRing();
    store.add(keyRing);
    assertEquals(RefUpdate.Result.NEW, store.save(newCommitBuilder()));
    long masterKeyId = key1.getKeyId();
    long subKeyId = 0;
    for (PGPPublicKey key : keyRing) {
        if (masterKeyId != subKeyId) {
            subKeyId = key.getKeyID();
        }
    }
    assertKeys(subKeyId, key1);
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) TestKey(com.google.gerrit.gpg.testing.TestKey) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) Test(org.junit.Test)

Example 34 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class PublicKeyStoreTest method get.

@Test
public void get() throws Exception {
    TestKey key1 = validKeyWithoutExpiration();
    tr.branch(REFS_GPG_KEYS).commit().add(keyObjectId(key1.getKeyId()).name(), key1.getPublicKeyArmored()).create();
    TestKey key2 = validKeyWithExpiration();
    tr.branch(REFS_GPG_KEYS).commit().add(keyObjectId(key2.getKeyId()).name(), key2.getPublicKeyArmored()).create();
    assertKeys(key1.getKeyId(), key1);
    assertKeys(key2.getKeyId(), key2);
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 35 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class PublicKeyStoreTest method addThenRemove.

@Test
public void addThenRemove() throws Exception {
    TestKey key1 = validKeyWithoutExpiration();
    store.add(key1.getPublicKeyRing());
    store.remove(key1.getPublicKey().getFingerprint());
    assertEquals(RefUpdate.Result.NO_CHANGE, store.save(newCommitBuilder()));
    assertKeys(key1.getKeyId());
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Aggregations

TestKey (com.google.gerrit.gpg.testing.TestKey)44 Test (org.junit.Test)41 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)9 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)7 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)6 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)5 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 PushCertificate (org.eclipse.jgit.transport.PushCertificate)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)2 GpgKeyInfo (com.google.gerrit.extensions.common.GpgKeyInfo)2 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 PublicKeyStore.keyIdToString (com.google.gerrit.gpg.PublicKeyStore.keyIdToString)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 StopStrategies (com.github.rholder.retry.StopStrategies)1 FluentIterable (com.google.common.collect.FluentIterable)1