ability to fetch client certs for p2p

This commit is contained in:
DecDuck
2024-10-21 10:14:13 +11:00
parent 395219d0cb
commit 0a715fef08
5 changed files with 601 additions and 562 deletions

View File

@ -0,0 +1,24 @@
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
export default defineClientEventHandler(async (h3) => {
const query = getQuery(h3);
const clientId = query.id?.toString();
if (!clientId)
throw createError({
statusCode: 400,
statusMessage: "Missing id in query",
});
const certificate = await h3.context.ca.fetchClientCertificate(clientId);
if (!certificate) {
// Either it doesn't exist or it's blacklisted
throw createError({
statusCode: 401,
statusMessage: "Invalid or blacklisted clientId",
});
}
return {
certificate: certificate.cert,
};
});