ca groundwork

This commit is contained in:
DecDuck
2024-10-07 22:35:54 +11:00
parent 1bd19ad917
commit bfafd2a044
44 changed files with 628 additions and 130 deletions

18
server/plugins/ca.ts Normal file
View File

@ -0,0 +1,18 @@
import { CertificateAuthority } from "../internal/clients/ca";
import fs from "fs";
import { fsCertificateStore } from "../internal/clients/store";
let ca: CertificateAuthority | undefined;
export const useGlobalCertificateAuthority = () => {
if (!ca) throw new Error("CA not initialised");
return ca;
};
export default defineNitroPlugin(async (nitro) => {
const basePath = process.env.CLIENT_CERTIFICATES ?? "./certs";
fs.mkdirSync(basePath, { recursive: true });
const store = fsCertificateStore(basePath);
ca = await CertificateAuthority.new(store);
});