Search in sources :

Example 1 with Status

use of com.google.gerrit.extensions.common.GpgKeyInfo.Status in project gerrit by GerritCodeReview.

the class PushCertificateChecker method combine.

private static Result combine(Result sigResult, List<CheckResult> results) {
    // Combine results:
    //  - If any input result is BAD, the final result is bad.
    //  - If sigResult is TRUSTED and no other result is BAD, the final result
    //    is TRUSTED.
    //  - Otherwise, the result is OK.
    List<String> problems = new ArrayList<>();
    boolean bad = false;
    for (CheckResult result : results) {
        problems.addAll(result.getProblems());
        bad |= result.getStatus() == BAD;
    }
    Status status = bad ? BAD : OK;
    PGPPublicKey key;
    if (sigResult != null) {
        key = sigResult.getPublicKey();
        CheckResult cr = sigResult.getCheckResult();
        problems.addAll(cr.getProblems());
        if (cr.getStatus() == BAD) {
            status = BAD;
        } else if (!bad && cr.getStatus() == TRUSTED) {
            status = TRUSTED;
        }
    } else {
        key = null;
    }
    return new Result(key, CheckResult.create(status, problems));
}
Also used : Status(com.google.gerrit.extensions.common.GpgKeyInfo.Status) NonceStatus(org.eclipse.jgit.transport.PushCertificate.NonceStatus) ArrayList(java.util.ArrayList) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PublicKeyStore.keyIdToString(com.google.gerrit.gpg.PublicKeyStore.keyIdToString)

Example 2 with Status

use of com.google.gerrit.extensions.common.GpgKeyInfo.Status in project gerrit by GerritCodeReview.

the class PublicKeyChecker method check.

private CheckResult check(PGPPublicKey key, int depth, boolean expand, Set<Fingerprint> seen) {
    CheckResult basicResult = checkBasic(key, effectiveTime);
    CheckResult customResult = checkCustom(key, depth);
    CheckResult trustResult = checkWebOfTrust(key, store, depth, seen);
    if (!expand && !trustResult.isTrusted()) {
        trustResult = CheckResult.create(trustResult.getStatus(), "Key is not trusted");
    }
    List<String> problems = new ArrayList<>(basicResult.getProblems().size() + customResult.getProblems().size() + trustResult.getProblems().size());
    problems.addAll(basicResult.getProblems());
    problems.addAll(customResult.getProblems());
    problems.addAll(trustResult.getProblems());
    Status status;
    if (basicResult.getStatus() == BAD || customResult.getStatus() == BAD || trustResult.getStatus() == BAD) {
        // Any BAD result and the final result is BAD.
        status = BAD;
    } else if (trustResult.getStatus() == TRUSTED) {
        // basicResult is BAD or OK, whereas trustResult is BAD or TRUSTED. If
        // TRUSTED, we trust the final result.
        status = TRUSTED;
    } else {
        // All results were OK or better, but trustResult was not TRUSTED. Don't
        // let subclasses bypass checkWebOfTrust by returning TRUSTED; just return
        // OK here.
        status = OK;
    }
    return CheckResult.create(status, problems);
}
Also used : Status(com.google.gerrit.extensions.common.GpgKeyInfo.Status) ArrayList(java.util.ArrayList) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PublicKeyStore.keyIdToString(com.google.gerrit.gpg.PublicKeyStore.keyIdToString)

Aggregations

Status (com.google.gerrit.extensions.common.GpgKeyInfo.Status)2 PublicKeyStore.keyIdToString (com.google.gerrit.gpg.PublicKeyStore.keyIdToString)2 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)2 ArrayList (java.util.ArrayList)2 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)1 NonceStatus (org.eclipse.jgit.transport.PushCertificate.NonceStatus)1