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
Address greptile comment
Carlos Monastyrski76c130cdceaf
diff --git a/backend/src/services/certificate-v3/certificate-renewal-fns.test.ts b/backend/src/services/certificate-v3/certificate-renewal-fns.test.tsindex df495e0e61..226de53e6e 100644--- a/backend/src/services/certificate-v3/certificate-renewal-fns.test.ts+++ b/backend/src/services/certificate-v3/certificate-renewal-fns.test.ts@@ -19,6 +19,7 @@ import {certificateSpanToTtl,importKeyPairFromPem,isCertificateContentEdit,+ resolveRenewalAltNames,resolveRenewalKeySource} from "./certificate-renewal-fns";import { CertificateRenewalKeySource } from "./certificate-v3-types";@@ -43,6 +44,26 @@ const original: TCertificateRequest = {signatureAlgorithm: "RSA-SHA256"};+describe("resolveRenewalAltNames", () => {+ const issued = "ca-added.example.com";++ it("keeps an empty request list, so an authority's own names are not re-requested", () => {+ expect(resolveRenewalAltNames({ exists: true, altNames: [] }, issued)).toEqual([]);+ });++ it("uses the names the request asked for when it has any", () => {+ const asked = [{ type: CertSubjectAlternativeNameType.DNS_NAME, value: "mine.example.com" }];+ expect(resolveRenewalAltNames({ exists: true, altNames: asked }, issued)).toEqual(asked);+ });++ it("falls back to the certificate only when there is no request behind it", () => {+ expect(resolveRenewalAltNames({ exists: false, altNames: null }, issued)).toEqual([+ { type: CertSubjectAlternativeNameType.DNS_NAME, value: issued }+ ]);+ expect(resolveRenewalAltNames({ exists: false, altNames: null }, null)).toEqual([]);+ });+});+describe("resolveRenewalKeySource", () => {it("defaults to a new key pair", () => {expect(resolveRenewalKeySource({})).toBe(CertificateRenewalKeySource.New);diff --git a/backend/src/services/certificate-v3/certificate-renewal-fns.ts b/backend/src/services/certificate-v3/certificate-renewal-fns.tsindex 3e2a4b3f93..d3daef6764 100644--- a/backend/src/services/certificate-v3/certificate-renewal-fns.ts+++ b/backend/src/services/certificate-v3/certificate-renewal-fns.ts@@ -16,6 +16,8 @@ import {keyAlgorithmToAlgCfg} from "@app/services/certificate-authority/certificate-authority-fns";import { caSupportsCapability } from "@app/services/certificate-authority/certificate-authority-maps";+import { CertSubjectAlternativeNameType } from "@app/services/certificate-common/certificate-constants";+import { detectSanType } from "@app/services/certificate-common/certificate-issuance-utils";import { CertKeyUsageType } from "../certificate-common/certificate-constants";import {@@ -245,6 +247,15 @@ export const assertCsrRenewalAttributes = (attributes?: TRenewalAttributes) => {}};+export const resolveRenewalAltNames = (+ requested: { exists: boolean; altNames: { type: CertSubjectAlternativeNameType; value: string }[] | null },+ certificateAltNames: string | null | undefined+): { type: CertSubjectAlternativeNameType; value: string }[] => {+ if (requested.exists) return requested.altNames ?? [];++ return certificateAltNames?.split(",").map((san) => detectSanType(san.trim())) ?? [];+};+/*** Renewal copies the current certificate and applies only what the caller explicitly changed.* Profile defaults are deliberately not consulted: they describe what a *new* certificate shoulddiff --git a/backend/src/services/certificate-v3/certificate-renewal-service.ts b/backend/src/services/certificate-v3/certificate-renewal-service.tsindex 2f125e0661..13ca210113 100644--- a/backend/src/services/certificate-v3/certificate-renewal-service.ts+++ b/backend/src/services/certificate-v3/certificate-renewal-service.ts@@ -107,6 +107,7 @@ import {certificateSpanToTtl,importKeyPairFromPem,isCertificateContentEdit,+ resolveRenewalAltNames,resolveRenewalKeySource,validateRenewalEligibility} from "./certificate-renewal-fns";@@ -745,9 +746,7 @@ export const certificateRenewalServiceFactory = ({const requested = issuedFrom.exists ? issuedFrom : null;- const requestedAltNames = requested?.altNames?.length- ? requested.altNames- : (originalCert.altNames?.split(",").map((san) => detectSanType(san.trim())) ?? []);+ const requestedAltNames = resolveRenewalAltNames(issuedFrom, originalCert.altNames);const originalRequest: TCertificateRequest = {commonName: requested?.commonName || originalCert.commonName || undefined,