#429·portless

CA cert gets duplicate critical Basic Constraints extension when system openssl.cnf sets x509_extensions for req — breaks macOS trust (ERR_CERT_AUTHORITY_INVALID)

Author: bilinkisCreated Sep 22, 2026Updated Sep 23, 2026

Summary

portless trust / portless proxy start generate a local root CA whose certificate ends up with the X509v3 Basic Constraints extension duplicated (both copies marked critical). macOS's Security framework refuses to validate any certificate chain through this CA with Unknown critical cert extension, so Chrome shows "Your connection is not private" (net::ERR_CERT_AUTHORITY_INVALID) for every *.localhost site even after portless trust reports success and the CA is correctly present (and trusted) in both the System and login keychains.

Root cause

generateCA() builds the CA cert with:

javascript
openssl([
  "req", "-new", "-x509", "-sha256", "-key", keyPath, "-out", certPath,
  "-days", CA_VALIDITY_DAYS.toString(),
  "-subj", `/CN=${CA_COMMON_NAME}`,
  "-addext", "basicConstraints=critical,CA:TRUE",
  "-addext", "keyUsage=critical,keyCertSign,cRLSign",
]);

This never passes -config, so openssl falls back to whatever openssl.cnf is first on $PATH/$OPENSSL_CONF/the build's OPENSSLDIR. The stock upstream openssl.cnf template (shipped as-is by several toolchains — in my case the openssl bundled with Miniconda, but plenty of Linux distro configs match it too) sets, under [ req ]:

x509_extensions = v3_ca

and [ v3_ca ] itself defines basicConstraints = critical,CA:TRUE. Because req -x509 applies this section and the -addext also injects basicConstraints=critical,CA:TRUE, the resulting certificate ends up with the same critical extension listed twice — which is invalid per RFC 5280 (extensions must be unique) and is exactly the kind of malformed cert macOS's SecTrustEvaluate rejects outright, independent of trust settings.

Repro

bash
$ openssl version
OpenSSL 1.1.1t  7 Feb 2023
$ openssl version -d
OPENSSLDIR: "/Users/me/miniconda3/ssl"
$ grep -n "x509_extensions\|v3_ca" "/Users/me/miniconda3/ssl/openssl.cnf"
60:x509_extensions	= usr_cert
112:x509_extensions	= v3_ca      # inside [ req ]
226:[ v3_ca ]

$ rm -r ~/.portless && portless trust
Generated local CA certificate.
Local CA added to system trust store.

$ openssl x509 -in ~/.portless/ca.pem -noout -text | grep -A2 critical
        X509v3 Basic Constraints: critical
            CA:TRUE
        X509v3 Basic Constraints: critical      # <-- duplicated
            CA:TRUE
        X509v3 Key Usage: critical
            Certificate Sign, CRL Sign

$ echo | openssl s_client -connect myapp.localhost:443 -servername myapp.localhost 2>/dev/null \
  | openssl x509 -outform der > /tmp/leaf.der
$ security verify-cert -c /tmp/leaf.der -p ssl -s myapp.localhost
Cert Verify Result: Unknown critical cert extension

Note this happens even though portless trust succeeded and the CA shows up correctly in security dump-trust-settings -d:

Cert 0: portless Local CA
   Number of trust settings : 0

(That 0 is normal/unconstrained trust — not the bug. It's a red herring that cost a lot of debugging time before finding the duplicate extension with security verify-cert.)

Fix

Point req -x509 -addext ... at a minimal, explicit config so it can never inherit an ambient x509_extensions default:

javascript
const reqConfig = [
  "[req]",
  "distinguished_name = req_distinguished_name",
  "prompt = no",
  "[req_distinguished_name]",
  "",
].join("\n");
fs.writeFileSync(minimalConfigPath, reqConfig);

openssl([
  "req", "-new", "-x509", "-sha256", "-key", keyPath, "-out", certPath,
  "-days", CA_VALIDITY_DAYS.toString(),
  "-config", minimalConfigPath,
  "-subj", `/CN=${CA_COMMON_NAME}`,
  "-addext", "basicConstraints=critical,CA:TRUE",
  "-addext", "keyUsage=critical,keyCertSign,cRLSign",
  "-addext", "subjectKeyIdentifier=hash",
  "-addext", "authorityKeyIdentifier=keyid:always",
]);

I verified this locally (regenerating ~/.portless/ca.pem with a minimal -config file, reusing the existing ca-key.pem so already-issued leaf certs' authorityKeyIdentifier still matches) and security verify-cert then reports certificate verification successful. for the same host that previously failed. Opening a PR with this fix shortly.

Worth double-checking generateServerCert() for the same class of issue — it already passes -extfile extPath explicitly for the leaf cert extensions, so it isn't affected, but any future -addext usage without -config is at risk on a system whose default openssl.cnf sets x509_extensions for the invoked subcommand.

Environment

  • portless 0.15.6 (also reproduced on 0.12.0)
  • macOS (Darwin 27.0.0)
  • openssl resolved on $PATH: OpenSSL 1.1.1t (Miniconda-bundled)