am 44291d9c: Merge "Use StrictJarFile instead of JarFile for cert collection."

* commit '44291d9c2722e0d22dc6f909585f4302abdce205':
  Use StrictJarFile instead of JarFile for cert collection.
This commit is contained in:
Narayan Kamath
2013-12-16 07:20:26 -08:00
committed by Android Git Automerger

View File

@@ -58,7 +58,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.StrictJarFile;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils;
@@ -456,7 +456,7 @@ public class PackageParser {
return pi; return pi;
} }
private Certificate[] loadCertificates(JarFile jarFile, JarEntry je, private Certificate[] loadCertificates(StrictJarFile jarFile, ZipEntry je,
byte[] readBuffer) { byte[] readBuffer) {
try { try {
// We must read the stream for the JarEntry to retrieve // We must read the stream for the JarEntry to retrieve
@@ -466,13 +466,11 @@ public class PackageParser {
// not using // not using
} }
is.close(); is.close();
return je != null ? je.getCertificates() : null; return je != null ? jarFile.getCertificates(je) : null;
} catch (IOException e) { } catch (IOException e) {
Slog.w(TAG, "Exception reading " + je.getName() + " in " Slog.w(TAG, "Exception reading " + je.getName() + " in " + jarFile, e);
+ jarFile.getName(), e);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Slog.w(TAG, "Exception reading " + je.getName() + " in " Slog.w(TAG, "Exception reading " + je.getName() + " in " + jarFile, e);
+ jarFile.getName(), e);
} }
return null; return null;
} }
@@ -591,9 +589,9 @@ public class PackageParser {
*/ */
public boolean collectManifestDigest(Package pkg) { public boolean collectManifestDigest(Package pkg) {
try { try {
final JarFile jarFile = new JarFile(mArchiveSourcePath); final StrictJarFile jarFile = new StrictJarFile(mArchiveSourcePath);
try { try {
final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME); final ZipEntry je = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
if (je != null) { if (je != null) {
pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je)); pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
} }
@@ -624,7 +622,7 @@ public class PackageParser {
} }
try { try {
JarFile jarFile = new JarFile(mArchiveSourcePath); StrictJarFile jarFile = new StrictJarFile(mArchiveSourcePath);
Certificate[] certs = null; Certificate[] certs = null;
@@ -633,7 +631,7 @@ public class PackageParser {
// can trust it... we'll just use the AndroidManifest.xml // can trust it... we'll just use the AndroidManifest.xml
// to retrieve its signatures, not validating all of the // to retrieve its signatures, not validating all of the
// files. // files.
JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME); ZipEntry jarEntry = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
certs = loadCertificates(jarFile, jarEntry, readBuffer); certs = loadCertificates(jarFile, jarEntry, readBuffer);
if (certs == null) { if (certs == null) {
Slog.e(TAG, "Package " + pkg.packageName Slog.e(TAG, "Package " + pkg.packageName
@@ -656,9 +654,9 @@ public class PackageParser {
} }
} }
} else { } else {
Enumeration<JarEntry> entries = jarFile.entries(); Iterator<ZipEntry> entries = jarFile.iterator();
while (entries.hasMoreElements()) { while (entries.hasNext()) {
final JarEntry je = entries.nextElement(); final ZipEntry je = entries.next();
if (je.isDirectory()) continue; if (je.isDirectory()) continue;
final String name = je.getName(); final String name = je.getName();
@@ -744,6 +742,10 @@ public class PackageParser {
Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e); Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING; mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
return false; return false;
} catch (SecurityException e) {
Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
return false;
} catch (RuntimeException e) { } catch (RuntimeException e) {
Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e); Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION; mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;