use of com.google.gerrit.gpg.testutil.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);
}
use of com.google.gerrit.gpg.testutil.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);
}
use of com.google.gerrit.gpg.testutil.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());
}
use of com.google.gerrit.gpg.testutil.TestKey in project gerrit by GerritCodeReview.
the class PublicKeyStoreTest method saveAppendsToExistingList.
@Test
public void saveAppendsToExistingList() throws Exception {
TestKey key1 = validKeyWithoutExpiration();
TestKey key2 = validKeyWithExpiration();
tr.branch(REFS_GPG_KEYS).commit().add(keyObjectId(key1.getKeyId()).name(), key2.getPublicKeyArmored()).create();
store.add(key1.getPublicKeyRing());
assertEquals(RefUpdate.Result.FAST_FORWARD, store.save(newCommitBuilder()));
assertKeys(key1.getKeyId(), key1, key2);
try (ObjectReader reader = tr.getRepository().newObjectReader();
RevWalk rw = new RevWalk(reader)) {
NoteMap notes = NoteMap.read(reader, tr.getRevWalk().parseCommit(tr.getRepository().exactRef(REFS_GPG_KEYS).getObjectId()));
String contents = new String(reader.open(notes.get(keyObjectId(key1.getKeyId()))).getBytes(), UTF_8);
String header = "-----BEGIN PGP PUBLIC KEY BLOCK-----";
int i1 = contents.indexOf(header);
assertTrue(i1 >= 0);
int i2 = contents.indexOf(header, i1 + header.length());
assertTrue(i2 >= 0);
}
}
use of com.google.gerrit.gpg.testutil.TestKey in project gerrit by GerritCodeReview.
the class PublicKeyStoreTest method save.
@Test
public void save() throws Exception {
TestKey key1 = validKeyWithoutExpiration();
TestKey key2 = validKeyWithExpiration();
store.add(key1.getPublicKeyRing());
store.add(key2.getPublicKeyRing());
assertEquals(RefUpdate.Result.NEW, store.save(newCommitBuilder()));
assertKeys(key1.getKeyId(), key1);
assertKeys(key2.getKeyId(), key2);
}
Aggregations