sbt-ivy-fix-bouncycastle-api.patch
1 | From 5c27ac3ca1ac9544c3d80a7a1abf2610ebec4ea6 Mon Sep 17 00:00:00 2001 |
2 | From: Julien Lepiller <julien@lepiller.eu> |
3 | Date: Thu, 17 Jun 2021 00:04:48 +0200 |
4 | Subject: [PATCH] Fix API breakage |
5 | |
6 | --- |
7 | .../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..a9282ed 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 | @@ -42,6 +42,10 @@ import org.bouncycastle.openpgp.PGPSignature; |
15 | import org.bouncycastle.openpgp.PGPSignatureGenerator; |
16 | import org.bouncycastle.openpgp.PGPUtil; |
17 | |
18 | +import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; |
19 | +import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; |
20 | +import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; |
21 | + |
22 | public class OpenPGPSignatureGenerator implements SignatureGenerator { |
23 | |
24 | private static final long MASK = 0xFFFFFFFFL; |
25 | @@ -101,11 +105,16 @@ public class OpenPGPSignatureGenerator implements SignatureGenerator { |
26 | pgpSec = readSecretKey(keyIn); |
27 | } |
28 | |
29 | - PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(password.toCharArray(), |
30 | - BouncyCastleProvider.PROVIDER_NAME); |
31 | - PGPSignatureGenerator sGen = new PGPSignatureGenerator(pgpSec.getPublicKey() |
32 | - .getAlgorithm(), PGPUtil.SHA1, BouncyCastleProvider.PROVIDER_NAME); |
33 | - sGen.initSign(PGPSignature.BINARY_DOCUMENT, pgpPrivKey); |
34 | + PGPPrivateKey pgpPrivKey = |
35 | + pgpSec.extractPrivateKey( |
36 | + new JcePBESecretKeyDecryptorBuilder().setProvider( new BouncyCastleProvider() ) |
37 | + .build( password.toCharArray() ) ); |
38 | + PGPSignatureGenerator sGen = new PGPSignatureGenerator( |
39 | + new JcaPGPContentSignerBuilder( pgpSec.getPublicKey().getAlgorithm(), |
40 | + PGPUtil.SHA1) |
41 | + .setProvider( new BouncyCastleProvider() ) ); |
42 | + |
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( |
76 | + in, new JcaKeyFingerprintCalculator() ); |
77 | |
78 | PGPSecretKey key = null; |
79 | for (Iterator it = pgpSec.getKeyRings(); key == null && it.hasNext();) { |
80 | -- |
81 | 2.31.1 |
82 | |
83 |