CL-HTTP SSL/TLS Configuration Guide



CL-HTTP supports TLS 1.3 and TLS 1.2 for server, client, proxy, and Web walker on both active ports:

Contents

  1. Quick Start
  2. Certificate Generation
  3. Server Configuration
  4. Client Configuration
  5. HTTP/2 over TLS
  6. X.509 Client Certificates
  7. Troubleshooting
  8. TLS via mitmproxy (Genera and other ports)

1. Quick Start

CL-HTTP ships with self-signed Ed25519 and RSA-2048 certificates in http:pw;ssl; for testing. To start an HTTPS server:

LispWorks (OpenSSL, RSA-2048)

(define-https-service
 :port 8443
 :certificate #p"http:pw;ssl;rsa2048-cert.pem"
 :private-key #p"http:pw;ssl;rsa2048-key.pem"
 :password :none
 :ciphers :all
 :ssl-version :tls-1.2
 :enable-service-p t)

LispWorks (OpenSSL, Ed25519)

(define-https-service
 :port 8443
 :certificate #p"http:pw;ssl;ed25519-cert.pem"
 :private-key #p"http:pw;ssl;ed25519-key.pem"
 :password :none
 :ciphers :all
 :ssl-version :tls-1.3
 :enable-service-p t)

SBCL (pure-tls, Ed25519)

(ensure-https-protocol-on-port 8443
 :certificate #p"http:pw;ssl;ed25519-cert.pem"
 :private-key #p"http:pw;ssl;ed25519-key.pem"
 :password :none)

Test with:

curl -sk https://localhost:8443/cl-http/cl-http.html | head -3

2. Certificate Generation

Ed25519 (recommended for development and SBCL)

Ed25519 provides fast handshakes and small key sizes. Supported by pure-tls (SBCL) and OpenSSL 1.1.1+ (LispWorks).

# Generate Ed25519 private key
openssl genpkey -algorithm Ed25519 -out ed25519-key.pem

# Generate self-signed certificate (10 years)
openssl req -new -x509 -key ed25519-key.pem -out ed25519-cert.pem \
    -days 3650 -subj "/CN=localhost/O=CL-HTTP/C=US"

RSA-2048 (maximum compatibility)

RSA-2048 is supported by all TLS libraries and browsers.

# Generate RSA-2048 private key (no passphrase)
openssl genrsa -out rsa2048-key.pem 2048

# Generate self-signed certificate (10 years)
openssl req -new -x509 -key rsa2048-key.pem -out rsa2048-cert.pem \
    -days 3650 -subj "/CN=localhost/O=CL-HTTP/C=US"

ECDSA P-256

openssl ecparam -genkey -name prime256v1 -out ecdsa-key.pem
openssl req -new -x509 -key ecdsa-key.pem -out ecdsa-cert.pem \
    -days 3650 -subj "/CN=localhost/O=CL-HTTP/C=US"

Installing Certificates

Copy key and certificate files to http:pw;ssl;:

(translated-pathname "http:pw;ssl;")
  ⇒ #P"/path/to/cl-http/log/pw/ssl/"

Restrict file permissions on private keys:

chmod 600 *-key.pem

3. Server Configuration

The define-https-service macro configures and starts an HTTPS listener. Key parameters:

ParameterDescriptionDefault
:portHTTPS listen port443
:certificatePathname to PEM certificate(required)
:private-keyPathname to PEM private key(required)
:passwordKey passphrase, or :none:prompt
:ssl-version:tls-1.3, :tls-1.2Implementation default
:ciphers:all, :high, or OpenSSL cipher string:all
:enable-service-pStart listening immediatelynil

URLs must be exported on the HTTPS port to be accessible:

(export-url #u("/cl-http/" :port 8443 :protocol :https)
            :directory
            :recursive-p t
            :pathname "http:www;cl-http;"
            :public t)

4. Client Configuration

The CL-HTTP client automatically uses TLS for HTTPS URLs. To control the SSL version and verify behavior:

;; Set default client SSL version
(setf *default-client-ssl-version* :tls-1.3)

;; Disable certificate verification for self-signed certs (testing only)
(setf *client-ssl-verify-p* nil)

The client negotiates ALPN for HTTP/2 when *client-http2-enabled* is true (the default).


5. HTTP/2 over TLS

HTTP/2 requires TLS and uses ALPN (Application-Layer Protocol Negotiation) to upgrade from HTTP/1.1. To enable HTTP/2:

;; Enable HTTP/2 protocol
(set-http-version :http/2)
(initialize-http2)

;; Then start HTTPS (ALPN is configured automatically)
(define-https-service :port 8443 ...)

Important: Call set-http-version and initialize-http2 before starting the HTTPS service. ALPN callbacks are registered on the SSL context at service creation time.

Verify HTTP/2 negotiation:

curl -svk --http2 https://localhost:8443/ 2>&1 | grep ALPN
  * ALPN: server accepted h2

