lev.tls_identity

lev

tls_identity(cert_path, key_path, names) -> identity, err

Parse a cert+key PEM pair into a reusable TLS identity

Parses the PEM certificate chain and private key from files into a Lua userdata that can be passed to starttls() via the identity config field, or as an element of its certs array. The identity is parsed once and reused across connections, avoiding per-connection file I/O and PEM parsing overhead.

An identity answers for a list of hostnames when used for SNI. names is a single hostname or an array of them; omitting it derives the list from the certificate itself -- its SAN dNSName entries, or its common name when it has none. A wildcard certificate covering both an apex and its subdomains therefore needs no configuration at all. Explicit names replace the certificate's own rather than adding to them.

Fails when the certificate declares no name usable for SNI and none was given.