Example usage for org.eclipse.jgit.transport PushCertificate toText

List of usage examples for org.eclipse.jgit.transport PushCertificate toText

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport PushCertificate toText.

Prototype

public String toText() 

Source Link

Document

Get text payload of the certificate for the signature verifier.

Usage

From source file:com.google.gerrit.gpg.PushCertificateChecker.java

License:Apache License

private void checkSignature(PGPSignature sig, PushCertificate cert, PublicKeyStore store, List<String> problems)
        throws PGPException, IOException {
    PGPPublicKeyRingCollection keys = store.get(sig.getKeyID());
    if (!keys.getKeyRings().hasNext()) {
        problems.add("No public keys found for key ID " + keyIdToString(sig.getKeyID()));
        return;/*from www  .  j a v a  2 s  .  c  o m*/
    }
    PGPPublicKey signer = PublicKeyStore.getSigner(keys, sig, Constants.encode(cert.toText()));
    if (signer == null) {
        problems.add("Signature by " + keyIdToString(sig.getKeyID()) + " is not valid");
        return;
    }
    CheckResult result = publicKeyChecker.check(signer, store);
    if (!result.isOk()) {
        StringBuilder err = new StringBuilder("Invalid public key ").append(keyToString(signer)).append(":");
        for (String problem : result.getProblems()) {
            err.append("\n  ").append(problem);
        }
        problems.add(err.toString());
    }
}

From source file:com.google.gerrit.server.git.gpg.PushCertificateChecker.java

License:Apache License

private void checkSignature(PGPSignature sig, PushCertificate cert, PGPPublicKeyRingCollection keys,
        List<String> problems) {
    List<String> deferredProblems = new ArrayList<>();
    boolean anyKeys = false;
    for (PGPPublicKeyRing kr : keys) {
        PGPPublicKey k = kr.getPublicKey();
        anyKeys = true;/*from w w  w  . j a va  2  s  .co  m*/
        try {
            sig.init(new BcPGPContentVerifierBuilderProvider(), k);
            sig.update(Constants.encode(cert.toText()));
            if (!sig.verify()) {
                // TODO(dborowitz): Privacy issues with exposing fingerprint/user ID
                // of keys having the same ID as the pusher's key?
                deferredProblems.add("Signature not valid with public key: " + keyToString(k));
                continue;
            }
            CheckResult result = publicKeyChecker.check(k, sig.getKeyID());
            if (result.isOk()) {
                return;
            }
            StringBuilder err = new StringBuilder("Invalid public key (").append(keyToString(k)).append("):");
            for (int i = 0; i < result.getProblems().size(); i++) {
                err.append('\n').append("  ").append(result.getProblems().get(i));
            }
            problems.add(err.toString());
            return;
        } catch (PGPException e) {
            deferredProblems
                    .add("Error checking signature with public key (" + keyToString(k) + ": " + e.getMessage());
        }
    }
    if (!anyKeys) {
        problems.add("No public keys found for Key ID " + keyIdToString(sig.getKeyID()));
    } else {
        problems.addAll(deferredProblems);
    }
}