lmssl guide
Overview
lmssl unifies the upstream OpenSSL 4.0.3 command-line utility, statically linked libcrypto and libssl libraries, an embedded default openssl.cnf, and the lmcode-cpp bytecode virtual machine in a single zero-dependency executable. It lets developers and agents run standard openssl commands or execute type-checked _lmcode_ scripts that make every DNS, TCP, TLS, PKI, and cryptographic step explicit.
Dual-mode architecture and embedded OpenSSL 4.0.3
A common frustration with standalone OpenSSL deployments is missing shared libraries or missing openssl.cnf configuration files on minimal containers and build runners. lmssl eliminates both dependencies:
- Static single-file linkage: OpenSSL 4.0.3's libcrypto, libssl, and apps/openssl.c (with main renamed) are statically linked with the lmcode-cpp VM. On Linux, ldd lmssl reports that the binary is not a dynamic executable.
- Compiled-in configuration: When invoked in native OpenSSL CLI mode (any command not starting with --lmcode, --dry-run, --json, --version, --lmcode-schema, or --lmcode-signatures) and OPENSSL_CONF is unset, lmssl automatically materializes OpenSSL's stock openssl.cnf so commands such as lmssl req and lmssl ca work out of the box.
- Multi-part bytecode execution: In _lmcode_ mode, lmssl validates every --lmcode FILE [ARG...] part against the embedded schema SHA-256 before executing any part. Each part receives its own argument vector through ssl.args(), writes human diagnostics to stderr via out.line/text/warn, and emits a single terminal JSON SDK frame on stdout.
Cryptographic primitives and X.509 PKI builders
The ssl context exposes deterministic wrappers around OpenSSL's EVP and X509 APIs:
- Hexadecimal binary boundary: Functions that produce or consume raw cryptographic material (ssl.digest, ssl.hmac, ssl.pbkdf2, ssl.seal, ssl.open, Key.sign, Key.verify, ssl.rand_hex) use lowercase hexadecimal strings for keys, IVs, tags, digests, and signatures, while plaintext payloads and PEM blocks remain regular UTF-8 or byte strings. For AEAD (AES-128-GCM, AES-256-GCM, ChaCha20-Poly1305), ssl.seal returns hex(ciphertext || 16-byte tag), and ssl.open verifies the 16-byte authentication tag before returning plaintext.
- Two-phase certificate construction: ssl.new_cert(key, subject) or ssl.cert_from_csr(csr) creates an unsigned X509 template with a random 63-bit serial number and 365-day default validity. Builder methods (san, ca, ext, valid_days, valid_between, serial) return the Cert receiver for chaining. Calling sign_self(key, digest) or sign_with(issuer_cert, issuer_key, digest) automatically attaches subjectKeyIdentifier, basicConstraints (CA:TRUE if ca(true) was set, otherwise CA:FALSE), and authorityKeyIdentifier before signing.
- Private key file hygiene: Key.save, Key.save_encrypted, and fs.write_private enforce 0600 file permissions at creation time so private keys are never world-readable.
Explicit DNS, TCP, and TLS handshake inspection
Unlike high-level HTTP clients that hide connection setup, lmssl separates name resolution, TCP socket connection, TLS policy configuration, and stream I/O so scripts can inspect or test each layer independently:
- Socket and listener layer: net.resolve(host) returns a StrList of resolved IP addresses, net.connect(host, port) opens a plain TCP Conn (backed by an OpenSSL BIO), and net.listen(port) binds a local TCP Listener (supporting port 0 ephemeral allocation via listener.port()).
- Fail-closed TLS policy: ssl.client_ctx() and ssl.server_ctx(cert, key) construct a TlsCtx. Client contexts enable peer certificate verification by default with no trust anchors loaded; scripts opt into trust via ctx.system_roots(), ctx.ca_file(path), or ctx.add_ca(cert), or disable enforcement with ctx.verify(false) to inspect untrusted chains via tls.verified() and tls.verify_result().
- Handshake telemetry: Enabling ctx.trace(true) before ctx.connect(conn, sni) or ctx.accept(conn) records every TLS record and handshake message with byte lengths. After handshake completion, tls.version(), tls.cipher(), tls.group() (including post-quantum hybrid groups like X25519MLKEM768 in OpenSSL 4.0.3), tls.peer_sigalg(), tls.alpn(), tls.peer(), and tls.chain_at(i) expose the negotiated session parameters.
Standard lmcode_std_v3 REST and CLI interfaces
lmssl embeds the full 226-signature lmcode_std_v3 standard library (cpp/stdlib/rest.hpp). Scripts can expose PKI, digest, or TLS inspection endpoints as HTTP routes or stateless CLI commands:
- HTTP route annotations: Functions annotated with static or parameterized paths (such as @"/pki/sign" or @"/certs/:serial") can implement RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, or RestHandler.
- Stateless CLI dispatch: Functions annotated with @"--flag" implement CliOption and functions annotated with @"command" implement CliCommand. rest_cli(args) dispatches flags, subcommands, or URL paths in-process and returns the response string.
- Stateful sessions and live listener: rest_config("session", "global") preserves key-value state across RestExchange.set and RestExchange.increment calls, while rest_serve() and rest_stop() control the embedded HTTP server loop.
p = _lmcode_ cli="lmssl" install="github:lmctl-ai/lmssl@latest";
@"--curve"
fn opt_curve(x: RestExchange) -> void implements CliOption {
x.set("curve", x.query("curve"));
}
@"gen-ca"
fn cmd_gen_ca(x: RestExchange) -> void implements CliCommand {
let k = ssl.gen_ec(x.get("curve"));
let c = ssl.new_cert(k, "CN=" + x.body()).ca(true).valid_days(365).sign_self(k, "SHA256");
x.send(c.subject() + ":" + k.curve());
}
@"/hash/:alg"
fn post_hash(x: RestExchange) -> void implements RestPost {
x.json("{\"alg\":\"" + x.param("alg") + "\",\"hex\":\"" + ssl.digest(x.param("alg"), x.body()) + "\"}");
}
rest_config("session", "global");
assert_eq(rest_cli(str_split("--curve=P-256 gen-ca -- RootCA", " ")), "CN=RootCA:P-256");
end _lmcode_