8268506: More Manifest Digests

Reviewed-by: xuelei, ahgross, weijun, rhalade
This commit is contained in:
Hai-May Chao 2021-06-30 18:02:46 +00:00 committed by Henry Jen
parent ab9170957f
commit 790dcc667d
3 changed files with 21 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 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
@ -331,8 +331,12 @@ public class ManifestDigester {
* @see #MF_MAIN_ATTRS
*/
public Entry getMainAttsEntry(boolean oldStyle) {
mainAttsEntry.oldStyle = oldStyle;
return mainAttsEntry;
if (mainAttsEntry != null) {
mainAttsEntry.oldStyle = oldStyle;
return mainAttsEntry;
} else {
return null;
}
}
public Entry get(String name) {

View File

@ -543,6 +543,10 @@ public class SignatureFileVerifier {
MessageDigest digest = getDigest(algorithm);
if (digest != null) {
ManifestDigester.Entry mde = md.getMainAttsEntry(false);
if (mde == null) {
throw new SignatureException("Manifest Main Attribute check " +
"failed due to missing main attributes entry");
}
byte[] computedHash = mde.digest(digest);
byte[] expectedHash =
Base64.getMimeDecoder().decode((String)se.getValue());

View File

@ -793,13 +793,19 @@ public final class JarSigner {
ManifestDigester oldMd = new ManifestDigester(mfRawBytes);
ManifestDigester newMd = new ManifestDigester(mfNewRawBytes);
ManifestDigester.Entry oldEntry = oldMd.getMainAttsEntry();
// main attributes
if (manifest.getMainAttributes().equals(
oldManifest.getMainAttributes())
if (oldEntry != null
&& manifest.getMainAttributes().equals(
oldManifest.getMainAttributes())
&& (manifest.getEntries().isEmpty() ||
oldMd.getMainAttsEntry().isProperlyDelimited())) {
oldMd.getMainAttsEntry().reproduceRaw(baos);
oldEntry.isProperlyDelimited())) {
oldEntry.reproduceRaw(baos);
} else {
if (newMd.getMainAttsEntry() == null) {
throw new SignatureException("Error getting new main attribute entry");
}
newMd.getMainAttsEntry().reproduceRaw(baos);
}