java-apache-ivy-port-to-latest-bouncycastle.patch
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. |
5 | |
6 | --- |
7 | .../bouncycastle/OpenPGPSignatureGenerator.java | 34 ++++++++++------------ |
8 | 1 file changed, 16 insertions(+), 18 deletions(-) |
9 | |
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; |
23 | |
24 | public class OpenPGPSignatureGenerator implements SignatureGenerator { |
25 | |
26 | @@ -101,11 +106,15 @@ public class OpenPGPSignatureGenerator implements SignatureGenerator { |
27 | pgpSec = readSecretKey(keyIn); |
28 | } |
29 | |
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); |
41 | + |
42 | + PGPSignatureGenerator sGen = new PGPSignatureGenerator(builder); |
43 | + sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey); |
44 | |
45 | in = new FileInputStream(src); |
46 | out = new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream(dest))); |
47 | @@ -116,22 +125,10 @@ public class OpenPGPSignatureGenerator implements SignatureGenerator { |
48 | } |
49 | |
50 | sGen.generate().encode(out); |
51 | - } catch (SignatureException e) { |
52 | - IOException ioexc = new IOException(); |
53 | - ioexc.initCause(e); |
54 | - throw ioexc; |
55 | } catch (PGPException e) { |
56 | IOException ioexc = new IOException(); |
57 | ioexc.initCause(e); |
58 | throw ioexc; |
59 | - } catch (NoSuchAlgorithmException e) { |
60 | - IOException ioexc = new IOException(); |
61 | - ioexc.initCause(e); |
62 | - throw ioexc; |
63 | - } catch (NoSuchProviderException e) { |
64 | - IOException ioexc = new IOException(); |
65 | - ioexc.initCause(e); |
66 | - throw ioexc; |
67 | } finally { |
68 | if (out != null) { |
69 | try { |
70 | @@ -156,7 +153,8 @@ public class OpenPGPSignatureGenerator implements SignatureGenerator { |
71 | |
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()); |
77 | |
78 | PGPSecretKey key = null; |
79 | for (Iterator it = pgpSec.getKeyRings(); key == null && it.hasNext();) { |
80 | -- |
81 | 2.15.1 |
82 | |
83 |