Search in sources :

Example 11 with TestKey

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

the class PublicKeyCheckerTest method keyExpiringInFuture.

@Test
public void keyExpiringInFuture() throws Exception {
    TestKey k = validKeyWithExpiration();
    PublicKeyChecker checker = new PublicKeyChecker().setStore(store);
    assertNoProblems(checker, k);
    checker.setEffectiveTime(parseDate("2015-07-10 12:00:00 -0400"));
    assertNoProblems(checker, k);
    checker.setEffectiveTime(parseDate("2075-07-10 12:00:00 -0400"));
    assertProblems(checker, k, "Key is expired");
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 12 with TestKey

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

the class PublicKeyCheckerTest method revokedKeyDueToCompromise.

@Test
public void revokedKeyDueToCompromise() throws Exception {
    TestKey k = add(revokedCompromisedKey());
    add(validKeyWithoutExpiration());
    save();
    assertProblems(k, "Key is revoked (key material has been compromised): test6 compromised");
    PGPPublicKeyRing kr = removeRevokers(k.getPublicKeyRing());
    store.add(kr);
    save();
    // Key no longer specified as revoker.
    assertNoProblems(kr.getPublicKey());
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 13 with TestKey

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

the class PublicKeyCheckerTest method trustValidPathLength1.

@Test
public void trustValidPathLength1() throws Exception {
    // A---Bx
    // \
    // \---C---D
    // \
    // \---Ex
    // 
    // D and E trust C to be a valid introducer of depth 2.
    TestKey ka = add(keyA());
    TestKey kb = add(keyB());
    TestKey kc = add(keyC());
    TestKey kd = add(keyD());
    add(keyE());
    save();
    PublicKeyChecker checker = newChecker(1, kd);
    assertProblems(checker, ka, "No path to a trusted key", notTrusted(kb), notTrusted(kc));
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 14 with TestKey

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

the class PublicKeyCheckerTest method keyRevokedByExpiredKeyBeforeExpirationIsRevoked.

@Test
public void keyRevokedByExpiredKeyBeforeExpirationIsRevoked() throws Exception {
    TestKey k = add(keyRevokedByExpiredKeyBeforeExpiration());
    add(expiredKey());
    save();
    PublicKeyChecker checker = new PublicKeyChecker().setStore(store);
    assertProblems(checker, k, "Key is revoked (retired and no longer valid): test9 not used");
    // Set time between key creation and revocation.
    checker.setEffectiveTime(parseDate("2005-08-01 13:00:00 -0400"));
    assertNoProblems(checker, k);
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 15 with TestKey

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

the class PublicKeyCheckerTest method newChecker.

private PublicKeyChecker newChecker(int maxTrustDepth, TestKey... trusted) {
    Map<Long, Fingerprint> fps = new HashMap<>();
    for (TestKey k : trusted) {
        Fingerprint fp = new Fingerprint(k.getPublicKey().getFingerprint());
        fps.put(fp.getId(), fp);
    }
    return new PublicKeyChecker().enableTrust(maxTrustDepth, fps).setStore(store);
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) HashMap(java.util.HashMap)

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