Skip to content

Commit 9db95ed

Browse files
author
Lance Andersen
committedSep 28, 2022
8215788: Clarify JarInputStream Manifest access
Reviewed-by: weijun, mullan, alanb
1 parent 9309786 commit 9db95ed

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed
 

‎src/java.base/share/classes/java/util/jar/JarInputStream.java

+61-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,11 +31,61 @@
3131
import jdk.internal.util.jar.JarIndex;
3232

3333
/**
34-
* The {@code JarInputStream} class is used to read the contents of
35-
* a JAR file from any input stream. It extends the class
36-
* {@code java.util.zip.ZipInputStream} with support for reading
37-
* an optional {@code Manifest} entry. The {@code Manifest}
38-
* can be used to store meta-information about the JAR file and its entries.
34+
* The {@code JarInputStream} class, which extends {@link ZipInputStream},
35+
* is used to read the contents of a JAR file from an input stream.
36+
* It provides support for reading an optional
37+
* <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">Manifest</a>
38+
* entry. The {@code Manifest} can be used to store
39+
* meta-information about the JAR file and its entries.
40+
*
41+
* <h2>Accessing the Manifest</h2>
42+
* <p>
43+
* The {@link #getManifest() getManifest} method is used to return the
44+
* <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">Manifest</a>
45+
* from the entry {@code META-INF/MANIFEST.MF} when it is the first entry
46+
* in the stream (or the second entry if the first entry in the stream is
47+
* {@code META-INF/} and the second entry is {@code META-INF/MANIFEST.MF}).
48+
* </p>
49+
* <p> The {@link #getNextJarEntry()} and {@link #getNextEntry()} methods are
50+
* used to read JAR file entries from the stream. These methods skip over the
51+
* Manifest ({@code META-INF/MANIFEST.MF}) when it is at the beginning of the
52+
* stream. In other words, these methods do not return an entry for the Manifest
53+
* when the Manifest is the first entry in the stream. If the first entry is
54+
* {@code META-INF/} and the second entry is the Manifest then both are skipped
55+
* over by these methods. Whether these methods skip over the Manifest when it
56+
* appears later in the stream is not specified.
57+
* </p>
58+
* <h2>Signed JAR Files</h2>
59+
*
60+
* A {@code JarInputStream} verifies the signatures of entries in a
61+
* <a href="{@docRoot}/../specs/jar/jar.html#signed-jar-file">Signed JAR file</a>
62+
* when:
63+
* <ul>
64+
* <li>
65+
* The {@code Manifest} is the first entry in the stream (or the second
66+
* entry if the first entry in the stream is {@code META-INF/} and the
67+
* second entry is {@code META-INF/MANIFEST.MF}).
68+
* </li>
69+
* <li>
70+
* All signature-related entries immediately follow the {@code Manifest}
71+
* </li>
72+
* </ul>
73+
* <p>
74+
* Once the {@code JarEntry} has been completely verified, which is done by
75+
* reading until the end of the entry's input stream,
76+
* {@link JarEntry#getCertificates()} may be called to obtain the certificates
77+
* for this entry and {@link JarEntry#getCodeSigners()} may be called to obtain
78+
* the signers.
79+
* </p>
80+
* <p>
81+
* It is important to note that the verification process does not include validating
82+
* the signer's certificate. A caller should inspect the return value of
83+
* {@link JarEntry#getCodeSigners()} to further determine if the signature
84+
* can be trusted.
85+
* </p>
86+
* @apiNote
87+
* If a {@code JarEntry} is modified after the JAR file is signed,
88+
* a {@link SecurityException} will be thrown when the entry is read.
3989
*
4090
* @author David Connelly
4191
* @see Manifest
@@ -103,11 +153,13 @@ private JarEntry checkManifest(JarEntry e)
103153
}
104154

105155
/**
106-
* Returns the {@code Manifest} for this JAR file, or
107-
* {@code null} if none.
156+
* Returns the {@code Manifest} for this JAR file when it is the first entry
157+
* in the stream (or the second entry if the first entry in the stream is
158+
* {@code META-INF/} and the second entry is {@code META-INF/MANIFEST.MF}), or
159+
* {@code null} otherwise.
108160
*
109161
* @return the {@code Manifest} for this JAR file, or
110-
* {@code null} if none.
162+
* {@code null} otherwise.
111163
*/
112164
public Manifest getManifest() {
113165
return man;

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Sep 28, 2022

@openjdk-notifier[bot]
Please sign in to comment.