3570N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The <code>JarFile</code> class is used to read the contents of a jar file 0N/A * from any file that can be opened with <code>java.io.RandomAccessFile</code>. 0N/A * It extends the class <code>java.util.zip.ZipFile</code> with support 0N/A * for reading an optional <code>Manifest</code> entry. The 0N/A * <code>Manifest</code> can be used to specify meta-information about the 0N/A * jar file and its entries. 0N/A * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor 0N/A * or method in this class will cause a {@link NullPointerException} to be 0N/A * @author David Connelly 0N/A * @see java.util.zip.ZipFile 0N/A * @see java.util.jar.JarEntry 0N/A // Set up JavaUtilJarAccess in SharedSecrets 0N/A * The JAR manifest file name. 0N/A * Creates a new <code>JarFile</code> to read from the specified 0N/A * file <code>name</code>. The <code>JarFile</code> will be verified if 0N/A * @param name the name of the jar file to be opened for reading 0N/A * @throws IOException if an I/O error has occurred 0N/A * @throws SecurityException if access to the file is denied 0N/A * by the SecurityManager 0N/A * Creates a new <code>JarFile</code> to read from the specified 0N/A * file <code>name</code>. 0N/A * @param name the name of the jar file to be opened for reading 0N/A * @param verify whether or not to verify the jar file if 0N/A * @throws IOException if an I/O error has occurred 0N/A * @throws SecurityException if access to the file is denied 0N/A * by the SecurityManager 0N/A * Creates a new <code>JarFile</code> to read from the specified 0N/A * <code>File</code> object. The <code>JarFile</code> will be verified if 0N/A * @param file the jar file to be opened for reading 0N/A * @throws IOException if an I/O error has occurred 0N/A * @throws SecurityException if access to the file is denied 0N/A * by the SecurityManager 0N/A * Creates a new <code>JarFile</code> to read from the specified 0N/A * <code>File</code> object. 0N/A * @param file the jar file to be opened for reading 0N/A * @param verify whether or not to verify the jar file if 0N/A * @throws IOException if an I/O error has occurred 0N/A * @throws SecurityException if access to the file is denied 0N/A * by the SecurityManager. 0N/A * Creates a new <code>JarFile</code> to read from the specified 0N/A * <code>File</code> object in the specified mode. The mode argument 0N/A * must be either <tt>OPEN_READ</tt> or <tt>OPEN_READ | OPEN_DELETE</tt>. 0N/A * @param file the jar file to be opened for reading 0N/A * @param verify whether or not to verify the jar file if 0N/A * @param mode the mode in which the file is to be opened 0N/A * @throws IOException if an I/O error has occurred 0N/A * @throws IllegalArgumentException 0N/A * if the <tt>mode</tt> argument is invalid 0N/A * @throws SecurityException if access to the file is denied 0N/A * by the SecurityManager 0N/A * Returns the jar file manifest, or <code>null</code> if none. 0N/A * @return the jar file manifest, or <code>null</code> if none 0N/A * @throws IllegalStateException 0N/A * may be thrown if the jar file has been closed 0N/A // If found then load the manifest 0N/A * Returns the <code>JarEntry</code> for the given entry name or 0N/A * <code>null</code> if not found. 0N/A * @param name the jar file entry name 0N/A * @return the <code>JarEntry</code> for the given entry name or 0N/A * <code>null</code> if not found. 0N/A * @throws IllegalStateException 0N/A * may be thrown if the jar file has been closed 0N/A * @see java.util.jar.JarEntry 0N/A * Returns the <code>ZipEntry</code> for the given entry name or 0N/A * <code>null</code> if not found. 0N/A * @param name the jar file entry name 0N/A * @return the <code>ZipEntry</code> for the given entry name or 0N/A * <code>null</code> if not found 0N/A * @throws IllegalStateException 0N/A * may be thrown if the jar file has been closed 0N/A * @see java.util.zip.ZipEntry 0N/A * Returns an enumeration of the zip file entries. 0N/A * Ensures that the JarVerifier has been created if one is 0N/A * necessary (i.e., the jar appears to be signed.) This is done as 0N/A * a quick check to avoid processing of the manifest for unsigned 0N/A // Assume since we found a signature-related file 0N/A // that the jar is signed and that we therefore 0N/A // need a JarVerifier and Manifest 0N/A // No signature-related files; don't instantiate a 0N/A * Initializes the verifier object by reading all the manifest 0N/A * entries and passing them to the verifier. 0N/A // Verify "META-INF/" entries... 0N/A // if we had an error parsing any blocks, just 0N/A // treat the jar file as being unsigned 0N/A // if after initializing the verifier we have nothing 0N/A // signed, we null it out. 0N/A * Reads all the bytes for a given entry. Used to process the 0N/A * Returns an input stream for reading the contents of the specified 0N/A * @param ze the zip file entry 0N/A * @return an input stream for reading the contents of the specified 0N/A * @throws ZipException if a zip file format error has occurred 0N/A * @throws IOException if an I/O error has occurred 0N/A * @throws SecurityException if any of the jar file entries 0N/A * are incorrectly signed. 0N/A * @throws IllegalStateException 0N/A * may be thrown if the jar file has been closed 0N/A // could be set to null after a call to 0N/A // initializeVerifier if we have nothing to 0N/A // wrap a verifier stream around the real stream 0N/A // Statics for hand-coded Boyer-Moore search in hasClassPathAttribute() 0N/A // The bad character shift for "class-path" 0N/A // The good suffix shift for "class-path" 0N/A // Initialize the shift arrays to search for "class-path" 0N/A private static char[]
src = {
'c',
'l',
'a',
's',
's',
'-',
'p',
'a',
't',
'h'};
0N/A for (
int i=
0; i<
9; i++)
0N/A // First look up manifest entry using standard name 0N/A // If not found, then iterate through all the "META-INF/" 0N/A // entries to find a match. 0N/A // Returns true iff this jar file has a manifest with a class path 0N/A // attribute. Returns false if there is no manifest or the manifest 0N/A // does not contain a "Class-Path" attribute. Currently exported to 0N/A // core libraries via sun.misc.SharedSecrets. 0N/A for (
int j=
9; j>=
0; j--) {
0N/A char c = (
char) b[i+j];
0N/A c = (((c-
'A')|(
'Z'-c)) >=
0) ? (
char)(c +
32) : c;
0N/A // Optimize away even scanning of manifest for jar files we 0N/A // deliver which don't have a class-path attribute. If one of 0N/A // these jars is changed to include such an attribute this code 3570N/A * JAR file has no signed content. Is there a non-signing 3570N/A * Returns an enumeration of the zip file entries 3570N/A * excluding internal JAR mechanism entries and including 3570N/A * signed entries missing from the ZIP directory. 3570N/A // screen out entries which are never signed 3570N/A * JAR file has no signed content. Is there a non-signing 3570N/A * Grab entries from ZIP directory but screen out