@@ -129,7 +129,7 @@ public final class GpgConfLoader implements Loader {
129
129
*
130
130
* @see <a href="https://wiki.gnupg.org/LargeKeys">Large Keys</a>
131
131
*/
132
- private static final long MAX_SIZE = 64 * 1024 + 1L ;
132
+ private static final long MAX_SIZE = 64 * 1000 + 1L ;
133
133
134
134
@ Override
135
135
public byte [] loadKeyRingMaterial (RepositorySystemSession session ) throws IOException {
@@ -143,7 +143,7 @@ public byte[] loadKeyRingMaterial(RepositorySystemSession session) throws IOExce
143
143
if (Files .size (keyPath ) < MAX_SIZE ) {
144
144
return Files .readAllBytes (keyPath );
145
145
} else {
146
- throw new IOException ("Refusing to load file " + keyPath + "; is larger than 64KB " );
146
+ throw new IOException ("Refusing to load file " + keyPath + "; is larger than 64 kB " );
147
147
}
148
148
}
149
149
return null ;
@@ -180,18 +180,15 @@ public char[] loadPassword(RepositorySystemSession session, byte[] fingerprint)
180
180
.resolve (socketLocationPath )
181
181
.toAbsolutePath ();
182
182
}
183
- String pw = load (fingerprint , socketLocationPath );
184
- if (pw != null ) {
185
- return pw .toCharArray ();
186
- }
183
+ return load (fingerprint , socketLocationPath );
187
184
} catch (SocketException e ) {
188
185
// try next location
189
186
}
190
187
}
191
188
return null ;
192
189
}
193
190
194
- private String load (byte [] fingerprint , Path socketPath ) throws IOException {
191
+ private char [] load (byte [] fingerprint , Path socketPath ) throws IOException {
195
192
try (AFUNIXSocket sock = AFUNIXSocket .newInstance ()) {
196
193
sock .connect (AFUNIXSocketAddress .of (socketPath ));
197
194
try (BufferedReader in = new BufferedReader (new InputStreamReader (sock .getInputStream ()));
@@ -224,11 +221,7 @@ private String load(byte[] fingerprint, Path socketPath) throws IOException {
224
221
+ "+to+use+it+for+signing+Maven+Artifacts\n " ;
225
222
os .write ((instruction ).getBytes ());
226
223
os .flush ();
227
- String pw = mayExpectOK (in );
228
- if (pw != null ) {
229
- return new String (Hex .decode (pw .trim ()));
230
- }
231
- return null ;
224
+ return mayExpectOK (in );
232
225
}
233
226
}
234
227
}
@@ -240,14 +233,16 @@ private void expectOK(BufferedReader in) throws IOException {
240
233
}
241
234
}
242
235
243
- private String mayExpectOK (BufferedReader in ) throws IOException {
236
+ private char [] mayExpectOK (BufferedReader in ) throws IOException {
244
237
String response = in .readLine ();
245
238
if (response .startsWith ("ERR" )) {
246
239
return null ;
247
240
} else if (!response .startsWith ("OK" )) {
248
241
throw new IOException ("Expected OK/ERR but got this instead: " + response );
249
242
}
250
- return response .substring (Math .min (response .length (), 3 ));
243
+ return new String (Hex .decode (
244
+ response .substring (Math .min (response .length (), 3 )).trim ()))
245
+ .toCharArray ();
251
246
}
252
247
}
253
248
@@ -359,6 +354,9 @@ public void prepare() throws MojoFailureException {
359
354
this .secretKey = secretKey ;
360
355
this .privateKey = secretKey .extractPrivateKey (
361
356
new BcPBESecretKeyDecryptorBuilder (new BcPGPDigestCalculatorProvider ()).build (keyPassword ));
357
+ if (keyPassword != null ) {
358
+ Arrays .fill (keyPassword , ' ' );
359
+ }
362
360
PGPSignatureSubpacketGenerator subPacketGenerator = new PGPSignatureSubpacketGenerator ();
363
361
subPacketGenerator .setIssuerFingerprint (false , secretKey );
364
362
this .hashSubPackets = subPacketGenerator .generate ();
0 commit comments