Merge change 3459 into donut

* changes:
  make signapk strip other signatures
This commit is contained in:
Android (Google) Code Review 2009-06-11 19:25:14 -07:00
commit 5aa299925d
1 changed files with 8 additions and 1 deletions

View File

@ -62,6 +62,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.regex.Pattern;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.EncryptedPrivateKeyInfo; import javax.crypto.EncryptedPrivateKeyInfo;
import javax.crypto.SecretKeyFactory; import javax.crypto.SecretKeyFactory;
@ -75,6 +76,10 @@ class SignApk {
private static final String CERT_SF_NAME = "META-INF/CERT.SF"; private static final String CERT_SF_NAME = "META-INF/CERT.SF";
private static final String CERT_RSA_NAME = "META-INF/CERT.RSA"; private static final String CERT_RSA_NAME = "META-INF/CERT.RSA";
// Files matching this pattern are not copied to the output.
private static Pattern stripPattern =
Pattern.compile("^META-INF/(.*)[.](SF|RSA|DSA)$");
private static X509Certificate readPublicKey(File file) private static X509Certificate readPublicKey(File file)
throws IOException, GeneralSecurityException { throws IOException, GeneralSecurityException {
FileInputStream input = new FileInputStream(file); FileInputStream input = new FileInputStream(file);
@ -193,7 +198,9 @@ class SignApk {
for (JarEntry entry: byName.values()) { for (JarEntry entry: byName.values()) {
String name = entry.getName(); String name = entry.getName();
if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) && if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) &&
!name.equals(CERT_SF_NAME) && !name.equals(CERT_RSA_NAME)) { !name.equals(CERT_SF_NAME) && !name.equals(CERT_RSA_NAME) &&
(stripPattern == null ||
!stripPattern.matcher(name).matches())) {
InputStream data = jar.getInputStream(entry); InputStream data = jar.getInputStream(entry);
while ((num = data.read(buffer)) > 0) { while ((num = data.read(buffer)) > 0) {
md.update(buffer, 0, num); md.update(buffer, 0, num);