Skip to content

Reuse the existing signed package when the unsigned content is unchanged - #829

Merged
bdovaz merged 7 commits into
bdovaz:masterfrom
favoyang:reuse-unchanged-signatures
Nov 29, 2026
Merged

bdovaz merged 7 commits into
bdovaz:masterfrom
favoyang:reuse-unchanged-signatures

Conversation

@favoyang

@favoyang favoyang commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Every build of a package runs upm pack, and signing is not deterministic: the attestation embeds an RFC 3161 timestamp, so the same content signed twice produces different bytes. The signed tarball, its SHA-1 and the dist.shasum in the registry metadata therefore change on every rebuild, even when the package content is identical.

This happens on every image update, because a changed registry version clears the cache and regenerates all packages. Downstream mirrors and clients then see a checksum change for packages that did not change, and anything caching by checksum has to re-download everything.

Change

  • The unsigned tarball is written to <file>.tgz.unsigned and hashed with SHA-256.
  • On a rebuild, when the recorded <file>.tgz.unsigned.sha256 digest matches and the signed tarball and .sha1 are present, the existing signed package is kept and the signer is not called.
  • When signing is needed, the package is extracted from <file>.tgz.unsigned and upm pack signs into a temporary staging directory before replacing the published .tgz and writing <file>.tgz.unsigned.sha256, so a failed signing run does not overwrite the existing signed tarball or record a sidecar for an unsigned package.
  • forceUpdate keeps signed packages on disk for packages eligible for signing so the reuse path can see them, while still deleting stale .tgz, .sha1, and .tgz.unsigned.sha256 artifacts when signing is disabled or excluded for a package.
  • DeleteUnityPackage deletes <file>.tgz.unsigned.sha256 alongside .tgz and .sha1.
  • Added offline unit tests in src/UnityNuGet.Tests/RegistryCacheSigningTests.cs covering initial signing, unchanged forceUpdate reuse, content/sidecar/artifact invalidation, DeleteUnityPackage cleanup, disabled/regex-excluded signing, and failed-signer preservation/recovery.

Packages without a recorded digest (all existing ones) are signed once, then start reusing.

Validation

  • dotnet test src/UnityNuGet.Tests -c Release offline suites (RegistryCacheSigningTests, PackageWithoutAssembliesTests, UnityPackageSignerTests, UnityMetaTests, VersionRangeConverterTests, PlatformDefinitionTests, NuGetHelperTests, NpmPackageListAllResponseConverterTests, NativeLibrariesTests, RoslynAnalyzersHelperTests, and RegistryCacheTests.GetNpmVersion): 132 passed, 0 failed (using an in-memory .nupkg and cross-platform upm shim for signing tests).
  • dotnet test src/UnityNuGet.Server.Tests -c Release: 12 passed, 0 failed.

Notes

  • Only active when signing is configured.
  • If a future version changes the conversion output, the digest differs and the package is signed as today.

favoyang and others added 7 commits November 18, 2026 06:25
Signing is not deterministic: the Unity attestation carries an RFC 3161
timestamp, so signing identical content produces a different tarball, a
different SHA-1 and a different published checksum. A full rebuild (image
update) therefore rewrites the checksum of every package, which invalidates
downstream mirrors and caches for no reason.

Record the SHA-256 of the unsigned tarball next to each signed package and
reuse the signed artifact when a rebuild produces the same unsigned bytes.
The conversion now writes the unsigned tarball to a sibling file, hashes it,
and only calls the signer when the digest differs from the recorded one.

forceUpdate no longer deletes signed packages up front, so the reuse path can
see the previous artifact; the conversion still runs for every version. The
recorded digest is removed together with the package, and a failed conversion
keeps the previous signed artifact when it was reused.
Add offline unit tests covering first signed package generation, byte-for-byte
reuse when unsigned content is unchanged across forced rebuilds, re-signing when
content or sidecar state changes, sidecar cleanup in DeleteUnityPackage, and
no-sidecar behavior when signing is disabled or excluded.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Keep the existing signed tarball untouched while extracting and running
the signer into a temporary staging directory, and require the signed
output file to exist and be non-empty before replacing the published
tarball and writing the .unsigned.sha256 sidecar. Also remove stale
sidecar files when a package is excluded from signing.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@bdovaz
bdovaz enabled auto-merge (squash) November 29, 2026 14:17
@bdovaz
bdovaz merged commit aabd460 into bdovaz:master Nov 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants