Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { createHash } from "node:crypto";
// Identity of "one logical certificate" for quotas: ACME re-enrolls rather than renews, minting a
// fresh order for the same names every cycle
export const buildCertificateQuotaKey = ({
commonName,
altNames
}: {
commonName?: string | null;
altNames?: string | null;
}): string => {
const sans = (altNames ?? "")
.split(",")
.map((san) => san.trim().toLowerCase())
.filter(Boolean);
const cn = (commonName ?? "").trim().toLowerCase();
const canonical = `CN=${cn}|SAN=${[...new Set(sans)].sort().join(",")}`;
return createHash("sha256").update(canonical).digest("hex");
};
// Stored on the row so the wildcard quota can be counted from the index. Deriving it in SQL instead
// would need commonName and altNames in the index, and altNames is varchar(4096).
export const certificateHasWildcard = ({
commonName,
altNames
}: {
commonName?: string | null;
altNames?: string | null;
}): boolean => `${commonName ?? ""},${altNames ?? ""}`.includes("*");