pin jar timestamps for reproducible builds - #198
Open
munzzyy wants to merge 1 commit into
Open
Conversation
fixes guardianproject#66 sourcesJar and javadocJar in tor-android-binary/build.gradle.kts had no preserveFileTimestamps/reproducibleFileOrder settings, so two otherwise identical builds produce different jar bytes depending on when the source checkout was made. This global tasks.withType block existed in the old Groovy build.gradle (7e1ff24, for guardianproject#45) but got dropped in the switch to Kotlin DSL. The bundle() step in tor-droid-make.sh had the same problem: jar -cvf stamps each entry, including the auto-generated META-INF/MANIFEST.MF, with the current time. Switch to jar --create --date=<fixed> so the staging bundle uploaded to Sonatype is also reproducible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #66
Two places were stamping build outputs with the current time instead of a fixed one:
tor-android-binary/build.gradle.kts
sourcesJarandjavadocJarhad nopreserveFileTimestamps/reproducibleFileOrdersettings, so building the same commit twice (or on two machines) produces jars that differ byte for byte, even though the content is identical. This exact settings block already existed once, in the old Groovybuild.gradle(commit 7e1ff24, closing #45), but it got dropped when the project moved to Kotlin DSL. I restored it as a project-widetasks.withType<AbstractArchiveTask>()block instead of duplicating it per task, so it also covers any other archive task added later.I built both jars twice from a clean tree with
--no-build-cachea few seconds apart and diffed the output:Dokka's javadoc output itself has no embedded generation timestamp (unlike the old raw javadoc tool the issue's diffoscope output was taken against), so pinning the jar tasks is enough to make both outputs reproducible.
tor-droid-make.sh
bundle()had a TODO for this.jar -cvfstamps every entry, including the auto-generatedMETA-INF/MANIFEST.MF, with the current wall-clock time, so the bundle jar differs between runs even when the input files (aar, pom, sources jar, etc.) are unchanged. Recent JDKs (19+, this project already targets 24) supportjar --create --date=<timestamp>, which pins the timestamp for every entry the tool writes, including the manifest. I used the same epoch already used for the native tor build inexternal/Makefile(SOURCE_DATE_EPOCH := 1234567890) so both halves of the release pin to the same instant.I couldn't run the actual
release()path locally since it needs the full NDK/tor native build plus a GPG key to sign with, so I verified the mechanism directly: built two jars from identical file content but different mtimes, once with the oldjar -cvf(bytes differ) and once withjar --create --date=...(bytes identical), same as the failure mode inbundle().Left out: the
.aaritself isn't touched here, AGP handles its packaging separately and wasn't part of the TODO or the diffoscope output in the issue.