From c61ee0f2d2bfa030cf85ae57bfceba437f0b1c00 Mon Sep 17 00:00:00 2001 From: Danny van Heumen Date: Fri, 15 May 2020 19:52:46 +0200 Subject: [PATCH] Fix 'noKey' specifier for PGP keysmap. The control flow logic for the 'noKey' specifier is broken as it matches on the wrong exception to identify the case. This is fixed and while fixing starts using Java's catch-syntax capabilities for implicitly performing the instance-of test. Added IT tests 'noKeyOK' and 'noKeyFail' for verifying correct behavior. Both tests use a PGP keypair that was never published. The 'helloworld' artifact is installed in the local repo used for IT tests only. Slightly modified capitalization in the exception's error message because of my OCD. --- src/it/noKeyFail/invoker.properties | 17 ++++ src/it/noKeyFail/keysmap.list | 19 ++++ src/it/noKeyFail/pom-test.xml | 60 ++++++++++++ src/it/noKeyFail/postbuild.groovy | 20 ++++ src/it/noKeyOK/keysmap.list | 18 ++++ src/it/noKeyOK/pom-test.xml | 60 ++++++++++++ src/it/noKeyOK/postbuild.groovy | 21 ++++ .../helloworld/1.0/helloworld-1.0.jar | Bin 0 -> 2764 bytes .../helloworld/1.0/helloworld-1.0.jar.asc | 11 +++ .../helloworld/1.0/helloworld-1.0.pom | 92 ++++++++++++++++++ .../helloworld/1.0/helloworld-1.0.pom.asc | 11 +++ .../helloworld/maven-metadata-local.xml | 12 +++ .../org/simplify4u/plugins/PGPVerifyMojo.java | 9 +- 13 files changed, 347 insertions(+), 3 deletions(-) create mode 100644 src/it/noKeyFail/invoker.properties create mode 100644 src/it/noKeyFail/keysmap.list create mode 100644 src/it/noKeyFail/pom-test.xml create mode 100644 src/it/noKeyFail/postbuild.groovy create mode 100644 src/it/noKeyOK/keysmap.list create mode 100644 src/it/noKeyOK/pom-test.xml create mode 100644 src/it/noKeyOK/postbuild.groovy create mode 100644 src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.jar create mode 100644 src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.jar.asc create mode 100644 src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom create mode 100644 src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom.asc create mode 100644 src/it/resources/local-repo/nl/dannyvanheumen/helloworld/maven-metadata-local.xml diff --git a/src/it/noKeyFail/invoker.properties b/src/it/noKeyFail/invoker.properties new file mode 100644 index 00000000..cb81151a --- /dev/null +++ b/src/it/noKeyFail/invoker.properties @@ -0,0 +1,17 @@ +# +# Copyright 2017 Slawomir Jaranowski +# Portions copyright 2020 Danny van Heumen +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +invoker.buildResult = failure diff --git a/src/it/noKeyFail/keysmap.list b/src/it/noKeyFail/keysmap.list new file mode 100644 index 00000000..c3c3d12f --- /dev/null +++ b/src/it/noKeyFail/keysmap.list @@ -0,0 +1,19 @@ +# +# Copyright 2020 Slawomir Jaranowski +# Portions copyright 2020 Danny van Heumen +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# PGP key below is not actually available anywhere. It was generated to sign the test artifact and then deleted. +nl.dannyvanheumen:helloworld:1.0 = 0x466583F9480EBE2462C46B309F1A263E15FD0AC9 diff --git a/src/it/noKeyFail/pom-test.xml b/src/it/noKeyFail/pom-test.xml new file mode 100644 index 00000000..da31197c --- /dev/null +++ b/src/it/noKeyFail/pom-test.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + + + test + it-test-parent + 0.0.1-SNAPSHOT + + + + test + 0.0.1-SNAPSHOT + pom + + + + nl.dannyvanheumen + helloworld + 1.0 + + + + + + + org.simplify4u.plugins + pgpverify-maven-plugin + @project.version@ + + ${project.basedir}/keysmap.list + + + + + check + + + + + + + diff --git a/src/it/noKeyFail/postbuild.groovy b/src/it/noKeyFail/postbuild.groovy new file mode 100644 index 00000000..651fed12 --- /dev/null +++ b/src/it/noKeyFail/postbuild.groovy @@ -0,0 +1,20 @@ +/* + * Copyright 2020 Slawomir Jaranowski + * Portions copyright 2020 Danny van Heumen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +def buildLog = new File( basedir, 'build.log' ).text + +assert buildLog.contains('for artifact nl.dannyvanheumen:helloworld:jar:1.0: cannot find public key on keyserver.') +assert buildLog.contains('[INFO] BUILD FAILURE') diff --git a/src/it/noKeyOK/keysmap.list b/src/it/noKeyOK/keysmap.list new file mode 100644 index 00000000..0dbf3a0a --- /dev/null +++ b/src/it/noKeyOK/keysmap.list @@ -0,0 +1,18 @@ +# +# Copyright 2020 Slawomir Jaranowski +# Portions copyright 2020 Danny van Heumen +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +nl.dannyvanheumen:helloworld:1.0 = noKey diff --git a/src/it/noKeyOK/pom-test.xml b/src/it/noKeyOK/pom-test.xml new file mode 100644 index 00000000..da31197c --- /dev/null +++ b/src/it/noKeyOK/pom-test.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + + + test + it-test-parent + 0.0.1-SNAPSHOT + + + + test + 0.0.1-SNAPSHOT + pom + + + + nl.dannyvanheumen + helloworld + 1.0 + + + + + + + org.simplify4u.plugins + pgpverify-maven-plugin + @project.version@ + + ${project.basedir}/keysmap.list + + + + + check + + + + + + + diff --git a/src/it/noKeyOK/postbuild.groovy b/src/it/noKeyOK/postbuild.groovy new file mode 100644 index 00000000..a23a8114 --- /dev/null +++ b/src/it/noKeyOK/postbuild.groovy @@ -0,0 +1,21 @@ +/* + * Copyright 2020 Slawomir Jaranowski + * Portions copyright 2020 Danny van Heumen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +def buildLog = new File( basedir, 'build.log' ).text + +assert buildLog.contains('[INFO] nl.dannyvanheumen:helloworld:jar:1.0 PGP key not found on server, consistent with keys map.') +assert buildLog.contains('[INFO] nl.dannyvanheumen:helloworld:pom:1.0 PGP key not found on server, consistent with keys map.') +assert buildLog.contains('[INFO] BUILD SUCCESS') diff --git a/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.jar b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..603763ce867b9363245e1624c4ed38764df2d73c GIT binary patch literal 2764 zcmWIWW@h1H0DjS_HD8UJ&eO*Hwbv^yu^aG&EI2fXU%I4k@pVbGH-U`Gb$jW>j z{XE@VgG2Ou-CTPexegf!xPEWEqbPo2fr!Yi?A?M3A9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>GM_%URJ`EZa{bOCk%GN%mlttr*M8&? zy}kdEScr*q#A%+LZ7WXSE8^jhU)7cUY)6Kw(3{wmZDF53zRAk!UgiET>%jg0_8k8i zVHpxqd^$c4W6A|4>3krzA|q)R6y+DB7L{bC76+I4pY_)D((&{S^jH=0!B@xo?Bk#^ z?Ncm9+M+zZqCC25d3x6P^oq=hZFUyv;pySoajE;0H@8i2&gY^pK|-HDX`L4OY!u{O z+$bg7?PYXXXtH<1B*~SQmOr2VbhXrsNnPoBbmq^>ZEaO-F$@9Tj7%cTxGP?uPk=yx z;jJTxhLfZI4wJpch9<9dlP4o3iDs~2EqFKN6^qRG%&0uhYZ nb0@-rO>7v!h#3+{P6t_l$g2U~tU&z?4BS9y4|HldJBSAWR7$mH literal 0 HcmV?d00001 diff --git a/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.jar.asc b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.jar.asc new file mode 100644 index 00000000..36f42140 --- /dev/null +++ b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.jar.asc @@ -0,0 +1,11 @@ +-----BEGIN PGP SIGNATURE----- + +iQEzBAABCgAdFiEERmWD+UgOviRixGswnxomPhX9CskFAl6+yzwACgkQnxomPhX9 +CslwWAf+IsAeoaZC0yo38k1PZ58IAeHQP9iavrfZ4LMCMxFacXmBGZF4SVniBmZ3 +o7gaQpp+EYi7LikfBDphX0iNchSn/7jGlDq8eK12JCeoyD7s0rYAYu94itQSPuvE +MZWDD//C0pGNSoK14EZB4TdzE2Ey87+lXqBd2NKNdmSTntL+ijyOPZRMTsLs7o6F +cEwRJQ1T2i26/uC2dpiQ4qelk/bo0eZM/BjJp6DZqjmh4CZDaY/vMTxrM5v7LNVE +4ChAcuu3V8oiNMgWicXFRGHNqyEMrJUM6f7yx325si7ziH3l/CL1iGymVt1DdLzq +3R/QK/dX6YGYEUjJJbxWmx7DTc3HDA== +=DNhd +-----END PGP SIGNATURE----- diff --git a/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom new file mode 100644 index 00000000..1e9b8251 --- /dev/null +++ b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom @@ -0,0 +1,92 @@ + + + 4.0.0 + + nl.dannyvanheumen + helloworld + 1.0 + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + enforce-maven + + enforce + + + + + 3.5 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + 11 + true + true + + + + org.apache.maven.plugins + maven-install-plugin + 2.4 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + nl.dannyvanheumen.helloworld.HelloWorld + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + + org.apache.maven.plugins + maven-site-plugin + 3.3 + + + org.apache.maven.plugins + maven-clean-plugin + 2.5 + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + + \ No newline at end of file diff --git a/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom.asc b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom.asc new file mode 100644 index 00000000..e64fec70 --- /dev/null +++ b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/1.0/helloworld-1.0.pom.asc @@ -0,0 +1,11 @@ +-----BEGIN PGP SIGNATURE----- + +iQEzBAABCgAdFiEERmWD+UgOviRixGswnxomPhX9CskFAl6+yzwACgkQnxomPhX9 +CsnFnAf/Tj2u5jhbYV3TgwWpS63zXPCcHr9ARv9OULozca5JvhMk7alBpsL6Dsyf +y0PMMTQP4mjcIwcf0HWgpIJtHe5WaL9CMLxJCo4nQ90AbF/lT2bs2+ZnA34wdZYE +4p/WaF/MXHRLZKtTf/+t/9OT5FFP7cxyUzqJKyG7lrasZvnEGPftMT0YuJ3vpoSd +tG86DSFXxn6GRvNh9rTi5mFpUw/066qrSTGuSST6jEC+hZh0kY2cUTsv12FDaVbm +XafwznmghUZFC9luBuM+QDNAMbnhZUNZ0u24pyikSoFXA9eO5o4TUgiNHMxPOvee +bn9RRRV7hufI/RVrDdCx6RTjSjO6Qw== +=E9yz +-----END PGP SIGNATURE----- diff --git a/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/maven-metadata-local.xml b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/maven-metadata-local.xml new file mode 100644 index 00000000..fd2c4164 --- /dev/null +++ b/src/it/resources/local-repo/nl/dannyvanheumen/helloworld/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + nl.dannyvanheumen + helloworld + + 1.0 + + 1.0 + + 20200515170252 + + diff --git a/src/main/java/org/simplify4u/plugins/PGPVerifyMojo.java b/src/main/java/org/simplify4u/plugins/PGPVerifyMojo.java index bde823f2..f1012b98 100644 --- a/src/main/java/org/simplify4u/plugins/PGPVerifyMojo.java +++ b/src/main/java/org/simplify4u/plugins/PGPVerifyMojo.java @@ -468,9 +468,9 @@ private boolean verifyPGPSignature(Artifact artifact, Artifact ascArtifact) thro + " signature.hashAlgorithm: " + pgpSignature.getHashAlgorithm()); return verifySignatureStatus(pgpSignature.verify(), artifact, publicKey, publicKeyRing); - } catch (IOException | PGPException e) { - if (e.getCause() instanceof PGPKeyNotFound && keysMap.isKeyMissing(artifact)) { - final String logMessage = String.format("%s PGP Key not found on server, consistent with keys map.", + } catch (PGPKeyNotFound e) { + if (keysMap.isKeyMissing(artifact)) { + final String logMessage = String.format("%s PGP key not found on server, consistent with keys map.", artifact.getId()); if (quiet) { getLog().debug(logMessage); @@ -479,6 +479,9 @@ private boolean verifyPGPSignature(Artifact artifact, Artifact ascArtifact) thro } return true; } + throw new MojoFailureException("Failed to process signature '" + signatureFile + "' for artifact " + + artifact.getId() + ": cannot find public key on keyserver.", e); + } catch (IOException | PGPException e) { throw new MojoFailureException("Failed to process signature '" + signatureFile + "' for artifact " + artifact.getId(), e); }