Exemplo n.º 1
0
 /**
  * Create a new {@code JarFile} using the contents of file.
  *
  * @param file
  *            the JAR file as {@link File}.
  * @param verify
  *            if this JAR filed is signed whether it must be verified.
  * @param mode
  *            the mode to use, either {@link ZipFile#OPEN_READ OPEN_READ} or
  *            {@link ZipFile#OPEN_DELETE OPEN_DELETE}.
  * @throws IOException
  *             If the file cannot be read.
  */
 public JarFile(java.io.File file, bool verify, int mode) ://throws IOException {
     base(file, mode)
 {
     if (verify)
     {
         verifier = new JarVerifier(file.getPath());
     }
     readMetaEntries();
 }
Exemplo n.º 2
0
 /**
  * Create a new {@code JarFile} from the contents of the file specified by
  * {@code filename}.
  *
  * @param filename
  *            the file name referring to the JAR file.
  * @param verify
  *            if this JAR filed is signed whether it must be verified.
  * @throws IOException
  *             If file cannot be opened or read.
  */
 public JarFile(String filename, bool verify) //throws IOException {
     : base(filename)
 {
     if (verify)
     {
         verifier = new JarVerifier(filename);
     }
     readMetaEntries();
 }
Exemplo n.º 3
0
        /**
         * Called by the JarFile constructors, this method reads the contents of the
         * file's META-INF/ directory and picks out the MANIFEST.MF file and
         * verifier signature files if they exist. Any signature files found are
         * registered with the verifier.
         *
         * @throws IOException
         *             if there is a problem reading the jar file entries.
         */
        private void readMetaEntries() // throws IOException {
        // Get all meta directory entries
        {
            java.util.zip.ZipEntry[] metaEntries = getMetaEntriesImpl();
            if (metaEntries == null)
            {
                verifier = null;
                return;
            }

            bool signed = false;

            foreach (java.util.zip.ZipEntry entry in metaEntries)
            {
                String entryName = entry.getName();
                // Is this the entry for META-INF/MANIFEST.MF ?
                if (manifestEntry == null &&
                    org.apache.harmony.archive.util.Util.asciiEqualsIgnoreCase(MANIFEST_NAME, entryName))
                {
                    manifestEntry = entry;
                    // If there is no verifier then we don't need to look any further.
                    if (verifier == null)
                    {
                        break;
                    }
                }
                else
                {
                    // Is this an entry that the verifier needs?
                    if (verifier != null &&
                        (org.apache.harmony.archive.util.Util.asciiEndsWithIgnoreCase(entryName, ".SF") ||
                         org.apache.harmony.archive.util.Util.asciiEndsWithIgnoreCase(entryName, ".DSA") ||
                         org.apache.harmony.archive.util.Util.asciiEndsWithIgnoreCase(entryName, ".RSA")))
                    {
                        signed = true;
                        java.io.InputStream isJ = base.getInputStream(entry);
                        byte[] buf = org.apache.harmony.luni.util.InputStreamHelper.readFullyAndClose(isJ);
                        verifier.addMetaEntry(entryName, buf);
                    }
                }
            }

            // If there were no signature files, then no verifier work to do.
            if (!signed)
            {
                verifier = null;
            }
        }