jdk/src/share/classes/java/util/jar/JarFile.java
author weijun
Thu, 06 May 2010 13:42:52 +0800
changeset 5462 cb614e59f7f9
parent 4152 bc36a9f01ac6
child 5506 202f599c92aa
permissions -rw-r--r--
6890876: jarsigner can add CRL info into signed jar Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
4152
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 2
diff changeset
     2
 * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.zip.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.CodeSigner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.util.ManifestEntryVerifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.misc.SharedSecrets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The <code>JarFile</code> class is used to read the contents of a jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * from any file that can be opened with <code>java.io.RandomAccessFile</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * It extends the class <code>java.util.zip.ZipFile</code> with support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * for reading an optional <code>Manifest</code> entry. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>Manifest</code> can be used to specify meta-information about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * jar file and its entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * or method in this class will cause a {@link NullPointerException} to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author  David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see     Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see     java.util.zip.ZipFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see     java.util.jar.JarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
class JarFile extends ZipFile {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private SoftReference<Manifest> manRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private JarEntry manEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private JarVerifier jv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private boolean jvInitialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private boolean verify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private boolean computedHasClassPathAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private boolean hasClassPathAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // Set up JavaUtilJarAccess in SharedSecrets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The JAR manifest file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Creates a new <code>JarFile</code> to read from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * file <code>name</code>. The <code>JarFile</code> will be verified if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param name the name of the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public JarFile(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this(new File(name), true, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Creates a new <code>JarFile</code> to read from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * file <code>name</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param name the name of the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param verify whether or not to verify the jar file if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public JarFile(String name, boolean verify) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this(new File(name), verify, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Creates a new <code>JarFile</code> to read from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <code>File</code> object. The <code>JarFile</code> will be verified if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param file the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public JarFile(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this(file, true, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Creates a new <code>JarFile</code> to read from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <code>File</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param file the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param verify whether or not to verify the jar file if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *         by the SecurityManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public JarFile(File file, boolean verify) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this(file, verify, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Creates a new <code>JarFile</code> to read from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>File</code> object in the specified mode.  The mode argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * must be either <tt>OPEN_READ</tt> or <tt>OPEN_READ | OPEN_DELETE</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param file the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param verify whether or not to verify the jar file if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param mode the mode in which the file is to be opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *         if the <tt>mode</tt> argument is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public JarFile(File file, boolean verify, int mode) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        super(file, mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.verify = verify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Returns the jar file manifest, or <code>null</code> if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return the jar file manifest, or <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *         may be thrown if the jar file has been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public Manifest getManifest() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return getManifestFromReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private Manifest getManifestFromReference() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Manifest man = manRef != null ? manRef.get() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (man == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            JarEntry manEntry = getManEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // If found then load the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (manEntry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    byte[] b = getBytes(manEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    man = new Manifest(new ByteArrayInputStream(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    if (!jvInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        jv = new JarVerifier(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    man = new Manifest(super.getInputStream(manEntry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                manRef = new SoftReference(man);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private native String[] getMetaInfEntryNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Returns the <code>JarEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <code>null</code> if not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param name the jar file entry name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return the <code>JarEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *         <code>null</code> if not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *         may be thrown if the jar file has been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @see java.util.jar.JarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public JarEntry getJarEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return (JarEntry)getEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Returns the <code>ZipEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <code>null</code> if not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param name the jar file entry name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return the <code>ZipEntry</code> for the given entry name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *         <code>null</code> if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *         may be thrown if the jar file has been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see java.util.zip.ZipEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public ZipEntry getEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        ZipEntry ze = super.getEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (ze != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return new JarFileEntry(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Returns an enumeration of the zip file entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public Enumeration<JarEntry> entries() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        final Enumeration enum_ = super.entries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return new Enumeration<JarEntry>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return enum_.hasMoreElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            public JarFileEntry nextElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                ZipEntry ze = (ZipEntry)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                return new JarFileEntry(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    private class JarFileEntry extends JarEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        JarFileEntry(ZipEntry ze) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            super(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        public Attributes getAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            Manifest man = JarFile.this.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (man != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                return man.getAttributes(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        public Certificate[] getCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                maybeInstantiateVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (certs == null && jv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                certs = jv.getCerts(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return certs == null ? null : certs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        public CodeSigner[] getCodeSigners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                maybeInstantiateVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (signers == null && jv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                signers = jv.getCodeSigners(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return signers == null ? null : signers.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Ensures that the JarVerifier has been created if one is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * necessary (i.e., the jar appears to be signed.) This is done as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * a quick check to avoid processing of the manifest for unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * jars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private void maybeInstantiateVerifier() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (jv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            String[] names = getMetaInfEntryNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (names != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    String name = names[i].toUpperCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    if (name.endsWith(".DSA") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        name.endsWith(".RSA") ||
4152
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 2
diff changeset
   300
                        name.endsWith(".EC") ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        name.endsWith(".SF")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        // Assume since we found a signature-related file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        // that the jar is signed and that we therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        // need a JarVerifier and Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // No signature-related files; don't instantiate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            // verifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            verify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Initializes the verifier object by reading all the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * entries and passing them to the verifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    private void initializeVerifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        ManifestEntryVerifier mev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // Verify "META-INF/" entries...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            String[] names = getMetaInfEntryNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (names != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    JarEntry e = getJarEntry(names[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    if (!e.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        if (mev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                            mev = new ManifestEntryVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                (getManifestFromReference());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        byte[] b = getBytes(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        if (b != null && b.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                            jv.beginEntry(e, mev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                            jv.update(b.length, b, 0, b.length, mev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                            jv.update(-1, null, 0, 0, mev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            // if we had an error parsing any blocks, just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            // treat the jar file as being unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            jv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            verify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        // if after initializing the verifier we have nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        // signed, we null it out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (jv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            jv.doneWithMeta();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (JarVerifier.debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                JarVerifier.debug.println("done with meta!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (jv.nothingToVerify()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                if (JarVerifier.debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    JarVerifier.debug.println("nothing to verify!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                jv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                verify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Reads all the bytes for a given entry. Used to process the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * META-INF files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    private byte[] getBytes(ZipEntry ze) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        byte[] b = new byte[(int)ze.getSize()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        DataInputStream is = new DataInputStream(super.getInputStream(ze));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        is.readFully(b, 0, b.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Returns an input stream for reading the contents of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * zip file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @param ze the zip file entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @return an input stream for reading the contents of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *         zip file entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @throws ZipException if a zip file format error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @throws SecurityException if any of the jar file entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *         are incorrectly signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *         may be thrown if the jar file has been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public synchronized InputStream getInputStream(ZipEntry ze)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        maybeInstantiateVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (jv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return super.getInputStream(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (!jvInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            initializeVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            jvInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            // could be set to null after a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            // initializeVerifier if we have nothing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            // verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (jv == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                return super.getInputStream(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        // wrap a verifier stream around the real stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return new JarVerifier.VerifierStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            getManifestFromReference(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            ze instanceof JarFileEntry ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            (JarEntry) ze : getJarEntry(ze.getName()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            super.getInputStream(ze),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            jv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    // Statics for hand-coded Boyer-Moore search in hasClassPathAttribute()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    // The bad character shift for "class-path"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private static int[] lastOcc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    // The good suffix shift for "class-path"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    private static int[] optoSft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    // Initialize the shift arrays to search for "class-path"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private static char[] src = {'c','l','a','s','s','-','p','a','t','h'};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        lastOcc = new int[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        optoSft = new int[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        lastOcc[(int)'c']=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        lastOcc[(int)'l']=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        lastOcc[(int)'s']=5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        lastOcc[(int)'-']=6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        lastOcc[(int)'p']=7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        lastOcc[(int)'a']=8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        lastOcc[(int)'t']=9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        lastOcc[(int)'h']=10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        for (int i=0; i<9; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            optoSft[i]=10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        optoSft[9]=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    private JarEntry getManEntry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if (manEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            // First look up manifest entry using standard name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            manEntry = getJarEntry(MANIFEST_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (manEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                // If not found, then iterate through all the "META-INF/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                // entries to find a match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                String[] names = getMetaInfEntryNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                if (names != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        if (MANIFEST_NAME.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                                                 names[i].toUpperCase(Locale.ENGLISH))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                            manEntry = getJarEntry(names[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return manEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    // Returns true iff this jar file has a manifest with a class path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    // attribute. Returns false if there is no manifest or the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    // does not contain a "Class-Path" attribute. Currently exported to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    // core libraries via sun.misc.SharedSecrets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    boolean hasClassPathAttribute() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (computedHasClassPathAttribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return hasClassPathAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        hasClassPathAttribute = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (!isKnownToNotHaveClassPathAttribute()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            JarEntry manEntry = getManEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (manEntry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                byte[] b = new byte[(int)manEntry.getSize()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                DataInputStream dis = new DataInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                                          super.getInputStream(manEntry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                dis.readFully(b, 0, b.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                dis.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                int last = b.length - src.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                next:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                while (i<=last) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    for (int j=9; j>=0; j--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        char c = (char) b[i+j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        c = (((c-'A')|('Z'-c)) >= 0) ? (char)(c + 32) : c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        if (c != src[j]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                            i += Math.max(j + 1 - lastOcc[c&0x7F], optoSft[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                            continue next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    hasClassPathAttribute = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        computedHasClassPathAttribute = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        return hasClassPathAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    private static String javaHome;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    private static String[] jarNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private boolean isKnownToNotHaveClassPathAttribute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        // Optimize away even scanning of manifest for jar files we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        // deliver which don't have a class-path attribute. If one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        // these jars is changed to include such an attribute this code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        // must be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (javaHome == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            javaHome = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                new GetPropertyAction("java.home"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (jarNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            String[] names = new String[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            String fileSep = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            names[i++] = fileSep + "rt.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            names[i++] = fileSep + "sunrsasign.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            names[i++] = fileSep + "jsse.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            names[i++] = fileSep + "jce.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            names[i++] = fileSep + "charsets.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            names[i++] = fileSep + "dnsns.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            names[i++] = fileSep + "ldapsec.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            names[i++] = fileSep + "localedata.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            names[i++] = fileSep + "sunjce_provider.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            names[i++] = fileSep + "sunpkcs11.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            jarNames = names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        String name = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        String localJavaHome = javaHome;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (name.startsWith(localJavaHome)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            String[] names = jarNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                if (name.endsWith(names[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
}