From 1e6afbae3b82936602f28c402379e04d0b00a47e Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Sat, 14 May 2016 14:05:35 +0200 Subject: [PATCH] [JENKINS-34745] - Prevent CheckUpdates PeriodicWork death if update site cert is missing (#2333) * [JENKINS-34745] - Prevent CheckUpdates PeriodicWork death in the case of the missing update site signature * [JENKINS-34745] - Fix typo in the validator * [JENKINS-34745] - Fix the formatting of the validation message (cc @lanwen) --- core/src/main/java/hudson/PluginManager.java | 26 +++++++++++-------- .../jenkins/util/JSONSignatureValidator.java | 6 ++++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index 56a4b0b5ad..8b83619253 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -1408,20 +1408,24 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas @Restricted(NoExternalUse.class) @RequirePOST public HttpResponse doCheckUpdatesServer() throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); - for (UpdateSite site : Jenkins.getInstance().getUpdateCenter().getSites()) { - FormValidation v = site.updateDirectlyNow(DownloadService.signatureCheck); - if (v.kind != FormValidation.Kind.OK) { - // TODO crude but enough for now - return v; + try { + for (UpdateSite site : Jenkins.getInstance().getUpdateCenter().getSites()) { + FormValidation v = site.updateDirectlyNow(DownloadService.signatureCheck); + if (v.kind != FormValidation.Kind.OK) { + // TODO crude but enough for now + return v; + } } - } - for (DownloadService.Downloadable d : DownloadService.Downloadable.all()) { - FormValidation v = d.updateNow(); - if (v.kind != FormValidation.Kind.OK) { - return v; + for (DownloadService.Downloadable d : DownloadService.Downloadable.all()) { + FormValidation v = d.updateNow(); + if (v.kind != FormValidation.Kind.OK) { + return v; + } } + return HttpResponses.forwardToPreviousPage(); + } catch(RuntimeException ex) { + throw new IOException("Unhandled exception during updates server check", ex); } - return HttpResponses.forwardToPreviousPage(); } protected String identifyPluginShortName(File t) { diff --git a/core/src/main/java/jenkins/util/JSONSignatureValidator.java b/core/src/main/java/jenkins/util/JSONSignatureValidator.java index b36f4e399f..73f9dd0a26 100644 --- a/core/src/main/java/jenkins/util/JSONSignatureValidator.java +++ b/core/src/main/java/jenkins/util/JSONSignatureValidator.java @@ -82,7 +82,11 @@ public class JSONSignatureValidator { // this is for computing a signature Signature sig = Signature.getInstance("SHA1withRSA"); - sig.initVerify(certs.get(0)); + if (certs.isEmpty()) { + return FormValidation.error("No certificate found in %s. Cannot verify the signature", name); + } else { + sig.initVerify(certs.get(0)); + } SignatureOutputStream sos = new SignatureOutputStream(sig); // until JENKINS-11110 fix, UC used to serve invalid digest (and therefore unverifiable signature)