Search in sources :

Example 16 with TestKey

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

the class PublicKeyCheckerTest method trustInsufficientDepthInSignature.

@Test
public void trustInsufficientDepthInSignature() throws Exception {
    // H---I---J, but J is only trusted to length 1.
    TestKey kh = add(keyH());
    TestKey ki = add(keyI());
    add(keyJ());
    save();
    PublicKeyChecker checker = newChecker(10, keyJ());
    // J trusts I to a depth of 1, so I itself is valid, but I's certification
    // of K is not valid.
    assertNoProblems(checker, ki);
    assertProblems(checker, kh, "No path to a trusted key", notTrusted(ki));
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 17 with TestKey

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

the class PublicKeyCheckerTest method revokedKeyDueToCompromiseRevokesKeyRetroactively.

@Test
public void revokedKeyDueToCompromiseRevokesKeyRetroactively() throws Exception {
    TestKey k = add(revokedCompromisedKey());
    add(validKeyWithoutExpiration());
    save();
    String problem = "Key is revoked (key material has been compromised): test6 compromised";
    assertProblems(k, problem);
    Instant instant = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()).parse("2010-01-01 12:00:00", Instant::from);
    PublicKeyChecker checker = new PublicKeyChecker().setStore(store).setEffectiveTime(instant);
    assertProblems(checker, k, problem);
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Instant(java.time.Instant) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) Test(org.junit.Test)

Example 18 with TestKey

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

the class PushCertificateCheckerTest method invalidKey.

@Test
public void invalidKey() throws Exception {
    TestKey key3 = expiredKey();
    PushCertificate cert = newSignedCert(validNonce(), key3);
    assertProblems(cert, "Invalid public key " + keyToString(key3.getPublicKey()) + ":\n  Key is expired");
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) PushCertificate(org.eclipse.jgit.transport.PushCertificate) Test(org.junit.Test)

Example 19 with TestKey

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

the class PushCertificateCheckerTest method signatureByExpiredKeyBeforeExpiration.

@Test
public void signatureByExpiredKeyBeforeExpiration() throws Exception {
    TestKey key3 = expiredKey();
    Date now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse("2005-07-10 12:00:00 -0400");
    PushCertificate cert = newSignedCert(validNonce(), key3, now);
    assertNoProblems(cert);
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) PushCertificate(org.eclipse.jgit.transport.PushCertificate) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 20 with TestKey

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

the class AccountIT method addGpgKey.

@Test
public void addGpgKey() throws Exception {
    TestKey key = validKeyWithoutExpiration();
    String id = key.getKeyIdString();
    addExternalIdEmail(admin, "test1@example.com");
    sender.clear();
    assertKeyMapContains(key, addGpgKey(key.getPublicKeyArmored()));
    assertKeys(key);
    assertThat(sender.getMessages()).hasSize(1);
    assertThat(sender.getMessages().get(0).body()).contains("new GPG keys have been added");
    requestScopeOperations.setApiUser(user.id());
    ResourceNotFoundException thrown = assertThrows(ResourceNotFoundException.class, () -> gApi.accounts().self().gpgKey(id).get());
    assertThat(thrown).hasMessageThat().contains(id);
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) 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