author | weijun |
Wed, 19 Sep 2012 12:58:43 +0800 | |
changeset 16082 | a042f1412a78 |
parent 11274 | 7e7196757acd |
child 16117 | 3c521ba54a81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.jar; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.lang.ref.SoftReference; |
|
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
30 |
import java.net.URL; |
2 | 31 |
import java.util.*; |
32 |
import java.util.zip.*; |
|
33 |
import java.security.CodeSigner; |
|
34 |
import java.security.cert.Certificate; |
|
35 |
import java.security.AccessController; |
|
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
36 |
import java.security.CodeSource; |
16082 | 37 |
import sun.misc.IOUtils; |
2 | 38 |
import sun.security.action.GetPropertyAction; |
39 |
import sun.security.util.ManifestEntryVerifier; |
|
40 |
import sun.misc.SharedSecrets; |
|
41 |
||
42 |
/** |
|
43 |
* The <code>JarFile</code> class is used to read the contents of a jar file |
|
44 |
* from any file that can be opened with <code>java.io.RandomAccessFile</code>. |
|
45 |
* It extends the class <code>java.util.zip.ZipFile</code> with support |
|
46 |
* for reading an optional <code>Manifest</code> entry. The |
|
47 |
* <code>Manifest</code> can be used to specify meta-information about the |
|
48 |
* jar file and its entries. |
|
49 |
* |
|
50 |
* <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor |
|
51 |
* or method in this class will cause a {@link NullPointerException} to be |
|
52 |
* thrown. |
|
53 |
* |
|
54 |
* @author David Connelly |
|
55 |
* @see Manifest |
|
56 |
* @see java.util.zip.ZipFile |
|
57 |
* @see java.util.jar.JarEntry |
|
58 |
* @since 1.2 |
|
59 |
*/ |
|
60 |
public |
|
61 |
class JarFile extends ZipFile { |
|
62 |
private SoftReference<Manifest> manRef; |
|
63 |
private JarEntry manEntry; |
|
64 |
private JarVerifier jv; |
|
65 |
private boolean jvInitialized; |
|
66 |
private boolean verify; |
|
67 |
private boolean computedHasClassPathAttribute; |
|
68 |
private boolean hasClassPathAttribute; |
|
69 |
||
70 |
// Set up JavaUtilJarAccess in SharedSecrets |
|
71 |
static { |
|
72 |
SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl()); |
|
73 |
} |
|
74 |
||
75 |
/** |
|
76 |
* The JAR manifest file name. |
|
77 |
*/ |
|
78 |
public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF"; |
|
79 |
||
80 |
/** |
|
81 |
* Creates a new <code>JarFile</code> to read from the specified |
|
82 |
* file <code>name</code>. The <code>JarFile</code> will be verified if |
|
83 |
* it is signed. |
|
84 |
* @param name the name of the jar file to be opened for reading |
|
85 |
* @throws IOException if an I/O error has occurred |
|
86 |
* @throws SecurityException if access to the file is denied |
|
87 |
* by the SecurityManager |
|
88 |
*/ |
|
89 |
public JarFile(String name) throws IOException { |
|
90 |
this(new File(name), true, ZipFile.OPEN_READ); |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Creates a new <code>JarFile</code> to read from the specified |
|
95 |
* file <code>name</code>. |
|
96 |
* @param name the name of the jar file to be opened for reading |
|
97 |
* @param verify whether or not to verify the jar file if |
|
98 |
* it is signed. |
|
99 |
* @throws IOException if an I/O error has occurred |
|
100 |
* @throws SecurityException if access to the file is denied |
|
101 |
* by the SecurityManager |
|
102 |
*/ |
|
103 |
public JarFile(String name, boolean verify) throws IOException { |
|
104 |
this(new File(name), verify, ZipFile.OPEN_READ); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Creates a new <code>JarFile</code> to read from the specified |
|
109 |
* <code>File</code> object. The <code>JarFile</code> will be verified if |
|
110 |
* it is signed. |
|
111 |
* @param file the jar file to be opened for reading |
|
112 |
* @throws IOException if an I/O error has occurred |
|
113 |
* @throws SecurityException if access to the file is denied |
|
114 |
* by the SecurityManager |
|
115 |
*/ |
|
116 |
public JarFile(File file) throws IOException { |
|
117 |
this(file, true, ZipFile.OPEN_READ); |
|
118 |
} |
|
119 |
||
120 |
||
121 |
/** |
|
122 |
* Creates a new <code>JarFile</code> to read from the specified |
|
123 |
* <code>File</code> object. |
|
124 |
* @param file the jar file to be opened for reading |
|
125 |
* @param verify whether or not to verify the jar file if |
|
126 |
* it is signed. |
|
127 |
* @throws IOException if an I/O error has occurred |
|
128 |
* @throws SecurityException if access to the file is denied |
|
129 |
* by the SecurityManager. |
|
130 |
*/ |
|
131 |
public JarFile(File file, boolean verify) throws IOException { |
|
132 |
this(file, verify, ZipFile.OPEN_READ); |
|
133 |
} |
|
134 |
||
135 |
||
136 |
/** |
|
137 |
* Creates a new <code>JarFile</code> to read from the specified |
|
138 |
* <code>File</code> object in the specified mode. The mode argument |
|
139 |
* must be either <tt>OPEN_READ</tt> or <tt>OPEN_READ | OPEN_DELETE</tt>. |
|
140 |
* |
|
141 |
* @param file the jar file to be opened for reading |
|
142 |
* @param verify whether or not to verify the jar file if |
|
143 |
* it is signed. |
|
144 |
* @param mode the mode in which the file is to be opened |
|
145 |
* @throws IOException if an I/O error has occurred |
|
146 |
* @throws IllegalArgumentException |
|
147 |
* if the <tt>mode</tt> argument is invalid |
|
148 |
* @throws SecurityException if access to the file is denied |
|
149 |
* by the SecurityManager |
|
150 |
* @since 1.3 |
|
151 |
*/ |
|
152 |
public JarFile(File file, boolean verify, int mode) throws IOException { |
|
153 |
super(file, mode); |
|
154 |
this.verify = verify; |
|
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Returns the jar file manifest, or <code>null</code> if none. |
|
159 |
* |
|
160 |
* @return the jar file manifest, or <code>null</code> if none |
|
161 |
* |
|
162 |
* @throws IllegalStateException |
|
163 |
* may be thrown if the jar file has been closed |
|
164 |
*/ |
|
165 |
public Manifest getManifest() throws IOException { |
|
166 |
return getManifestFromReference(); |
|
167 |
} |
|
168 |
||
169 |
private Manifest getManifestFromReference() throws IOException { |
|
170 |
Manifest man = manRef != null ? manRef.get() : null; |
|
171 |
||
172 |
if (man == null) { |
|
173 |
||
174 |
JarEntry manEntry = getManEntry(); |
|
175 |
||
176 |
// If found then load the manifest |
|
177 |
if (manEntry != null) { |
|
178 |
if (verify) { |
|
179 |
byte[] b = getBytes(manEntry); |
|
180 |
man = new Manifest(new ByteArrayInputStream(b)); |
|
181 |
if (!jvInitialized) { |
|
9365 | 182 |
jv = new JarVerifier(b); |
2 | 183 |
} |
184 |
} else { |
|
185 |
man = new Manifest(super.getInputStream(manEntry)); |
|
186 |
} |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
187 |
manRef = new SoftReference<>(man); |
2 | 188 |
} |
189 |
} |
|
190 |
return man; |
|
191 |
} |
|
192 |
||
193 |
private native String[] getMetaInfEntryNames(); |
|
194 |
||
195 |
/** |
|
196 |
* Returns the <code>JarEntry</code> for the given entry name or |
|
197 |
* <code>null</code> if not found. |
|
198 |
* |
|
199 |
* @param name the jar file entry name |
|
200 |
* @return the <code>JarEntry</code> for the given entry name or |
|
201 |
* <code>null</code> if not found. |
|
202 |
* |
|
203 |
* @throws IllegalStateException |
|
204 |
* may be thrown if the jar file has been closed |
|
205 |
* |
|
206 |
* @see java.util.jar.JarEntry |
|
207 |
*/ |
|
208 |
public JarEntry getJarEntry(String name) { |
|
209 |
return (JarEntry)getEntry(name); |
|
210 |
} |
|
211 |
||
212 |
/** |
|
213 |
* Returns the <code>ZipEntry</code> for the given entry name or |
|
214 |
* <code>null</code> if not found. |
|
215 |
* |
|
216 |
* @param name the jar file entry name |
|
217 |
* @return the <code>ZipEntry</code> for the given entry name or |
|
218 |
* <code>null</code> if not found |
|
219 |
* |
|
220 |
* @throws IllegalStateException |
|
221 |
* may be thrown if the jar file has been closed |
|
222 |
* |
|
223 |
* @see java.util.zip.ZipEntry |
|
224 |
*/ |
|
225 |
public ZipEntry getEntry(String name) { |
|
226 |
ZipEntry ze = super.getEntry(name); |
|
227 |
if (ze != null) { |
|
228 |
return new JarFileEntry(ze); |
|
229 |
} |
|
230 |
return null; |
|
231 |
} |
|
232 |
||
233 |
/** |
|
234 |
* Returns an enumeration of the zip file entries. |
|
235 |
*/ |
|
236 |
public Enumeration<JarEntry> entries() { |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
237 |
final Enumeration<? extends ZipEntry> enum_ = super.entries(); |
2 | 238 |
return new Enumeration<JarEntry>() { |
239 |
public boolean hasMoreElements() { |
|
240 |
return enum_.hasMoreElements(); |
|
241 |
} |
|
242 |
public JarFileEntry nextElement() { |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
243 |
ZipEntry ze = enum_.nextElement(); |
2 | 244 |
return new JarFileEntry(ze); |
245 |
} |
|
246 |
}; |
|
247 |
} |
|
248 |
||
249 |
private class JarFileEntry extends JarEntry { |
|
250 |
JarFileEntry(ZipEntry ze) { |
|
251 |
super(ze); |
|
252 |
} |
|
253 |
public Attributes getAttributes() throws IOException { |
|
254 |
Manifest man = JarFile.this.getManifest(); |
|
255 |
if (man != null) { |
|
256 |
return man.getAttributes(getName()); |
|
257 |
} else { |
|
258 |
return null; |
|
259 |
} |
|
260 |
} |
|
261 |
public Certificate[] getCertificates() { |
|
262 |
try { |
|
263 |
maybeInstantiateVerifier(); |
|
264 |
} catch (IOException e) { |
|
265 |
throw new RuntimeException(e); |
|
266 |
} |
|
267 |
if (certs == null && jv != null) { |
|
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
268 |
certs = jv.getCerts(JarFile.this, this); |
2 | 269 |
} |
270 |
return certs == null ? null : certs.clone(); |
|
271 |
} |
|
272 |
public CodeSigner[] getCodeSigners() { |
|
273 |
try { |
|
274 |
maybeInstantiateVerifier(); |
|
275 |
} catch (IOException e) { |
|
276 |
throw new RuntimeException(e); |
|
277 |
} |
|
278 |
if (signers == null && jv != null) { |
|
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
279 |
signers = jv.getCodeSigners(JarFile.this, this); |
2 | 280 |
} |
281 |
return signers == null ? null : signers.clone(); |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
/* |
|
286 |
* Ensures that the JarVerifier has been created if one is |
|
287 |
* necessary (i.e., the jar appears to be signed.) This is done as |
|
288 |
* a quick check to avoid processing of the manifest for unsigned |
|
289 |
* jars. |
|
290 |
*/ |
|
291 |
private void maybeInstantiateVerifier() throws IOException { |
|
292 |
if (jv != null) { |
|
293 |
return; |
|
294 |
} |
|
295 |
||
296 |
if (verify) { |
|
297 |
String[] names = getMetaInfEntryNames(); |
|
298 |
if (names != null) { |
|
299 |
for (int i = 0; i < names.length; i++) { |
|
300 |
String name = names[i].toUpperCase(Locale.ENGLISH); |
|
9365 | 301 |
if (name.endsWith(".DSA") || |
302 |
name.endsWith(".RSA") || |
|
303 |
name.endsWith(".EC") || |
|
304 |
name.endsWith(".SF")) { |
|
2 | 305 |
// Assume since we found a signature-related file |
306 |
// that the jar is signed and that we therefore |
|
307 |
// need a JarVerifier and Manifest |
|
308 |
getManifest(); |
|
309 |
return; |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
// No signature-related files; don't instantiate a |
|
314 |
// verifier |
|
315 |
verify = false; |
|
316 |
} |
|
317 |
} |
|
318 |
||
319 |
||
320 |
/* |
|
321 |
* Initializes the verifier object by reading all the manifest |
|
322 |
* entries and passing them to the verifier. |
|
323 |
*/ |
|
324 |
private void initializeVerifier() { |
|
325 |
ManifestEntryVerifier mev = null; |
|
326 |
||
327 |
// Verify "META-INF/" entries... |
|
328 |
try { |
|
329 |
String[] names = getMetaInfEntryNames(); |
|
330 |
if (names != null) { |
|
331 |
for (int i = 0; i < names.length; i++) { |
|
332 |
JarEntry e = getJarEntry(names[i]); |
|
16082 | 333 |
if (e == null) { |
334 |
throw new JarException("corrupted jar file"); |
|
335 |
} |
|
9365 | 336 |
if (!e.isDirectory()) { |
2 | 337 |
if (mev == null) { |
338 |
mev = new ManifestEntryVerifier |
|
339 |
(getManifestFromReference()); |
|
340 |
} |
|
9365 | 341 |
byte[] b = getBytes(e); |
342 |
if (b != null && b.length > 0) { |
|
343 |
jv.beginEntry(e, mev); |
|
344 |
jv.update(b.length, b, 0, b.length, mev); |
|
345 |
jv.update(-1, null, 0, 0, mev); |
|
346 |
} |
|
2 | 347 |
} |
348 |
} |
|
349 |
} |
|
350 |
} catch (IOException ex) { |
|
351 |
// if we had an error parsing any blocks, just |
|
352 |
// treat the jar file as being unsigned |
|
353 |
jv = null; |
|
354 |
verify = false; |
|
16082 | 355 |
if (JarVerifier.debug != null) { |
356 |
JarVerifier.debug.println("jarfile parsing error!"); |
|
357 |
ex.printStackTrace(); |
|
358 |
} |
|
2 | 359 |
} |
360 |
||
361 |
// if after initializing the verifier we have nothing |
|
362 |
// signed, we null it out. |
|
363 |
||
364 |
if (jv != null) { |
|
365 |
||
366 |
jv.doneWithMeta(); |
|
367 |
if (JarVerifier.debug != null) { |
|
368 |
JarVerifier.debug.println("done with meta!"); |
|
369 |
} |
|
370 |
||
371 |
if (jv.nothingToVerify()) { |
|
372 |
if (JarVerifier.debug != null) { |
|
373 |
JarVerifier.debug.println("nothing to verify!"); |
|
374 |
} |
|
375 |
jv = null; |
|
376 |
verify = false; |
|
377 |
} |
|
378 |
} |
|
379 |
} |
|
380 |
||
381 |
/* |
|
382 |
* Reads all the bytes for a given entry. Used to process the |
|
383 |
* META-INF files. |
|
384 |
*/ |
|
385 |
private byte[] getBytes(ZipEntry ze) throws IOException { |
|
16082 | 386 |
try (InputStream is = super.getInputStream(ze)) { |
387 |
return IOUtils.readFully(is, (int)ze.getSize(), true); |
|
8553
46c2babb1e44
7021582: convert jar/zip code and tests to use try-with-resources
smarks
parents:
8387
diff
changeset
|
388 |
} |
2 | 389 |
} |
390 |
||
391 |
/** |
|
392 |
* Returns an input stream for reading the contents of the specified |
|
393 |
* zip file entry. |
|
394 |
* @param ze the zip file entry |
|
395 |
* @return an input stream for reading the contents of the specified |
|
396 |
* zip file entry |
|
397 |
* @throws ZipException if a zip file format error has occurred |
|
398 |
* @throws IOException if an I/O error has occurred |
|
399 |
* @throws SecurityException if any of the jar file entries |
|
400 |
* are incorrectly signed. |
|
401 |
* @throws IllegalStateException |
|
402 |
* may be thrown if the jar file has been closed |
|
403 |
*/ |
|
404 |
public synchronized InputStream getInputStream(ZipEntry ze) |
|
405 |
throws IOException |
|
406 |
{ |
|
407 |
maybeInstantiateVerifier(); |
|
408 |
if (jv == null) { |
|
409 |
return super.getInputStream(ze); |
|
410 |
} |
|
411 |
if (!jvInitialized) { |
|
412 |
initializeVerifier(); |
|
413 |
jvInitialized = true; |
|
414 |
// could be set to null after a call to |
|
415 |
// initializeVerifier if we have nothing to |
|
416 |
// verify |
|
417 |
if (jv == null) |
|
418 |
return super.getInputStream(ze); |
|
419 |
} |
|
420 |
||
421 |
// wrap a verifier stream around the real stream |
|
422 |
return new JarVerifier.VerifierStream( |
|
423 |
getManifestFromReference(), |
|
424 |
ze instanceof JarFileEntry ? |
|
425 |
(JarEntry) ze : getJarEntry(ze.getName()), |
|
426 |
super.getInputStream(ze), |
|
427 |
jv); |
|
428 |
} |
|
429 |
||
430 |
// Statics for hand-coded Boyer-Moore search in hasClassPathAttribute() |
|
431 |
// The bad character shift for "class-path" |
|
432 |
private static int[] lastOcc; |
|
433 |
// The good suffix shift for "class-path" |
|
434 |
private static int[] optoSft; |
|
435 |
// Initialize the shift arrays to search for "class-path" |
|
436 |
private static char[] src = {'c','l','a','s','s','-','p','a','t','h'}; |
|
437 |
static { |
|
438 |
lastOcc = new int[128]; |
|
439 |
optoSft = new int[10]; |
|
440 |
lastOcc[(int)'c']=1; |
|
441 |
lastOcc[(int)'l']=2; |
|
442 |
lastOcc[(int)'s']=5; |
|
443 |
lastOcc[(int)'-']=6; |
|
444 |
lastOcc[(int)'p']=7; |
|
445 |
lastOcc[(int)'a']=8; |
|
446 |
lastOcc[(int)'t']=9; |
|
447 |
lastOcc[(int)'h']=10; |
|
448 |
for (int i=0; i<9; i++) |
|
449 |
optoSft[i]=10; |
|
450 |
optoSft[9]=1; |
|
451 |
} |
|
452 |
||
453 |
private JarEntry getManEntry() { |
|
454 |
if (manEntry == null) { |
|
455 |
// First look up manifest entry using standard name |
|
456 |
manEntry = getJarEntry(MANIFEST_NAME); |
|
457 |
if (manEntry == null) { |
|
458 |
// If not found, then iterate through all the "META-INF/" |
|
459 |
// entries to find a match. |
|
460 |
String[] names = getMetaInfEntryNames(); |
|
461 |
if (names != null) { |
|
462 |
for (int i = 0; i < names.length; i++) { |
|
463 |
if (MANIFEST_NAME.equals( |
|
464 |
names[i].toUpperCase(Locale.ENGLISH))) { |
|
465 |
manEntry = getJarEntry(names[i]); |
|
466 |
break; |
|
467 |
} |
|
468 |
} |
|
469 |
} |
|
470 |
} |
|
471 |
} |
|
472 |
return manEntry; |
|
473 |
} |
|
474 |
||
475 |
// Returns true iff this jar file has a manifest with a class path |
|
476 |
// attribute. Returns false if there is no manifest or the manifest |
|
477 |
// does not contain a "Class-Path" attribute. Currently exported to |
|
478 |
// core libraries via sun.misc.SharedSecrets. |
|
479 |
boolean hasClassPathAttribute() throws IOException { |
|
480 |
if (computedHasClassPathAttribute) { |
|
481 |
return hasClassPathAttribute; |
|
482 |
} |
|
483 |
||
484 |
hasClassPathAttribute = false; |
|
485 |
if (!isKnownToNotHaveClassPathAttribute()) { |
|
486 |
JarEntry manEntry = getManEntry(); |
|
487 |
if (manEntry != null) { |
|
16082 | 488 |
byte[] b = getBytes(manEntry); |
2 | 489 |
int last = b.length - src.length; |
490 |
int i = 0; |
|
491 |
next: |
|
492 |
while (i<=last) { |
|
493 |
for (int j=9; j>=0; j--) { |
|
494 |
char c = (char) b[i+j]; |
|
495 |
c = (((c-'A')|('Z'-c)) >= 0) ? (char)(c + 32) : c; |
|
496 |
if (c != src[j]) { |
|
497 |
i += Math.max(j + 1 - lastOcc[c&0x7F], optoSft[j]); |
|
498 |
continue next; |
|
499 |
} |
|
500 |
} |
|
501 |
hasClassPathAttribute = true; |
|
502 |
break; |
|
503 |
} |
|
504 |
} |
|
505 |
} |
|
506 |
computedHasClassPathAttribute = true; |
|
507 |
return hasClassPathAttribute; |
|
508 |
} |
|
509 |
||
510 |
private static String javaHome; |
|
511 |
private static String[] jarNames; |
|
512 |
private boolean isKnownToNotHaveClassPathAttribute() { |
|
513 |
// Optimize away even scanning of manifest for jar files we |
|
514 |
// deliver which don't have a class-path attribute. If one of |
|
515 |
// these jars is changed to include such an attribute this code |
|
516 |
// must be changed. |
|
517 |
if (javaHome == null) { |
|
518 |
javaHome = AccessController.doPrivileged( |
|
519 |
new GetPropertyAction("java.home")); |
|
520 |
} |
|
521 |
if (jarNames == null) { |
|
522 |
String[] names = new String[10]; |
|
523 |
String fileSep = File.separator; |
|
524 |
int i = 0; |
|
525 |
names[i++] = fileSep + "rt.jar"; |
|
526 |
names[i++] = fileSep + "sunrsasign.jar"; |
|
527 |
names[i++] = fileSep + "jsse.jar"; |
|
528 |
names[i++] = fileSep + "jce.jar"; |
|
529 |
names[i++] = fileSep + "charsets.jar"; |
|
530 |
names[i++] = fileSep + "dnsns.jar"; |
|
531 |
names[i++] = fileSep + "ldapsec.jar"; |
|
532 |
names[i++] = fileSep + "localedata.jar"; |
|
533 |
names[i++] = fileSep + "sunjce_provider.jar"; |
|
534 |
names[i++] = fileSep + "sunpkcs11.jar"; |
|
535 |
jarNames = names; |
|
536 |
} |
|
537 |
||
538 |
String name = getName(); |
|
539 |
String localJavaHome = javaHome; |
|
540 |
if (name.startsWith(localJavaHome)) { |
|
541 |
String[] names = jarNames; |
|
542 |
for (int i = 0; i < names.length; i++) { |
|
543 |
if (name.endsWith(names[i])) { |
|
544 |
return true; |
|
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
return false; |
|
549 |
} |
|
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
550 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
551 |
private synchronized void ensureInitialization() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
552 |
try { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
553 |
maybeInstantiateVerifier(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
554 |
} catch (IOException e) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
555 |
throw new RuntimeException(e); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
556 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
557 |
if (jv != null && !jvInitialized) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
558 |
initializeVerifier(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
559 |
jvInitialized = true; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
560 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
561 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
562 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
563 |
JarEntry newEntry(ZipEntry ze) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
564 |
return new JarFileEntry(ze); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
565 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
566 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
567 |
Enumeration<String> entryNames(CodeSource[] cs) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
568 |
ensureInitialization(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
569 |
if (jv != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
570 |
return jv.entryNames(this, cs); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
571 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
572 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
573 |
/* |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
574 |
* JAR file has no signed content. Is there a non-signing |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
575 |
* code source? |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
576 |
*/ |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
577 |
boolean includeUnsigned = false; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
578 |
for (int i = 0; i < cs.length; i++) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
579 |
if (cs[i].getCodeSigners() == null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
580 |
includeUnsigned = true; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
581 |
break; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
582 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
583 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
584 |
if (includeUnsigned) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
585 |
return unsignedEntryNames(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
586 |
} else { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
587 |
return new Enumeration<String>() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
588 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
589 |
public boolean hasMoreElements() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
590 |
return false; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
591 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
592 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
593 |
public String nextElement() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
594 |
throw new NoSuchElementException(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
595 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
596 |
}; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
597 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
598 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
599 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
600 |
/** |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
601 |
* Returns an enumeration of the zip file entries |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
602 |
* excluding internal JAR mechanism entries and including |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
603 |
* signed entries missing from the ZIP directory. |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
604 |
*/ |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
605 |
Enumeration<JarEntry> entries2() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
606 |
ensureInitialization(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
607 |
if (jv != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
608 |
return jv.entries2(this, super.entries()); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
609 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
610 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
611 |
// screen out entries which are never signed |
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
612 |
final Enumeration<? extends ZipEntry> enum_ = super.entries(); |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
613 |
return new Enumeration<JarEntry>() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
614 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
615 |
ZipEntry entry; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
616 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
617 |
public boolean hasMoreElements() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
618 |
if (entry != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
619 |
return true; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
620 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
621 |
while (enum_.hasMoreElements()) { |
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
622 |
ZipEntry ze = enum_.nextElement(); |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
623 |
if (JarVerifier.isSigningRelated(ze.getName())) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
624 |
continue; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
625 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
626 |
entry = ze; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
627 |
return true; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
628 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
629 |
return false; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
630 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
631 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
632 |
public JarFileEntry nextElement() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
633 |
if (hasMoreElements()) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
634 |
ZipEntry ze = entry; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
635 |
entry = null; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
636 |
return new JarFileEntry(ze); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
637 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
638 |
throw new NoSuchElementException(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
639 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
640 |
}; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
641 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
642 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
643 |
CodeSource[] getCodeSources(URL url) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
644 |
ensureInitialization(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
645 |
if (jv != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
646 |
return jv.getCodeSources(this, url); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
647 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
648 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
649 |
/* |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
650 |
* JAR file has no signed content. Is there a non-signing |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
651 |
* code source? |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
652 |
*/ |
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
653 |
Enumeration<String> unsigned = unsignedEntryNames(); |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
654 |
if (unsigned.hasMoreElements()) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
655 |
return new CodeSource[]{JarVerifier.getUnsignedCS(url)}; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
656 |
} else { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
657 |
return null; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
658 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
659 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
660 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
661 |
private Enumeration<String> unsignedEntryNames() { |
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
662 |
final Enumeration<JarEntry> entries = entries(); |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
663 |
return new Enumeration<String>() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
664 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
665 |
String name; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
666 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
667 |
/* |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
668 |
* Grab entries from ZIP directory but screen out |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
669 |
* metadata. |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
670 |
*/ |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
671 |
public boolean hasMoreElements() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
672 |
if (name != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
673 |
return true; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
674 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
675 |
while (entries.hasMoreElements()) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
676 |
String value; |
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
677 |
ZipEntry e = entries.nextElement(); |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
678 |
value = e.getName(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
679 |
if (e.isDirectory() || JarVerifier.isSigningRelated(value)) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
680 |
continue; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
681 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
682 |
name = value; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
683 |
return true; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
684 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
685 |
return false; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
686 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
687 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
688 |
public String nextElement() { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
689 |
if (hasMoreElements()) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
690 |
String value = name; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
691 |
name = null; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
692 |
return value; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
693 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
694 |
throw new NoSuchElementException(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
695 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
696 |
}; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
697 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
698 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
699 |
CodeSource getCodeSource(URL url, String name) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
700 |
ensureInitialization(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
701 |
if (jv != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
702 |
if (jv.eagerValidation) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
703 |
CodeSource cs = null; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
704 |
JarEntry je = getJarEntry(name); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
705 |
if (je != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
706 |
cs = jv.getCodeSource(url, this, je); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
707 |
} else { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
708 |
cs = jv.getCodeSource(url, name); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
709 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
710 |
return cs; |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
711 |
} else { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
712 |
return jv.getCodeSource(url, name); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
713 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
714 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
715 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
716 |
return JarVerifier.getUnsignedCS(url); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
717 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
718 |
|
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
719 |
void setEagerValidation(boolean eager) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
720 |
try { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
721 |
maybeInstantiateVerifier(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
722 |
} catch (IOException e) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
723 |
throw new RuntimeException(e); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
724 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
725 |
if (jv != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
726 |
jv.setEagerValidation(eager); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
727 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
728 |
} |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
729 |
|
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
730 |
List<Object> getManifestDigests() { |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
731 |
ensureInitialization(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
732 |
if (jv != null) { |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
733 |
return jv.getManifestDigests(); |
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
734 |
} |
11274
7e7196757acd
7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents:
9365
diff
changeset
|
735 |
return new ArrayList<Object>(); |
8387
f0fa7bbf889e
6742654: Code insertion/replacement attacks against signed jars
weijun
parents:
5506
diff
changeset
|
736 |
} |
2 | 737 |
} |