6. X.509 Client Certificates

CL-HTTP supports X.509 client certificate authentication. See Using Self-Signed Certificates for detailed instructions on creating a certificate authority and minting client certificates.

To require client certificates on a port:

(define-https-service
 :port 8443
 :certificate #p"http:pw;ssl;server-cert.pem"
 :private-key #p"http:pw;ssl;server-key.pem"
 :password :none
 :certificate-authorities #p"http:pw;ssl;ca.crt"
 :verify :require
 :enable-service-p t)

7. Troubleshooting

Connection refused on HTTPS port
Verify the service is running: (listening-on-http-ports). Check that the certificate and key files exist and are readable.
TLS handshake failure
Ensure the certificate matches the private key. For Ed25519, both LW (OpenSSL 1.1.1+) and SBCL (pure-tls) support it. For RSA, use at least 2048-bit keys.
HTTP/2 not negotiating
Call (set-http-version :http/2) and (initialize-http2) before starting the HTTPS service. Verify: (http2-protocol-enabled-p) should return T.
SBCL pure-tls: MAC error under rapid reconnection
Known issue with rapid TLS session resumption under load. Workaround: disable PSK session caching or increase connection timeout.
LW: ECDSA handshake failure
LW's OpenSSL integration currently only supports RSA and Ed25519 at the handshake level. Use RSA-2048 or Ed25519 certificates.

8. TLS via mitmproxy (Genera and other ports)

Ports without native SSL/TLS support (such as Symbolics Genera) can use mitmproxy as a TLS termination and origination proxy. mitmproxy handles TLS 1.2/1.3 encryption, HTTP/2, and HTTP/3 (QUIC) while CL-HTTP communicates with it over plain HTTP/1.1 on localhost. This provides full HTTPS capability for the server, client, and proxy subsystems.

8.1 Installation

mitmproxy is available via package managers on most platforms:

# macOS (MacPorts)
sudo port install mitmproxy

# Linux (pip)
pip install mitmproxy

# Or download binaries from https://mitmproxy.org/

Verify installation:

mitmdump --version

8.2 Server: TLS Termination (HTTPS → HTTP)

mitmproxy terminates incoming TLS connections from external clients and forwards the decrypted requests to CL-HTTP over plain HTTP/1.1 on localhost. This gives external clients HTTPS/H2/H3 access to a CL-HTTP server that only speaks HTTP/1.1.

