mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 09:28:06 +00:00
Test decrypt fix
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import crypto from "crypto";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { SecretKeyEncoding, TProjectKeys } from "@app/db/schemas";
|
import { SecretKeyEncoding, TProjectKeys } from "@app/db/schemas";
|
||||||
@@ -50,6 +51,7 @@ const symmetricDecrypt = ({
|
|||||||
key,
|
key,
|
||||||
isApprovalSecret
|
isApprovalSecret
|
||||||
}: TDecryptSymmetricInput & { keyEncoding: SecretKeyEncoding; isApprovalSecret: boolean }) => {
|
}: TDecryptSymmetricInput & { keyEncoding: SecretKeyEncoding; isApprovalSecret: boolean }) => {
|
||||||
|
try {
|
||||||
if (keyEncoding === SecretKeyEncoding.UTF8 || isApprovalSecret) {
|
if (keyEncoding === SecretKeyEncoding.UTF8 || isApprovalSecret) {
|
||||||
const data = decryptSymmetric128BitHexKeyUTF8({ key, iv, tag, ciphertext });
|
const data = decryptSymmetric128BitHexKeyUTF8({ key, iv, tag, ciphertext });
|
||||||
return data;
|
return data;
|
||||||
@@ -58,8 +60,21 @@ const symmetricDecrypt = ({
|
|||||||
const data = decryptSymmetric({ key, iv, tag, ciphertext });
|
const data = decryptSymmetric({ key, iv, tag, ciphertext });
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
throw new Error("BAD_ENCODING");
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof Error && err.message === "BAD_ENCODING") {
|
||||||
|
throw new Error("Invalid key encoding, cannot decrypt secret!");
|
||||||
|
}
|
||||||
|
|
||||||
throw new Error("Missing both encryption keys");
|
// This is taken directly from our frontend secret decryption logic.
|
||||||
|
const decipher = crypto.createDecipheriv("aes-256-gcm", key, Buffer.from(iv, "base64"));
|
||||||
|
decipher.setAuthTag(Buffer.from(tag, "base64"));
|
||||||
|
|
||||||
|
let data = decipher.update(ciphertext, "base64", "utf8");
|
||||||
|
data += decipher.final("utf8");
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const decryptSecrets = (
|
export const decryptSecrets = (
|
||||||
|
|||||||
Reference in New Issue
Block a user