Drop old getsig.java test

getsig.java was replaced by a Python implementation in 6e2d0a9e (2014)
and the test was only there to compare the results for the transition.

Dropping this as it no longer works starting with 11.0.17+8.
This commit is contained in:
Jochen Sprickerhof 2022-10-30 07:14:20 +01:00 committed by Hans-Christoph Steiner
parent 2c77880b23
commit 90a79c8b26
No known key found for this signature in database
GPG key ID: 3E177817BA1B9BFA
6 changed files with 1 additions and 160 deletions

View file

@ -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/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/skiaparser/1/source.properties
include tests/get_android_tools_versions/android-sdk/tools/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/pubring.gpg
include tests/gnupghome/random_seed include tests/gnupghome/random_seed
include tests/gnupghome/secring.gpg include tests/gnupghome/secring.gpg

View file

@ -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<sig.length; j++) {
byte v = sig[j];
int d = (v>>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);
}
}
}

View file

@ -1,2 +0,0 @@
#!/bin/sh
javac getsig.java

View file

@ -1,2 +0,0 @@
#!/bin/sh
java getsig $1 $2 $3

View file

@ -151,10 +151,7 @@ test -x ./hooks/pre-commit && ./hooks/pre-commit
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
echo_header "test python getsig replacement" echo_header "run unit tests"
cd $WORKSPACE/tests/getsig
./make.sh
cd $WORKSPACE/tests cd $WORKSPACE/tests
for testcase in $WORKSPACE/tests/*.TestCase; do for testcase in $WORKSPACE/tests/*.TestCase; do

View file

@ -20,7 +20,6 @@ import unittest
import yaml import yaml
import zipfile import zipfile
import textwrap import textwrap
from binascii import unhexlify
from datetime import datetime from datetime import datetime
from distutils.version import LooseVersion from distutils.version import LooseVersion
from testcommon import TmpCwd from testcommon import TmpCwd
@ -53,7 +52,6 @@ import fdroidserver.common
import fdroidserver.exception import fdroidserver.exception
import fdroidserver.metadata import fdroidserver.metadata
import fdroidserver.update import fdroidserver.update
from fdroidserver.common import FDroidPopen
DONATION_FIELDS = ('Donate', 'Liberapay', 'OpenCollective') DONATION_FIELDS = ('Donate', 'Liberapay', 'OpenCollective')
@ -461,48 +459,6 @@ class UpdateTest(unittest.TestCase):
app = apps[packageName] app = apps[packageName]
self.assertEqual(app['localized']['en-US']['name'], names[p]) 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): def testBadGetsig(self):
"""getsig() should still be able to fetch the fingerprint of bad signatures""" """getsig() should still be able to fetch the fingerprint of bad signatures"""
# config needed to use jarsigner and keytool # config needed to use jarsigner and keytool