ACME/LetsEncrypt client for Zig
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Emi 1452679180 feat: forward TLS peer IP to upstream
Signed-off-by: Emi <emi@hexops.com>
2026-08-23 02:54:28 -07:00
example initial autocert implementation 2026-06-21 09:04:27 -07:00
src feat: forward TLS peer IP to upstream 2026-08-23 02:54:28 -07:00
.gitattributes init repo 2026-06-16 19:24:45 -07:00
.gitignore init repo 2026-06-16 19:24:45 -07:00
build.zig initial autocert implementation 2026-06-21 09:04:27 -07:00
build.zig.zon initial autocert implementation 2026-06-21 09:04:27 -07:00
LICENSE init repo 2026-06-16 19:24:45 -07:00
LICENSE-APACHE init repo 2026-06-16 19:24:45 -07:00
LICENSE-MIT init repo 2026-06-16 19:24:45 -07:00
README.md initial autocert implementation 2026-06-21 09:04:27 -07:00

autocert - ACME/LetsEncrypt client for Zig

autocert is a small Zig library for ACME HTTP-01 certificate issuance and renewal, intended to allow Zig services to manage Let's Encrypt certificates in-process.

Reverse proxy

autocert provides an in-process TLS reverse proxy, which can acquire/renew certificates via e.g. Let's Encrypt, and terminate TLS traffic (via tls.zig) before proxying it to your in-process HTTP server. The proxy supports HTTP/1.1, chunked encodings, and WebSockets.

Limitations:

  • TLS 1.3 only, older TLS handshake versions are not supported.
  • HTTP/1.1 and WebSockets only, no HTTP/2 support, no HTTP/3/QUIC support.
  • WebSocket support is not yet high-throughput full-duplex: TLS connection access must be serialized because tls.Connection does not guarantee concurrent read/write safety (tls.zig#34). Server-to-client WebSocket messages may be delayed by up to TLSReverseProxy.Options.websocket_poll_timeout_ms while the proxy polls client reads, so it is not yet suitable as a high-throughput full-duplex WebSocket tunnel as a result.

Usage

See example/main.zig for a complete example of usage.

Build the example:

zig build -Dtarget=x86_64-linux -Dcpu=x86_64_v3 -Doptimize=ReleaseFast

It can be run on a Linux host with e.g. example.com DNS pointed at it:

export HTTP_PORT='80'
export HTTP_BIND_HOST='0.0.0.0'
export ENABLE_HTTPS='true'
export HTTPS_PORT='443'
export HTTPS_BIND_HOST='0.0.0.0'
export HTTP_REDIRECT_HTTPS='true'
export ACME_DOMAIN='example.com'
export ACME_CONTACT_EMAIL='admin@example.com'
export ACME_TERMS_OF_SERVICE_AGREED='true'
export ACME_DIRECTORY_URL='https://acme-v02.api.letsencrypt.org/directory'
export DATA_DIR='/var/lib/autocert'
export BASE_URL='https://example.com'
./zig-out/bin/autocert-example