Development (mitmproxy's built-in CA)

For development and testing, mitmproxy generates its own CA certificate on first run (stored in ~/.mitmproxy/). No certificate setup is needed:

mitmdump --mode reverse:http://localhost:8001 \
         --listen-port 8443

Clients connect to https://host:8443/. Since the certificate is self-signed, use curl -k or install ~/.mitmproxy/mitmproxy-ca-cert.pem in your browser's trust store.

Production (your own certificate)

For production deployment with a certificate trusted by browsers, mitmproxy requires the certificate and private key combined in a single PEM file with the certificate first, then the key:

# Combine certificate chain and private key into one PEM file
cat /path/to/fullchain.pem /path/to/privkey.pem > /path/to/combined.pem

# Or for self-signed (generated per Section 2 above):
cat rsa2048-cert.pem rsa2048-key.pem > combined.pem

Deploy with the --certs option. The * matches all hostnames; replace with a specific hostname to serve different certificates per virtual host:

# Single certificate for all hostnames
mitmdump --mode reverse:http://localhost:8001 \
         --listen-host 0.0.0.0 \
         --listen-port 443 \
         --certs *=/path/to/combined.pem

# Per-hostname certificates (virtual hosting)
mitmdump --mode reverse:http://localhost:8001 \
         --listen-host 0.0.0.0 \
         --listen-port 443 \
         --certs www.example.com=/path/to/example-combined.pem \
         --certs api.example.com=/path/to/api-combined.pem

Let's Encrypt certificates

If you use Let's Encrypt via certbot, the certificate files are in /etc/letsencrypt/live/yourdomain/:

# Combine Let's Encrypt certificate chain and key
cat /etc/letsencrypt/live/yourdomain/fullchain.pem \
    /etc/letsencrypt/live/yourdomain/privkey.pem \
    > /path/to/combined.pem

mitmdump --mode reverse:http://localhost:8001 \
         --listen-host 0.0.0.0 \
         --listen-port 443 \
         --certs *=/path/to/combined.pem

Set up a cron job or certbot timer to renew and rebuild the combined PEM file. Restart mitmproxy after renewal.

Clients connect to https://host/ and mitmproxy forwards to CL-HTTP on http://localhost:8001/.

HTTP/2 and HTTP/3 Support

mitmproxy supports HTTP/2 by default on HTTPS connections (ALPN negotiation). For HTTP/3 (QUIC):

# Enable HTTP/3 (experimental in mitmproxy 10+)
mitmdump --mode reverse:http://localhost:8001 \
         --listen-port 8443 \
         --set http3=true

CL-HTTP sees only HTTP/1.1 requests from mitmproxy. The protocol upgrade (H2/H3) is handled entirely between the external client and mitmproxy. Response headers like Alt-Svc for H3 advertisement are managed by mitmproxy.

8.3 Client: TLS Origination (HTTP → HTTPS)

For CL-HTTP's client to access external HTTPS sites from a port without native TLS, configure mitmproxy as a forward proxy. The CL-HTTP client sends plaintext HTTP requests to the proxy, which upgrades them to HTTPS for the upstream server. This is required for cloud LLM platforms (Anthropic, Google, OpenAI, xAI) which mandate HTTPS for API access.

Starting the forward proxy

# Listen on the subnet shared with the CL-HTTP host
mitmdump --mode regular \
         --listen-host 10.0.3.10 \
         --listen-port 9443 \
         --ssl-insecure

Replace 10.0.3.10 with the proxy host's IP address on the subnet shared with the CL-HTTP system. The --ssl-insecure flag disables upstream certificate verification (acceptable for trusted local networks; omit for production).

Restricting access to the local subnet (macOS/BSD)

echo "block in quick proto tcp from ! 10.0.3.0/24 to 10.0.3.10 port 9443" \
  | sudo pfctl -ef -

CL-HTTP client proxy configuration

;; Direct all HTTPS client requests through the proxy
(http:define-client-proxy-mapping
  :standard-proxies ((:https :default "10.0.3.10" 9443)))

This directs all HTTPS client requests from CL-HTTP through the proxy. The proxy terminates TLS on behalf of CL-HTTP's HTTP client. Local services that use plain HTTP (e.g., LM Studio, Ollama) are not affected.

For ports with native SSL/TLS (LispWorks, SBCL), conditionalize the proxy mapping so it is skipped:

;; Only configure the proxy on ports without native TLS
#-CL-HTTP-SSL
(http:define-client-proxy-mapping
  :standard-proxies ((:https :default "10.0.3.10" 9443)))

See http:llm;init-file-example.lisp for a complete working configuration including LLM platform setup.

mitmproxy handles TLS negotiation with the upstream server, including certificate verification, SNI, and ALPN for HTTP/2.

8.4 Bidirectional: Server and Client

For ports that need both HTTPS serving and HTTPS client access, run two mitmproxy instances:

# Instance 1: TLS termination for incoming requests
mitmdump --mode reverse:http://localhost:8001 \
         --listen-port 8443 &

# Instance 2: Forward proxy for outgoing requests
mitmdump --mode regular \
         --listen-host 127.0.0.1 \
         --listen-port 8080 &

CL-HTTP configuration:

;; Start HTTP service on the port mitmproxy forwards to
(http:enable-http-service :on-ports '(8001))

;; Configure client proxy for outgoing HTTPS
(http:define-client-proxy-mapping
  "*" "localhost" 8080)

8.5 Genera Configuration

On Symbolics Genera, CL-HTTP runs on the Lisp Machine and mitmproxy runs on a host machine (macOS, Linux) that is network-accessible from the Genera system. The typical setup:

  1. Genera runs CL-HTTP on HTTP port 8001 (accessible from the host)
  2. The host runs mitmproxy in reverse mode, listening on 8443
  3. External clients connect to the host on 8443 (HTTPS/H2/H3)
  4. mitmproxy forwards decrypted requests to Genera on 8001 (HTTP/1.1)
# On the host machine (macOS/Linux):
mitmdump --mode reverse:http://genera-host:8001 \
         --listen-host 0.0.0.0 \
         --listen-port 8443

For Genera's client to access external HTTPS sites, run a forward proxy on the host and configure CL-HTTP's client proxy mapping to point to it.

8.6 Notes

Performance
mitmproxy adds latency for TLS processing. For high-throughput applications, native TLS (LispWorks OpenSSL or SBCL pure-tls) is preferred. mitmproxy is best suited for development, testing, and moderate-traffic deployments.
Certificate management
mitmproxy generates a CA certificate in ~/.mitmproxy/ on first run. For production use, supply your own certificates with the --certs option. The CA certificate must be trusted by clients connecting to the proxy.
Logging
Use mitmweb instead of mitmdump for a browser-based traffic inspector useful during development. Or use mitmdump -v for verbose console logging.
Transparent mode
mitmproxy also supports transparent mode where it intercepts traffic without explicit proxy configuration. This requires iptables/pf rules on the host. See the mitmproxy transparent mode documentation.
HTTP/3 maturity
HTTP/3 (QUIC) support in mitmproxy is experimental as of version 10. It works for basic request/response but may have issues with streaming or WebSocket upgrades. HTTP/2 support is stable and production-ready.

Please report bugs to bug-cl-http@cl-http.com.

John C. Mallery -- M.I.T. Computer Science & Artificial Intelligence Laboratory