8347847: Enhance jar file support

Reviewed-by: yan, andrew
Backport-of: ef84ee26d6891c824eb798863f4ef9334e473bb8
This commit is contained in:
Martin Balao 2025-03-19 10:46:00 +00:00 committed by Andrew John Hughes
parent 68d10daaba
commit 898c0ef620

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -503,6 +503,8 @@ public class SignatureFileVerifier {
boolean attrsVerified = true;
// If only weak algorithms are used.
boolean weakAlgs = true;
// If only unsupported algorithms are used.
boolean unsupportedAlgs = true;
// If a ATTR_DIGEST entry is found.
boolean validEntry = false;
@ -527,6 +529,7 @@ public class SignatureFileVerifier {
MessageDigest digest = getDigest(algorithm);
if (digest != null) {
unsupportedAlgs = false;
ManifestDigester.Entry mde =
md.get(ManifestDigester.MF_MAIN_ATTRS, false);
if (mde == null) {
@ -570,12 +573,22 @@ public class SignatureFileVerifier {
}
}
// If there were only weak algorithms entries used, throw an exception.
if (validEntry && weakAlgs) {
throw new SignatureException("Manifest Main Attribute check " +
"failed (" + ATTR_DIGEST + "). " +
"Disabled algorithm(s) used: " +
getWeakAlgorithms(ATTR_DIGEST));
if (validEntry) {
// If there were only weak algorithms entries used, throw an exception.
if (weakAlgs) {
throw new SignatureException(
"Manifest Main Attribute check "
+ "failed (" + ATTR_DIGEST + "). "
+ "Disabled algorithm(s) used: "
+ getWeakAlgorithms(ATTR_DIGEST));
}
// If there were only unsupported algorithms entries used, throw an exception.
if (unsupportedAlgs) {
throw new SignatureException(
"Manifest Main Attribute check failed ("
+ ATTR_DIGEST + "). Unsupported algorithm(s) used");
}
}
// this method returns 'true' if either: