diff --git a/src/certificate-manager/ACME.ts b/src/certificate-manager/ACME.ts index 20fc51a..4ef22de 100644 --- a/src/certificate-manager/ACME.ts +++ b/src/certificate-manager/ACME.ts @@ -60,4 +60,8 @@ export class ACME { return [key, csr, certificate, validFrom, expiresAt]; } + + public revokeCertificate(certificate: acme.CertificateBuffer | acme.CertificateString) { + this.client.revokeCertificate(certificate); + } } diff --git a/src/routes/ApiAdmin.ts b/src/routes/ApiAdmin.ts index 6ec42fa..2ed54e7 100644 --- a/src/routes/ApiAdmin.ts +++ b/src/routes/ApiAdmin.ts @@ -1,4 +1,5 @@ import { Config } from "../Config.js"; +import { CertificateObject } from "../database/Certificate.js"; import { ClusterEntity } from "../database/Cluster.js"; import { UserEntity } from "../database/User.js"; import JwtHelper from "../JwtHelper.js"; @@ -91,5 +92,48 @@ export class ApiAdmin { }); res.json(result); }); + + inst.app.post("/api/admin/certificates/revoke", async (req, res) => { + if (!Utilities.verifyAdmin(req, res, inst.db)) return; + const data = req.body as { + id: string + }; + const cluster = inst.db.getEntity(ClusterEntity, data.id); + if (!cluster) { + res.status(404).json({ message: "Cluster not found" }); + return; + } + + const cert = inst.db.getEntity(CertificateObject, cluster.clusterId); + if (!cert) { + res.status(404).json({ message: "Certificate not found" }); + return; + } + + await inst.acme?.revokeCertificate(cert.certificate); + if (inst.acme) inst.db.remove(CertificateObject, cert); + + res.status(200).json({ message: "Certificate revoked" }); + }); + + inst.app.get("/api/admin/certificates/cluster", async (req, res) => { + if (!Utilities.verifyAdmin(req, res, inst.db)) return; + const data = req.query as { + id: string + }; + const cluster = inst.db.getEntity(ClusterEntity, data.id); + if (!cluster) { + res.status(404).json({ message: "Cluster not found" }); + return; + } + + const cert = inst.db.getEntity(CertificateObject, cluster.clusterId); + if (!cert) { + res.status(404).json({ message: "Certificate not found" }); + return; + } + + res.status(200).json(cert); + }); } } \ No newline at end of file