-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
what are the blockers for reassembling ZIPs like apksigner does? #35
Comments
AFAIK
|
FYI
|
I'm also not trying to handle "corrupt" zip files (with e.g. incorrect internal length fields). Not sure how |
The only thing I would currently consider "blocking" is the "file size was not known at time of writing" one. |
See also #19. |
As far as I understand the apksigner code, it just copies as much as possible. That's different than |
It needs to do much less, this is true. But it still needs to parse the headers and various length fields etc. to do its job. And I don't know enough about the specifics of ZIP extensions to know whether they could possibly change the interpretations of fields that |
|
Whether that parser and Python's |
This should be fixed. Testing it now on all the previously tested APKs to see if anything breaks. |
The apksigner and |
|
It seems that jarsigner also rejects signing twosig.apk. Unfortunately, this does not trigger any more memories on the details of that test. It could be that it is more to maintain compatibility and ease of use rather than security. E.g. just try stripping all signature materials and copying the signature, and let the final verification be the test. $ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /home/hans/.android/release-keystore.jks ./.testfiles/test_verify_apksld4pqcx2/urzip-twosig.apk release -storepass lasdjfkhasdkjfhkjasfdh
updating: META-INF/MANIFEST.MF
adding: META-INF/RELEASE.SF
adding: META-INF/RELEASE.RSA
adding: META-INF/CERT.SF
adding: META-INF/CERT.SF
jarsigner: unable to sign jar: java.util.zip.ZipException: duplicate entry: META-INF/CERT.SF |
CI & tests pass :) |
So is the |
Note that according to http://www.saurik.com/id/17 Android will also reject APKs with multiple signatures IIUC. |
At this point I think the question becomes whether handling every possible ZIP file under the sun exactly the same way apksigner does is worth it, especially if those that are handled differently would be rejected by Android anyway. |
At this point I think |
Based on the current understanding of the usefulness, I'm not planning to support APKs with duplicate entries in You are of course free to remove them before calling |
You can't just call |
I don't think there are currently any relevant differences between And I don't think there any issues with unreasonable input. There might be differences, but I don't think |
If apksigner can make a perfect copy of the ZIP, I don't see why the Python code can't use the same algorithm to strip existing signatures while maintaining the rest. Do you have specific APKs where this fails? I only did a couple tests, but it worked there. What am I missing here? |
No. That was my point. I can't guarantee the implementations are equal, but they seem to behave identically for any APK I've seen. |
FYI the reason the Python code failed on the duplicate entries in the
|
@eighthave do we agree that there are no known blockers now? |
Sounds like it then. The open question is how to integrate it into the existing fdroidserver code and workflow. The tricky part is that ZIP tools can work with that file: $ unzip -l ./.testfiles/test_verify_apkstua6tgfp/urzip-twosig.apk
Archive: ./.testfiles/test_verify_apkstua6tgfp/urzip-twosig.apk
Length Date Time Name
--------- ---------- ----- ----
1413 2013-10-15 18:21 res/drawable/ic_launcher.png
588 2013-10-15 18:21 res/layout/activity_main.xml
4636 2013-10-15 18:21 AndroidManifest.xml
1172 2013-10-15 18:21 resources.arsc
7336 2013-10-15 18:21 classes.dex
417 2013-10-15 18:21 META-INF/MANIFEST.MF
417 2013-10-15 18:21 META-INF/MANIFEST.MF
470 2013-10-15 18:21 META-INF/CERT.SF
470 2013-10-15 18:21 META-INF/CERT.SF
2176 2013-10-15 18:21 META-INF/CERT.RSA
2176 2013-10-15 18:21 META-INF/CERT.RSA
--------- -------
21271 11 files |
I fixed the code that generates the |
Listing is easy. I'm not sure |
I was just going to say, the core idea here is "be conservative in what you send, be liberal in what you accept" https://en.wikipedia.org/wiki/Robustness_principle where "accepting" is receiving APKs, and "sending" is running |
Can we close this now? |
I'm assuming "yes". Let me know if I missed something. |
apksigner assembles a whole new ZIP file when signing, including copying the contents, metadata, and even the odd padding that is added in one or more ways. Right now, apksigcopier can copy the contents, order, metadata, and extra field padding. What are the parts that apksigner can copy that apksigcopier cannot?
I guess we're seeing clearly why apksigner uses its own ZIP implementation, so we might not be able to do exactly what it does by using zipfile directly.
The text was updated successfully, but these errors were encountered: