mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 16:27:46 +00:00
Merge pull request #3556 from Infisical/misc/remove-unnecessary-key-encryption-for-service-token
misc: removed unnecessary key encryption for service token
This commit is contained in:
+4
-22
@@ -10,10 +10,6 @@ import { AxiosError } from "axios";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import {
|
|
||||||
decryptAssymmetric,
|
|
||||||
encryptSymmetric
|
|
||||||
} from "@app/components/utilities/cryptography/crypto";
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -28,7 +24,7 @@ import {
|
|||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { useWorkspace } from "@app/context";
|
import { useWorkspace } from "@app/context";
|
||||||
import { useToggle } from "@app/hooks";
|
import { useToggle } from "@app/hooks";
|
||||||
import { useCreateServiceToken, useGetUserWsKey } from "@app/hooks/api";
|
import { useCreateServiceToken } from "@app/hooks/api";
|
||||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
const apiTokenExpiry = [
|
const apiTokenExpiry = [
|
||||||
@@ -97,7 +93,6 @@ export const AddServiceTokenModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
const [newToken, setToken] = useState("");
|
const [newToken, setToken] = useState("");
|
||||||
const [isTokenCopied, setIsTokenCopied] = useToggle(false);
|
const [isTokenCopied, setIsTokenCopied] = useToggle(false);
|
||||||
|
|
||||||
const { data: latestFileKey } = useGetUserWsKey(currentWorkspace?.id ?? "");
|
|
||||||
const createServiceToken = useCreateServiceToken();
|
const createServiceToken = useCreateServiceToken();
|
||||||
const hasServiceToken = Boolean(newToken);
|
const hasServiceToken = Boolean(newToken);
|
||||||
|
|
||||||
@@ -118,26 +113,13 @@ export const AddServiceTokenModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
const onFormSubmit = async ({ name, scopes, expiresIn, permissions }: FormData) => {
|
const onFormSubmit = async ({ name, scopes, expiresIn, permissions }: FormData) => {
|
||||||
try {
|
try {
|
||||||
if (!currentWorkspace?.id) return;
|
if (!currentWorkspace?.id) return;
|
||||||
if (!latestFileKey) return;
|
|
||||||
|
|
||||||
const key = decryptAssymmetric({
|
|
||||||
ciphertext: latestFileKey.encryptedKey,
|
|
||||||
nonce: latestFileKey.nonce,
|
|
||||||
publicKey: latestFileKey.sender.publicKey,
|
|
||||||
privateKey: localStorage.getItem("PRIVATE_KEY") as string
|
|
||||||
});
|
|
||||||
|
|
||||||
const randomBytes = crypto.randomBytes(16).toString("hex");
|
const randomBytes = crypto.randomBytes(16).toString("hex");
|
||||||
|
|
||||||
const { ciphertext, iv, tag } = encryptSymmetric({
|
|
||||||
plaintext: key,
|
|
||||||
key: randomBytes
|
|
||||||
});
|
|
||||||
|
|
||||||
const { serviceToken } = await createServiceToken.mutateAsync({
|
const { serviceToken } = await createServiceToken.mutateAsync({
|
||||||
encryptedKey: ciphertext,
|
encryptedKey: "",
|
||||||
iv,
|
iv: "",
|
||||||
tag,
|
tag: "",
|
||||||
scopes,
|
scopes,
|
||||||
expiresIn: Number(expiresIn),
|
expiresIn: Number(expiresIn),
|
||||||
name,
|
name,
|
||||||
|
|||||||
Reference in New Issue
Block a user