diff --git a/WHATSNEW b/WHATSNEW index 041559255..abebee631 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -27,6 +27,16 @@ Fixed bugs: tokens, would be replaced by property values Bugzilla Report 62147 + * Added a workaround for a bug in the jarsigner tool to + which requires the -storepass command line argument when verifying + signatures using -strict together with a PKCS12 keystore. Unlike + when signing the jar it will not prompt for the keystore's password + and read it from standard input. + This means Ant will now pass the keystore's password on the command + line when using , which poses a security risk you should + be aware of. + Bugzilla Report 62194 + Other changes: -------------- diff --git a/manual/Tasks/signjar.html b/manual/Tasks/signjar.html index 53269f3fd..e7e75cc84 100644 --- a/manual/Tasks/signjar.html +++ b/manual/Tasks/signjar.html @@ -63,7 +63,9 @@ place.

storepass - password for keystore integrity. + password for keystore integrity. Ant will not use + the -storepass command line argument but send the + password to jarsigner when it prompts for it. Yes diff --git a/manual/Tasks/verifyjar.html b/manual/Tasks/verifyjar.html index e20c4016b..e10d756ca 100644 --- a/manual/Tasks/verifyjar.html +++ b/manual/Tasks/verifyjar.html @@ -50,8 +50,12 @@ the jar attribute. Nested paths are also supported.

storepass - password for keystore integrity. - Yes + password for keystore integrity. + Note that + jarsigner does not read the password from stdin during + verification, so the password must be send via a command line + interface and may be visible to other users of the system. + No keystore diff --git a/src/etc/testcases/testkeystore.pkcs12 b/src/etc/testcases/testkeystore.pkcs12 new file mode 100644 index 000000000..c0016c574 Binary files /dev/null and b/src/etc/testcases/testkeystore.pkcs12 differ diff --git a/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java b/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java index 5f9c8f3e0..adf1bce32 100644 --- a/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java @@ -59,6 +59,8 @@ public class VerifyJar extends AbstractJarSignerTask { private boolean certificates = false; private BufferingOutputFilter outputCache = new BufferingOutputFilter(); + private String savedStorePass = null; + /** * Ask for certificate information to be printed * @param certificates if true print certificates. @@ -99,6 +101,42 @@ public class VerifyJar extends AbstractJarSignerTask { } } + /** + * @since 1.10.3 + */ + @Override + protected void beginExecution() { + // when using a PKCS12 keystore jarsigner -verify will not + // prompt for the keystore password but will only properly + // verify the jar with -strict enabled if the -storepass + // parameter is used. Note that the documentation of jarsigner + // says -storepass was never required with -verify - this is + // wrong. + // + // See https://bz.apache.org/bugzilla/show_bug.cgi?id=62194 + // + // So if strict is true then we hide storepass from the base + // implementation and instead add the -storepass command line + // argument + if (mustHideStorePass()) { + savedStorePass = storepass; + setStorepass(null); + } + super.beginExecution(); + } + + /** + * @since 1.10.3 + */ + @Override + protected void endExecution() { + if (savedStorePass != null) { + setStorepass(savedStorePass); + savedStorePass = null; + } + super.endExecution(); + } + /** * verify a JAR. * @param jar the jar to verify. @@ -112,6 +150,10 @@ public class VerifyJar extends AbstractJarSignerTask { setCommonOptions(cmd); bindToKeystore(cmd); + if (savedStorePass != null) { + addValue(cmd, "-storepass"); + addValue(cmd, savedStorePass); + } //verify special operations addValue(cmd, "-verify"); @@ -123,6 +165,10 @@ public class VerifyJar extends AbstractJarSignerTask { //JAR is required addValue(cmd, jar.getPath()); + if (alias != null) { + addValue(cmd, alias); + } + log("Verifying JAR: " + jar.getAbsolutePath()); outputCache.clear(); BuildException ex = null; @@ -147,6 +193,10 @@ public class VerifyJar extends AbstractJarSignerTask { } } + private boolean mustHideStorePass() { + return strict && storepass != null; + } + /** * we are not thread safe here. Do not use on multiple threads at the same time. */ diff --git a/src/tests/antunit/taskdefs/signjar-test.xml b/src/tests/antunit/taskdefs/signjar-test.xml index 0f03bc586..30671cfb2 100644 --- a/src/tests/antunit/taskdefs/signjar-test.xml +++ b/src/tests/antunit/taskdefs/signjar-test.xml @@ -25,6 +25,7 @@ + @@ -43,6 +44,11 @@ + + + + @@ -60,6 +66,10 @@ + + + + @@ -232,6 +242,10 @@ + + + + @@ -268,5 +282,14 @@ + + + + + + + +