@berthos / tls
由Berth的服务器和CLI共享的TLS助手:加载证书,生成用于开发的自签名证书,并信任客户端的自定义CA。
泊位 在沙盒中运行人工智能代理的工具。每个工具在类中声明它可以接触什么 berth.yml manifest, Linux内核强制执行它。
npm install @berthos/tls
使用
import { generateSelfSignedCerts, resolveServerTlsFromEnv, trustCa } from "@berthos/tls";
const certs = generateSelfSignedCerts({ dir: "./certs" }); // localhost, 127.0.0.1 and ::1, valid 365 days
// -> { caCertPath, certPath, keyPath }
// Reads MYSERVER_TLS_CERT, MYSERVER_TLS_KEY, MYSERVER_TLS_CA, MYSERVER_TLS_REQUIRE_CLIENT_CERT
const tls = resolveServerTlsFromEnv("MYSERVER");
trustCa(certs.caCertPath); // client side: trust that CA for outgoing HTTPS
generateSelfSignedCerts() 需要 openssl 在 PATH. CLI的 berth tls init 对你来说也是一样的。