Skip to content

fix(desktop): rebuild the ASC API key PEM before notarizing - #14560

Merged
dylanjeffers merged 1 commit into
mainfrom
fix/asc-api-key-pem
Aug 14, 2026
Merged

fix(desktop): rebuild the ASC API key PEM before notarizing#14560
dylanjeffers merged 1 commit into
mainfrom
fix/asc-api-key-pem

Conversation

@dylanjeffers

Copy link
Copy Markdown
Contributor

Problem

With the Developer ID signing cert replaced, the Mac desktop build now signs successfully and reaches notarization for the first time — where it fails:

• signing  file=dist/mac-arm64/Audius.app  identity=8F3E89764D9E3669B6DE070A9EF8D30373FC1D6A
Error: Failed to notarize via notarytool
Error: invalidPEMDocument

invalidPEMDocument means notarytool could not parse the .p8 written from APP_STORE_CONNECT_API_KEY_KEY. The key itself is healthy — App Store Connect shows the team key active and in use.

writeApiKeyFile trusted the stored formatting whenever the BEGIN PRIVATE KEY marker was present. Secret stores commonly flatten PEM newlines to literal \n or strip them altogether, both of which keep the marker while producing a file notarytool rejects.

Fix

Extract the base64 body and rebuild the PEM at 64-column wrapping, so every common storage shape converges on a valid key. When the secret isn't a PKCS#8 key at all, throw an error that says so instead of writing a broken file and letting notarytool report a generic parse failure.

Testing

Generated a P-256 PKCS#8 key (same shape as an App Store Connect .p8) and ran each mangling through the normalizer, checking the result with openssl pkey -check:

Input shape Result
raw PEM (already correct) PASS
literal \n escapes PASS
newlines stripped entirely PASS
CRLF line endings PASS
base64 of the PEM PASS
base64 of \n-escaped PEM PASS
garbage input rejected with a clear error

Note this cannot be verified in CI without merging, since desktop-build-mac only runs on main behind the production gate.

🤖 Generated with Claude Code

notarytool rejects a malformed .p8 with a bare `invalidPEMDocument`, which
says nothing about what was wrong — the Mac build hit exactly this once the
signing cert was fixed and it finally got far enough to notarize.

Secret stores routinely mangle PEMs, either flattening the newlines to
literal \n or stripping them entirely, and the previous code trusted the
stored formatting as long as the BEGIN marker was present. Pull out the
base64 body and rebuild the PEM instead, so all the usual shapes converge on
a valid key, and throw a message that names the actual problem when the
secret isn't a PKCS#8 key at all.

Verified against six mangling modes (raw, literal \n, no newlines, CRLF, and
base64 of the first two) plus a garbage input, checking each result parses
with `openssl pkey -check`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e44f714

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dylanjeffers
dylanjeffers merged commit 1791ccb into main Aug 14, 2026
17 checks passed
@dylanjeffers
dylanjeffers deleted the fix/asc-api-key-pem branch August 14, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant