1 From 29055a825af5405e44ffcd59a776f8952bdc7203 Mon Sep 17 00:00:00 2001
2 From: Julien Lepiller <julien@lepiller.eu>
3 Date: Fri, 15 Dec 2017 16:03:23 +0100
4 Subject: [PATCH] Port to latest bouncycastle.
7 .../bouncycastle/OpenPGPSignatureGenerator.java | 34 ++++++++++------------
8 1 file changed, 16 insertions(+), 18 deletions(-)
10 diff --git a/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java b/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java
11 index af7beae..34c204f 100644
12 --- a/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java
13 +++ b/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java
14 @@ -41,6 +41,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
15 import org.bouncycastle.openpgp.PGPSignature;
16 import org.bouncycastle.openpgp.PGPSignatureGenerator;
17 import org.bouncycastle.openpgp.PGPUtil;
18 +import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
19 +import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
20 +import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
21 +import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder;
22 +import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
24 public class OpenPGPSignatureGenerator implements SignatureGenerator {
26 @@ -101,11 +106,15 @@ public class OpenPGPSignatureGenerator implements SignatureGenerator {
27 pgpSec = readSecretKey(keyIn);
30 - PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(password.toCharArray(),
31 - BouncyCastleProvider.PROVIDER_NAME);
32 - PGPSignatureGenerator sGen = new PGPSignatureGenerator(pgpSec.getPublicKey()
33 - .getAlgorithm(), PGPUtil.SHA1, BouncyCastleProvider.PROVIDER_NAME);
34 - sGen.initSign(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
35 + PBESecretKeyDecryptor decryptor =
36 + new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
37 + .build(password.toCharArray());
38 + PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(decryptor);
39 + BcPGPContentSignerBuilder builder = new BcPGPContentSignerBuilder(
40 + pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1);
42 + PGPSignatureGenerator sGen = new PGPSignatureGenerator(builder);
43 + sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
45 in = new FileInputStream(src);
46 out = new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream(dest)));
47 @@ -116,22 +125,10 @@ public class OpenPGPSignatureGenerator implements SignatureGenerator {
50 sGen.generate().encode(out);
51 - } catch (SignatureException e) {
52 - IOException ioexc = new IOException();
55 } catch (PGPException e) {
56 IOException ioexc = new IOException();
59 - } catch (NoSuchAlgorithmException e) {
60 - IOException ioexc = new IOException();
63 - } catch (NoSuchProviderException e) {
64 - IOException ioexc = new IOException();
70 @@ -156,7 +153,8 @@ public class OpenPGPSignatureGenerator implements SignatureGenerator {
72 private PGPSecretKey readSecretKey(InputStream in) throws IOException, PGPException {
73 in = PGPUtil.getDecoderStream(in);
74 - PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(in);
75 + PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(in,
76 + new BcKeyFingerprintCalculator());
78 PGPSecretKey key = null;
79 for (Iterator it = pgpSec.getKeyRings(); key == null && it.hasNext();) {