Skip to content

Commit 577ff98

Browse files
committedFeb 19, 2025
8347946: Add API note that caller should validate/trust signers to the getCertificates and getCodeSigners methods of JarEntry and JarURLConnection
Reviewed-by: lancea, jpai
1 parent 014701a commit 577ff98

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed
 

‎src/java.base/share/classes/java/net/JarURLConnection.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, 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
@@ -301,9 +301,23 @@ public Attributes getMainAttributes() throws IOException {
301301
* can only be called once
302302
* the connection has been completely verified by reading
303303
* from the input stream until the end of the stream has been
304-
* reached. Otherwise, this method will return {@code null}
304+
* reached. Otherwise, this method will return {@code null}.
305305
*
306-
* @return the Certificate object for this connection if the URL
306+
* <p>The returned certificate array comprises all the signer certificates
307+
* that were used to verify this entry. Each signer certificate is
308+
* followed by its supporting certificate chain (which may be empty).
309+
* Each signer certificate and its supporting certificate chain are ordered
310+
* bottom-to-top (i.e., with the signer certificate first and the (root)
311+
* certificate authority last).
312+
*
313+
* @apiNote
314+
* The verification process does not include validating or establishing
315+
* trust in the code signers. A caller should perform additional checks,
316+
* such as using a {@link java.security.cert.CertPathValidator} to
317+
* validate each signer's certificate chain, and determining whether
318+
* to trust the entry signed by the signers.
319+
*
320+
* @return the Certificate objects for this connection if the URL
307321
* for it points to a JAR file entry, null otherwise.
308322
*
309323
* @throws IOException if getting the JAR entry causes an

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

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, 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
@@ -97,15 +97,26 @@ public Attributes getAttributes() throws IOException {
9797
* from the entry input stream until the end of the stream has been
9898
* reached. Otherwise, this method will return {@code null}.
9999
*
100+
* <p>It is recommended to use the {@link getCodeSigners} method instead,
101+
* which returns an array of {@code CodeSigner}s.
102+
*
100103
* <p>The returned certificate array comprises all the signer certificates
101104
* that were used to verify this entry. Each signer certificate is
102105
* followed by its supporting certificate chain (which may be empty).
103106
* Each signer certificate and its supporting certificate chain are ordered
104107
* bottom-to-top (i.e., with the signer certificate first and the (root)
105108
* certificate authority last).
106109
*
110+
* @apiNote
111+
* The verification process does not include validating or establishing
112+
* trust in the code signers. A caller should perform additional checks,
113+
* such as using a {@link java.security.cert.CertPathValidator} to
114+
* validate each signer's certificate chain, and determining whether
115+
* to trust the entry signed by the signers.
116+
*
107117
* @return the {@code Certificate} objects for this entry, or
108118
* {@code null} if none.
119+
*
109120
*/
110121
public Certificate[] getCertificates() {
111122
return certs == null ? null : certs.clone();
@@ -121,6 +132,13 @@ public Certificate[] getCertificates() {
121132
* <p>The returned array comprises all the code signers that have signed
122133
* this entry.
123134
*
135+
* @apiNote
136+
* The verification process does not include validating or establishing
137+
* trust in the code signers. A caller should perform additional checks,
138+
* such as using a {@link java.security.cert.CertPathValidator} to
139+
* validate each signer's certificate chain, and determining whether
140+
* to trust the entry signed by the signers.
141+
*
124142
* @return the {@code CodeSigner} objects for this entry, or
125143
* {@code null} if none.
126144
*

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, 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
@@ -93,7 +93,7 @@
9393
* multi-release jar file, the content of a versioned entry is verified against
9494
* its own signature and {@link JarEntry#getCodeSigners()} returns its own signers.
9595
*
96-
* Please note that the verification process does not include validating the
96+
* <p>Please note that the verification process does not include validating the
9797
* signer's certificate. A caller should inspect the return value of
9898
* {@link JarEntry#getCodeSigners()} to further determine if the signature
9999
* can be trusted.

0 commit comments

Comments
 (0)