Skip to content

fix(openssl): detect LibreSSL, auto-install brew openssl@3, loud die instead of silent exit (#341) - #342

Merged
joelteply merged 1 commit into
canaryfrom
fix/openssl-ed25519-loud-failure
Apr 30, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/openssl-ed25519-loud-failure

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Fixes the silent-exit 1 Carl-on-fresh-Mac bug from #341. Minimal-scope fix; the bigger change (drop shell openssl entirely in favor of the venv cryptography module) is being picked up separately by other-mac.

What Carl saw before

$ curl -fsSL https://raw.githubusercontent.com/CambrianTech/airc/main/install.sh | bash
   ... 'Installed.' ...
$ airc join
   No mesh found on your gh account → becoming the host.
$ echo $?
1

No error. No log. No doctor pointer. /usr/bin/openssl on macOS is LibreSSL 3.3.6, which doesn't implement Ed25519; the 2>/dev/null on the openssl call swallowed the actual error and set -e killed the script.

What Carl sees now

Path A — install.sh detects LibreSSL on Mac and auto-installs brew openssl@3 during install:

   ...
   -> All required prereqs present
   -> System openssl is LibreSSL (no Ed25519). Installing openssl@3 via brew...
   -> openssl@3 installed (airc resolves it at runtime; no PATH change needed)
   -> Installed.
$ airc join
   ... hosting #general normally ...

Path B — install.sh ran on a Mac without brew:
loud warning during install, AND if Carl skips it, the airc join failure path now prints actionable guidance pointing at brew install openssl@3 (or AIRC_OPENSSL=/path/to/openssl), plus the issue link.

Implementation

airc binary:

  • New _resolve_openssl() runs at startup: probes AIRC_OPENSSL env var → /opt/homebrew/opt/openssl@3 → /opt/homebrew/opt/openssl → /usr/local/opt/openssl@3 → /usr/local/opt/openssl → PATH default. First candidate that successfully runs genpkey -algorithm Ed25519 -out /dev/null wins. On Mac this routes around /usr/bin/openssl (LibreSSL) when a working brew binary is present.
  • AIRC_OPENSSL env var is the result, exported for downstream use AND as the user override for non-standard layouts.
  • init_identity() and sign_message() gate on AIRC_OPENSSL non-empty; if empty, _die_no_ed25519_openssl prints a clear actionable error.
  • The 2>/dev/null stays on the actual openssl calls — it suppresses normal status noise on success. Failures now never reach those calls because the resolver pre-validated the binary at startup; if no capable openssl exists, we die early with a real message.

install.sh:

  • After the existing prereq install loop, runs openssl genpkey -algorithm Ed25519 -out /dev/null against the on-PATH openssl. If it fails on Mac, looks for an existing brew openssl@3 (keg-only, /opt/homebrew/opt/openssl@3/bin/openssl); if absent and brew is available, runs brew install openssl@3. If neither, warns loudly with manual guidance.
  • Brew openssl@3 is keg-only by design — it doesn't shadow /usr/bin/openssl (which would break system tools that depend on LibreSSL's behaviors). The airc binary's runtime resolver is what makes this work.

Test results on this Mac

$ openssl version
LibreSSL 3.3.6                                  # /usr/bin/openssl

# Without my fix:
$ airc join
  No mesh found on your gh account → becoming the host.
$ echo $?
1                                                # silent

# With my fix, no brew openssl yet:
$ airc join
  No mesh found on your gh account → becoming the host.
ERROR: airc identity needs an openssl that supports Ed25519, and none was found.
  ...
  macOS ships LibreSSL as /usr/bin/openssl — it does not implement Ed25519.
  Fix:
    brew install openssl@3
    airc join
  ...

# After brew install openssl@3:
$ airc join
  No mesh found on your gh account → becoming the host.
  Hosting as 'airc-test-26f1' (reminder: 300s)
  Hosting #general — no existing room on your gh account, fresh start.
  ✓ Found canonical gist for #general on this gh account → using existing
  Hosting #general (gh-account substrate).
  ...                                            # works

