use of org.bouncycastle.openpgp.PGPException in project gerrit by GerritCodeReview.
the class PublicKeyChecker method gatherRevocationProblems.
private void gatherRevocationProblems(PGPPublicKey key, Instant now, List<String> problems) {
try {
List<PGPSignature> revocations = new ArrayList<>();
Map<Long, RevocationKey> revokers = new HashMap<>();
PGPSignature selfRevocation = scanRevocations(key, now, revocations, revokers);
if (selfRevocation != null) {
RevocationReason reason = getRevocationReason(selfRevocation);
if (isRevocationValid(selfRevocation, reason, now)) {
problems.add(reasonToString(reason));
}
} else {
checkRevocations(key, revocations, revokers, problems);
}
} catch (PGPException | IOException e) {
problems.add("Error checking key revocation");
}
}
use of org.bouncycastle.openpgp.PGPException in project ant-ivy by apache.
the class OpenPGPSignatureGenerator method sign.
public void sign(File src, File dest) throws IOException {
OutputStream out = null;
InputStream in = null;
InputStream keyIn = null;
try {
if (secring == null) {
secring = System.getProperty("user.home") + "/.gnupg/secring.gpg";
}
if (pgpSec == null) {
keyIn = new FileInputStream(secring);
pgpSec = readSecretKey(keyIn);
}
PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(password.toCharArray());
PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(decryptor);
PGPSignatureGenerator sGen = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1));
sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
in = new FileInputStream(src);
out = new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream(dest)));
int ch = 0;
while ((ch = in.read()) >= 0) {
sGen.update((byte) ch);
}
sGen.generate().encode(out);
} catch (PGPException e) {
throw new IOException(e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (keyIn != null) {
try {
keyIn.close();
} catch (IOException e) {
}
}
}
}
Aggregations