AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-onlyscripts/acme-dns01.mjs
1#!/usr/bin/env node2// Trusted-certificate issuance via ACME DNS-01 (Let's Encrypt), no root, no open port 80/443, no DNS API credentials.3// node scripts/acme-dns01.mjs begin [--domain cloud.zoobd.com] [--staging] -> prints the TXT record the DNS owner must publish4// node scripts/acme-dns01.mjs finish [--staging] -> verifies the record, validates, issues, installs ~/.config/zoo-cloud-studio/tls/trusted/5// node scripts/acme-dns01.mjs status6// Only the DNS name is sent to the CA (no email, no account contact). The ACME account key stays in ~/.config/zoo-cloud-studio/acme (0600).7import crypto from "node:crypto"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { execFileSync } from "node:child_process";8const [cmd = "status", ...rest] = process.argv.slice(2); const flag = n => rest.includes("--" + n); const arg = (n, d) => { const i = rest.indexOf("--" + n); return i >= 0 ? rest[i + 1] : d; };9const staging = flag("staging"); const DIR = staging ? "https://acme-staging-v02.api.letsencrypt.org/directory" : "https://acme-v02.api.letsencrypt.org/directory";10const CFG = path.join(os.homedir(), ".config/zoo-cloud-studio"); const AD = path.join(CFG, staging ? "acme-staging" : "acme"); fs.mkdirSync(AD, { recursive: true, mode: 0o700 });11const STATE = path.join(AD, "state.json"); const b64 = b => Buffer.from(b).toString("base64url");12let acct = path.join(AD, "account.pem"); if (!fs.existsSync(acct)) fs.writeFileSync(acct, crypto.generateKeyPairSync("ec", { namedCurve: "P-256" }).privateKey.export({ type: "pkcs8", format: "pem" }), { mode: 0o600 });13const akey = crypto.createPrivateKey(fs.readFileSync(acct)); const jwk = crypto.createPublicKey(akey).export({ format: "jwk" });14const thumb = b64(crypto.createHash("sha256").update(JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y })).digest());15let dir, nonce, kid;16async function j(url, payload, useKid = true) {17 if (!nonce) nonce = (await fetch(dir.newNonce, { method: "HEAD" })).headers.get("replay-nonce");18 const prot = b64(JSON.stringify({ alg: "ES256", nonce, url, ...(useKid && kid ? { kid } : { jwk }) })); const pl = payload === "" ? "" : b64(JSON.stringify(payload));19 const sig = crypto.sign("sha256", Buffer.from(prot + "." + pl), { key: akey, dsaEncoding: "ieee-p1363" });20 const r = await fetch(url, { method: "POST", headers: { "content-type": "application/jose+json" }, body: JSON.stringify({ protected: prot, payload: pl, signature: b64(sig) }) });21 nonce = r.headers.get("replay-nonce"); const t = await r.text(); let body; try { body = JSON.parse(t); } catch { body = t; }22 if (!r.ok) throw new Error(`ACME ${r.status}: ${typeof body === "string" ? body.slice(0, 200) : body.detail || JSON.stringify(body).slice(0, 200)}`);23 return { body, headers: r.headers, text: t };24}25async function init() { dir = await (await fetch(DIR)).json(); const r = await j(dir.newAccount, { termsOfServiceAgreed: true }, false); kid = r.headers.get("location"); }26const txtName = d => `_acme-challenge.${d}`; const txtVal = tok => b64(crypto.createHash("sha256").update(tok + "." + thumb).digest());27const sleep = ms => new Promise(r => setTimeout(r, ms));28const dig = (name) => { try { return execFileSync("dig", ["+short", "TXT", name, "@8.8.8.8"], { encoding: "utf8", timeout: 15000 }).split("\n").map(s => s.replace(/"/g, "").trim()).filter(Boolean); } catch { return []; } };2930if (cmd === "begin") {31 const domain = arg("domain", "cloud.zoobd.com").toLowerCase(); if (!/^[a-z0-9.-]+\.[a-z]{2,}$/.test(domain)) throw new Error("invalid domain");32 await init(); const o = await j(dir.newOrder, { identifiers: [{ type: "dns", value: domain }] }); const order = o.headers.get("location");33 const az = (await j(o.body.authorizations[0], "")).body; const ch = az.challenges.find(c => c.type === "dns-01");34 fs.writeFileSync(STATE, JSON.stringify({ domain, order, finalize: o.body.finalize, authz: o.body.authorizations[0], challenge: ch.url, token: ch.token, createdAt: new Date().toISOString(), staging }), { mode: 0o600 });35 console.log(`\nACME order created (${staging ? "STAGING — test certificate, NOT browser-trusted" : "Let's Encrypt production"}).\n\nOWNER ACTION — add exactly this DNS record at the zoobd.com DNS provider (do not change any other record):\n\n Type : TXT\n Name : ${txtName(domain)} (relative host: _acme-challenge.${domain.replace(/\.zoobd\.com$/, "")})\n Value: ${txtVal(ch.token)}\n TTL : 300\n\nThen run: node scripts/acme-dns01.mjs finish${staging ? " --staging" : ""}\nThe order expires in ~7 days; the TXT record can be deleted after issuance.`);36} else if (cmd === "finish") {37 const st = JSON.parse(fs.readFileSync(STATE, "utf8")); const want = txtVal(st.token);38 const seen = dig(txtName(st.domain)); if (!seen.includes(want)) { console.error(`TXT ${txtName(st.domain)} not visible yet via 8.8.8.8 (saw: ${seen.join(", ") || "nothing"}). Expected ${want}. Wait for DNS propagation and re-run.`); process.exit(2); }39 await init(); await j(st.challenge, {});40 for (let i = 0; i < 30; i++) { const a = (await j(st.authz, "")).body; if (a.status === "valid") break; if (a.status === "invalid") throw new Error("validation failed: " + JSON.stringify(a.challenges?.[0]?.error ?? a).slice(0, 300)); await sleep(2000); }41 const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "acme-")); const kf = path.join(tmp, "key.pem"), cf = path.join(tmp, "csr.der");42 execFileSync("openssl", ["ecparam", "-genkey", "-name", "prime256v1", "-noout", "-out", kf]); execFileSync("openssl", ["req", "-new", "-key", kf, "-subj", "/CN=" + st.domain, "-addext", `subjectAltName=DNS:${st.domain}`, "-outform", "DER", "-out", cf]);43 await j(st.finalize, { csr: b64(fs.readFileSync(cf)) });44 let o; for (let i = 0; i < 30; i++) { o = (await j(st.order, "")).body; if (o.status === "valid") break; if (o.status === "invalid") throw new Error("order invalid"); await sleep(2000); }45 const cert = (await j(o.certificate, "")).text;46 const out = path.join(CFG, "tls", staging ? "trusted-staging" : "trusted"); fs.mkdirSync(out, { recursive: true, mode: 0o700 });47 fs.writeFileSync(path.join(out, "fullchain.pem"), cert, { mode: 0o600 }); fs.copyFileSync(kf, path.join(out, "key.pem")); fs.chmodSync(path.join(out, "key.pem"), 0o600); fs.writeFileSync(path.join(out, "names.txt"), st.domain + "\n");48 fs.rmSync(tmp, { recursive: true, force: true });49 const end = execFileSync("openssl", ["x509", "-noout", "-enddate", "-issuer"], { input: cert, encoding: "utf8" });50 console.log(`Certificate installed in ${out}\n${end}${staging ? "STAGING certificate: browsers will NOT trust it (edge ignores trusted-staging/)." : "The edge loads it automatically via SNI for " + st.domain + " (no restart)."}`);51} else {52 const st = fs.existsSync(STATE) ? JSON.parse(fs.readFileSync(STATE, "utf8")) : null; const t = path.join(CFG, "tls", staging ? "trusted-staging" : "trusted", "fullchain.pem");53 console.log(JSON.stringify({ pendingOrder: st && { domain: st.domain, createdAt: st.createdAt, txtName: txtName(st.domain), txtValue: txtVal(st.token), visibleInDns: dig(txtName(st.domain)).includes(txtVal(st.token)) }, installed: fs.existsSync(t) }, null, 1));54}55
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 1c27633 on master.
Approval requests
None pending.