1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
25
26 package java.util.jar;
27
28 import java.io.*;
29 import java.lang.ref.SoftReference;
30 import java.net.URL;
31 import java.util.*;
32 import java.util.stream.Stream;
33 import java.util.stream.StreamSupport;
34 import java.util.zip.*;
35 import java.security.CodeSigner;
36 import java.security.cert.Certificate;
37 import java.security.AccessController;
38 import java.security.CodeSource;
39 import sun.misc.IOUtils;
40 import sun.security.action.GetPropertyAction;
41 import sun.security.util.ManifestEntryVerifier;
42 import sun.misc.SharedSecrets;
43 import sun.security.util.SignatureFileVerifier;
44
45 /**
46 * The <code>JarFile</code> class is used to read the contents of a jar file
47 * from any file that can be opened with <code>java.io.RandomAccessFile</code>.
48 * It extends the class <code>java.util.zip.ZipFile</code> with support
49 * for reading an optional <code>Manifest</code> entry. The
50 * <code>Manifest</code> can be used to specify meta-information about the
377 (getManifestFromReference());
378 }
379 byte[] b = getBytes(e);
380 if (b != null && b.length > 0) {
381 jv.beginEntry(e, mev);
382 jv.update(b.length, b, 0, b.length, mev);
383 jv.update(-1, null, 0, 0, mev);
384 }
385 }
386 }
387 }
388 } catch (IOException ex) {
389 // if we had an error parsing any blocks, just
390 // treat the jar file as being unsigned
391 jv = null;
392 verify = false;
393 if (JarVerifier.debug != null) {
394 JarVerifier.debug.println("jarfile parsing error!");
395 ex.printStackTrace();
396 }
397 }
398
399 // if after initializing the verifier we have nothing
400 // signed, we null it out.
401
402 if (jv != null) {
403
404 jv.doneWithMeta();
405 if (JarVerifier.debug != null) {
406 JarVerifier.debug.println("done with meta!");
407 }
408
409 if (jv.nothingToVerify()) {
410 if (JarVerifier.debug != null) {
411 JarVerifier.debug.println("nothing to verify!");
412 }
413 jv = null;
414 verify = false;
415 }
416 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
25
26 package java.util.jar;
27
28 import java.io.*;
29 import java.lang.ref.SoftReference;
30 import java.net.URL;
31 import java.nio.file.Paths;
32 import java.util.*;
33 import java.util.stream.Stream;
34 import java.util.stream.StreamSupport;
35 import java.util.zip.*;
36 import java.security.CodeSigner;
37 import java.security.cert.Certificate;
38 import java.security.AccessController;
39 import java.security.CodeSource;
40 import sun.misc.IOUtils;
41 import sun.security.action.GetPropertyAction;
42 import sun.security.util.ManifestEntryVerifier;
43 import sun.misc.SharedSecrets;
44 import sun.security.util.SignatureFileVerifier;
45
46 /**
47 * The <code>JarFile</code> class is used to read the contents of a jar file
48 * from any file that can be opened with <code>java.io.RandomAccessFile</code>.
49 * It extends the class <code>java.util.zip.ZipFile</code> with support
50 * for reading an optional <code>Manifest</code> entry. The
51 * <code>Manifest</code> can be used to specify meta-information about the
378 (getManifestFromReference());
379 }
380 byte[] b = getBytes(e);
381 if (b != null && b.length > 0) {
382 jv.beginEntry(e, mev);
383 jv.update(b.length, b, 0, b.length, mev);
384 jv.update(-1, null, 0, 0, mev);
385 }
386 }
387 }
388 }
389 } catch (IOException ex) {
390 // if we had an error parsing any blocks, just
391 // treat the jar file as being unsigned
392 jv = null;
393 verify = false;
394 if (JarVerifier.debug != null) {
395 JarVerifier.debug.println("jarfile parsing error!");
396 ex.printStackTrace();
397 }
398 } catch (SecurityException se) {
399
400 throw new SecurityException("Error in " +
401 Paths.get(getName()).getFileName() + " - " + se.getMessage(),
402 se);
403 }
404
405 // if after initializing the verifier we have nothing
406 // signed, we null it out.
407
408 if (jv != null) {
409
410 jv.doneWithMeta();
411 if (JarVerifier.debug != null) {
412 JarVerifier.debug.println("done with meta!");
413 }
414
415 if (jv.nothingToVerify()) {
416 if (JarVerifier.debug != null) {
417 JarVerifier.debug.println("nothing to verify!");
418 }
419 jv = null;
420 verify = false;
421 }
422 }
|