Skip to content

Commit 1ce2a8b

Browse files
committed
[JENKINS-75905] Include update site URL in signature verification error messages
1 parent 338090d commit 1ce2a8b

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

core/src/main/java/hudson/model/UpdateSite.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,29 @@ protected UpdateCenter.InstallationJob createInstallationJob(Plugin plugin, Upda
294294
*/
295295
@Restricted(NoExternalUse.class)
296296
public final FormValidation verifySignatureInternal(JSONObject o) throws IOException {
297-
return getJsonSignatureValidator().verifySignature(o);
297+
FormValidation result = getJsonSignatureValidator().verifySignature(o);
298+
299+
if (result.kind == FormValidation.Kind.ERROR) {
300+
String message = result.getMessage();
301+
if (message != null) {
302+
// String siteUrl = getUrl();
303+
String updatedMessage;
304+
305+
if (message.contains("update site") && message.contains(" Path") && !message.contains(url)) {
306+
// Ensure the update site URL is included in error messages by replacing the site identifier in messages of the 'update site … Path' pattern or appending it otherwise.
307+
updatedMessage = message.replaceAll(
308+
"(update site\\s+).*?(\\s+Path)",
309+
"$1" + url + "$2"
310+
);
311+
} else {
312+
// Do not alter message structure; only add URL context
313+
updatedMessage = message + " (URL: " + url + ")";
314+
}
315+
return FormValidation.error(updatedMessage);
316+
}
317+
}
318+
319+
return result;
298320
}
299321

300322
/**

core/src/main/java/jenkins/util/JSONSignatureValidator.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ public FormValidation verifySignature(JSONObject o) throws IOException {
138138
if (warning != null) return warning;
139139
return FormValidation.ok();
140140
} catch (GeneralSecurityException e) {
141-
return FormValidation.error(e, "Signature verification failed in " + name);
141+
// Return a user-friendly error message without the full stack trace
142+
String rootCauseMessage = getRootCauseMessage(e);
143+
return FormValidation.error("Signature verification failed in " + name + ": " + rootCauseMessage);
142144
}
143145
}
144146

@@ -321,5 +323,25 @@ protected Set<TrustAnchor> loadTrustAnchors(CertificateFactory cf) throws IOExce
321323
return anchors;
322324
}
323325

326+
/**
327+
* Extracts a user-friendly message from an exception chain.
328+
*
329+
* @param e the exception to extract the message from
330+
* @return a concise, readable error message
331+
*/
332+
private String getRootCauseMessage(Throwable e) {
333+
Throwable cause = e;
334+
while (cause.getCause() != null && cause.getCause() != cause) {
335+
cause = cause.getCause();
336+
}
337+
338+
String message = cause.getMessage();
339+
if (message != null && !message.isEmpty()) {
340+
return message;
341+
}
342+
343+
return cause.getClass().getSimpleName();
344+
}
345+
324346
private static final Logger LOGGER = Logger.getLogger(JSONSignatureValidator.class.getName());
325347
}

test/src/test/java/hudson/model/UpdateSiteTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,24 @@ private PluginWrapper buildPluginWrapper(String name, String wikiUrl) {
299299
new ArrayList<>()
300300
);
301301
}
302+
303+
@Test
304+
void signatureVerificationFailureIncludesUpdateSiteUrl() throws Exception {
305+
// Create an UpdateSite with an invalid/malformed signature that will trigger an error
306+
URL url = new URL(baseUrl, "/plugins/invalid-signature-update-center.json");
307+
UpdateSite site = new UpdateSite(UpdateCenter.ID_DEFAULT, url.toString());
308+
overrideUpdateSite(site);
309+
310+
FormValidation validation = site.updateDirectlyNow(true);
311+
312+
assertEquals(FormValidation.Kind.ERROR, validation.kind);
313+
314+
String message = validation.getMessage();
315+
assertNotNull(message);
316+
assertTrue(
317+
message.contains(url.toString()),
318+
"Signature verification error should include update site URL"
319+
);
320+
}
321+
302322
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"updateCenterVersion": "1",
3+
"connectionCheckUrl": "http://www.google.com/",
4+
"core": {
5+
"name": "core",
6+
"version": "2.0",
7+
"url": "http://updates.jenkins-ci.org/download/war/2.0/jenkins.war"
8+
},
9+
"plugins": {},
10+
"signature": {
11+
"certificates": [
12+
"InvalidBase64CertificateDataThatWillFailValidation=="
13+
],
14+
"correct_digest": "invalid_digest_value",
15+
"correct_signature": "invalid_signature_value"
16+
}
17+
}

0 commit comments

Comments
 (0)