diff --git a/MANIFEST.in b/MANIFEST.in index 9b4990a7..ac61e02c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -559,9 +559,6 @@ include tests/get_android_tools_versions/android-sdk/patcher/v4/source.propertie include tests/get_android_tools_versions/android-sdk/platforms/android-30/source.properties include tests/get_android_tools_versions/android-sdk/skiaparser/1/source.properties include tests/get_android_tools_versions/android-sdk/tools/source.properties -include tests/getsig/getsig.java -include tests/getsig/make.sh -include tests/getsig/run.sh include tests/gnupghome/pubring.gpg include tests/gnupghome/random_seed include tests/gnupghome/secring.gpg diff --git a/tests/getsig/getsig.java b/tests/getsig/getsig.java deleted file mode 100644 index 78e7ac0c..00000000 --- a/tests/getsig/getsig.java +++ /dev/null @@ -1,105 +0,0 @@ -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.security.Signature; -import java.security.cert.*; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -public class getsig { - - public static void main(String[] args) { - - String apkPath = null; - boolean full = false; - - if(args.length == 1) { - apkPath = args[0]; - } else if (args.length == 2) { - if(!args[0].equals("-f")) { - System.out.println("Only -f is supported"); - System.exit(1); - } - apkPath = args[1]; - full = true; - } else { - System.out.println("Specify the APK file to get the signature from!"); - System.exit(1); - } - - try { - - JarFile apk = new JarFile(apkPath); - java.security.cert.Certificate[] certs = null; - - Enumeration entries = apk.entries(); - while (entries.hasMoreElements()) { - JarEntry je = (JarEntry) entries.nextElement(); - if (!je.isDirectory() && !je.getName().startsWith("META-INF/")) { - // Just need to read the stream (discarding the data) to get - // it to process the certificate... - byte[] b = new byte[4096]; - InputStream is = apk.getInputStream(je); - while (is.read(b, 0, b.length) != -1); - is.close(); - certs = je.getCertificates(); - if(certs != null) - break; - } - } - apk.close(); - - if (certs == null) { - System.out.println("Not signed"); - System.exit(1); - } - if (certs.length != 1) { - System.out.println("One signature expected"); - System.exit(1); - } - - // Get the signature in the same form that is returned by - // android.content.pm.Signature.toCharsString() (but in the - // form of a byte array so we can pass it to the MD5 function)... - byte[] sig = certs[0].getEncoded(); - byte[] csig = new byte[sig.length * 2]; - for (int j=0; j>4)&0xf; - csig[j*2] = (byte)(d >= 10 ? ('a' + d - 10) : ('0' + d)); - d = v&0xf; - csig[j*2+1] = (byte)(d >= 10 ? ('a' + d - 10) : ('0' + d)); - } - - String result; - if(full) { - result = new String(csig); - } else { - // Get the MD5 sum... - MessageDigest md; - md = MessageDigest.getInstance("MD5"); - byte[] md5sum = new byte[32]; - md.update(csig); - md5sum = md.digest(); - BigInteger bigInt = new BigInteger(1, md5sum); - String md5hash = bigInt.toString(16); - while (md5hash.length() < 32) - md5hash = "0" + md5hash; - result = md5hash; - } - - System.out.println("Result:" + result); - System.exit(0); - - } catch (Exception e) { - System.out.println("Exception:" + e); - System.exit(1); - } - } - -} - - diff --git a/tests/getsig/make.sh b/tests/getsig/make.sh deleted file mode 100755 index aa63c1a2..00000000 --- a/tests/getsig/make.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -javac getsig.java diff --git a/tests/getsig/run.sh b/tests/getsig/run.sh deleted file mode 100755 index 726995bf..00000000 --- a/tests/getsig/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -java getsig $1 $2 $3 diff --git a/tests/run-tests b/tests/run-tests index 460179ab..c2507f99 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -151,10 +151,7 @@ test -x ./hooks/pre-commit && ./hooks/pre-commit #------------------------------------------------------------------------------# -echo_header "test python getsig replacement" - -cd $WORKSPACE/tests/getsig -./make.sh +echo_header "run unit tests" cd $WORKSPACE/tests for testcase in $WORKSPACE/tests/*.TestCase; do diff --git a/tests/update.TestCase b/tests/update.TestCase index acc9f3b4..33d03540 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -20,7 +20,6 @@ import unittest import yaml import zipfile import textwrap -from binascii import unhexlify from datetime import datetime from distutils.version import LooseVersion from testcommon import TmpCwd @@ -53,7 +52,6 @@ import fdroidserver.common import fdroidserver.exception import fdroidserver.metadata import fdroidserver.update -from fdroidserver.common import FDroidPopen DONATION_FIELDS = ('Donate', 'Liberapay', 'OpenCollective') @@ -461,48 +459,6 @@ class UpdateTest(unittest.TestCase): app = apps[packageName] self.assertEqual(app['localized']['en-US']['name'], names[p]) - def javagetsig(self, apkfile): - getsig_dir = 'getsig' - if not os.path.exists(os.path.join(getsig_dir, "getsig.class")): - logging.critical("getsig.class not found. To fix: cd '%s' && ./make.sh" % getsig_dir) - sys.exit(1) - # FDroidPopen needs some config to work - config = dict() - fdroidserver.common.fill_config_defaults(config) - fdroidserver.common.config = config - p = FDroidPopen(['java', '-cp', 'getsig', 'getsig', apkfile]) - sig = None - for line in p.output.splitlines(): - if line.startswith('Result:'): - sig = line[7:].strip() - break - if p.returncode == 0: - return sig - else: - return None - - def testGoodGetsig(self): - # config needed to use jarsigner and keytool - config = dict() - fdroidserver.common.fill_config_defaults(config) - fdroidserver.common.options = Options - fdroidserver.update.config = config - apkfile = 'urzip.apk' - sig = self.javagetsig(apkfile) - self.assertIsNotNone(sig, "sig is None") - pysig = fdroidserver.update.getsig(apkfile) - self.assertIsNotNone(pysig, "pysig is None") - self.assertEqual(sig, fdroidserver.update.getsig(apkfile), - "python sig not equal to java sig!") - self.assertEqual(len(sig), len(pysig), - "the length of the two sigs are different!") - try: - self.assertEqual(unhexlify(sig), unhexlify(pysig), - "the length of the two sigs are different!") - except TypeError as e: - print(e) - self.assertTrue(False, 'TypeError!') - def testBadGetsig(self): """getsig() should still be able to fetch the fingerprint of bad signatures""" # config needed to use jarsigner and keytool