Out of scope (deliberately)

  • Drop shell openssl entirely in favor of lib/airc_core/identity.py using python-cryptography (already a venv dep). Other-mac picked this up — same issue, separate PR.
  • Doctor scenario for Ed25519 capability — worth adding once the migration lands; the probe shape will change.
  • Scope .airc/ autoderive into \$PWD/.airc/ for non-project dirs (Carl install woes — fresh-Mac airc join silent exit 1 (LibreSSL can't do Ed25519) #341 sub-bullet) — separate fix, separate PR.

Test plan

  • Fresh Mac with only LibreSSL → install.sh auto-installs brew openssl@3
  • Fresh Mac with brew openssl@3 already present → install.sh detects, no-op
  • Fresh Mac with no brew at all → loud warning during install + actionable error at airc join
  • After brew openssl@3 installed → airc join succeeds, hosts #general
  • AIRC_OPENSSL=/custom/path airc join → uses the override
  • Linux machine — should be no-op (PATH openssl already supports Ed25519)
  • Windows Git Bash — Git for Windows openssl supports Ed25519, no-op expected

🤖 Generated with Claude Code

…d of silent exit (#341)

Carl on a fresh Mac ran 'airc join' after the documented curl install and
got 'No mesh found on your gh account → becoming the host.' followed by
exit 1, no error, no diagnostic. The whole stack was working — gh authed,
gist about to be created — except 'openssl genpkey -algorithm Ed25519'
silently failed because /usr/bin/openssl on macOS is LibreSSL 3.3.6, and
LibreSSL doesn't implement Ed25519. The 2>/dev/null on the openssl call
swallowed the actual error; set -e killed the script with no trap.

Two-part fix:

airc binary: resolve openssl with Ed25519 capability at startup
(_resolve_openssl), prefer brew openssl@3 / openssl over PATH default
on Mac (so /usr/bin/openssl LibreSSL is bypassed when a working brew
binary is present), expose as AIRC_OPENSSL. init_identity + sign_message
gate on AIRC_OPENSSL non-empty; if empty, _die_no_ed25519_openssl prints
a clear actionable error pointing the user at 'brew install openssl@3'
or AIRC_OPENSSL=/path env override, plus the issue link. AIRC_OPENSSL
env var is also the user override for non-standard layouts.

install.sh: 'openssl --version' is not enough — LibreSSL passes that
probe. Add a real 'openssl genpkey -algorithm Ed25519' probe after the
existing prereq install loop. On Mac, if the probe fails AND brew is
available AND brew openssl@3 isn't already keg-installed, auto-install
it. Brew openssl@3 is keg-only (doesn't shadow /usr/bin/openssl) but
airc's runtime resolver locates it at /opt/homebrew/opt/openssl@3/bin/.
On Linux/Windows the probe failing is rare; emit a warning with manual
fix guidance.

Tested both paths on this Mac:
  * with only LibreSSL → loud actionable error, exit 1
  * after 'brew install openssl@3' → 'airc join' succeeds, hosts #general

Doesn't change the bigger question (raised by Joel: do we need shell
openssl at all when the venv already has python-cryptography?). That's
a follow-up — this PR just stops Carl from hitting a silent failure
on every fresh Mac install.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit 5009da8 into canary Apr 30, 2026
6 checks passed
@joelteply
joelteply deleted the fix/openssl-ed25519-loud-failure branch April 30, 2026 00:08
joelteply added a commit that referenced this pull request Apr 30, 2026
)

Identity gen (genpkey) and message signing (pkeyutl -sign) used to
shell out to system openssl. macOS LibreSSL doesn't implement Ed25519
via genpkey, which silently broke fresh-Mac installs (the 2>/dev/null
ate the error — exactly the error-suppression antipattern that "Never
swallow errors" exists to forbid). #342 made the failure loud and
auto-installed brew openssl@3; this PR removes the dependency on
system openssl entirely by routing both ops through the venv
python-cryptography module that's already installed for envelope
encryption.

What changed:
- lib/airc_core/crypto.py: add generate_ed25519_keypair_pem,
  load_ed25519_priv_pem, sign_ed25519_pem, save_ed25519_keypair_pem.
  PEM format (PKCS#8 priv, SPKI pub) matches openssl byte-for-byte —
  existing scopes that paired under shell-openssl load + verify
  cleanly here. Cross-checked: signing a Python-gen key via openssl
  pkeyutl -sign and signing the same message via the new path
  produces byte-identical base64 output.
- lib/airc_core/identity.py: bootstrap_ed25519 + sign_ed25519
  siblings to the existing X25519 functions, plus bootstrap-ed25519
  and sign-ed25519 CLI subcommands so bash invokes via
  $AIRC_PYTHON -m airc_core.identity ...
- airc top-level: sign_message and init_identity now route through
  the python CLI. Removed _resolve_openssl, AIRC_OPENSSL,
  _die_no_ed25519_openssl — all dead code post-migration. ssh-keygen
  remains (it's an OpenSSH client tool, not a libcrypto consumer,
  and ships working on every supported platform).
- install.sh: drop openssl from the prereq list; drop the
  LibreSSL-detect + brew-install-openssl@3 dance (no longer needed
  since shell openssl isn't called). cryptography stays a hard dep
  via the existing venv pip-install step.
- cmd_doctor.sh: replace the openssl probe with a cryptography
  import probe ("import cryptography.hazmat.primitives.asymmetric
  .ed25519"). Surfaces "re-run install.sh" if the venv didn't
  finish setting up.

Backward compat: existing scopes' private.pem / public.pem files
(generated by shell openssl in any prior version) continue to work
unchanged. The PEM wrapping format is the same; load_pem_private_key
parses both. No identity rotation triggered by upgrade.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

1 participant