Repository navigation
Mobile bundles, signing, and two phar fixes that also affect desktop - #7
Merged
Merged
Conversation
Two things go quietly missing when a Laravel app runs from a bundle. glob() only reads the real filesystem, so under a phar:// path it returns nothing. Laravel finds migrations and discovers event listeners with it, so a bundled app ran no migrations and registered no discovered listeners. The compactor now points global glob() calls at nativephp_glob(), which walks the phar with scandir() and matches names itself. It doesn't use fnmatch(), because PHP built for iOS doesn't have it. Methods called glob, like Filesystem::glob(), are left alone. The compactor also returned early for LoadConfiguration, SplFileInfo and BladeIconsServiceProvider, so the general realpath() rewrite never ran on them. LoadConfiguration then called the real realpath() on the config path inside the phar, got false, and loaded none of the app's config files. The special cases now add to the general rewrites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`parcel prepare --mobile` sets up an app staged by NativePHP Mobile's native:build, which has no artisan file. Its Box config takes the whole staged app except public/, storage/ and .env, which stay outside the bundle on the device, and keeps the app's own autoloader so debug builds with dev packages still boot. The output is named __nativephp_app_bundle.phar: the device opens files inside it by phar:// path, and PHP can only find the end of the archive in such a path when the file name has an extension. `parcel sign <bundle>` writes a detached Ed25519 signature over "nativephp.parcel-bundle.v1:" and the bundle's SHA-256. The key comes from PARCEL_SIGNING_KEY so it never shows in a process list, and --public-key-output writes the public key for the build to embed in the app. Ed25519 because iOS can check it with CryptoKit; it can't check GPG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`parcel sign` now uses ECDSA P-256, the scheme Bifrost already signs OTA
releases with, so Bifrost's existing key can sign bundles too. The signed
message follows the OTA one: a format line, the project, the bundle's
SHA-256 and its size. Binding the project means one key can sign for
every app without a bundle from one running in another.
With PARCEL_SIGNING_URL and PARCEL_SIGNING_TOKEN set, parcel sends only
the project, hash and size to that endpoint and Bifrost signs, so the
private key never has to be on the build machine. Otherwise it signs
with a local PEM key from PARCEL_SIGNING_KEY. Either way the signature
is checked against the returned public key before it's written, as
JSON with the key id, and --public-key-output writes {key id: public
key} for the build to put in the app.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Gets Parcel bundles working for NativePHP Mobile, and fixes two bugs that also affect desktop bundles.
Bugs that affect desktop too
Migrations and discovered event listeners go missing. PHP's
glob()only reads the real filesystem, so under aphar://path it returns nothing, with no error. Laravel's migrator and event discovery both use it. The compactor now rewrites globalglob()calls to\nativephp_glob()(inbox-helper.php), which walks the phar withscandir()and does its own pattern matching. Outside a phar it just callsglob(). It handlesGLOB_BRACE,GLOB_ONLYDIR,GLOB_MARK,GLOB_NOSORT,GLOB_NOCHECKandGLOB_NOESCAPE, and it doesn't usefnmatch()because PHP built for iOS doesn't have it. The rewrite works on tokens, so methods namedglob(likeFilesystem::glob()) are left alone.None of the app's config files load. The compactor returned early for
LoadConfiguration.php,SplFileInfo.phpandBladeIconsServiceProvider.php, so the generalrealpath()rewrite never ran on them.LoadConfiguration::getConfigurationFiles()then called the realrealpath()on the config path inside the phar, gotfalse, and returned no files. The app ran on framework and package defaults. I suspect desktop got away with it because Bifrost runsphp artisan optimizebefore bundling, but anything that rebuilds the config cache from inside the bundle would hit it. The special cases now add to the general rewrites.After both fixes, booting the same app as plain files and as a phar gives the same config, routes, providers and event listeners. The one difference left is a trailing slash on view paths, which
nativephp_rp()adds to directories.Mobile
parcel prepare --mobilesets up an app that mobile-air'snative:buildhas staged. That copy has noartisan, so it looks forbootstrap/app.phpinstead. The mobile Box config:public/,storage/and.env, which stay beside the bundle on the devicedump-autoload: false). Box's dump is--no-dev, which breaks debug builds whose package manifest lists dev providersbuild/__nativephp_app_bundle.phar. The device opens files inside it byphar://path, and PHP can only find where the archive ends in such a path if its file name has an extension.parcel sign <bundle> --project=<id>signs with ECDSA P-256, the scheme Bifrost already uses for OTA releases. The message follows the OTA one:nativephp-parcel-bundle-v1, the project, the bundle's SHA-256 and its size, one per line. Binding the project lets Bifrost's single key sign for every app without a bundle from one running in another.PARCEL_SIGNING_URLandPARCEL_SIGNING_TOKENset, Parcel sends only the project, hash and size to that endpoint and Bifrost signs. The private key never has to be on the build machine.PARCEL_SIGNING_KEY(named byPARCEL_SIGNING_KEY_ID, defaultlocal), for testing..sigis JSON with the key id and a base64 DER signature, and--public-key-outputwrites{key id: public key}for the build to embed in the app.This adds
ext-opensslto the requirements.Testing
Unit tests cover the glob helper against a real phar (including a run with
fnmatchdisabled), the compactor rewrites, the mobile stubs, and signing both locally and through a stand-in for Bifrost's endpoint (tests/Fixtures/signing-server.phpunderphp -S). 65 pass. I didn't run the Feature suite, which clones kitchen-sink from GitHub.End to end: the mobile-air side (NativePHP/mobile-air#707) built devnull-mobile with this, and it ran on an iOS simulator from a signed 12.5 MB phar. The normal debug build's
app.zipis 64 MB. A release build, without dev packages, comes out at 7.5 MB.For review
nativephp_rp()never returnsfalseand doesn't resolve.., unlikerealpath(). The compactor swaps it in across all of vendor, so any package that relies onrealpath()returningfalse, or uses it to block path traversal, behaves differently inside a bundle. That was already true before this PR; I didn't find a case in devnull's dependencies, but it's worth keeping in mind.box.jsonand GPG signing. Nothing changes for them except the two fixes above.🤖 Generated with Claude Code