Skip to content

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

Make CA / cert certs exportable

Tuan Dang2f06168b29af
diff --git a/frontend/src/views/Project/CertificatesPage/components/CaTab/components/CaCertModal.tsx b/frontend/src/views/Project/CertificatesPage/components/CaTab/components/CaCertModal.tsx
index 320245cae0..df1f104699 100644
--- a/frontend/src/views/Project/CertificatesPage/components/CaTab/components/CaCertModal.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CaTab/components/CaCertModal.tsx
@@ -1,8 +1,8 @@
import { useEffect } from "react";
-import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
+import { faCheck, faCopy, faDownload } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { IconButton,Modal, ModalContent } from "@app/components/v2";
+import { IconButton, Modal, ModalContent } from "@app/components/v2";
import { useToggle } from "@app/hooks";
import { useGetCaCert } from "@app/hooks/api";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -35,6 +35,18 @@ export const CaCertModal = ({ popUp, handlePopUpToggle }: Props) => {
return () => clearTimeout(timer);
}, [isSerialNumberCopied, isCertificateCopied, isCertificateChainCopied]);
+ const downloadTxtFile = (filename: string, content: string) => {
+ const blob = new Blob([content], { type: "text/plain" });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = filename;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ };
+
return (
<Modal
isOpen={popUp?.caCert?.isOpen}
@@ -63,42 +75,81 @@ export const CaCertModal = ({ popUp, handlePopUpToggle }: Props) => {
</span>
</IconButton>
</div>
- <h2 className="mb-4">Certificate Body</h2>
- <div className="mb-8 flex items-center justify-between rounded-md bg-white/[0.07] p-2 text-base text-gray-400">
- <p className="mr-4 whitespace-pre-wrap break-all">{data.certificate}</p>
- <IconButton
- ariaLabel="copy icon"
- colorSchema="secondary"
- className="group relative"
- onClick={() => {
- navigator.clipboard.writeText(data.certificate);
- setIsCertificateCopied.on();
- }}
- >
- <FontAwesomeIcon icon={isCertificateCopied ? faCheck : faCopy} />
- <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- Click to copy
- </span>
- </IconButton>
+
+ <div className="mb-4 flex items-center justify-between">
+ <h2>Certificate Body</h2>
+ <div className="flex">
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative"
+ onClick={() => {
+ navigator.clipboard.writeText(data.certificate);
+ setIsCertificateCopied.on();
+ }}
+ >
+ <FontAwesomeIcon icon={isCertificateCopied ? faCheck : faCopy} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Copy
+ </span>
+ </IconButton>
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative ml-2"
+ onClick={() => {
+ downloadTxtFile("certificate.txt", data.certificate);
+ }}
+ >
+ <FontAwesomeIcon icon={faDownload} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Download
+ </span>
+ </IconButton>
+ </div>
</div>
- <h2 className="mb-4">Certificate Chain</h2>
<div className="mb-8 flex items-center justify-between rounded-md bg-white/[0.07] p-2 text-base text-gray-400">
- <p className="mr-4 whitespace-pre-wrap break-all">{data.certificateChain}</p>
- <IconButton
- ariaLabel="copy icon"
- colorSchema="secondary"
- className="group relative"
- onClick={() => {
- navigator.clipboard.writeText(data.certificateChain);
- setIsCertificateChainCopied.on();
- }}
- >
- <FontAwesomeIcon icon={isCertificateChainCopied ? faCheck : faCopy} />
- <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- Click to copy
- </span>
- </IconButton>
+ <p className="mr-4 whitespace-pre-wrap break-all">{data.certificate}</p>
</div>
+ {data.certificateChain && (
+ <>
+ <div className="mb-4 flex items-center justify-between">
+ <h2>Certificate Chain</h2>
+ <div className="flex">
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative"
+ onClick={() => {
+ navigator.clipboard.writeText(data.certificateChain);
+ setIsCertificateChainCopied.on();
+ }}
+ >
+ <FontAwesomeIcon icon={isCertificateChainCopied ? faCheck : faCopy} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Copy
+ </span>
+ </IconButton>
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative ml-2"
+ onClick={() => {
+ downloadTxtFile("certificate_chain.txt", data.certificate);
+ }}
+ >
+ <FontAwesomeIcon icon={faDownload} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Download
+ </span>
+ </IconButton>
+ </div>
+ </div>
+ <div className="mb-8 flex items-center justify-between rounded-md bg-white/[0.07] p-2 text-base text-gray-400">
+ <p className="mr-4 whitespace-pre-wrap break-all">{data.certificateChain}</p>
+ </div>
+ </>
+ )}
</div>
) : (
<div />
diff --git a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateCertModal.tsx b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateCertModal.tsx
index 8a48d4f0d7..78777b2952 100644
--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateCertModal.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateCertModal.tsx
@@ -1,8 +1,8 @@
import { useEffect } from "react";
-import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
+import { faCheck, faCopy, faDownload } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { IconButton,Modal, ModalContent } from "@app/components/v2";
+import { IconButton, Modal, ModalContent } from "@app/components/v2";
import { useToggle } from "@app/hooks";
import { useGetCertCert } from "@app/hooks/api";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -43,6 +43,18 @@ export const CertificateCertModal = ({ popUp, handlePopUpToggle }: Props) => {
return () => clearTimeout(timer);
}, [isSerialNumberCopied, isCertificateCopied, isCertificateChainCopied, isCertificateSkCopied]);
+ const downloadTxtFile = (filename: string, content: string) => {
+ const blob = new Blob([content], { type: "text/plain" });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = filename;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ };
+
return (
<Modal
isOpen={popUp?.certificateCert?.isOpen}
@@ -71,59 +83,110 @@ export const CertificateCertModal = ({ popUp, handlePopUpToggle }: Props) => {
</span>
</IconButton>
</div>
- <h2 className="mb-4">Certificate Body</h2>
+ <div className="mb-4 flex items-center justify-between">
+ <h2>Certificate Body</h2>
+ <div className="flex">
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative"
+ onClick={() => {
+ navigator.clipboard.writeText(data.certificate);
+ setIsCertificateCopied.on();
+ }}
+ >
+ <FontAwesomeIcon icon={isCertificateCopied ? faCheck : faCopy} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Copy
+ </span>
+ </IconButton>
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative ml-2"
+ onClick={() => {
+ downloadTxtFile("certificate.txt", data.certificate);
+ }}
+ >
+ <FontAwesomeIcon icon={faDownload} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Download
+ </span>
+ </IconButton>
+ </div>
+ </div>
<div className="mb-8 flex items-center justify-between rounded-md bg-white/[0.07] p-2 text-base text-gray-400">
<p className="mr-4 whitespace-pre-wrap break-all">{data.certificate}</p>
- <IconButton
- ariaLabel="copy icon"
- colorSchema="secondary"
- className="group relative"
- onClick={() => {
- navigator.clipboard.writeText(data.certificate);
- setIsCertificateCopied.on();
- }}
- >
- <FontAwesomeIcon icon={isCertificateCopied ? faCheck : faCopy} />
- <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- Click to copy
- </span>
- </IconButton>
</div>
- <h2 className="mb-4">Certificate Chain</h2>
+ <div className="mb-4 flex items-center justify-between">
+ <h2>Certificate Chain</h2>
+ <div className="flex">
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative"
+ onClick={() => {
+ navigator.clipboard.writeText(data.certificateChain);
+ setIsCertificateChainCopied.on();
+ }}
+ >
+ <FontAwesomeIcon icon={isCertificateChainCopied ? faCheck : faCopy} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Copy
+ </span>
+ </IconButton>
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative ml-2"
+ onClick={() => {
+ downloadTxtFile("certificate_chain.txt", data.certificate);
+ }}
+ >
+ <FontAwesomeIcon icon={faDownload} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Download
+ </span>
+ </IconButton>
+ </div>
+ </div>
<div className="mb-8 flex items-center justify-between rounded-md bg-white/[0.07] p-2 text-base text-gray-400">
<p className="mr-4 whitespace-pre-wrap break-all">{data.certificateChain}</p>
- <IconButton
- ariaLabel="copy icon"
- colorSchema="secondary"
- className="group relative"
- onClick={() => {
- navigator.clipboard.writeText(data.certificateChain);
- setIsCertificateChainCopied.on();
- }}
- >
- <FontAwesomeIcon icon={isCertificateChainCopied ? faCheck : faCopy} />
- <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- Click to copy
- </span>
- </IconButton>
</div>
- <h2 className="mb-4">Certificate Private Key</h2>
+ <div className="mb-4 flex items-center justify-between">
+ <h2>Certificate Private Key</h2>
+ <div className="flex">
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative"
+ onClick={() => {
+ navigator.clipboard.writeText(data.privateKey);
+ setIsCertificateSkCopied.on();
+ }}
+ >
+ <FontAwesomeIcon icon={isCertificateSkCopied ? faCheck : faCopy} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Copy
+ </span>
+ </IconButton>
+ <IconButton
+ ariaLabel="copy icon"
+ colorSchema="secondary"
+ className="group relative ml-2"
+ onClick={() => {
+ downloadTxtFile("private_key.txt", data.privateKey);
+ }}
+ >
+ <FontAwesomeIcon icon={faDownload} />
+ <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
+ Download
+ </span>
+ </IconButton>
+ </div>
+ </div>
<div className="mb-8 flex items-center justify-between rounded-md bg-white/[0.07] p-2 text-base text-gray-400">
<p className="mr-4 whitespace-pre-wrap break-all">{data.privateKey}</p>
- <IconButton
- ariaLabel="copy icon"
- colorSchema="secondary"
- className="group relative"
- onClick={() => {
- navigator.clipboard.writeText(data.certificateChain);
- setIsCertificateSkCopied.on();
- }}
- >
- <FontAwesomeIcon icon={isCertificateSkCopied ? faCheck : faCopy} />
- <span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- Click to copy
- </span>
- </IconButton>
</div>
</div>
) : (