Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Merge remote-tracking branch 'origin/main' into feat/acme-and-external-ca

Sheen Capadngan7f6dcd3afa8a
diff --cc backend/src/services/certificate/certificate-service.ts
index d0dd620acd,292b5f1098..3921774fdb
--- a/backend/src/services/certificate/certificate-service.ts
+++ b/backend/src/services/certificate/certificate-service.ts
@@@ -572,41 -322,46 +572,50 @@@ export const certificateServiceFactory
const certObj = new x509.X509Certificate(decryptedCert);
const certificate = certObj.toString("pem");
- const { caCert, caCertChain } = await getCaCertChain({
- caCertId: cert.caCertId,
- certificateAuthorityDAL,
- certificateAuthorityCertDAL,
- projectDAL,
- kmsService
- });
+ let certificateChain = null;
- const certificateChain = await buildCertificateChain({
- caCert,
- caCertChain,
- kmsId: certificateManagerKeyId,
- kmsService,
- encryptedCertificateChain: certBody.encryptedCertificateChain || undefined
- });
+ // On newer certs the certBody.encryptedCertificateChain column will always exist.
+ // Older certs will have a caCertId which will be used as a fallback mechanism for structuring the chain.
+ if (certBody.encryptedCertificateChain) {
+ const decryptedCertChain = await kmsDecryptor({
+ cipherTextBlob: certBody.encryptedCertificateChain
+ });
+ certificateChain = decryptedCertChain.toString();
+ } else if (cert.caCertId) {
+ const { caCert, caCertChain } = await getCaCertChain({
+ caCertId: cert.caCertId,
+ certificateAuthorityDAL,
+ certificateAuthorityCertDAL,
+ projectDAL,
+ kmsService
+ });
+
+ certificateChain = `${caCert}\n${caCertChain}`.trim();
+ }
- const { certPrivateKey } = await getCertificateCredentials({
- certId: cert.id,
- projectId: cert.projectId,
- certificateSecretDAL,
- projectDAL,
- kmsService
- });
+ let privateKey: string | null = null;
+ try {
+ const { certPrivateKey } = await getCertificateCredentials({
+ certId: cert.id,
- projectId: ca.projectId,
++ projectId: cert.projectId,
+ certificateSecretDAL,
+ projectDAL,
+ kmsService
+ });
+ privateKey = certPrivateKey;
+ } catch (e) {
+ // Skip NotFound errors but throw all others
+ if (!(e instanceof NotFoundError)) {
+ throw e;
+ }
+ }
return {
certificate,
certificateChain,
- privateKey: certPrivateKey,
+ privateKey,
serialNumber,
- cert,
- ca
+ cert
};
};