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
improvement(kms): migrate signing form controls to v3 (#8436)
Andrew Huang9d5153d5c92b
diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsxindex eb5f8eb1b1..b0e3a86b83 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekSignModal.tsx@@ -1,3 +1,4 @@+import { useId } from "react";import { Controller, useForm } from "react-hook-form";import { faCheckCircle, faFileSignature, faInfoCircle } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";@@ -6,17 +7,25 @@ import { z } from "zod";import { createNotification } from "@app/components/notifications";import {- Button,FormControl,Modal,ModalClose,ModalContent,Select,- SelectItem,- Switch,- TextArea,- Tooltip+ SelectItem} from "@app/components/v2";+import {+ Button,+ Field,+ FieldError,+ FieldLabel,+ IconButton,+ TextArea,+ Toggle,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";import { getDefaultSigningAlgorithm } from "@app/helpers/kms";import { useTimedReset } from "@app/hooks";import { SigningAlgorithm, TCmek, useCmekSign } from "@app/hooks/api/cmeks";@@ -39,6 +48,7 @@ type FormProps = Pick<Props, "cmek">;const SignForm = ({ cmek }: FormProps) => {const cmekSign = useCmekSign();+ const fieldId = useId();const {handleSubmit,@@ -82,24 +92,25 @@ const SignForm = ({ cmek }: FormProps) => {return (<form onSubmit={handleSubmit(handleSignData)}>{signature ? (- <FormControl label="Data Signature">- <TextArea- className="max-h-80 min-h-40 max-w-full min-w-full"- isDisabled- value={signature}- />- </FormControl>+ <Field className="mb-4">+ <FieldLabel htmlFor={`${fieldId}-signature`}>Data Signature</FieldLabel>+ <TextArea id={`${fieldId}-signature`} rows={4} readOnly value={signature} />+ </Field>) : (<>- <FormControl- label="Data to Sign"- errorText={errors.data?.message}- isError={Boolean(errors.data)}- >- <TextArea {...register("data")} className="max-h-80 min-h-40 max-w-full min-w-full" />- </FormControl>-- <div className="mb-6 flex w-full items-center justify-between gap-2">+ <Field className="mb-4" data-invalid={Boolean(errors.data)}>+ <FieldLabel htmlFor={`${fieldId}-data`}>Data to Sign</FieldLabel>+ <TextArea+ {...register("data")}+ rows={7}+ id={`${fieldId}-data`}+ isError={Boolean(errors.data)}+ aria-describedby={errors.data ? `${fieldId}-data-error` : undefined}+ />+ <FieldError id={`${fieldId}-data-error`} errors={[errors.data]} />+ </Field>++ <div className="mb-6 flex flex-col gap-2"><Controllercontrol={control}name="signingAlgorithm"@@ -120,22 +131,43 @@ const SignForm = ({ cmek }: FormProps) => {control={control}name="isBase64Encoded"render={({ field: { onChange, value } }) => (- <Switch id="encode-base-64" isChecked={value} onCheckedChange={onChange}>- Data is Base64 encoded{" "}- <Tooltip content="Toggle this switch on if your data is already Base64 encoded to avoid redundant encoding.">- <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ <Field orientation="horizontal">+ <Toggle+ id={`${fieldId}-encode-base-64`}+ checked={value}+ onCheckedChange={onChange}+ />+ <FieldLabel htmlFor={`${fieldId}-encode-base-64`}>+ Data is Base64 encoded+ </FieldLabel>+ <Tooltip hoverable selectable={false} delayDuration={50}>+ <TooltipTrigger asChild>+ <IconButton variant="ghost" size="xs" aria-label="About Base64 encoding">+ <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ </IconButton>+ </TooltipTrigger>+ <TooltipContent className="max-w-xs" sideOffset={5}>+ Toggle this switch on if your data is already Base64 encoded to avoid+ redundant encoding.+ </TooltipContent></Tooltip>- </Switch>+ </Field>)}/></div></>)}- <div className="flex items-center">+ <div className="flex flex-wrap items-center gap-4"><Button- className={`mr-4 ${signature ? "w-44" : ""}`}+ className={signature ? "w-44" : undefined}size="sm"- leftIcon={+ variant="project"+ onClick={signature ? handleCopyToClipboard : undefined}+ type={signature ? "button" : "submit"}+ isPending={isSubmitting}+ isDisabled={isSubmitting}+ >+ {// eslint-disable-next-line no-nested-ternarysignature ? (isCopyingSignature ? (@@ -147,17 +179,10 @@ const SignForm = ({ cmek }: FormProps) => {<FontAwesomeIcon icon={faFileSignature} />)}- onClick={signature ? handleCopyToClipboard : undefined}- type={signature ? "button" : "submit"}- isLoading={isSubmitting}- isDisabled={isSubmitting}- >{signature ? copySignature : "Sign"}</Button><ModalClose asChild>- <Button colorSchema="secondary" variant="plain">- {signature ? "Close" : "Cancel"}- </Button>+ <Button variant="ghost">{signature ? "Close" : "Cancel"}</Button></ModalClose></div></form>diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsxindex 5c5ac7ecfe..058ecacf57 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekVerifyModal.tsx@@ -1,24 +1,34 @@+import { useId } from "react";import { Controller, useForm } from "react-hook-form";import { faFileSignature, faInfoCircle } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { zodResolver } from "@hookform/resolvers/zod";+import { CircleCheckIcon, CircleXIcon } from "lucide-react";import { z } from "zod";import { createNotification } from "@app/components/notifications";import { decodeBase64 } from "@app/components/utilities/cryptography/crypto";import {- Button,FormControl,Modal,ModalClose,ModalContent,Select,- SelectItem,- Switch,- TextArea,- Tooltip+ SelectItem} from "@app/components/v2";-import { Badge } from "@app/components/v3";+import {+ Badge,+ Button,+ Field,+ FieldError,+ FieldLabel,+ IconButton,+ TextArea,+ Toggle,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";import { getDefaultSigningAlgorithm } from "@app/helpers/kms";import { SigningAlgorithm, TCmek, useCmekVerify } from "@app/hooks/api/cmeks";import { isBase64 } from "@app/lib/fn/base64";@@ -52,6 +62,7 @@ type FormProps = Pick<Props, "cmek">;const VerifyForm = ({ cmek }: FormProps) => {const cmekVerify = useCmekVerify();+ const fieldId = useId();const {handleSubmit,@@ -103,16 +114,18 @@ const VerifyForm = ({ cmek }: FormProps) => {<div className="mb-6 flex flex-col gap-2"><div className="flex items-center justify-between space-x-2"><span className="text-sm opacity-60">Signature Status:</span>- <Tooltip- content={- signatureValid+ <Tooltip hoverable selectable={false} delayDuration={50}>+ <TooltipTrigger asChild>+ <Badge variant={signatureValid ? "success" : "danger"} tabIndex={0}>+ {signatureValid ? <CircleCheckIcon /> : <CircleXIcon />}+ {signatureValid ? "Valid" : "Invalid"}+ </Badge>+ </TooltipTrigger>+ <TooltipContent className="max-w-xs" sideOffset={5}>+ {signatureValid? "The signature is valid. signature was created using the same signing algorithm and key as the one used to sign the data."- : "The signature is invalid. The signature was not created using the same signing algorithm and key as the one used to sign the data. The data and signature may have been tampered with."- }- >- <Badge variant={signatureValid ? "success" : "danger"}>- {signatureValid ? "Valid" : "Invalid"}- </Badge>+ : "The signature is invalid. The signature was not created using the same signing algorithm and key as the one used to sign the data. The data and signature may have been tampered with."}+ </TooltipContent></Tooltip></div>@@ -122,40 +135,56 @@ const VerifyForm = ({ cmek }: FormProps) => {</div><div className="mt-3"><span className="text-sm opacity-60">Signature:</span>{" "}- <div className="rounded-md border border-border-subtle bg-surface-base p-2 text-sm break-words whitespace-pre-wrap">+ <div className="rounded-md border border-border bg-container p-2 font-mono text-sm break-words whitespace-pre-wrap">{signature}</div></div><div><span className="text-sm opacity-60">Data:</span>{" "}- <div className="rounded-md border border-border-subtle bg-surface-base p-2 text-sm">+ <div className="rounded-md border border-border bg-container p-2 text-sm">{isBase64Encoded ? decodeBase64(data).toString() : data}</div></div></div>) : (<>- <FormControl- label="Data to Verify"- errorText={errors.data?.message}- isError={Boolean(errors.data)}- >- <TextArea {...register("data")} className="max-h-80 min-h-40 max-w-full min-w-full" />- </FormControl>-- <FormControl- label="Signature of Data"- tooltipText="Must be base64-encoded, like the signature you received when you signed the data."- errorText={errors.signature?.message}- isError={Boolean(errors.signature)}- >+ <Field className="mb-4" data-invalid={Boolean(errors.data)}>+ <FieldLabel htmlFor={`${fieldId}-data`}>Data to Verify</FieldLabel>+ <TextArea+ {...register("data")}+ rows={7}+ id={`${fieldId}-data`}+ isError={Boolean(errors.data)}+ aria-describedby={errors.data ? `${fieldId}-data-error` : undefined}+ />+ <FieldError id={`${fieldId}-data-error`} errors={[errors.data]} />+ </Field>++ <Field className="mb-4" data-invalid={Boolean(errors.signature)}>+ <div className="flex items-center gap-1">+ <FieldLabel htmlFor={`${fieldId}-signature`}>Signature of Data</FieldLabel>+ <Tooltip hoverable selectable={false} delayDuration={50}>+ <TooltipTrigger asChild>+ <IconButton variant="ghost" size="2xs" aria-label="About signature encoding">+ <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ </IconButton>+ </TooltipTrigger>+ <TooltipContent className="max-w-xs" sideOffset={5}>+ Must be base64-encoded, like the signature you received when you signed the data.+ </TooltipContent>+ </Tooltip>+ </div><TextArea{...register("signature")}- className="max-h-80 min-h-40 max-w-full min-w-full"+ rows={7}+ id={`${fieldId}-signature`}+ isError={Boolean(errors.signature)}+ aria-describedby={errors.signature ? `${fieldId}-signature-error` : undefined}/>- </FormControl>+ <FieldError id={`${fieldId}-signature-error`} errors={[errors.signature]} />+ </Field>- <div className="mb-6 flex w-full items-center justify-between gap-2">+ <div className="mb-6 flex flex-col gap-2"><Controllercontrol={control}name="signingAlgorithm"@@ -176,35 +205,48 @@ const VerifyForm = ({ cmek }: FormProps) => {control={control}name="isBase64Encoded"render={({ field: { onChange, value } }) => (- <Switch id="encode-base-64" isChecked={value} onCheckedChange={onChange}>- Data is Base64 encoded{" "}- <Tooltip content="Toggle this switch on if your data is already Base64 encoded to avoid redundant encoding.">- <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ <Field orientation="horizontal">+ <Toggle+ id={`${fieldId}-encode-base-64`}+ checked={value}+ onCheckedChange={onChange}+ />+ <FieldLabel htmlFor={`${fieldId}-encode-base-64`}>+ Data is Base64 encoded+ </FieldLabel>+ <Tooltip hoverable selectable={false} delayDuration={50}>+ <TooltipTrigger asChild>+ <IconButton variant="ghost" size="xs" aria-label="About Base64 encoding">+ <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ </IconButton>+ </TooltipTrigger>+ <TooltipContent className="max-w-xs" sideOffset={5}>+ Toggle this switch on if your data is already Base64 encoded to avoid+ redundant encoding.+ </TooltipContent></Tooltip>- </Switch>+ </Field>)}/></div></>)}- <div className="flex items-center">+ <div className="flex flex-wrap items-center gap-4">{signatureValid === undefined && (<Button- className="mr-4 w-44"+ className="w-44"size="sm"- leftIcon={<FontAwesomeIcon icon={faFileSignature} />}+ variant="project"type="submit"- isLoading={isSubmitting}+ isPending={isSubmitting}isDisabled={isSubmitting}>+ <FontAwesomeIcon icon={faFileSignature} />Verify</Button>)}<ModalClose asChild>- <Button- colorSchema={signatureValid === undefined ? "secondary" : "primary"}- variant={signatureValid === undefined ? "plain" : undefined}- >+ <Button variant={signatureValid === undefined ? "ghost" : "project"}>{signatureValid !== undefined ? "Close" : "Cancel"}</Button></ModalClose>