Search in sources :

Example 1 with PushCertificate

use of org.eclipse.jgit.transport.PushCertificate in project gerrit by GerritCodeReview.

the class GpgApiAdapterImpl method checkPushCertificate.

@Override
public PushCertificateInfo checkPushCertificate(String certStr, IdentifiedUser expectedUser) throws GpgException {
    try {
        PushCertificate cert = PushCertificateParser.fromString(certStr);
        PushCertificateChecker.Result result = pushCertCheckerFactory.create(expectedUser).setCheckNonce(false).check(cert);
        PushCertificateInfo info = new PushCertificateInfo();
        info.certificate = certStr;
        info.key = GpgKeys.toJson(result.getPublicKey(), result.getCheckResult());
        return info;
    } catch (IOException e) {
        throw new GpgException(e);
    }
}
Also used : GpgException(com.google.gerrit.server.GpgException) PushCertificate(org.eclipse.jgit.transport.PushCertificate) GerritPushCertificateChecker(com.google.gerrit.gpg.GerritPushCertificateChecker) PushCertificateChecker(com.google.gerrit.gpg.PushCertificateChecker) IOException(java.io.IOException) PushCertificateInfo(com.google.gerrit.extensions.common.PushCertificateInfo)

Example 2 with PushCertificate

use of org.eclipse.jgit.transport.PushCertificate 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 3 with PushCertificate

use of org.eclipse.jgit.transport.PushCertificate in project gerrit by GerritCodeReview.

the class PushCertificateCheckerTest method invalidNonce.

@Test
public void invalidNonce() throws Exception {
    PushCertificate cert = newSignedCert("invalid-nonce", validKeyWithoutExpiration());
    assertProblems(cert, "Invalid nonce");
}
Also used : PushCertificate(org.eclipse.jgit.transport.PushCertificate) Test(org.junit.Test)

Example 4 with PushCertificate

use of org.eclipse.jgit.transport.PushCertificate 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 5 with PushCertificate

use of org.eclipse.jgit.transport.PushCertificate in project gerrit by GerritCodeReview.

the class PushCertificateCheckerTest method invalidNonceNotChecked.

@Test
public void invalidNonceNotChecked() throws Exception {
    checker = newChecker(false);
    PushCertificate cert = newSignedCert("invalid-nonce", validKeyWithoutExpiration());
    assertNoProblems(cert);
}
Also used : PushCertificate(org.eclipse.jgit.transport.PushCertificate) Test(org.junit.Test)

Aggregations

PushCertificate (org.eclipse.jgit.transport.PushCertificate)8 Test (org.junit.Test)6 TestKey (com.google.gerrit.gpg.testing.TestKey)3 PushCertificateInfo (com.google.gerrit.extensions.common.PushCertificateInfo)1 GerritPushCertificateChecker (com.google.gerrit.gpg.GerritPushCertificateChecker)1 PushCertificateChecker (com.google.gerrit.gpg.PushCertificateChecker)1 GpgException (com.google.gerrit.server.GpgException)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1