@@ -51,11 +51,13 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
51
51
private String agentSocketLocations ;
52
52
53
53
/**
54
- * BC Signer only: The path of the exported key in TSK format, and probably passphrase protected. If relative,
55
- * the file is resolved against Maven local repository root.
54
+ * BC Signer only: The path of the exported key in
55
+ * <a href="https://openpgp.dev/book/private_keys.html#transferable-secret-key-format">TSK format</a>,
56
+ * and may be passphrase protected. If relative, the file is resolved against user home directory.
56
57
* <p>
57
- * <em>Note: it is not recommended to have sensitive files on disk or SCM repository, this mode is more to be used
58
- * in local environment (workstations) or for testing purposes.</em>
58
+ * <em>Note: it is not recommended to have sensitive files checked into SCM repository. Key file should reside on
59
+ * developer workstation, outside of SCM tracked repository. For CI-like use cases you should set the
60
+ * key material as env variable instead.</em>
59
61
*
60
62
* @since 3.2.0
61
63
*/
@@ -71,9 +73,11 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
71
73
private String keyFingerprint ;
72
74
73
75
/**
74
- * BC Signer only: The env variable name where the GnuPG key is set. The default value is {@code MAVEN_GPG_KEY}.
76
+ * BC Signer only: The env variable name where the GnuPG key is set.
75
77
* To use BC Signer you must provide GnuPG key, as it does not use GnuPG home directory to extract/find the
76
- * key (while it does use GnuPG Agent to ask for password in interactive mode).
78
+ * key (while it does use GnuPG Agent to ask for password in interactive mode). The key should be in
79
+ * <a href="https://openpgp.dev/book/private_keys.html#transferable-secret-key-format">TSK format</a> and may
80
+ * be passphrase protected.
77
81
*
78
82
* @since 3.2.0
79
83
*/
@@ -82,16 +86,16 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
82
86
83
87
/**
84
88
* BC Signer only: The env variable name where the GnuPG key fingerprint is set, if the provided keyring contains
85
- * multiple keys. The default value is {@code MAVEN_GPG_KEY_FINGERPRINT}.
89
+ * multiple keys.
86
90
*
87
91
* @since 3.2.0
88
92
*/
89
93
@ Parameter (property = "gpg.keyFingerprintEnvName" , defaultValue = DEFAULT_ENV_MAVEN_GPG_FINGERPRINT )
90
94
private String keyFingerprintEnvName ;
91
95
92
96
/**
93
- * The env variable name where the GnuPG passphrase is set. The default value is {@code MAVEN_GPG_PASSPHRASE}.
94
- * This is the recommended way to pass passphrase for signing in batch mode execution of Maven.
97
+ * The env variable name where the GnuPG passphrase is set. This is the recommended way to pass passphrase
98
+ * for signing in batch mode execution of Maven.
95
99
*
96
100
* @since 3.2.0
97
101
*/
@@ -109,23 +113,25 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
109
113
110
114
/**
111
115
* The passphrase to use when signing. If not given, look up the value under Maven
112
- * settings using server id at 'passphraseServerKey' configuration. <em>Do not use this parameter, if set, the
113
- * plugin will fail . Passphrase should be provided only via gpg-agent (interactive) or via env variable
114
- * (non-interactive) .</em>
116
+ * settings using server id at 'passphraseServerKey' configuration. <em>Do not use this parameter, it leaks
117
+ * sensitive data . Passphrase should be provided only via gpg-agent or via env variable.
118
+ * If parameter {@link #bestPractices} set to {@code true}, plugin fails when this parameter is configured .</em>
115
119
*
116
- * @deprecated Do not use this configuration, plugin will fail if set.
120
+ * @deprecated Do not use this configuration, it may leak sensitive information. Rely on gpg-agent or env
121
+ * variables instead.
117
122
**/
118
123
@ Deprecated
119
124
@ Parameter (property = "gpg.passphrase" )
120
125
private String passphrase ;
121
126
122
127
/**
123
- * Server id to lookup the passphrase under Maven settings. <em>Do not use this parameter, if set, the
124
- * plugin will fail . Passphrase should be provided only via gpg-agent (interactive) or via env variable
125
- * (non-interactive) .</em>
128
+ * Server id to lookup the passphrase under Maven settings. <em>Do not use this parameter, it leaks
129
+ * sensitive data . Passphrase should be provided only via gpg-agent or via env variable.
130
+ * If parameter {@link #bestPractices} set to {@code true}, plugin fails when this parameter is configured .</em>
126
131
*
127
132
* @since 1.6
128
- * @deprecated Do not use this configuration, plugin will fail if set.
133
+ * @deprecated Do not use this configuration, it may leak sensitive information. Rely on gpg-agent or env
134
+ * variables instead.
129
135
**/
130
136
@ Deprecated
131
137
@ Parameter (property = "gpg.passphraseServerId" )
@@ -138,23 +144,22 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
138
144
private String keyname ;
139
145
140
146
/**
141
- * GPG Signer only: Passes <code>--use-agent</code> or <code>--no-use-agent</code> to gpg. If using an agent, the
142
- * passphrase is optional as the agent will provide it. For gpg2, specify true as --no-use-agent was removed in
143
- * gpg2 and doesn't ask for a passphrase anymore. Deprecated, and better to rely on session "interactive" setting
144
- * (if interactive, agent will be used, otherwise not).
145
- *
146
- * @deprecated
147
+ * All signers: whether gpg-agent is allowed to be used or not. If enabled, passphrase is optional, as agent may
148
+ * provide it. Have to be noted, that in "batch" mode, gpg-agent will be prevented to pop up pinentry
149
+ * dialogue, hence best is to "prime" the agent caches beforehand.
150
+ * <p>
151
+ * GPG Signer: Passes <code>--use-agent</code> or <code>--no-use-agent</code> option to gpg if it is version 2.1
152
+ * or older. Otherwise, will use an agent. In non-interactive mode gpg options are appended with
153
+ * <code>--pinentry-mode error</code>, preventing gpg agent to pop up pinentry dialogue. Agent will be able to
154
+ * hand over only cached passwords.
155
+ * <p>
156
+ * BC Signer: Allows signer to communicate with gpg agent. In non-interactive mode it uses
157
+ * <code>--no-ask</code> option with the <code>GET_PASSPHRASE</code> function. Agent will be able to hand over
158
+ * only cached passwords.
147
159
*/
148
- @ Deprecated
149
160
@ Parameter (property = "gpg.useagent" , defaultValue = "true" )
150
161
private boolean useAgent ;
151
162
152
- /**
153
- * Detect is session interactive or not.
154
- */
155
- @ Parameter (defaultValue = "${settings.interactiveMode}" , readonly = true )
156
- private boolean interactive ;
157
-
158
163
/**
159
164
* GPG Signer only: The path to the GnuPG executable to use for artifact signing. Defaults to either "gpg" or
160
165
* "gpg.exe" depending on the operating system.
@@ -182,7 +187,7 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
182
187
* ‘private-keys-v1.d’ directory below the GnuPG home directory.
183
188
*
184
189
* @since 1.2
185
- * @deprecated
190
+ * @deprecated Obsolete option since GnuPG 2.1 version.
186
191
*/
187
192
@ Deprecated
188
193
@ Parameter (property = "gpg.secretKeyring" )
@@ -198,7 +203,7 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
198
203
* ‘pubring.kbx’ file below the GnuPG home directory.
199
204
*
200
205
* @since 1.2
201
- * @deprecated
206
+ * @deprecated Obsolete option since GnuPG 2.1 version.
202
207
*/
203
208
@ Deprecated
204
209
@ Parameter (property = "gpg.publicKeyring" )
@@ -224,7 +229,7 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
224
229
private boolean skip ;
225
230
226
231
/**
227
- * Sets the arguments to be passed to gpg. Example:
232
+ * GPG Signer only: Sets the arguments to be passed to gpg. Example:
228
233
*
229
234
* <pre>
230
235
* <gpgArguments>
@@ -256,32 +261,32 @@ public abstract class AbstractGpgMojo extends AbstractMojo {
256
261
// === Deprecated stuff
257
262
258
263
/**
259
- * Switch to lax plugin enforcement of "best practices". If set to {@code false}, plugin will retain all the
260
- * backward compatibility regarding getting secrets (but will warn). By default, plugin enforces "best practices"
261
- * and in such cases plugin fails.
264
+ * Switch to improve plugin enforcement of "best practices". If set to {@code false}, plugin retains all the
265
+ * backward compatibility regarding getting secrets (but will warn). If set to {@code true}, plugin will fail
266
+ * if any "bad practices" regarding sensitive data handling are detected. By default, plugin remains backward
267
+ * compatible (this flag is {@code false}). Somewhere in the future, when this parameter enabling transitioning
268
+ * from older plugin versions is removed, the logic using this flag will be modified like it is set to {@code true}.
269
+ * It is warmly advised to configure this parameter to {@code true} and migrate project and user environment
270
+ * regarding how sensitive information is stored.
262
271
*
263
272
* @since 3.2.0
264
- * @deprecated
265
273
*/
266
- @ Deprecated
267
- @ Parameter (property = "gpg.bestPractices" , defaultValue = "true" )
274
+ @ Parameter (property = "gpg.bestPractices" , defaultValue = "false" )
268
275
private boolean bestPractices ;
269
276
270
277
/**
271
278
* Current user system settings for use in Maven.
272
279
*
273
280
* @since 1.6
274
- * @deprecated
275
281
*/
276
- @ Deprecated
277
282
@ Parameter (defaultValue = "${settings}" , readonly = true , required = true )
278
283
private Settings settings ;
279
284
280
285
/**
281
286
* Maven Security Dispatcher.
282
287
*
283
288
* @since 1.6
284
- * @deprecated
289
+ * @deprecated Provides quasi-encryption, should be avoided.
285
290
*/
286
291
@ Deprecated
287
292
@ Component
@@ -310,7 +315,7 @@ private void logBestPracticeWarning(String source) {
310
315
getLog ().warn ("W A R N I N G" );
311
316
getLog ().warn ("" );
312
317
getLog ().warn ("Do not store passphrase in any file (disk or SCM repository)," );
313
- getLog ().warn ("instead rely on GnuPG agent in interactive sessions, or provide passphrase in " );
318
+ getLog ().warn ("instead rely on GnuPG agent or provide passphrase in " );
314
319
getLog ().warn (passphraseEnvName + " environment variable for batch mode." );
315
320
getLog ().warn ("" );
316
321
getLog ().warn ("Sensitive content loaded from " + source );
@@ -334,7 +339,7 @@ protected AbstractGpgSigner newSigner(MavenProject mavenProject) throws MojoFail
334
339
}
335
340
336
341
signer .setLog (getLog ());
337
- signer .setInteractive (interactive );
342
+ signer .setInteractive (settings . isInteractiveMode () );
338
343
signer .setKeyName (keyname );
339
344
signer .setUseAgent (useAgent );
340
345
signer .setHomeDirectory (homedir );
@@ -371,13 +376,6 @@ protected AbstractGpgSigner newSigner(MavenProject mavenProject) throws MojoFail
371
376
}
372
377
}
373
378
}
374
-
375
- // gpg signer: always failed if no passphrase and no agent and not interactive: retain this behavior
376
- // bc signer: it is optimistic, will fail during prepare() only IF key is passphrase protected
377
- if (GpgSigner .NAME .equals (this .signer ) && null == passphrase && !useAgent && !interactive ) {
378
- throw new MojoFailureException ("Cannot obtain passphrase in batch mode" );
379
- }
380
-
381
379
signer .prepare ();
382
380
383
381
return signer ;
@@ -419,7 +417,7 @@ public String getPassphrase(MavenProject project) {
419
417
pass = prj2 .getProperties ().getProperty (GPG_PASSPHRASE );
420
418
}
421
419
}
422
- if (project != null ) {
420
+ if (project != null && pass != null ) {
423
421
findReactorProject (project ).getProperties ().setProperty (GPG_PASSPHRASE , pass );
424
422
}
425
423
return pass ;
0 commit comments