jdk/src/share/classes/java/util/jar/JarFile.java
changeset 9365 469cd39a25de
parent 9248 44d129a2adfa
child 11274 7e7196757acd
equal deleted inserted replaced
9307:f4298bc3f4b6 9365:469cd39a25de
    35 import java.security.AccessController;
    35 import java.security.AccessController;
    36 import java.security.CodeSource;
    36 import java.security.CodeSource;
    37 import sun.security.action.GetPropertyAction;
    37 import sun.security.action.GetPropertyAction;
    38 import sun.security.util.ManifestEntryVerifier;
    38 import sun.security.util.ManifestEntryVerifier;
    39 import sun.misc.SharedSecrets;
    39 import sun.misc.SharedSecrets;
    40 import sun.security.util.SignatureFileVerifier;
       
    41 
    40 
    42 /**
    41 /**
    43  * The <code>JarFile</code> class is used to read the contents of a jar file
    42  * 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>.
    43  * 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
    44  * It extends the class <code>java.util.zip.ZipFile</code> with support
   177             if (manEntry != null) {
   176             if (manEntry != null) {
   178                 if (verify) {
   177                 if (verify) {
   179                     byte[] b = getBytes(manEntry);
   178                     byte[] b = getBytes(manEntry);
   180                     man = new Manifest(new ByteArrayInputStream(b));
   179                     man = new Manifest(new ByteArrayInputStream(b));
   181                     if (!jvInitialized) {
   180                     if (!jvInitialized) {
   182                         jv = new JarVerifier(b, man);
   181                         jv = new JarVerifier(b);
   183                     }
   182                     }
   184                 } else {
   183                 } else {
   185                     man = new Manifest(super.getInputStream(manEntry));
   184                     man = new Manifest(super.getInputStream(manEntry));
   186                 }
   185                 }
   187                 manRef = new SoftReference(man);
   186                 manRef = new SoftReference(man);
   296         if (verify) {
   295         if (verify) {
   297             String[] names = getMetaInfEntryNames();
   296             String[] names = getMetaInfEntryNames();
   298             if (names != null) {
   297             if (names != null) {
   299                 for (int i = 0; i < names.length; i++) {
   298                 for (int i = 0; i < names.length; i++) {
   300                     String name = names[i].toUpperCase(Locale.ENGLISH);
   299                     String name = names[i].toUpperCase(Locale.ENGLISH);
   301                     if (SignatureFileVerifier.isBlockOrSF(name)) {
   300                     if (name.endsWith(".DSA") ||
       
   301                         name.endsWith(".RSA") ||
       
   302                         name.endsWith(".EC") ||
       
   303                         name.endsWith(".SF")) {
   302                         // Assume since we found a signature-related file
   304                         // Assume since we found a signature-related file
   303                         // that the jar is signed and that we therefore
   305                         // that the jar is signed and that we therefore
   304                         // need a JarVerifier and Manifest
   306                         // need a JarVerifier and Manifest
   305                         getManifest();
   307                         getManifest();
   306                         return;
   308                         return;
   325         try {
   327         try {
   326             String[] names = getMetaInfEntryNames();
   328             String[] names = getMetaInfEntryNames();
   327             if (names != null) {
   329             if (names != null) {
   328                 for (int i = 0; i < names.length; i++) {
   330                 for (int i = 0; i < names.length; i++) {
   329                     JarEntry e = getJarEntry(names[i]);
   331                     JarEntry e = getJarEntry(names[i]);
   330                     if (!e.isDirectory() &&
   332                     if (!e.isDirectory()) {
   331                             SignatureFileVerifier.isBlock(names[i])) {
       
   332                         if (mev == null) {
   333                         if (mev == null) {
   333                             mev = new ManifestEntryVerifier
   334                             mev = new ManifestEntryVerifier
   334                                 (getManifestFromReference());
   335                                 (getManifestFromReference());
   335                         }
   336                         }
   336                         String key = names[i].substring(
   337                         byte[] b = getBytes(e);
   337                                 0, names[i].lastIndexOf("."));
   338                         if (b != null && b.length > 0) {
   338                         jv.verifyBlock(names[i],
   339                             jv.beginEntry(e, mev);
   339                                 getBytes(e),
   340                             jv.update(b.length, b, 0, b.length, mev);
   340                                 super.getInputStream(getJarEntry(key + ".SF")));
   341                             jv.update(-1, null, 0, 0, mev);
       
   342                         }
   341                     }
   343                     }
   342                 }
   344                 }
   343             }
   345             }
   344         } catch (IOException ex) {
   346         } catch (IOException ex) {
   345             // if we had an error parsing any blocks, just
   347             // if we had an error parsing any blocks, just